Comment sont-PE de la Base de Délocalisations, de construire?

Je suis actuellement de la difficulté à comprendre comment PE de la Base de Délocalisations sont à construire.

Je comprends il peut y avoir plus d'une réinstallation, je comprends aussi pourquoi et comment cela est fait, mais je ne comprends pas par programmation:

Lequel des énoncés suivants est vrai (IMAGE_BASE_RELOCATION dans 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];

Ou

DWORD   VirtualAddress;
DWORD   SizeOfBlock; //size of all relocations
WORD    TypeOffset[1]; //relocation #1
WORD    TypeOffset[1]; //relocation #2
WORD    TypeOffset[1]; //relocation #3

Ou les deux sont incorrectes? Comment dois-je faire une boucle par tous les délocalisations par programmation?

Actuellement, j'ai ce code, semble être incorrect quelque part:

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;
            } 
C'est une question difficile, non?
Les délocalisations sont ridicule, personne ne semble connaître la bonne façon de les gérer.
avez-vous comprendre cela?

OriginalL'auteur John Smith | 2013-07-02