MCPcopy Create free account
hub / github.com/d35ha/CallObfuscator / disable_the_relocation

Method disable_the_relocation

src/obfuscate.cpp:369–402  ·  view source on GitHub ↗

Disable the relocations at the PE.

Source from the content-addressed store, hash-verified

367
368// Disable the relocations at the PE.
369BOOL cobf::disable_the_relocation()
370{
371 // Get the headers.
372 PIMAGE_DOS_HEADER dos_hdr = (PIMAGE_DOS_HEADER)this->pe_rawf.data();
373 PIMAGE_NT_HEADERS nt_hdrs = (PIMAGE_NT_HEADERS)&this->pe_rawf.data()[dos_hdr->e_lfanew];
374
375 // Get the table.
376 PIMAGE_RESOURCE_DIRECTORY p_relocs; size_t relocs_size;
377 if (!this->get_data_table(IMAGE_DIRECTORY_ENTRY_BASERELOC, (PVOID*)&p_relocs, relocs_size))
378 {
379 // Cannot verify the relocations.
380 return FALSE;
381 };
382
383 // Zero it.
384 if (p_relocs) ZeroMemory(p_relocs, relocs_size);
385 nt_hdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC] = { 0, 0 };
386
387 // Stop the relocations.
388 nt_hdrs->FileHeader.Characteristics |= IMAGE_FILE_RELOCS_STRIPPED;
389
390 // Configure the sections.
391 PIMAGE_SECTION_HEADER c_sec = (PIMAGE_SECTION_HEADER)&this->pe_rawf[dos_hdr->e_lfanew +
392 sizeof(nt_hdrs->Signature) + sizeof(nt_hdrs->FileHeader) +
393 nt_hdrs->FileHeader.SizeOfOptionalHeader];
394 for (size_t idx = 0; idx < nt_hdrs->FileHeader.NumberOfSections; idx++)
395 {
396 // Strip all of the information.
397 c_sec[idx].PointerToRelocations = 0;
398 c_sec[idx].NumberOfRelocations = 0;
399 };
400
401 return TRUE;
402};
403
404// Strip any debug symbols from the PE.
405BOOL cobf::remove_debug_symbols()

Callers 1

generateMethod · 0.95

Calls 1

get_data_tableMethod · 0.95

Tested by

no test coverage detected