Strip any debug symbols from the PE.
| 403 | |
| 404 | // Strip any debug symbols from the PE. |
| 405 | BOOL cobf::remove_debug_symbols() |
| 406 | { |
| 407 | // Get the headers. |
| 408 | PIMAGE_DOS_HEADER dos_hdr = (PIMAGE_DOS_HEADER)this->pe_rawf.data(); |
| 409 | PIMAGE_NT_HEADERS nt_hdrs = (PIMAGE_NT_HEADERS)&this->pe_rawf.data()[dos_hdr->e_lfanew]; |
| 410 | |
| 411 | // Get the table. |
| 412 | PIMAGE_DEBUG_DIRECTORY p_debug; size_t debug_size; |
| 413 | if (!this->get_data_table(IMAGE_DIRECTORY_ENTRY_DEBUG, (PVOID*)&p_debug, debug_size)) |
| 414 | { |
| 415 | // Cannot verify the debug table. |
| 416 | return FALSE; |
| 417 | }; |
| 418 | |
| 419 | // Zero it. |
| 420 | if (p_debug) ZeroMemory(p_debug, debug_size); |
| 421 | nt_hdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG] = { 0, 0 }; |
| 422 | |
| 423 | // Strip it. |
| 424 | nt_hdrs->FileHeader.NumberOfSymbols = 0; |
| 425 | nt_hdrs->FileHeader.PointerToSymbolTable = 0; |
| 426 | |
| 427 | // Configure the sections. |
| 428 | PIMAGE_SECTION_HEADER c_sec = (PIMAGE_SECTION_HEADER)&this->pe_rawf[dos_hdr->e_lfanew + |
| 429 | sizeof(nt_hdrs->Signature) + sizeof(nt_hdrs->FileHeader) + |
| 430 | nt_hdrs->FileHeader.SizeOfOptionalHeader]; |
| 431 | for (size_t idx = 0; idx < nt_hdrs->FileHeader.NumberOfSections; idx++) |
| 432 | { |
| 433 | // Strip all of the information. |
| 434 | c_sec[idx].PointerToLinenumbers = 0; |
| 435 | c_sec[idx].NumberOfLinenumbers = 0; |
| 436 | }; |
| 437 | |
| 438 | return TRUE; |
| 439 | }; |
| 440 | |
| 441 | // Make the import table section writable for the shellcode. |
| 442 | BOOL cobf::make_the_iat_writable() |
no test coverage detected