Projects STRLCPY CaveCarver Commits 229639c2
🤬
  • ■ ■ ■ ■ ■ ■
    CaveCarver/Source.cpp
    skipped 5 lines
    6 6  #include <iostream>
    7 7  #include <filesystem>
    8 8   
     9 +// http://www.rohitab.com/discuss/topic/41466-add-a-new-pe-section-code-inside-of-it/
    9 10  DWORD align(DWORD size, DWORD align, DWORD addr) {
    10 11   if (!(size % align))
    11 12   return addr + size;
    skipped 100 lines
    112 113   file.read(buffer, fileSize);
    113 114   
    114 115   // Get the DOS header
    115  - IMAGE_DOS_HEADER* dosHeader = reinterpret_cast<IMAGE_DOS_HEADER*>(buffer);
     116 + PIMAGE_DOS_HEADER dosHeader = reinterpret_cast<PIMAGE_DOS_HEADER>(buffer);
    116 117   if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) {
    117 118   std::cerr << "Invalid DOS signature." << std::endl;
    118 119   return FALSE;
    119 120   }
    120 121   
    121 122   // Get the NT headers
    122  - IMAGE_NT_HEADERS64* ntHeader = reinterpret_cast<IMAGE_NT_HEADERS64*>(buffer + dosHeader->e_lfanew);
     123 + PIMAGE_NT_HEADERS64 ntHeader = reinterpret_cast<PIMAGE_NT_HEADERS64>(buffer + dosHeader->e_lfanew);
    123 124   if (ntHeader->Signature != IMAGE_NT_SIGNATURE) {
    124 125   std::cerr << "Invalid NT signature." << std::endl;
    125 126   return FALSE;
    126 127   }
    127 128   
    128 129   // Get the section headers
    129  - IMAGE_SECTION_HEADER* sectionHeader = IMAGE_FIRST_SECTION(ntHeader);
     130 + PIMAGE_SECTION_HEADER sectionHeader = IMAGE_FIRST_SECTION(ntHeader);
    130 131   
    131 132   // Find the .cave section
    132  - IMAGE_SECTION_HEADER* caveSectionHeader = nullptr;
     133 + PIMAGE_SECTION_HEADER caveSectionHeader = nullptr;
    133 134   for (int i = 0; i < ntHeader->FileHeader.NumberOfSections; i++) {
    134 135   if (strncmp(reinterpret_cast<char*>(sectionHeader[i].Name), ".cave", IMAGE_SIZEOF_SHORT_NAME) == 0) {
    135 136   caveSectionHeader = &sectionHeader[i];
    skipped 22 lines
    158 159   
    159 160   if (entryPointOffset == 0) {
    160 161   std::cerr << "Could not find file offset of entry point." << std::endl;
    161  - return 1;
     162 + return FALSE;
    162 163   }
    163 164   
    164 165   // Calculate the address of the jump target
    skipped 24 lines
    189 190   std::ofstream outputFile("patched.exe", std::ios::binary);
    190 191   if (!outputFile.is_open()) {
    191 192   std::cerr << "Could not create output file." << std::endl;
    192  - return 1;
     193 + return FALSE;
    193 194   }
    194 195   outputFile.write(buffer, fileSize);
    195 196   
    skipped 51 lines
Please wait...
Page is in error, reload to recover