i never had problem in using VirtualProtect() and WriteProcessMemory() to write into my own code section, but, if you cant, why dont use the stack? it can have executable code
You use selectors by moveing them into CS, DS, ES.FS and GS ..evantually SS ;) just like in 16 bits...only they are not "segments" they are "selectors" that is: a index into the GDT or LDT (Win95->LDT)...
dont forget they are 16 bits values...
However this is NOT recomended to be done on Win32 (any version)...use it ONLY is you know exactly what are you doing....
for example on your OWN OS Code ;)
MikeW, what's your problem with VirtualProtect and WriteProcessMemory?
If you only need to change your code "every once in a while", or
perhaps even only at program start, they are (imho) both good
choices, since you can turn protection back on, and thus still
catch any other (invalid) attempt to write in the code section.
That is, after all, the idea of protection the code section.
Using the data section is a choice as well, but...if you're only
going to modify a few values (opposed to generating code runtime),
code section is logically prettier.
Also, you could use VirtualAlloc if you're going to "generate" code,
or using "template code" to generate optimized encryptors,
decryptors, linefillers or whatever.
Bogdan, could you clarify about selectors 30 and 31?
Would this do it:
mov ax,30 ;decimal or hex?
mov ds,ax
or is 30 an index, so we need
mov ax,30*8 ;or similar
mov ds,ax
Thx,
Larry