Attualmente non riesco a capire come si creano le rilocazioni della base PE.Come si accumulano le rilocche della base PE?
ho capito non ci può essere più di una delocalizzazione, capisco anche perché e come questo è fatto, ma io proprio non capisco a livello di codice:
Quale delle seguenti affermazioni è vera (IMAGE_BASE_RELOCATION in WinNT.h)?
// Base relocation #1
DWORD VirtualAddress;
DWORD SizeOfBlock; // size of current relocation
WORD TypeOffset[1];
// Base relocation #2
DWORD VirtualAddress;
DWORD SizeOfBlock; // size of current relocation
WORD TypeOffset[1];
// Base relocation #3
DWORD VirtualAddress;
DWORD SizeOfBlock; // size of current relocation
WORD TypeOffset[1];
O
DWORD VirtualAddress;
DWORD SizeOfBlock; // size of all relocations
WORD TypeOffset[1]; // relocation #1
WORD TypeOffset[1]; // relocation #2
WORD TypeOffset[1]; // relocation #3
O sono entrambi errati? Come devo effettuare il ciclo di tutte le riposizionazioni di base a livello di codice?
Attualmente ho questo codice, sembra non essere corretto da qualche parte:
DWORD baseRelocationSize = imageNtHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
unsigned int baseRelocationCount = baseRelocationSize/sizeof(IMAGE_BASE_RELOCATION);
DWORD baseDelta = (DWORD_PTR)moduleBase - (DWORD_PTR)imageNtHeaders->OptionalHeader.ImageBase;
IMAGE_BASE_RELOCATION* baseRelocation = (IMAGE_BASE_RELOCATION*)((DWORD_PTR)moduleBase + (DWORD_PTR)imageNtHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress);
for(unsigned int i = 0; i != baseRelocationCount; ++i)
{
unsigned int entryCount = (baseRelocation->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION))/sizeof(WORD);
for(unsigned int j = 0; j != entryCount; ++j)
{
WORD* entry = (WORD*)((DWORD_PTR)baseRelocation + (DWORD_PTR)sizeof(IMAGE_BASE_RELOCATION));
if((*entry >> 12) & IMAGE_REL_BASED_HIGHLOW)
{
DWORD* pdw = (PDWORD)((DWORD_PTR)moduleBase + (DWORD_PTR)baseRelocation->VirtualAddress + ((*entry) & 0xfff));
(*pdw) += baseDelta;
}
entry++;
}
baseRelocation += baseRelocation->SizeOfBlock;
}
È difficile, vero? –
Le delocalizzazioni sono ridicole, nessuno sembra conoscere il modo corretto per gestirle. – iDomo
@JohnSmith l'hai capito? – Benny