Trek.exe: in-memory patching with C/C++

General Modding Information/Questions; support/discussion/questions

Moderator: thunderchero

Forum rules
:idea: Please search before starting new topic. :idea:
There is a good chance it has already been asked.
User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 3258
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Re: Trek.exe: in-memory patching with C/C++

Post by Flocke »

QuasarDonkey wrote:I guess the simplest answer is to keep the loader program simple, and use LoadLibrary() to load plugin DLLs that do any heavy modding.
Hm, good point. A plain launcher with plugin system for all the modding.
That way dynamic loading should be fairly safe. :)
User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 3258
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Re: Trek.exe: in-memory patching with C/C++

Post by Flocke »

QuasarDonkey wrote:If you tried to patch code in a running program, it would crash out. This is because the memory is protected from being overwritten. But we can change the properties in Trek.exe to make the code writable, so we can patch it while it's running. Basically, all we need to do is patch a single byte in Trek.exe. You could use special tools, like CFF Explorer, but I'll just tell you which byte to set in trek.exe:

Code: Select all

At offset 0x019f, change C0 to E0
You meant to change 60 to E0 (20 = executable, 40 = readable, 80 = writable), but CFF Explorer is a great tool, thx!

I now interated this with the mpr++ Extension Adapter I'm working on and it works perfect! :grin:
Beside "Monkey Patching" (funny term) the way described, which is great to completely replace a function, I also added to patch the actual call or jmp statement so other references to same old code location aren't affected.
I just hope all this won't result in troubles with anti-virus software or such. :roll:

Added your example for galaxy generation and it works fine. :up:
Once, with UDM at max tech many races, it freezed on galaxy generation. But that's the usual trouble with not finding enough room for all starting systems I guess. Maybe some anomalies were placed aside home system or whatever.
QuasarDonkey wrote:This should allow for some interesting patches, with no need to modify Trek.exe.
Indeed, and it allows to switch features on and off again without fiddling with trek.exe all the time.
Any chance to see you back on this?
User avatar
QuasarDonkey
Code Analyst
Code Analyst
Posts: 433
Joined: Tue Jul 26, 2011 8:29 pm
Location: Ireland

Re: Trek.exe: in-memory patching with C/C++

Post by QuasarDonkey »

Yeah, definitely.

I've spent the last few days working on a totally new version of the IDA database (there were some problems with the old one). I've already coded up all the old info into the new database. I'm identifying all the UI functions now. The more we know about Trek.exe, the more patches we can make.

And I'm still hopeful for full decompilation one day :cool: Or at least partial decompilation by patching the replacement code into Trek.exe.
Flocke wrote:Added your example for galaxy generation and it works fine. :up:
Once, with UDM at max tech many races, it freezed on galaxy generation.
I never tested with minors. But it is not surprising that it froze, there's not a lot of space on that map :grin:
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7963
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Trek.exe: in-memory patching with C/C++

Post by thunderchero »

QuasarDonkey wrote:I've spent the last few days working on a totally new version of the IDA database
I was just thinking it was due for an update last time I used it. :up: :up:

thunderchero
User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 3258
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Re: Trek.exe: in-memory patching with C/C++

Post by Flocke »

QuasarDonkey wrote:Yeah, definitely.

I've spent the last few days working on a totally new version of the IDA database (there were some problems with the old one). I've already coded up all the old info into the new database. I'm identifying all the UI functions now. The more we know about Trek.exe, the more patches we can make.
Hey, cool! Looking forward to even more key variables. :shock:
The list already is immense and yeah it helps alot to read the code!
QuasarDonkey wrote:And I'm still hopeful for full decompilation one day :cool: Or at least partial decompilation by patching the replacement code into Trek.exe.
I think chances for the latter aren't that bad. We just need to work from top to the ground. :grin:
Post Reply

Return to “General Modding Information/Questions”