1
0
Fork 0

DBG: extended the scriptapi to support Get/Set/Delete/Enum/Whatever for labels/comments/bookmarks/functions

This commit is contained in:
mrexodia 2016-01-07 11:51:20 +01:00
parent 20e0803ad4
commit ce7a77a093
18 changed files with 518 additions and 12 deletions

View File

@ -0,0 +1,58 @@
#include "_scriptapi_bookmark.h"
#include "bookmark.h"
SCRIPT_EXPORT bool Script::Bookmark::Set(duint addr, bool manual)
{
return BookmarkSet(addr, manual);
}
SCRIPT_EXPORT bool Script::Bookmark::Get(duint addr)
{
return BookmarkGet(addr);
}
SCRIPT_EXPORT bool Script::Bookmark::GetInfo(duint addr, BookmarkInfo* info)
{
BOOKMARKSINFO comment;
if(!BookmarkGetInfo(addr, &comment))
return false;
if(info)
{
strcpy_s(info->mod, comment.mod);
info->addr = comment.addr;
info->manual = comment.manual;
}
return true;
}
SCRIPT_EXPORT bool Script::Bookmark::Delete(duint addr)
{
return BookmarkDelete(addr);
}
SCRIPT_EXPORT void Script::Bookmark::DeleteRange(duint start, duint end)
{
BookmarkDelRange(start, end);
}
SCRIPT_EXPORT void Script::Bookmark::Clear()
{
BookmarkClear();
}
SCRIPT_EXPORT bool Script::Bookmark::GetList(ListOf(CommentInfo) listInfo)
{
std::vector<BOOKMARKSINFO> bookmarkList;
BookmarkGetList(bookmarkList);
std::vector<BookmarkInfo> bookmarkScriptList;
bookmarkScriptList.reserve(bookmarkList.size());
for(const auto & bookmark : bookmarkList)
{
BookmarkInfo scriptComment;
strcpy_s(scriptComment.mod, bookmark.mod);
scriptComment.addr = bookmark.addr;
scriptComment.manual = bookmark.manual;
bookmarkScriptList.push_back(scriptComment);
}
return List<BookmarkInfo>::CopyData(listInfo, bookmarkScriptList);
}

View File

@ -0,0 +1,27 @@
#ifndef _SCRIPTAPI_MODULE_H
#define _SCRIPTAPI_MODULE_H
#include "_scriptapi.h"
namespace Script
{
namespace Bookmark
{
struct BookmarkInfo
{
char mod[MAX_MODULE_SIZE];
duint addr;
bool manual;
};
SCRIPT_EXPORT bool Set(duint addr, bool manual = false);
SCRIPT_EXPORT bool Get(duint addr);
SCRIPT_EXPORT bool GetInfo(duint addr, BookmarkInfo* info);
SCRIPT_EXPORT bool Delete(duint addr);
SCRIPT_EXPORT void DeleteRange(duint start, duint end);
SCRIPT_EXPORT void Clear();
SCRIPT_EXPORT bool GetList(ListOf(BookmarkInfo) listInfo); //caller has the responsibility to free the list
}; //Bookmark
}; //Script
#endif //_SCRIPTAPI_MODULE_H

View File

@ -0,0 +1,60 @@
#include "_scriptapi_comment.h"
#include "comment.h"
SCRIPT_EXPORT bool Script::Comment::Set(duint addr, const char* text, bool manual)
{
return CommentSet(addr, text, manual);
}
SCRIPT_EXPORT bool Script::Comment::Get(duint addr, char* text)
{
return CommentGet(addr, text);
}
SCRIPT_EXPORT bool Script::Comment::GetInfo(duint addr, CommentInfo* info)
{
COMMENTSINFO comment;
if(!CommentGetInfo(addr, &comment))
return false;
if(info)
{
strcpy_s(info->mod, comment.mod);
info->addr = comment.addr;
strcpy_s(info->text, comment.text);
info->manual = comment.manual;
}
return true;
}
SCRIPT_EXPORT bool Script::Comment::Delete(duint addr)
{
return CommentDelete(addr);
}
SCRIPT_EXPORT void Script::Comment::DeleteRange(duint start, duint end)
{
CommentDelRange(start, end);
}
SCRIPT_EXPORT void Script::Comment::Clear()
{
CommentClear();
}
SCRIPT_EXPORT bool Script::Comment::GetList(ListOf(CommentInfo) listInfo)
{
std::vector<COMMENTSINFO> commentList;
CommentGetList(commentList);
std::vector<CommentInfo> commentScriptList;
commentScriptList.reserve(commentList.size());
for(const auto & comment : commentList)
{
CommentInfo scriptComment;
strcpy_s(scriptComment.mod, comment.mod);
scriptComment.addr = comment.addr;
strcpy_s(scriptComment.text, comment.text);
scriptComment.manual = comment.manual;
commentScriptList.push_back(scriptComment);
}
return List<CommentInfo>::CopyData(listInfo, commentScriptList);
}

View File

@ -0,0 +1,28 @@
#ifndef _SCRIPTAPI_MODULE_H
#define _SCRIPTAPI_MODULE_H
#include "_scriptapi.h"
namespace Script
{
namespace Comment
{
struct CommentInfo
{
char mod[MAX_MODULE_SIZE];
duint addr;
char text[MAX_LABEL_SIZE];
bool manual;
};
SCRIPT_EXPORT bool Set(duint addr, const char* text, bool manual = false);
SCRIPT_EXPORT bool Get(duint addr, char* text);
SCRIPT_EXPORT bool GetInfo(duint addr, CommentInfo* info);
SCRIPT_EXPORT bool Delete(duint addr);
SCRIPT_EXPORT void DeleteRange(duint start, duint end);
SCRIPT_EXPORT void Clear();
SCRIPT_EXPORT bool GetList(ListOf(CommentInfo) listInfo); //caller has the responsibility to free the list
}; //Comment
}; //Script
#endif //_SCRIPTAPI_MODULE_H

View File

@ -0,0 +1,67 @@
#include "_scriptapi_function.h"
#include "function.h"
SCRIPT_EXPORT bool Script::Function::Add(duint start, duint end, bool manual, duint instructionCount)
{
return FunctionAdd(start, end, manual, instructionCount);
}
SCRIPT_EXPORT bool Script::Function::Get(duint addr, duint* start, duint* end, duint* instructionCount)
{
return FunctionGet(addr, start, end, instructionCount);
}
SCRIPT_EXPORT bool Script::Function::GetInfo(duint addr, FunctionInfo* info)
{
FUNCTIONSINFO function;
if(!FunctionGetInfo(addr, &function))
return false;
if(info)
{
strcpy_s(info->mod, function.mod);
info->start = function.start;
info->end = function.end;
info->manual = function.manual;
info->instructioncount = function.instructioncount;
}
return true;
}
SCRIPT_EXPORT bool Script::Function::Overlaps(duint start, duint end)
{
return FunctionOverlaps(start, end);
}
SCRIPT_EXPORT bool Script::Function::Delete(duint address)
{
return FunctionDelete(address);
}
SCRIPT_EXPORT void Script::Function::DeleteRange(duint start, duint end)
{
FunctionDelRange(start, end);
}
SCRIPT_EXPORT void Script::Function::Clear()
{
FunctionClear();
}
SCRIPT_EXPORT bool Script::Function::GetList(ListOf(FunctionInfo) listInfo)
{
std::vector<FUNCTIONSINFO> functionList;
FunctionGetList(functionList);
std::vector<FunctionInfo> functionScriptList;
functionScriptList.reserve(functionList.size());
for(const auto & function : functionList)
{
FunctionInfo scriptFunction;
strcpy_s(scriptFunction.mod, function.mod);
scriptFunction.start = function.start;
scriptFunction.end = function.end;
scriptFunction.manual = function.manual;
scriptFunction.instructioncount = function.instructioncount;
functionScriptList.push_back(scriptFunction);
}
return List<FunctionInfo>::CopyData(listInfo, functionScriptList);
}

View File

@ -0,0 +1,30 @@
#ifndef _SCRIPTAPI_MODULE_H
#define _SCRIPTAPI_MODULE_H
#include "_scriptapi.h"
namespace Script
{
namespace Function
{
struct FunctionInfo
{
char mod[MAX_MODULE_SIZE];
duint start;
duint end;
bool manual;
duint instructioncount;
};
SCRIPT_EXPORT bool Add(duint start, duint end, bool manual, duint instructionCount = 0);
SCRIPT_EXPORT bool Get(duint addr, duint* start = nullptr, duint* end = nullptr, duint* instructionCount = nullptr);
SCRIPT_EXPORT bool GetInfo(duint addr, FunctionInfo* info);
SCRIPT_EXPORT bool Overlaps(duint start, duint end);
SCRIPT_EXPORT bool Delete(duint address);
SCRIPT_EXPORT void DeleteRange(duint start, duint end);
SCRIPT_EXPORT void Clear();
SCRIPT_EXPORT bool GetList(ListOf(FunctionInfo) listInfo); //caller has the responsibility to free the list
}; //Function
}; //Script
#endif //_SCRIPTAPI_MODULE_H

View File

@ -0,0 +1,65 @@
#include "_scriptapi_label.h"
#include "label.h"
SCRIPT_EXPORT bool Script::Label::Set(duint addr, const char* text, bool manual)
{
return LabelSet(addr, text, manual);
}
SCRIPT_EXPORT bool Script::Label::FromString(const char* label, duint* addr)
{
return LabelFromString(label, addr);
}
SCRIPT_EXPORT bool Script::Label::Get(duint addr, char* text)
{
return LabelGet(addr, text);
}
SCRIPT_EXPORT bool Script::Label::GetInfo(duint addr, LabelInfo* info)
{
LABELSINFO label;
if(!LabelGetInfo(addr, &label))
return false;
if(info)
{
strcpy_s(info->mod, label.mod);
info->addr = label.addr;
strcpy_s(info->text, label.text);
info->manual = label.manual;
}
return true;
}
SCRIPT_EXPORT bool Script::Label::Delete(duint addr)
{
return LabelDelete(addr);
}
SCRIPT_EXPORT void Script::Label::DeleteRange(duint start, duint end)
{
LabelDelRange(start, end);
}
SCRIPT_EXPORT void Script::Label::Clear()
{
LabelClear();
}
SCRIPT_EXPORT bool Script::Label::GetList(ListOf(LabelInfo) listInfo)
{
std::vector<LABELSINFO> labelList;
LabelGetList(labelList);
std::vector<LabelInfo> labelScriptList;
labelScriptList.reserve(labelList.size());
for(const auto & label : labelList)
{
LabelInfo scriptLabel;
strcpy_s(scriptLabel.mod, label.mod);
scriptLabel.addr = label.addr;
strcpy_s(scriptLabel.text, label.text);
scriptLabel.manual = label.manual;
labelScriptList.push_back(scriptLabel);
}
return List<LabelInfo>::CopyData(listInfo, labelScriptList);
}

View File

@ -0,0 +1,29 @@
#ifndef _SCRIPTAPI_MODULE_H
#define _SCRIPTAPI_MODULE_H
#include "_scriptapi.h"
namespace Script
{
namespace Label
{
struct LabelInfo
{
char mod[MAX_MODULE_SIZE];
duint addr;
char text[MAX_LABEL_SIZE];
bool manual;
};
SCRIPT_EXPORT bool Set(duint addr, const char* text, bool manual = false);
SCRIPT_EXPORT bool FromString(const char* label, duint* addr);
SCRIPT_EXPORT bool Get(duint addr, char* text);
SCRIPT_EXPORT bool GetInfo(duint addr, LabelInfo* info);
SCRIPT_EXPORT bool Delete(duint addr);
SCRIPT_EXPORT void DeleteRange(duint start, duint end);
SCRIPT_EXPORT void Clear();
SCRIPT_EXPORT bool GetList(ListOf(LabelInfo) listInfo); //caller has the responsibility to free the list
}; //Label
}; //Script
#endif //_SCRIPTAPI_MODULE_H

View File

@ -196,4 +196,24 @@ void BookmarkClear()
{
EXCLUSIVE_ACQUIRE(LockBookmarks);
bookmarks.clear();
}
}
void BookmarkGetList(std::vector<BOOKMARKSINFO> & list)
{
SHARED_ACQUIRE(LockBookmarks);
list.clear();
list.reserve(bookmarks.size());
for(const auto & itr : bookmarks)
list.push_back(itr.second);
}
bool BookmarkGetInfo(duint Address, BOOKMARKSINFO* info)
{
SHARED_ACQUIRE(LockBookmarks);
auto found = bookmarks.find(Address);
if(found == bookmarks.end())
return false;
if(info)
memcpy(info, &found->second, sizeof(BOOKMARKSINFO));
return true;
}

View File

@ -16,4 +16,6 @@ void BookmarkDelRange(duint Start, duint End);
void BookmarkCacheSave(JSON Root);
void BookmarkCacheLoad(JSON Root);
bool BookmarkEnum(BOOKMARKSINFO* List, size_t* Size);
void BookmarkClear();
void BookmarkClear();
void BookmarkGetList(std::vector<BOOKMARKSINFO> & list);
bool BookmarkGetInfo(duint Address, BOOKMARKSINFO* info);

View File

@ -53,10 +53,13 @@ bool CommentGet(duint Address, char* Text)
if(found == comments.end())
return false;
if(found->second.manual) //autocomment
strcpy_s(Text, MAX_COMMENT_SIZE, found->second.text);
else
sprintf_s(Text, MAX_COMMENT_SIZE, "\1%s", found->second.text);
if(Text)
{
if(found->second.manual) //autocomment
strcpy_s(Text, MAX_COMMENT_SIZE, found->second.text);
else
sprintf_s(Text, MAX_COMMENT_SIZE, "\1%s", found->second.text);
}
return true;
}
@ -233,4 +236,30 @@ void CommentClear()
{
EXCLUSIVE_ACQUIRE(LockComments);
comments.clear();
}
}
void CommentGetList(std::vector<COMMENTSINFO> & list)
{
SHARED_ACQUIRE(LockComments);
list.clear();
list.reserve(comments.size());
for(const auto & itr : comments)
list.push_back(itr.second);
}
bool CommentGetInfo(duint Address, COMMENTSINFO* info)
{
SHARED_ACQUIRE(LockComments);
// Get an existing comment and copy the string buffer
auto found = comments.find(ModHashFromAddr(Address));
// Was it found?
if(found == comments.end())
return false;
if(info)
memcpy(info, &found->second, sizeof(COMMENTSINFO));
return true;
}

View File

@ -17,4 +17,6 @@ void CommentDelRange(duint Start, duint End);
void CommentCacheSave(JSON Root);
void CommentCacheLoad(JSON Root);
bool CommentEnum(COMMENTSINFO* List, size_t* Size);
void CommentClear();
void CommentClear();
void CommentGetList(std::vector<COMMENTSINFO> & list);
bool CommentGetInfo(duint Address, COMMENTSINFO* info);

View File

@ -252,4 +252,31 @@ void FunctionClear()
{
EXCLUSIVE_ACQUIRE(LockFunctions);
functions.clear();
}
}
void FunctionGetList(std::vector<FUNCTIONSINFO> & list)
{
SHARED_ACQUIRE(LockFunctions);
list.clear();
list.reserve(functions.size());
for(const auto & itr : functions)
list.push_back(itr.second);
}
bool FunctionGetInfo(duint Address, FUNCTIONSINFO* info)
{
auto moduleBase = ModBaseFromAddr(Address);
// Lookup by module hash, then function range
SHARED_ACQUIRE(LockFunctions);
auto found = functions.find(ModuleRange(ModHashFromAddr(moduleBase), Range(Address - moduleBase, Address - moduleBase)));
// Was this range found?
if(found == functions.end())
return false;
if(info)
memcpy(info, &found->second, sizeof(FUNCTIONSINFO));
return true;
}

View File

@ -19,4 +19,6 @@ void FunctionDelRange(duint Start, duint End);
void FunctionCacheSave(JSON Root);
void FunctionCacheLoad(JSON Root);
bool FunctionEnum(FUNCTIONSINFO* List, size_t* Size);
void FunctionClear();
void FunctionClear();
void FunctionGetList(std::vector<FUNCTIONSINFO> & list);
bool FunctionGetInfo(duint Address, FUNCTIONSINFO* info);

View File

@ -262,4 +262,30 @@ void LabelClear()
{
EXCLUSIVE_ACQUIRE(LockLabels);
labels.clear();
}
}
void LabelGetList(std::vector<LABELSINFO> & list)
{
SHARED_ACQUIRE(LockLabels);
list.clear();
list.reserve(labels.size());
for(const auto & itr : labels)
list.push_back(itr.second);
}
bool LabelGetInfo(duint Address, LABELSINFO* info)
{
SHARED_ACQUIRE(LockLabels);
// Was the label at this address exist?
auto found = labels.find(ModHashFromAddr(Address));
if(found == labels.end())
return false;
// Copy to user buffer
if(info)
memcpy(info, &found->second, sizeof(LABELSINFO));
return true;
}

View File

@ -18,4 +18,6 @@ void LabelDelRange(duint Start, duint End);
void LabelCacheSave(JSON root);
void LabelCacheLoad(JSON root);
bool LabelEnum(LABELSINFO* List, size_t* Size);
void LabelClear();
void LabelClear();
void LabelGetList(std::vector<LABELSINFO> & list);
bool LabelGetInfo(duint Address, LABELSINFO* info);

View File

@ -76,9 +76,13 @@
<ClCompile Include="_global.cpp" />
<ClCompile Include="_plugins.cpp" />
<ClCompile Include="_scriptapi_assembler.cpp" />
<ClCompile Include="_scriptapi_bookmark.cpp" />
<ClCompile Include="_scriptapi_comment.cpp" />
<ClCompile Include="_scriptapi_debug.cpp" />
<ClCompile Include="_scriptapi_flag.cpp" />
<ClCompile Include="_scriptapi_function.cpp" />
<ClCompile Include="_scriptapi_gui.cpp" />
<ClCompile Include="_scriptapi_label.cpp" />
<ClCompile Include="_scriptapi_misc.cpp" />
<ClCompile Include="_scriptapi_pattern.cpp" />
<ClCompile Include="_scriptapi_memory.cpp" />
@ -200,9 +204,13 @@
<ClInclude Include="_plugins.h" />
<ClInclude Include="_plugin_types.h" />
<ClInclude Include="_scriptapi_assembler.h" />
<ClInclude Include="_scriptapi_bookmark.h" />
<ClInclude Include="_scriptapi_comment.h" />
<ClInclude Include="_scriptapi_debug.h" />
<ClInclude Include="_scriptapi_flag.h" />
<ClInclude Include="_scriptapi_function.h" />
<ClInclude Include="_scriptapi_gui.h" />
<ClInclude Include="_scriptapi_label.h" />
<ClInclude Include="_scriptapi_misc.h" />
<ClInclude Include="_scriptapi_pattern.h" />
<ClInclude Include="_scriptapi_memory.h" />

View File

@ -281,6 +281,18 @@
<ClCompile Include="commandline.cpp">
<Filter>Source Files\Information</Filter>
</ClCompile>
<ClCompile Include="_scriptapi_label.cpp">
<Filter>Source Files\Interfaces/Exports\_scriptapi</Filter>
</ClCompile>
<ClCompile Include="_scriptapi_comment.cpp">
<Filter>Source Files\Interfaces/Exports\_scriptapi</Filter>
</ClCompile>
<ClCompile Include="_scriptapi_bookmark.cpp">
<Filter>Source Files\Interfaces/Exports\_scriptapi</Filter>
</ClCompile>
<ClCompile Include="_scriptapi_function.cpp">
<Filter>Source Files\Interfaces/Exports\_scriptapi</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="x64_dbg.h">
@ -649,5 +661,17 @@
<ClInclude Include="commandline.h">
<Filter>Header Files\Information</Filter>
</ClInclude>
<ClInclude Include="_scriptapi_label.h">
<Filter>Header Files\Interfaces/Exports\_scriptapi</Filter>
</ClInclude>
<ClInclude Include="_scriptapi_comment.h">
<Filter>Header Files\Interfaces/Exports\_scriptapi</Filter>
</ClInclude>
<ClInclude Include="_scriptapi_bookmark.h">
<Filter>Header Files\Interfaces/Exports\_scriptapi</Filter>
</ClInclude>
<ClInclude Include="_scriptapi_function.h">
<Filter>Header Files\Interfaces/Exports\_scriptapi</Filter>
</ClInclude>
</ItemGroup>
</Project>