Skip to main content
gamedev.net
🔒 Locked

Self-modifying code problem - Help!

Started by LoreKeeper Oct 13, 2000 at 9:48 AM 3 replies 600+ views
Original Post
LoreKeeper
LoreKeeper
Hey Everybud I''ve been very busy working (mostly on Varsity projects) but I''ve had some time to spend on my own little diversions. Particularly some very good bump-mapping routines. To create the functionality with the speed necessary I''ve even gone as far, as to make the bump-procedures self-modifying code, to optimize certain features, and to make certain other features possible. This all works beautifully when run in under Delphi. But when the project is build and run straight under windows, then a run-time error is created by Windows, complaining that I''m writing into illegal memory regions. Anybody know how to make Windows yield to my will? (I assume I''ve got to do something similar to Locking a Surface, except for a code region...) thanx for the help A-Lore
jenova
jenova
if you are using self-modifying code then you must be aware of protected modem programming. with self-modifying code you need to create and "Data" segment alias to the "Code" segment because the "Code" segment is write protected. so you will need to create a "Data" segment selector alias which points to the same address and write to that segment selector. hope this helps. look up segment selector aliasing in MSDN.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
LoreKeeper
LoreKeeper
Hi Jenova

and thank you, I unforetunately don''t have access to the full MSDN, and exactly >that< is not available to me. (I can look-up how to do something in VisualBasic though - *YUK!*)

Currently I''m already using the Data Segment register when writing into my code. So I assume that I first have to make that region of the memory writable. Or I must lock the region first.

Any suggestions? (Preferably in Delphi-speak?)

If anybody actually has an example, that would be perfect.

thanks again
A-Lore
ggs
ggs
First off "segment selector aliasing" is overkill and I dont think it is supported by the win32 api.
If the self-modifying procedure is of fixed length then use the following functions :
ReadProcessMemory
WriteProcessMemory
and use GetCurrentProcess for the proccess handle

Or if it is a variable length allocated some memory with 'VirtualAlloc' with the flag PAGE_EXECUTE_READWRITE.
Remember to deallocate the memory with 'VirtualFree'

PS i'm going to upload a new version of my memory monitor some time tonight. It contains a bug fix and the app I use to test it

[edit] I'll email you an example of self-modifing code in delphi that I have

Edited by - ggs on October 14, 2000 5:38:03 AM

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.