Deprecated: Array and string offset access syntax with curly braces is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Subs.php on line 3825 Print Page - Calling OpCode Strings
Theo's Forum
IT-Consultant: Charles Pegge => Assembler => Assembly Code Examples => Topic started by: Charles Pegge on June 22, 2007, 08:28:03 AM
Title: Calling OpCode Strings
Post by: Charles Pegge on June 22, 2007, 08:28:03 AM
This shows how to call strings of x86 machine code. It shows how the EAX register is used to return integer results and how to extract a parameter from the stack, replacing the return address. This assumes the SDECL calling protocol where the called function cleans the stack of any parameters before returning to the caller.
This approach can be used for dynamic assembly or compilation during run time.
CALL DWORD act.f USING f() TO v: t=STR$(v) CALL DWORD act1.f1 USING f1(42) TO v: t=t+" "+STR$(v)
MSGBOX t
END FUNCTION
Title: Re: Calling OpCode Strings
Post by: Edwin Knoppert on June 22, 2007, 10:08:36 AM
Neat.. I thought it required VirtualAlloc() or something to execute opcode.
Title: Re: Calling OpCode Strings
Post by: Charles Pegge on June 22, 2007, 11:43:58 AM
No, you can execute opcodes from anywhere as long as there are no address dependencies in the code itself. Since most x86 calls and jumps are 'relative' and variables are stack based or indexed from a register, this is very easy to do.
As you can see, some of the coding effort goes into persuading Basic that what you want to do is legitimate and that you are not just messing about.
Title: Re: Calling OpCode Strings
Post by: Donald Darden on June 23, 2007, 01:32:24 AM
It's an interesting idea, but where or why would you expect to resort to this? I could see that you could read something into a string to esecute it this way, but I can't conceive of anything I would trust to read in this manner and trust on the blind to do something beneficial for my program. It it were already in my program, then it would actually be much easier to use the inline assembler.
Title: Re: Calling OpCode Strings
Post by: Charles Pegge on June 23, 2007, 04:52:53 AM
This technique can be used in scripting languages to compile on-the-fly instead of interpreting rext or byte code. This is especially useful for speeding up repetitive blocks of code.
It opens up all kinds of possibilities for high level language development, resolving the conflict between speed and flexibility.
Title: Re: Calling OpCode Strings
Post by: Eros Olmi on June 23, 2007, 11:50:04 AM
FBSL interpreter uses this technique: www.fbsl.net If you install it there are some examples showing it
Title: Re: Calling OpCode Strings
Post by: Charles Pegge on June 23, 2007, 01:47:03 PM
Thanks Eros, I had a look at their website and online manual. They seem to have everything! I would quite like to know how to create DLLs and EXE files from scratch. Header formats and table etc. Not that these are needed with dynamic compilation.
Title: Re: Calling OpCode Strings
Post by: Gérôme Guillemin on February 04, 2009, 08:57:52 PM
Thanks Eros, I had a look at their website and online manual. They seem to have everything! I would quite like to know how to create DLLs and EXE files from scratch. Header formats and table etc. Not that these are needed with dynamic compilation.
The opcode technique is used within the FBSL Eclecta's IDE, an IDE 100% made in FBSL code with syntax color done thanks to these opcodes :)