Weird idea about threads

Everything else that doesn't fall into one of the other PB categories.
Seldon
Enthusiast
Enthusiast
Posts: 405
Joined: Fri Aug 22, 2003 7:12 am
Location: Italia

Weird idea about threads

Post by Seldon »

If your opinion, if I store a procedure in my source as a sequence of bytes (that is the real machine code -> I'd use a HEX editor for this to retrieve the values) , then I load such procedure in memory (in an allocated memory area) and I pass the pointer of that area to CreateThread (the PB version or the API version) would that work ? Any ideas ? I saw the VirtualAlloc() call accepts the PAGE_EXECUTE flag to be passed.
I know that it can sound silly, but I think it could be useful for copy protection functions that would be created at run-time (the machine code could be crypted too).
Seldon
Enthusiast
Enthusiast
Posts: 405
Joined: Fri Aug 22, 2003 7:12 am
Location: Italia

Post by Seldon »

Ok, little update. I included some code in IncludeBinary and then I passed it to CreateThread and ALL Windows blocked !! 8O Impressive, nothing was reacting anymore (I use Win98SE). I guess because the code was loaded in the data section and not the code section. I'll try what happens using VirtualAlloc.
freak
PureBasic Team
PureBasic Team
Posts: 5947
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

There is a code snip at the german forum, that creates and executes a
Procedure on runtime.
http://robsite.de/php/pureboard/viewtopic.php?p=573#573

Unfortunately, i don't understand anything in this code, so you'll have to
find some other german speaking geek to help you on this.

Timo
quidquid Latine dictum sit altum videtur
Seldon
Enthusiast
Enthusiast
Posts: 405
Joined: Fri Aug 22, 2003 7:12 am
Location: Italia

Post by Seldon »

Thanks for the post, I saw the program and it seems very interesting. Though from what I've understood sofar, it seems the procedure to be called (or an API call) must stay in the code and that wouldn't be useful as the code would be readable as always and you could see it by using a disassembler.
Post Reply