oh ya, i always wanted to ask this, when using topo (refers to topo V1.2 thread), the section they add and named as xptable, it automatically gets assigned to be the default exp table in the exe? o.0
Of course not. That would be far too easy.
All executable files on Win32 OS are comprised of several "sections". When an executive kernel (the part of the OS that loads a program into memory and adds it to the task roster for execution) is asked to load a binary executable in memory, it has to understand the executable file format. In simple early OS, this may have been a simple flat file containing no external references, not relocation fixups and running single tasked, like a DOS .com file. That really isn't practical on modern multi-tasking OS.
If Windows, or Linux where to use a .com file there would be problems... Each .com file requires the same fixed start and load address... execution begins from the start of the file, and everything fits in a single 16-bit page of memory... Do this in a multi-tasking environment and every program you loaded would overwrite the last one. >_<
So you need to be able to remap the memory addresses of the program to a free hole. Virtual addressing helps this process a lot on modern systems. But we also use a lot of shared libraries to reduce the code per program, ensure compatibility, and increase standardisation accross the system as a whole. These have to be linked into the executable at load time, or dynamically at run time. All of that is the job of the executive kernel.
Windows OS (Win*** WinDotNet WinCE & WinX64, as well as WinPPC & WinAlpha etc) use an executable encapsulation called PE (Portable Executable) based on standard COFF binary format. Microsoft had to change the format, because they already use MZ format in DOS and wanted to keep compatibility. They had also used LE, and NE formats on OS/2 and Windows 2/3 varients which where similar to modified COFF files, but 16-bit.
The primary "sections" in a PE file, are the header, (or group of headers) which describes all the other sections, ".text" curiously where the code is stored, ".rdata" which is the relocation fixup table for DLL import, ".data" where constant declairations and some variable storage is pre-allocated fixed space, and more recently (since NT4) a ".rsrc" section for Icons, pre-configured window dialogues and such can be stored. Prior to NT4, these where typically stored outside the executabe file in a .res file... It was all an attempt to match Apple Mac's Resource Fork without implementing multiple data forkes for individual files to keep compatability with the FAT filesystem.
Okay... those are the sections Windows needs, and knows how to deal with... They are normally created during program build time by your development environments "link" tool, which will take all the static linked code (all the .obj files) and link them together in a single file which is executable on the target OS.
The "make" or "build" process on modern development environments hides a lot of this behind very automated interfaces, but we used to pre-compile to get forward jumps and fix-ups in the compiler. Then issue another command to compile which gave us an assembly listing. We could issue another command to assemble that to get binary objects that we could use with our linker to link into an executable file for our OS. Then, and only then did our program actually load and do something. ^_^
The PE format (and COFF and ELF files for other OSs) allows us to add sections from binary files with any name we like. But to do so in any modern development environment, you would have to alter the standard build process and issue very specific instructions to the linker, telling it to add a section to the executable, give it a name and execution permissions and a prefered start address in the memory map, and point it to the binary file containing the initial data for that section.
Using a tool like ToPo, we essentially un-link the executable into it's constituant sections and fix-up data, then re-link it with a new empty section. In practice ToPo only half does this job, and does it in memory for speed and because it's perpose is very specific, compared to that of a linker. The end result is indentical however.
If you where to do this during the initial build of a program you had source code for, you would either be doing it because you wanted to make changes to the source assembly produced by your compiler, or because you used specific meta-assembler in your source (as can be done in some languages) which addressed this table directly... even though the compiler has no idea what it contains.
It's really not something anyone would ever
need to do, but could be desirable in certain situations, if you have a large table of constant binary data you'd rather not turn into C source, or for some reason don't want to use OS mallocs or define a massive array just to get some free memory. This can be faster, because you know the addresses of the data before hand and don't need to reference it against a malloc return, and easier because you can leave the OS to deal with "insufficient memory" problems. But it's still "dirty" and more the sort of thing that hackers, crackers and Demo coders do than something you should add to standard decent coding practices.
So... once we've linked in a new empty section... we can move any data into there that we need more room for, and we can point the code (in Olly) to use it. But you have to find the code that is pointing to the original data, and adjust the pointers to point to our new data section... of course.
Hope the history lesson isn't too much... but I find looking at how the first wheel was invented, and developed explains why Alloys are so good better than anything else.
