MCPcopy Create free account
hub / github.com/connorjaydunn/BinaryShield / virtualizeFunction

Method virtualizeFunction

src/pe.cpp:57–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57bool PE::virtualizeFunction(Function function)
58{
59 // todo: check if function can be vm'd (i.e. is sizeof(function->bytes) >= 5)
60
61 if (!vmSection.isInitialised())
62 vmSection.initialise(getNewSectionVirtualAddress(), getNewSectionFileOffset());
63
64 if (!function.disassemble())
65 return 0;
66
67 if (!function.compileInstructionsToVirtualInstructions())
68 return 0;
69
70 removeOriginalFunctionBytes(function);
71
72 DWORD bytecodeRva = vmSection.getWritePointerRva();
73
74 // resolve branch instructions now we know bytecode rva
75 function.resolveBranchInstructions(bytecodeRva);
76
77 vmSection.addBytes(function.getVirtualInstructionBytes());
78
79 // redirect function to a vm trampoline
80 redirectFunctionToVmTramp(function, vmSection.getWritePointerRva());
81 vmSection.addVmTramp(bytecodeRva);
82
83 return 1;
84}
85
86bool PE::virtualizeFunctions()
87{

Callers

nothing calls this directly

Calls 9

isInitialisedMethod · 0.80
initialiseMethod · 0.80
disassembleMethod · 0.80
getWritePointerRvaMethod · 0.80
addBytesMethod · 0.80
addVmTrampMethod · 0.80

Tested by

no test coverage detected