How to extend trek.exe code sections

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
Tethys
Past Administrator
Past Administrator
Posts: 2392
Joined: Fri Jul 18, 2008 2:00 am
Location: Your mom's bed ;)
Contact:

Re: How to extend trek.exe code sections

Post by Tethys »

thunderchero wrote: Wed Apr 14, 2021 1:14 pmsad part is even if I get this call figured out my new code calls sprintf_ and I am sure that will not be easy to call correct code location.
If you take both code addresses and convert them to decimal address with UE, you can subtract the smaller value from the larger value and then reconvert that value back to hex with UE. Assuming UE will convert, this SHOULD be the distance between the 2 code addresses from starting byte to starting byte. You will have to then further adjust manually to account for length of operation/code and/or that of any jump statement. I just tested a small jump and the byte count was off by one. If you use the address of the LAST byte in your operation it should give you the exact number.

Hope that helps... Giving an example would be difficult, but can be done if requested.

As for subroutine, it is small and lacks certain prequisites to be called a true subroutine. For example there is no table of values preceding, there are no push statements to get the registers setup. I believe this here may be what QD referred to as "fastcall". Looks like they can carry additional code to "enlarge" areas of full subroutines lacking codespace. Also you can probably even have a call inside a call if you needed even more. Calling also appears to be more efficient than jumping back (C3 Return as opposed to E9 xx xx xx xx long jump). I will admit that I do not fully understand calls and what all they can be used for, but just from looking at them I can see what they do, and if it works, it works.. matters not how, just that it does. Lol.
Not for the weak of heart...
Galaxies MOD v0.4.0 <--- GALM/Galaxies Mod latest version
User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 3197
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Re: How to extend trek.exe code sections

Post by Flocke »

thunderchero wrote: Wed Apr 14, 2021 10:43 pm section 5 does not list;
OS type : MS Windows
Application type: 32bit
That is likely identified by the section name and not relevant. I'll check myself later if you can't get it work.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7851
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: How to extend trek.exe code sections

Post by thunderchero »

I did get it to work,

the issue was I had to use OllyDbg to calculate the virtual address of new code. plus any call within the old reloc section you need to also use OllyDbg to calculate return virtual address.

I have tested using "call" command with C3 return on simple 10 bytes of code, as well as my XY code changes with a call to sprintf_ within my code.

I will do some clean up and post a patch of change for .reloc section to EXTEN section later. I will also post a quick instructions on how to get virtual address offset.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7851
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: How to extend trek.exe code sections

Post by thunderchero »

I wanted to split the relocation table to have a small data area (5002 bytes) but every time I attempt this exe will no longer load.

here is a screenshot of section header
2_sections.jpg
2_sections.jpg (245.02 KiB) Viewed 1531 times
is this even possible? or what might I be doing wrong?

I think I have all my values correct
User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 3197
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Re: How to extend trek.exe code sections

Post by Flocke »

thunderchero wrote: Sat Apr 24, 2021 12:25 pm is this even possible? or what might I be doing wrong?
Sure it is possible, but you must regard the alignment! All sections must be 4KB aligned! Means, each section must start a multiple of 1000h.
390h however breaks with the alignment and is not supported by Windows. ;)

You actually can leave the raw size smaller and keep some gap, but your EXTEN section must start at 28C000 and be shrinked above case.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7851
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: How to extend trek.exe code sections

Post by thunderchero »

Flocke wrote: Sat Apr 24, 2021 2:06 pm Sure it is possible, but you must regard the alignment! All sections must be 4KB aligned! Means, each section must start a multiple of 1000h.
390h however breaks with the alignment and is not supported by Windows. ;)

You actually can leave the raw size smaller and keep some gap, but your EXTEN section must start at 28C000 and be shrinked above case.
Thank for the explanation, and it works again. Now I can put data in a data section and 4096 bytes should be more than enough. :wink:

when I added a table it listed as offset Dword_68A320 instead of offset unk_68A320

now the statement is as it should be offset unk_68A320 :cool:
Post Reply

Return to “General Modding Information/Questions”