Skip to content

Commit c66b1b2

Browse files
committed
Fixed disassembler range bug.
1 parent 3517453 commit c66b1b2

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

NativeHelper/dllmain.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,8 @@ EXTERN_DLL_EXPORT VOID __stdcall DisassembleRemoteCode(HANDLE process, LPVOID ad
320320
}
321321

322322
UIntPtr start = (UIntPtr)address;
323-
UIntPtr end = start + length;
324-
if (end <= start)
325-
{
326-
return;
327-
}
328323

329-
DISASM disasm;
330-
std::memset(&disasm, 0, sizeof(DISASM));
324+
DISASM disasm = { };
331325
disasm.Options = NasmSyntax + PrefixedNumeral;
332326
#ifdef _WIN64
333327
disasm.Archi = 64;
@@ -338,12 +332,14 @@ EXTERN_DLL_EXPORT VOID __stdcall DisassembleRemoteCode(HANDLE process, LPVOID ad
338332
std::vector<uint8_t> buffer(length);
339333
readRemoteMemory(process, address, buffer.data(), buffer.size());
340334

335+
UIntPtr end = (UIntPtr)buffer.data() + length;
336+
341337
disasm.EIP = (UIntPtr)buffer.data();
342338
disasm.VirtualAddr = start;
343339

344340
while (true)
345341
{
346-
disasm.SecurityBlock = ((UIntPtr)buffer.data() + buffer.size()) - disasm.EIP;
342+
disasm.SecurityBlock = end - disasm.EIP;
347343

348344
auto disamLength = Disasm(&disasm);
349345
if (disamLength == OUT_OF_BLOCK || disamLength == UNKNOWN_OPCODE)
@@ -354,7 +350,7 @@ EXTERN_DLL_EXPORT VOID __stdcall DisassembleRemoteCode(HANDLE process, LPVOID ad
354350
callbackDisassembledCode((LPVOID)disasm.VirtualAddr, disamLength, disasm.CompleteInstr);
355351

356352
disasm.EIP += disamLength;
357-
if (disasm.EIP >= end)
353+
if (disasm.EIP >= end || buffer[disasm.EIP - (UIntPtr)buffer.data()] == 0xCC)
358354
{
359355
break;
360356
}

0 commit comments

Comments
 (0)