Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void AjouterSection(HANDLE hFile)
- {
- PIMAGE_SECTION_HEADER pNewSection = NULL;
- PIMAGE_SECTION_HEADER pSectionHeader = NULL;
- PIMAGE_FILE_HEADER pCOFFHeader = NULL;
- PIMAGE_OPTIONAL_HEADER pOptHeader = NULL;
- DWORD dwTailleSection, dwAlignementSection, dwAlignementFile;
- pSectionHeader = GetSectionHeader(hFile);
- pCOFFHeader = GetFileHeader(hFile);
- pOptHeader = GetOptionalHeader(hFile);
- dwTailleSection = sizeof(myLoader) + sizeof(DWORD)+1;
- dwAlignementSection = pOptHeader->SectionAlignment;
- dwAlignementFile = pOptHeader->FileAlignment;
- pNewSection = (PIMAGE_SECTION_HEADER)((PUCHAR)(&pSectionHeader[pCOFFHeader->NumberOfSections-1].Characteristics) + 0x4);
- memcpy(*(&pNewSection->Name), ".loader", 7);
- *(&pNewSection->Misc.VirtualSize) = Aligner(dwTailleSection, dwAlignementSection);
- *(&pNewSection->VirtualAddress) = Aligner(pSectionHeader[pCOFFHeader->NumberOfSections-1].VirtualAddress + pSectionHeader[pCOFFHeader->NumberOfSections-1].Misc.VirtualSize, dwAlignementSection);
- *(&pNewSection->SizeOfRawData) = Aligner(dwTailleSection, dwAlignementFile);
- *(&pNewSection->PointerToRawData) = Aligner(pSectionHeader[pCOFFHeader->NumberOfSections-1].PointerToRawData + pSectionHeader[pCOFFHeader->NumberOfSections-1].SizeOfRawData, dwAlignementFile);
- *(&pNewSection->Characteristics) = IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE;
- *(&pNewSection->PointerToRelocations) = 0x0;
- *(&pNewSection->PointerToLinenumbers) = 0x0;
- *(&pNewSection->NumberOfRelocations) = 0x0;
- *(&pNewSection->NumberOfLinenumbers) = 0x0;
- *(&pCOFFHeader->NumberOfSections) += 0x1;
- *(&pOptHeader->SizeOfImage) = Aligner(pOptHeader->SizeOfImage + dwTailleSection, dwAlignementSection);
- *(&pOptHeader->SizeOfHeaders) = Aligner(pOptHeader->SizeOfHeaders + sizeof(IMAGE_SECTION_HEADER), dwAlignementFile);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement