Skip to content

Commit 0115164

Browse files
committed
DBG: added modentryfromaddr function
1 parent a4a3eaa commit 0115164

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

x64_dbg_dbg/addrinfo.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ bool modload(uint base, uint size, const char* fullpath)
9999
while(name[len] != '.' and len)
100100
len--;
101101
MODINFO info;
102+
memset(&info, 0, sizeof(MODINFO));
102103
info.sections.clear();
103104
info.hash = modhashfromname(name);
104105
if(len)
@@ -117,6 +118,7 @@ bool modload(uint base, uint size, const char* fullpath)
117118
ULONG_PTR FileMapVA;
118119
if(StaticFileLoad((char*)fullpath, UE_ACCESS_READ, false, &FileHandle, &LoadedSize, &FileMap, &FileMapVA))
119120
{
121+
info.entry = GetPE32DataFromMappedFile(FileMapVA, 0, UE_OEP) + info.base; //get entry point
120122
int SectionCount = (int)GetPE32DataFromMappedFile(FileMapVA, 0, UE_SECTIONNUMBER);
121123
if(SectionCount > 0)
122124
{
@@ -268,6 +270,14 @@ bool modsectionsfromaddr(uint addr, std::vector<MODSECTIONINFO>* sections)
268270
return true;
269271
}
270272

273+
uint modentryfromaddr(uint addr)
274+
{
275+
const ModulesInfo::iterator found = modinfo.find(Range(addr, addr));
276+
if(found == modinfo.end()) //not found
277+
return 0;
278+
return found->second.entry;
279+
}
280+
271281
///api functions
272282
bool apienumexports(uint base, EXPORTENUMCALLBACK cbEnum)
273283
{

x64_dbg_dbg/addrinfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct MODINFO
6565
uint base; //module base
6666
uint size; //module size
6767
uint hash; //full module name hash
68+
uint entry; //entry point
6869
char name[MAX_MODULE_SIZE]; //module name (without extension)
6970
char extension[MAX_MODULE_SIZE]; //file extension
7071
std::vector<MODSECTIONINFO> sections;
@@ -134,6 +135,7 @@ uint modhashfromname(const char* mod);
134135
uint modbasefromname(const char* modname);
135136
uint modsizefromaddr(uint addr);
136137
bool modsectionsfromaddr(uint addr, std::vector<MODSECTIONINFO>* sections);
138+
uint modentryfromaddr(uint addr);
137139

138140
bool apienumexports(uint base, EXPORTENUMCALLBACK cbEnum);
139141

0 commit comments

Comments
 (0)