Advertisement
Guest User

Untitled

a guest
Feb 17th, 2010
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.91 KB | None | 0 0
  1. void AjouterSection(HANDLE hFile)
  2. {
  3.     PIMAGE_SECTION_HEADER pNewSection = NULL;
  4.     PIMAGE_SECTION_HEADER pSectionHeader = NULL;
  5.     PIMAGE_FILE_HEADER pCOFFHeader = NULL;
  6.     PIMAGE_OPTIONAL_HEADER pOptHeader = NULL;
  7.  
  8.     DWORD dwTailleSection, dwAlignementSection, dwAlignementFile;
  9.  
  10.     pSectionHeader = GetSectionHeader(hFile);
  11.     pCOFFHeader = GetFileHeader(hFile);
  12.     pOptHeader = GetOptionalHeader(hFile);
  13.  
  14.     dwTailleSection = sizeof(myLoader) + sizeof(DWORD)+1;
  15.     dwAlignementSection = pOptHeader->SectionAlignment;
  16.     dwAlignementFile = pOptHeader->FileAlignment;
  17.  
  18.     pNewSection = (PIMAGE_SECTION_HEADER)((PUCHAR)(&pSectionHeader[pCOFFHeader->NumberOfSections-1].Characteristics) + 0x4);
  19.  
  20.     memcpy(*(&pNewSection->Name), ".loader", 7);
  21.  
  22.     *(&pNewSection->Misc.VirtualSize) = Aligner(dwTailleSection, dwAlignementSection);
  23.     *(&pNewSection->VirtualAddress) = Aligner(pSectionHeader[pCOFFHeader->NumberOfSections-1].VirtualAddress + pSectionHeader[pCOFFHeader->NumberOfSections-1].Misc.VirtualSize, dwAlignementSection);
  24.     *(&pNewSection->SizeOfRawData) = Aligner(dwTailleSection, dwAlignementFile);
  25.     *(&pNewSection->PointerToRawData) = Aligner(pSectionHeader[pCOFFHeader->NumberOfSections-1].PointerToRawData + pSectionHeader[pCOFFHeader->NumberOfSections-1].SizeOfRawData, dwAlignementFile);
  26.     *(&pNewSection->Characteristics) = IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE;
  27.     *(&pNewSection->PointerToRelocations) = 0x0;
  28.     *(&pNewSection->PointerToLinenumbers) = 0x0;
  29.     *(&pNewSection->NumberOfRelocations) = 0x0;
  30.     *(&pNewSection->NumberOfLinenumbers) = 0x0;
  31.  
  32.  
  33.     *(&pCOFFHeader->NumberOfSections) += 0x1;
  34.     *(&pOptHeader->SizeOfImage) = Aligner(pOptHeader->SizeOfImage + dwTailleSection, dwAlignementSection);
  35.     *(&pOptHeader->SizeOfHeaders) = Aligner(pOptHeader->SizeOfHeaders + sizeof(IMAGE_SECTION_HEADER), dwAlignementFile);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement