DBG: extended script api with module and section enumeration functions
This commit is contained in:
parent
c567996372
commit
f3ad2bc8b5
|
@ -10,6 +10,8 @@ typedef struct
|
|||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
\brief A list object. This object is NOT thread safe.
|
||||
\tparam Type List contents type.
|
||||
|
@ -62,35 +64,16 @@ public:
|
|||
{
|
||||
if(_listInfo.data)
|
||||
{
|
||||
Free(_listInfo.data);
|
||||
BridgeFree(_listInfo.data);
|
||||
_listInfo.data = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Allocates memory with the given size.
|
||||
\param size The size to allocate.
|
||||
\return A pointer to the allocated data. Cannot return null.
|
||||
*/
|
||||
static void* Alloc(size_t size)
|
||||
{
|
||||
return BridgeAlloc(size);
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Frees data allocated by List::Alloc.
|
||||
\param [in] The data to free.
|
||||
*/
|
||||
static void Free(void* ptr)
|
||||
{
|
||||
BridgeFree(ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Reference operator.
|
||||
\return Pointer to the ListInfo.
|
||||
*/
|
||||
ListInfo* operator&()
|
||||
inline ListInfo* operator&()
|
||||
{
|
||||
return &_listInfo;
|
||||
}
|
||||
|
@ -107,6 +90,33 @@ public:
|
|||
return data()[index];
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Copies data to a ListInfo structure..
|
||||
\param [out] listInfo If non-null, information describing the list.
|
||||
\param listData Data to copy in the ListInfo structure.
|
||||
\return true if it succeeds, false if it fails.
|
||||
*/
|
||||
static inline bool CopyData(ListInfo* listInfo, const std::vector<Type> & listData)
|
||||
{
|
||||
if (!listInfo)
|
||||
return false;
|
||||
listInfo->count = listData.size();
|
||||
listInfo->size = listInfo->count * sizeof(Type);
|
||||
if (listInfo->count)
|
||||
{
|
||||
listInfo->data = BridgeAlloc(listInfo->size);
|
||||
Type* curItem = reinterpret_cast<Type*>(listInfo->data);
|
||||
for (const auto & item : listData)
|
||||
{
|
||||
*curItem = item;
|
||||
++curItem;
|
||||
}
|
||||
}
|
||||
else
|
||||
listInfo->data = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
ListInfo _listInfo;
|
||||
};
|
||||
|
|
|
@ -24,10 +24,10 @@ SCRIPT_EXPORT duint Script::Misc::ResolveLabel(const char* label)
|
|||
|
||||
SCRIPT_EXPORT void* Script::Misc::Alloc(duint size)
|
||||
{
|
||||
return emalloc(size, "Script::Misc::Alloc");
|
||||
return BridgeAlloc(size);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT void Script::Misc::Free(void* ptr)
|
||||
{
|
||||
return efree(ptr, "Script::Misc::Free");
|
||||
return BridgeFree(ptr);
|
||||
}
|
|
@ -1,16 +1,18 @@
|
|||
#include "_scriptapi_module.h"
|
||||
#include "threading.h"
|
||||
#include "module.h"
|
||||
#include "debugger.h"
|
||||
|
||||
SCRIPT_EXPORT bool Script::Module::InfoFromAddr(duint addr, Script::Module::ModuleInfo* info)
|
||||
{
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
MODINFO* modInfo = ModInfoFromAddr(addr);
|
||||
if(!info || !modInfo)
|
||||
return false;
|
||||
info->base = modInfo->base;
|
||||
info->size = modInfo->size;
|
||||
info->entry = modInfo->entry;
|
||||
info->sectionCount = (int)modInfo->sections.size();
|
||||
info->sectionCount = int(modInfo->sections.size());
|
||||
strcpy_s(info->name, modInfo->name);
|
||||
strcat_s(info->name, modInfo->extension);
|
||||
strcpy_s(info->path, modInfo->path);
|
||||
|
@ -69,8 +71,9 @@ SCRIPT_EXPORT duint Script::Module::EntryFromName(const char* name)
|
|||
|
||||
SCRIPT_EXPORT int Script::Module::SectionCountFromAddr(duint addr)
|
||||
{
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
MODINFO* modInfo = ModInfoFromAddr(addr);
|
||||
return modInfo ? (int)modInfo->sections.size() : 0;
|
||||
return modInfo ? int(modInfo->sections.size()) : 0;
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT int Script::Module::SectionCountFromName(const char* name)
|
||||
|
@ -80,8 +83,9 @@ SCRIPT_EXPORT int Script::Module::SectionCountFromName(const char* name)
|
|||
|
||||
SCRIPT_EXPORT bool Script::Module::SectionFromAddr(duint addr, int number, ModuleSectionInfo* section)
|
||||
{
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
MODINFO* modInfo = ModInfoFromAddr(addr);
|
||||
if(!section || !modInfo || number < 0 || number >= (int)modInfo->sections.size())
|
||||
if(!section || !modInfo || number < 0 || number >= int(modInfo->sections.size()))
|
||||
return false;
|
||||
const MODSECTIONINFO & secInfo = modInfo->sections.at(number);
|
||||
section->addr = secInfo.addr;
|
||||
|
@ -95,6 +99,28 @@ SCRIPT_EXPORT bool Script::Module::SectionFromName(const char* name, int number,
|
|||
return Module::SectionFromAddr(Module::BaseFromName(name), number, section);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Module::SectionListFromAddr(duint addr, ListInfo* listInfo)
|
||||
{
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
MODINFO* modInfo = ModInfoFromAddr(addr);
|
||||
if (!modInfo)
|
||||
return false;
|
||||
std::vector<ModuleSectionInfo> scriptSectionList(modInfo->sections.size());
|
||||
for (const auto & section : modInfo->sections)
|
||||
{
|
||||
ModuleSectionInfo scriptSection;
|
||||
scriptSection.addr = section.addr;
|
||||
scriptSection.size = section.size;
|
||||
strcpy_s(scriptSection.name, section.name);
|
||||
}
|
||||
return List<ModuleSectionInfo>::CopyData(listInfo, scriptSectionList);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Module::SectionListFromName(const char* name, ListInfo* listInfo)
|
||||
{
|
||||
return Module::SectionListFromAddr(Module::BaseFromName(name), listInfo);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Module::GetMainModuleInfo(ModuleInfo* info)
|
||||
{
|
||||
return Module::InfoFromAddr(Module::GetMainModuleBase(), info);
|
||||
|
@ -128,4 +154,29 @@ SCRIPT_EXPORT bool Script::Module::GetMainModuleName(char* name)
|
|||
SCRIPT_EXPORT bool Script::Module::GetMainModulePath(char* path)
|
||||
{
|
||||
return Module::PathFromAddr(Module::GetMainModuleBase(), path);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Module::GetMainModuleSectionList(ListInfo* listInfo)
|
||||
{
|
||||
return Module::SectionListFromAddr(Module::GetMainModuleBase(), listInfo);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Module::GetList(ListInfo* listInfo)
|
||||
{
|
||||
std::vector<MODINFO> modList;
|
||||
ModGetList(modList);
|
||||
std::vector<ModuleInfo> modScriptList(modList.size());
|
||||
for (const auto & mod : modList)
|
||||
{
|
||||
ModuleInfo scriptMod;
|
||||
scriptMod.base = mod.base;
|
||||
scriptMod.size = mod.size;
|
||||
scriptMod.entry = mod.entry;
|
||||
scriptMod.sectionCount = int(mod.sections.size());
|
||||
strcpy_s(scriptMod.name, mod.name);
|
||||
strcat_s(scriptMod.name, mod.extension);
|
||||
strcpy_s(scriptMod.path, mod.path);
|
||||
modScriptList.push_back(scriptMod);
|
||||
}
|
||||
return List<ModuleInfo>::CopyData(listInfo, modScriptList);
|
||||
}
|
|
@ -39,6 +39,8 @@ SCRIPT_EXPORT int SectionCountFromAddr(duint addr);
|
|||
SCRIPT_EXPORT int SectionCountFromName(const char* name);
|
||||
SCRIPT_EXPORT bool SectionFromAddr(duint addr, int number, ModuleSectionInfo* section);
|
||||
SCRIPT_EXPORT bool SectionFromName(const char* name, int number, ModuleSectionInfo* section);
|
||||
SCRIPT_EXPORT bool SectionListFromAddr(duint addr, ListInfo* listInfo);
|
||||
SCRIPT_EXPORT bool SectionListFromName(const char* name, ListInfo* listInfo);
|
||||
SCRIPT_EXPORT bool GetMainModuleInfo(ModuleInfo* info);
|
||||
SCRIPT_EXPORT duint GetMainModuleBase();
|
||||
SCRIPT_EXPORT duint GetMainModuleSize();
|
||||
|
@ -46,6 +48,8 @@ SCRIPT_EXPORT duint GetMainModuleEntry();
|
|||
SCRIPT_EXPORT int GetMainModuleSectionCount();
|
||||
SCRIPT_EXPORT bool GetMainModuleName(char* name); //name[MAX_MODULE_SIZE]
|
||||
SCRIPT_EXPORT bool GetMainModulePath(char* path); //path[MAX_PATH]
|
||||
SCRIPT_EXPORT bool GetMainModuleSectionList(ListInfo* listInfo); //caller has the responsibility to free the list
|
||||
SCRIPT_EXPORT bool GetList(ListInfo* listInfo); //caller has the responsibility to free the list
|
||||
}; //Module
|
||||
}; //Script
|
||||
|
||||
|
|
|
@ -323,4 +323,12 @@ int ModPathFromAddr(duint Address, char* Path, int Size)
|
|||
int ModPathFromName(const char* Module, char* Path, int Size)
|
||||
{
|
||||
return ModPathFromAddr(ModBaseFromName(Module), Path, Size);
|
||||
}
|
||||
|
||||
void ModGetList(std::vector<MODINFO> & list)
|
||||
{
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
list.clear();
|
||||
for (const auto & mod : modinfo)
|
||||
list.push_back(mod.second);
|
||||
}
|
|
@ -36,4 +36,5 @@ uint ModSizeFromAddr(uint Address);
|
|||
bool ModSectionsFromAddr(uint Address, std::vector<MODSECTIONINFO>* Sections);
|
||||
uint ModEntryFromAddr(uint Address);
|
||||
int ModPathFromAddr(duint Address, char* Path, int Size);
|
||||
int ModPathFromName(const char* Module, char* Path, int Size);
|
||||
int ModPathFromName(const char* Module, char* Path, int Size);
|
||||
void ModGetList(std::vector<MODINFO> & list);
|
Loading…
Reference in New Issue