can any body tell me how to write self modifying codes?
At least a reference would do.
Thankz in adv
bye
Posted on 2002-10-17 09:25:58 by ajith
Hi,
a simple search on the forum will help you ;)
anyway, there's an example in the masm pack

regards,
ZaiRoN
Posted on 2002-10-17 09:57:37 by ZaiRoN
Self-modifying code is Evil. The CPU will stall for a long time if you modify some code and soon after execute it. It's also a big mess if you want to change instructions because they can be of different length. I've found a cleaner solution: run-time conditional compilation: softwire.sourceforge.net
Posted on 2002-10-17 14:36:43 by C0D1F1ED
run-time conditional compilation IS SMC. ;)
Posted on 2002-10-17 15:11:34 by Maverick
In a certain way, that's true, but if you think that far then you could also say all code is self-modifying code (running in a kernel) which is a bit absurd :rolleyes:
Posted on 2002-10-17 17:12:41 by C0D1F1ED
It depends at which level the code modifies itself... :)

An old friend of mine told me one day: "nothing ever get created... all get transformed", is the whole World absurd then ? :rolleyes:
Posted on 2002-10-17 17:21:15 by JCP

It depends at which level the code modifies itself...


Well if you look at the same level, a run-time assembler does not modify it's own code. A new memory buffer is allocated, instead of overwriting existing code. Ok it owns this code because it created it itself, so in a way it's at the same level, but let's not start nitpicking ;)
Posted on 2002-10-17 17:30:58 by C0D1F1ED
I meant, since you wrote ;)
Self-modifying code is Evil. The CPU will stall for a long time if you modify some code and soon after execute it. It's also a big mess if you want to change instructions because they can be of different length. I've found a cleaner solution: run-time conditional compilation: softwire.sourceforge.net

Then penalization-wise (which is not a sharp word :grin: ) assembling and executing code on the fly, again in this "CPU flushes pipelines and all" context, is just like SMC (actually, it's worse, because all the instructions will be "flushed" if you reassemble all, while in classic SMC you modify just one or two).

This is an important consideration, and is not splitting the hair. ;)
Posted on 2002-10-18 03:19:13 by Maverick
Ajith,

Why are you interested in self-modifying code? Maybe some evil purpose... Such as coding virii...? ;)

Regards,

Vortex
Posted on 2002-10-18 04:43:39 by Vortex

Ajith,

Why are you interested in self-modifying code? Maybe some evil purpose... Such as coding virii...? ;)

Regards,

Vortex


Or perhaps he's trying to make a PE-crypter/packer wich protects itself, well makes it harder to
to disassemble and whatnot... The uses of SMC are not really eandless but many... Never assume
anything... :)
Posted on 2002-10-18 05:14:32 by NervGaz
You can quote myself on "SMC rocks". :)
..but, like any other thing, it must be used only when it's really useful (and in those cases it can be VERY useful, also given the lack of registers in the x86 architecture.. but not only for performance purposes, also for protections and such).
Posted on 2002-10-18 05:39:19 by Maverick

can any body tell me how to write self modifying codes?
At least a reference would do.


You will need: IA-32 Intel? Architecture Software Developer?s Manual Volume 2: Instruction Set Reference

Also you can download some good ezines (like XXXXXXXX :( ), where you can find a lot of good tutorials about polymorphism and self-modifing. I could give you a link, but Bazik will be crazy about it.

Sorry but we cannot have reference to that type of data here. :)
Posted on 2002-10-18 07:27:04 by Aquila
Originally posted by Vortex
Why are you interested in self-modifying code? Maybe some evil purpose... Such as coding virii...? ;)


Don't you know in our days all virii are coded in Delphi and VB? :)
Posted on 2002-10-18 07:29:12 by Aquila
Don't you know in our days all virii are coded in Delphi and VB?


lol.. that must be why the virii keep floodin my limited mailbox. Couldn't they keep the size of the exe down? Damm them :grin:
Posted on 2002-10-18 07:31:54 by roticv
SMC is neither good or bad, just know what you are doing with it and why you are doing it. If you are worried about the stall from messing up the code cache, modify it first, do something else THEN run the modified code. Usually this means doing it at startup where a stall just does not matter and when everything is up and running, then run the modified code.

Regards,

hutch@movsd.com
Posted on 2002-10-18 07:35:56 by hutch--
I just experimented a bit with SoftWire and found it to be extremely easy to write self-modifying code since labels in code and data are treated equally and can be used anywhere. Now how will we call this, self-modifying conditional run-time assembly? :cool:

If you only need to change some constants, I have to agree that SMC is very usefull. But it's totally useless if you need to change more than a few opcodes like with run-time compilation for scripts or shaders. So let's just conclude it depends on the situation :grin:
Posted on 2002-10-18 07:37:23 by C0D1F1ED
Oh, it's weird nobody has mentioned sandpile yet. This is where I got most of my x86 resources to write SoftWire. It's the same info as in the Intel docs, but handier for browsing.
Posted on 2002-10-18 07:43:41 by C0D1F1ED

the lack of registers in the x86 architecture..

...but no for long, the x86-64 is comming. rax->r15, xmm1->xmm15, mmx1(/fpr0)->mmx7(/fpr7), I'm already dreaming happy dreams... :grin: :grin: :grin:
Posted on 2002-10-18 08:26:55 by scientica
Run-time compilation???

Sounds rigmarolish to me. Why not just compile all possible versions at development time, have several versions in a handy-dandy file, and load the version you need at init/run time?? Why make the user wait for you to compile while he's trying to run your program, when you can do all the compiling on YOUR computer and let the user run as soon as you select which version to use? That way you skip the overhead of compiling at init/run. Also... that way a crax0r will need a disassembler and a patcher, if you use run-time compilation all he'll need is a text editor.
Posted on 2002-10-18 08:49:27 by AmkG

Run-time compilation???

Sounds rigmarolish to me. Why not just compile all possible versions at development time, have several versions in a handy-dandy file, and load the version you need at init/run time?? Why make the user wait for you to compile while he's trying to run your program, when you can do all the compiling on YOUR computer and let the user run as soon as you select which version to use? That way you skip the overhead of compiling at init/run. Also... that way a crax0r will need a disassembler and a patcher, if you use run-time compilation all he'll need is a text editor.


I can't compile all possible versions at development time because of space and time limitations. Space because I currently have 12960 combinations. Suppose they all had a constant length of 1 KB, then I had almost 13 MB of code. If that doesn't sound much to you, then you should know that every new setting I add multiplies this by the number of options. So obviously time is also a limitation because I don't want to wait till all combinations are compiled until I can test them all. Besides, compiling one shader happens in a praction of a second, so simply caching the last couple of shaders is much more economical.

Disassembling a library is a lot easier than reading an encrypted file with a run-time assembled decryptor...
Posted on 2002-10-18 10:23:18 by C0D1F1ED