|
3 | 3 | #include <atltime.h>
|
4 | 4 | #include <DbgHelp.h>
|
5 | 5 | #include "..\External\Capstone\capstone.h"
|
| 6 | +#include <DiaHelper.h> |
6 | 7 |
|
7 | 8 | #pragma comment(lib, "dbghelp")
|
8 | 9 |
|
@@ -190,10 +191,27 @@ std::wstring PEStrings::ResourceTypeToString(WORD id) {
|
190 | 191 | return id >= _countof(types) ? L"" : types[id];
|
191 | 192 | }
|
192 | 193 |
|
193 |
| -CStringA PEStrings::FormatInstruction(const cs_insn& inst) { |
194 |
| - CStringA text; |
195 |
| - text.Format("%llX %-10s %-40s ;", inst.address, inst.mnemonic, inst.op_str); |
196 |
| -// text.Format("%-10s %-40s ;", inst.mnemonic, inst.op_str); |
| 194 | +CStringA PEStrings::FormatInstruction(const cs_insn& inst, DiaSession const& symbols) { |
| 195 | + CStringA text, extra; |
| 196 | + static PCSTR branches[] = { "call", "je", "jmp", "jne", "js" }; |
| 197 | + for (auto& br : branches) |
| 198 | + if (_stricmp(inst.mnemonic, br) == 0) { |
| 199 | + long disp; |
| 200 | + auto address = strtoll(inst.op_str, nullptr, 16); |
| 201 | + if (address != 0 && address != LLONG_MAX && address != LLONG_MIN) { |
| 202 | + auto sym = symbols.GetSymbolByVA(address, SymbolTag::Null, &disp); |
| 203 | + if (sym) { |
| 204 | + extra = sym.Name().c_str(); |
| 205 | + if (!extra.IsEmpty() && disp) |
| 206 | + extra += std::format(" + 0x{:X}", disp).c_str(); |
| 207 | + } |
| 208 | + } |
| 209 | + break; |
| 210 | + } |
| 211 | + |
| 212 | + if (!extra.IsEmpty()) |
| 213 | + extra = std::format("{} ({})", inst.op_str, (PCSTR)extra).c_str(); |
| 214 | + text.Format("%llX %-10s %-55s;", inst.address, inst.mnemonic, !extra.IsEmpty() ? (PCSTR)extra : inst.op_str); |
197 | 215 | for (int i = 0; i < inst.size; i++)
|
198 | 216 | text += std::format(" {:02X}", inst.bytes[i]).c_str();
|
199 | 217 | return text;
|
|
0 commit comments