tinyLoader example
The following example is the peLoader.cpp
source code under the Chapter#6
folder of the GitHub project. In order to save space, this book only extracts the highlighted code; please refer to the complete source code see all the details of the project.
We first compile our msgbox.c
source code as we did in Chapter 1 with MinGW
and use the -Wl,--dynamicbase,--export-all-symbols
arguments to generate an EXE file with a relocation table, msgbox_reloc.exe
, as shown in Figure 6.3:
Figure 6.3 – The generation of msgbox_reloc.exe
Figure 6.4 shows the fixReloc
function responsible for correcting the relocation task for the entire PE module:
Figure 6.4 – The fixReloc function
At lines 56-57 of the code, we can retrieve the starting point of the relocation table held in the current .reloc
section from DataDirectory[IMAGE_BASE_RELOCATION]
and later use it to analyze the relocation fields.
At lines...