1
0
Fork 0

DBG: fixed a bug in the module enumeration function + better readable ListInfo (now you can use ListOf(ModuleInfo) instead of ListInfo*)

This commit is contained in:
Mr. eXoDia 2015-08-02 19:06:51 +02:00
parent 11affdd5f0
commit 4c313061cf
3 changed files with 19 additions and 14 deletions

View File

@ -3,11 +3,13 @@
typedef struct
{
size_t count; //Number of element in the list.
int count; //Number of element in the list.
size_t size; //Size of list in bytes (used for type checking).
void* data; //Pointer to the list contents. Must be deleted by the caller using BridgeFree (or List::Free).
} ListInfo;
#define ListOf(Type) ListInfo*
#ifdef __cplusplus
#include <vector>
@ -50,7 +52,7 @@ public:
\brief Gets the number of elements in the list. This will crash the program if the data is not consistent with the specified template argument.
\return The number of elements in the list.
*/
inline size_t count() const
inline int count() const
{
if(_listInfo.size != _listInfo.count * sizeof(Type)) //make sure the user is using the correct type.
__debugbreak();
@ -70,11 +72,12 @@ public:
}
/**
\brief Reference operator.
\brief Reference operator (cleans up the previous list)
\return Pointer to the ListInfo.
*/
inline ListInfo* operator&()
{
cleanup();
return &_listInfo;
}
@ -100,7 +103,7 @@ public:
{
if (!listInfo)
return false;
listInfo->count = listData.size();
listInfo->count = int(listData.size());
listInfo->size = listInfo->count * sizeof(Type);
if (listInfo->count)
{

View File

@ -99,13 +99,14 @@ 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)
SCRIPT_EXPORT bool Script::Module::SectionListFromAddr(duint addr, ListOf(ModuleSectionInfo) listInfo)
{
SHARED_ACQUIRE(LockModules);
MODINFO* modInfo = ModInfoFromAddr(addr);
if (!modInfo)
return false;
std::vector<ModuleSectionInfo> scriptSectionList(modInfo->sections.size());
std::vector<ModuleSectionInfo> scriptSectionList;
scriptSectionList.reserve(modInfo->sections.size());
for (const auto & section : modInfo->sections)
{
ModuleSectionInfo scriptSection;
@ -116,7 +117,7 @@ SCRIPT_EXPORT bool Script::Module::SectionListFromAddr(duint addr, ListInfo* lis
return List<ModuleSectionInfo>::CopyData(listInfo, scriptSectionList);
}
SCRIPT_EXPORT bool Script::Module::SectionListFromName(const char* name, ListInfo* listInfo)
SCRIPT_EXPORT bool Script::Module::SectionListFromName(const char* name, ListOf(ModuleSectionInfo) listInfo)
{
return Module::SectionListFromAddr(Module::BaseFromName(name), listInfo);
}
@ -156,16 +157,17 @@ SCRIPT_EXPORT bool Script::Module::GetMainModulePath(char* path)
return Module::PathFromAddr(Module::GetMainModuleBase(), path);
}
SCRIPT_EXPORT bool Script::Module::GetMainModuleSectionList(ListInfo* listInfo)
SCRIPT_EXPORT bool Script::Module::GetMainModuleSectionList(ListOf(ModuleSectionInfo) listInfo)
{
return Module::SectionListFromAddr(Module::GetMainModuleBase(), listInfo);
}
SCRIPT_EXPORT bool Script::Module::GetList(ListInfo* listInfo)
SCRIPT_EXPORT bool Script::Module::GetList(ListOf(ModuleInfo) listInfo)
{
std::vector<MODINFO> modList;
ModGetList(modList);
std::vector<ModuleInfo> modScriptList(modList.size());
std::vector<ModuleInfo> modScriptList;
modScriptList.reserve(modList.size());
for (const auto & mod : modList)
{
ModuleInfo scriptMod;

View File

@ -39,8 +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 SectionListFromAddr(duint addr, ListOf(ModuleSectionInfo) listInfo);
SCRIPT_EXPORT bool SectionListFromName(const char* name, ListOf(ModuleSectionInfo) listInfo);
SCRIPT_EXPORT bool GetMainModuleInfo(ModuleInfo* info);
SCRIPT_EXPORT duint GetMainModuleBase();
SCRIPT_EXPORT duint GetMainModuleSize();
@ -48,8 +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
SCRIPT_EXPORT bool GetMainModuleSectionList(ListOf(ModuleSectionInfo) listInfo); //caller has the responsibility to free the list
SCRIPT_EXPORT bool GetList(ListOf(ModuleInfo) listInfo); //caller has the responsibility to free the list
}; //Module
}; //Script