From 84bf8c659f6ab195de3d0cf841f8f52877d660d0 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 31 Jan 2019 12:47:56 -0500 Subject: [PATCH] fix code generation --- GUI/host/util.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/GUI/host/util.cpp b/GUI/host/util.cpp index 71d3bc7..502d46f 100644 --- a/GUI/host/util.cpp +++ b/GUI/host/util.cpp @@ -169,9 +169,15 @@ namespace return hp; } + std::wstring HexString(int64_t num) // only needed for signed nums + { + return (std::wstringstream() << std::uppercase << std::hex << (num < 0 ? "-" : "") << abs(num)).str(); + } + std::wstring GenerateRCode(HookParam hp) { - std::wstringstream RCode(L"R"); + std::wstringstream RCode; + RCode << "R"; if (hp.type & USING_UNICODE) { @@ -185,7 +191,7 @@ namespace RCode << std::uppercase << std::hex; - if (hp.type & DATA_INDIRECT) RCode << "*" << hp.index; + if (hp.type & DATA_INDIRECT) RCode << "*" << HexString(hp.index); RCode << "@" << hp.address; @@ -194,7 +200,8 @@ namespace std::wstring GenerateHCode(HookParam hp, DWORD processId) { - std::wstringstream HCode(L"H"); + std::wstringstream HCode; + HCode << "H"; if (hp.type & USING_UNICODE) { @@ -217,10 +224,10 @@ namespace if (hp.offset < 0) hp.offset += 4; if (hp.split < 0) hp.split += 4; - HCode << hp.offset; - if (hp.type & DATA_INDIRECT) HCode << "*" << hp.index; - if (hp.type & USING_SPLIT) HCode << ":" << hp.split; - if (hp.type & SPLIT_INDIRECT) HCode << "*" << hp.split_index; + HCode << HexString(hp.offset); + if (hp.type & DATA_INDIRECT) HCode << "*" << HexString(hp.index); + if (hp.type & USING_SPLIT) HCode << ":" << HexString(hp.split); + if (hp.type & SPLIT_INDIRECT) HCode << "*" << HexString(hp.split_index); // Attempt to make the address relative if (!(hp.type & MODULE_OFFSET))