Assembly question

BlitzMax Forums/BlitzMax Programming/Assembly question

Boris(Posted 2005) [#1]
Hi there. I have a small problem -(

I need to know if its possible to insert ASM Code directly into the code by opcodes.

Example:

There is a routine and I want to execute the following asm opcodes:

&hEB,&h03,&hD6,&hD6,&h00

some other blitzmax code..

and then I need to execute

&hEB,&h03,&hD6,&hD6,&hFF

Any ideas?

If there is a way to directly insert asm-code in any way it would be nice if someone could point me to the right direction. Opcodes or asm-instructions.

It is important that the asm-code is executed exactly in the position where its inserted, not called as function.


Perturbatio(Posted 2005) [#2]
Could you have your asm in functions in a seperate file and call them at the required points?


marksibly(Posted 2005) [#3]
You're mad, but here goes:
Function Call( p:Byte Ptr )
	Local f()=p
	f
End Function

Local p:Byte[]=[Byte($eb),Byte($03),Byte($d6),Byte($00)]

Call p

Of course, I have not and will not run this - and if it crashes, please, no bug reports!

A tidier way would be to Import the asm source, and declare an extern function, eg:
Import "myasm.s"
Extern
Function myfunc()    'declare as '_myfunc' in asm...
End Extern
myfunc



Boris(Posted 2005) [#4]
Wow, cool -)

My problem is I can not run the code as a function.

Background: I am using a software that encrypts the .exe file and it uses the Opcodes as an identifier for start/stop the encryption. The tool encrypts and protects the exe file to make shareware-stuff.

Any more ideas?

btw: Blitz3D and BlitzMax are the coolest thing on earth -)


LarsG(Posted 2005) [#5]
is it possible to insert the opcodes with a hex editor perhaps?!


Boris(Posted 2005) [#6]
No because you need to insert them on specific positions.


ImaginaryHuman(Posted 2005) [#7]
If you use incbin to include the opcode data, would it get included at that exact location, or would it have some kind of header thing int he way?


Boris(Posted 2005) [#8]
There is no separation between data and code section so I expect that this won't work but I'll give it a try.


ImaginaryHuman(Posted 2005) [#9]
I'm thinking it might not work. If the program flow had to go `past` an incbin statement, either the incbin would end up at the end of the actual file or there would be an extra jump instruction which would completely skip the data. It couldn't be treated as a program.

Could you use Data statements to define the opcodes you want stored? Maybe same problems tho?


ImaginaryHuman(Posted 2005) [#10]
If you are just trying to encrypt `most of` the program or whatever, would it matter that there is some kind of a `jump` instruction just prior to the opcodes? Or do you need the opcodes to actually be executed?


Boris(Posted 2005) [#11]
I tried a lot of ways now, even the direct ASM way without success.

I tried to include ASM-Code like this
; test.s
format MS COFF
section "code" code

db $eb,$03,$d6,$d6,$ff

but the include statement is only possible at the beginning of the file.

I tried to write C Code and implement it via Inline-ASM and GCC was funny enough to tell my that my DB command is not understood..

#define SECUREBEGIN asm ("db 0xEB,0x03,0xD6,0xD6,0x00;")

Well what I need is a command to insert an opcode -((( Playing and mixing around is very interesting, specially the thing that its possible to mix c and blitzmax, but its a little bit oversized for my problem.

Something like:

Opcode $eb,$03,$d6,D6,$0

thats what I need -((((