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

Method apply_obfuscations

src/obfuscate.cpp:267–297  ·  view source on GitHub ↗

Apply the patches to the PE.

Source from the content-addressed store, hash-verified

265
266// Apply the patches to the PE.
267VOID cobf::apply_obfuscations(PIMAGE_SECTION_HEADER& sh_sec, DWORD& syms_rva)
268{
269 // The array of symbols to load.
270 vector<BYTE> strings_of_imports;
271 vector<shellcode::obfuscated_sym> symbols;
272
273 // Enumerate the obfuscate by name array.
274 DWORD c_rva = sh_sec->VirtualAddress + (DWORD_PTR)sh_sec->SizeOfRawData;
275 for (auto& mod : this->pe_mods) for (auto& sym : mod.mod_syms) sym.apply_obfuscation(
276 this->pe_rawf.data(), c_rva, strings_of_imports, symbols);
277
278 // Set the section info.
279 symbols.push_back({ 0 });
280 DWORD sh_sec_offset = (DWORD)((PBYTE)sh_sec - this->pe_rawf.data());
281
282 // Resize the whole pe.
283 size_t size_of_symbols = symbols.size() * sizeof(shellcode::obfuscated_sym);
284 this->pe_rawf.resize(this->pe_rawf.size() + strings_of_imports.size() + size_of_symbols);
285 sh_sec = (PIMAGE_SECTION_HEADER)(this->pe_rawf.data() + sh_sec_offset);
286
287 // Copy the strings and the symbols.
288 memcpy_s(this->pe_rawf.data() + sh_sec->PointerToRawData + sh_sec->SizeOfRawData,
289 strings_of_imports.size() + size_of_symbols, strings_of_imports.data(),
290 strings_of_imports.size());
291 memcpy_s(this->pe_rawf.data() + sh_sec->PointerToRawData + sh_sec->SizeOfRawData +
292 strings_of_imports.size(), size_of_symbols, symbols.data(), size_of_symbols);
293
294 // Edit the properties.
295 syms_rva = sh_sec->VirtualAddress + sh_sec->SizeOfRawData + (DWORD)strings_of_imports.size();
296 sh_sec->SizeOfRawData += (DWORD)strings_of_imports.size() + (DWORD)size_of_symbols;
297};
298
299// Add the stub for shellcode.
300VOID cobf::add_shellcode_stub(PIMAGE_SECTION_HEADER& sh_sec, DWORD funs_offset, DWORD syms_rva, DWORD& entry)

Callers 1

generateMethod · 0.95

Calls 1

apply_obfuscationMethod · 0.80

Tested by

no test coverage detected