flat assembler
Message board for the users of flat assembler.
Index
> Main > Self-writing code |
Author |
|
polygon7 01 Feb 2006, 17:05
Hi,
if i understand You correctly then this technique is known as "Self modifying code". _________________ best regards p7 |
|||
01 Feb 2006, 17:05 |
|
Reverend 01 Feb 2006, 17:34
Modyfing your own code is not hard - you just have to declare the section with code as writeable. But, adding new code each time is another task. First of all, in windows there are these sections which are aligned to some value. During compilation FASM evaluates all the code size, etc. and put it in the section info structure. If you add new code the characteristics change and so you would have to change them in the file (and of course first evaluate them). Second thing, addresses are continous ie. the end of one section (aligned with zeroes) is the beginning of the next one. And it is nearly impossible to relocate whole next section to find place for your added data to section before. Third, probably the hardest part, you would have to write some kind of an assembler of your own. FASM gets instructions operands from the text you type (like 'mov eax, 1'). Your program would have another source. I don't know what you are planning but even though you would have to pass all input and assemble it somehow to the code you want to add. In my opinion such thing is surely possible, but the effort is extremely huge!
Also for the part of saving the result in its own file. It is also possible but only using some special tricks for current os (ie. you'd have to use some bugs to get past the file security ) btw. there was some thread about that here I guess... |
|||
01 Feb 2006, 17:34 |
|
Madis731 01 Feb 2006, 20:19
You can make an additional section with say a MB of free room to begin with. Then if your "code knows" what its doing, it can add all data+code to this section and there will be no alignment nor relocation issues. Just that you can only ADD to the end and REMOVE from the end, but its impossible to MODIFY!
Why it is so hard to modify is the fact that you are now dealing with binary and there is no way you can tell which part it an instruction and what instruction in particular without disassembling the whole file at first |
|||
01 Feb 2006, 20:19 |
|
chris 03 Feb 2006, 13:55
Is the code encryption an example of what you guys are talking about?
since the code have to be decrypted at runtime and hence self-modifying. |
|||
03 Feb 2006, 13:55 |
|
bogdanontanu 03 Feb 2006, 17:24
FORTH does that!
Each word you add to the vocabulary has the same power as any other word defined in the language. You can even overwrite and or erase basic language words. Just take care to setup FENCE. Save an image of FORTH after you have compiled some new words in Forth --> And here you have a new Forth system/compiler/interpreter eventually with a new language ready to run Such features come with a price tag: the applications/code programs written in Forth are slower that the one compiled by FASM. Also FASM itself is much faster than Forth at compiling. |
|||
03 Feb 2006, 17:24 |
|
dr_dred 16 Feb 2006, 13:30
Code: format PE GUI 4.0 include 'include\win32a.inc' section '.code' code readable writeable executable start: mov esi, [ebp+8] lea edi, [esi+12] mov [ebp+8], edi movsd movsd movsd |
|||
16 Feb 2006, 13:30 |
|
okasvi 16 Feb 2006, 14:05
forgot something?
Code: entry start _________________ When We Ride On Our Enemies support reverse smileys |: |
|||
16 Feb 2006, 14:05 |
|
vid 16 Feb 2006, 14:18
for what you want, it would be best to create some interface which allows adding keyword at runtime. Just maintain some list of directives, which can be easily expanded.
|
|||
16 Feb 2006, 14:18 |
|
OzzY 16 Feb 2006, 15:03
dr_dred: What does that code?
Here is an example of SMC: I posted here: http://board.flatassembler.net/topic.php?p=35277#35277[/url] |
|||
16 Feb 2006, 15:03 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.