Skip to content

Commit 58b494f

Browse files
committed
added symbol names for addresses in disassembly view
1 parent 048914d commit 58b494f

7 files changed

+196
-136
lines changed

TotalPE/ExportsView.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ LRESULT CExportsView::OnDissassemble(WORD, WORD, HWND, BOOL&) const {
150150
auto code = m_PE.GetSpan(offset, size);
151151

152152
ULONGLONG imageBase = m_PE->GetFileInfo()->IsPE64 ? m_PE->GetNTHeader()->NTHdr64.OptionalHeader.ImageBase : m_PE->GetNTHeader()->NTHdr32.OptionalHeader.ImageBase;
153-
Frame()->CreateAssemblyView(code, offset + imageBase, exp.FuncRVA,
153+
Frame()->CreateAssemblyView(code, exp.FuncRVA + imageBase, exp.FuncRVA,
154154
exp.Name.c_str(), TreeItemType::DirectoryExports);
155155

156156
return 0;

TotalPE/PEStrings.cpp

+22-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <atltime.h>
44
#include <DbgHelp.h>
55
#include "..\External\Capstone\capstone.h"
6+
#include <DiaHelper.h>
67

78
#pragma comment(lib, "dbghelp")
89

@@ -190,10 +191,27 @@ std::wstring PEStrings::ResourceTypeToString(WORD id) {
190191
return id >= _countof(types) ? L"" : types[id];
191192
}
192193

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);
197215
for (int i = 0; i < inst.size; i++)
198216
text += std::format(" {:02X}", inst.bytes[i]).c_str();
199217
return text;

TotalPE/PEStrings.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
struct cs_insn;
44
enum class SymbolTag;
55
enum class LocationKind;
6+
class DiaSession;
67

78
enum class DllCharacteristics : unsigned short {
89
None = 0,
@@ -32,7 +33,7 @@ struct PEStrings abstract final {
3233
static std::wstring ToHex(ULONGLONG value);
3334
static std::wstring ToMemorySize(ULONGLONG size);
3435
static std::wstring ResourceTypeToString(WORD id);
35-
static CStringA FormatInstruction(const cs_insn& inst);
36+
static CStringA FormatInstruction(const cs_insn& inst, DiaSession const& symbols);
3637
static std::wstring ManagedTypeAttributesToString(CorTypeAttr attr);
3738
//static std::wstring MemberAttributesToString(const ManagedMember& member);
3839
static std::wstring MethodAttributesToString(CorMethodAttr attr);

TotalPE/ScintillaView.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ bool CScintillaView::SetAsmCode(std::span<const std::byte> code, uint64_t addres
128128
cs_insn inst{};
129129
CStringA text;
130130
while (cs_disasm_iter(handle, &bytes, &size, &address, &inst)) {
131-
text += PEStrings::FormatInstruction(inst) + L"\r\n";
131+
text += PEStrings::FormatInstruction(inst, Frame()->GetSymbols()) + L"\r\n";
132132
if (_strcmpi(inst.mnemonic, "ret") == 0)
133133
break;
134134
}
@@ -252,7 +252,7 @@ LRESULT CScintillaView::OnDisassembleAtEnd(WORD, WORD, HWND, BOOL&) {
252252
cs_insn inst{};
253253
CStringA text;
254254
while (cs_disasm_iter(handle, &bytes, &size, &address, &inst)) {
255-
text += PEStrings::FormatInstruction(inst) + L"\r\n";
255+
text += PEStrings::FormatInstruction(inst, Frame()->GetSymbols()) + L"\r\n";
256256
if (_strcmpi(inst.mnemonic, "ret") == 0)
257257
break;
258258
}

TotalPE/StructView.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@ LRESULT CStructView::OnCreate(UINT, WPARAM, LPARAM, BOOL&) {
2727

2828
m_TL.Create(m_Splitter, rcDefault, nullptr, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN |
2929
LVS_REPORT | LVS_SHAREIMAGELISTS | LVS_NOSORTHEADER);
30-
m_TL.SetExtendedListViewStyle(LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT);
30+
m_TL.SetExtendedListViewStyle(LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
3131
m_TL.SetImageList(Frame()->GetImageList(), LVSIL_SMALL);
32-
// m_TL.SetIcons(AtlLoadIconImage(IDI_EXPANDED, 0, 16, 16), AtlLoadIconImage(IDI_COLLAPSED, 0, 16, 16));
3332
m_TL.InsertColumn(0, L"Member", LVCFMT_LEFT, 250);
3433
m_TL.InsertColumn(1, L"Offset", LVCFMT_RIGHT, 60);
3534
m_TL.InsertColumn(2, L"Type", 0, 180);
36-
m_TL.InsertColumn(3, L"Value", 0, 150);
37-
m_TL.InsertColumn(4, L"Details", 0, 150);
35+
m_TL.InsertColumn(3, L"Value", LVCFMT_RIGHT, 150);
3836

3937
m_HexView.Create(m_Splitter, rcDefault, nullptr, WS_CHILD | WS_VISIBLE);
4038
m_HexView.SetStatic(true);

0 commit comments

Comments
 (0)