DBG: improved Script:: Bookmark/Comment/Function/Label functions
This commit is contained in:
parent
e1dfb0c813
commit
b69ef83e01
|
@ -26,7 +26,7 @@ public:
|
|||
\brief List constructor.
|
||||
\param _freeData (Optional) the free function.
|
||||
*/
|
||||
explicit inline List()
|
||||
explicit List()
|
||||
{
|
||||
memset(&_listInfo, 0, sizeof(_listInfo));
|
||||
}
|
||||
|
@ -34,16 +34,16 @@ public:
|
|||
/**
|
||||
\brief List destructor.
|
||||
*/
|
||||
inline ~List()
|
||||
~List()
|
||||
{
|
||||
cleanup();
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Gets the list data.
|
||||
\return Returns ListInfo->data. Can be null if the list was never initialized. Will be destroyed once this object goes out of scope!
|
||||
*/
|
||||
inline Type* data() const
|
||||
Type* Data() const
|
||||
{
|
||||
return reinterpret_cast<Type*>(_listInfo.data);
|
||||
}
|
||||
|
@ -52,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 int count() const
|
||||
int Count() const
|
||||
{
|
||||
if(_listInfo.size != _listInfo.count * sizeof(Type)) //make sure the user is using the correct type.
|
||||
__debugbreak();
|
||||
|
@ -62,7 +62,7 @@ public:
|
|||
/**
|
||||
\brief Cleans up the list, freeing the list data when it is not null.
|
||||
*/
|
||||
inline void cleanup()
|
||||
void Cleanup()
|
||||
{
|
||||
if(_listInfo.data)
|
||||
{
|
||||
|
@ -75,9 +75,9 @@ public:
|
|||
\brief Reference operator (cleans up the previous list)
|
||||
\return Pointer to the ListInfo.
|
||||
*/
|
||||
inline ListInfo* operator&()
|
||||
ListInfo* operator&()
|
||||
{
|
||||
cleanup();
|
||||
Cleanup();
|
||||
return &_listInfo;
|
||||
}
|
||||
|
||||
|
@ -86,11 +86,11 @@ public:
|
|||
\param index Zero-based index of the item you want to get.
|
||||
\return Reference to a value at that index.
|
||||
*/
|
||||
inline Type & operator[](size_t index) const
|
||||
Type & operator[](size_t index) const
|
||||
{
|
||||
if(index >= size_t(count())) //make sure the out-of-bounds access is caught as soon as possible.
|
||||
if(index >= size_t(Count())) //make sure the out-of-bounds access is caught as soon as possible.
|
||||
__debugbreak();
|
||||
return data()[index];
|
||||
return Data()[index];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,7 +99,7 @@ public:
|
|||
\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)
|
||||
static bool CopyData(ListInfo* listInfo, const std::vector<Type> & listData)
|
||||
{
|
||||
if(!listInfo)
|
||||
return false;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "_scriptapi_bookmark.h"
|
||||
#include "_scriptapi_module.h"
|
||||
#include "bookmark.h"
|
||||
|
||||
SCRIPT_EXPORT bool Script::Bookmark::Set(duint addr, bool manual)
|
||||
|
@ -6,6 +7,16 @@ SCRIPT_EXPORT bool Script::Bookmark::Set(duint addr, bool manual)
|
|||
return BookmarkSet(addr, manual);
|
||||
}
|
||||
|
||||
bool Script::Bookmark::Set(const BookmarkInfo* info)
|
||||
{
|
||||
if(!info)
|
||||
return false;
|
||||
auto base = Module::BaseFromName(info->mod);
|
||||
if(!base)
|
||||
return false;
|
||||
return Set(base + info->rva, info->manual);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Bookmark::Get(duint addr)
|
||||
{
|
||||
return BookmarkGet(addr);
|
||||
|
@ -19,7 +30,7 @@ SCRIPT_EXPORT bool Script::Bookmark::GetInfo(duint addr, BookmarkInfo* info)
|
|||
if(info)
|
||||
{
|
||||
strcpy_s(info->mod, comment.mod);
|
||||
info->addr = comment.addr;
|
||||
info->rva = comment.addr;
|
||||
info->manual = comment.manual;
|
||||
}
|
||||
return true;
|
||||
|
@ -50,7 +61,7 @@ SCRIPT_EXPORT bool Script::Bookmark::GetList(ListOf(CommentInfo) listInfo)
|
|||
{
|
||||
BookmarkInfo scriptComment;
|
||||
strcpy_s(scriptComment.mod, bookmark.mod);
|
||||
scriptComment.addr = bookmark.addr;
|
||||
scriptComment.rva = bookmark.addr;
|
||||
scriptComment.manual = bookmark.manual;
|
||||
bookmarkScriptList.push_back(scriptComment);
|
||||
}
|
||||
|
|
|
@ -10,11 +10,12 @@ namespace Script
|
|||
struct BookmarkInfo
|
||||
{
|
||||
char mod[MAX_MODULE_SIZE];
|
||||
duint addr;
|
||||
duint rva;
|
||||
bool manual;
|
||||
};
|
||||
|
||||
SCRIPT_EXPORT bool Set(duint addr, bool manual = false);
|
||||
SCRIPT_EXPORT bool Set(const BookmarkInfo* info);
|
||||
SCRIPT_EXPORT bool Get(duint addr);
|
||||
SCRIPT_EXPORT bool GetInfo(duint addr, BookmarkInfo* info);
|
||||
SCRIPT_EXPORT bool Delete(duint addr);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "_scriptapi_comment.h"
|
||||
#include "_scriptapi_module.h"
|
||||
#include "comment.h"
|
||||
|
||||
SCRIPT_EXPORT bool Script::Comment::Set(duint addr, const char* text, bool manual)
|
||||
|
@ -6,6 +7,16 @@ SCRIPT_EXPORT bool Script::Comment::Set(duint addr, const char* text, bool manua
|
|||
return CommentSet(addr, text, manual);
|
||||
}
|
||||
|
||||
bool Script::Comment::Set(const CommentInfo* info)
|
||||
{
|
||||
if(!info)
|
||||
return false;
|
||||
auto base = Module::BaseFromName(info->mod);
|
||||
if(!base)
|
||||
return false;
|
||||
return Set(base + info->rva, info->text, info->manual);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Comment::Get(duint addr, char* text)
|
||||
{
|
||||
return CommentGet(addr, text);
|
||||
|
@ -19,7 +30,7 @@ SCRIPT_EXPORT bool Script::Comment::GetInfo(duint addr, CommentInfo* info)
|
|||
if(info)
|
||||
{
|
||||
strcpy_s(info->mod, comment.mod);
|
||||
info->addr = comment.addr;
|
||||
info->rva = comment.addr;
|
||||
strcpy_s(info->text, comment.text);
|
||||
info->manual = comment.manual;
|
||||
}
|
||||
|
@ -51,7 +62,7 @@ SCRIPT_EXPORT bool Script::Comment::GetList(ListOf(CommentInfo) listInfo)
|
|||
{
|
||||
CommentInfo scriptComment;
|
||||
strcpy_s(scriptComment.mod, comment.mod);
|
||||
scriptComment.addr = comment.addr;
|
||||
scriptComment.rva = comment.addr;
|
||||
strcpy_s(scriptComment.text, comment.text);
|
||||
scriptComment.manual = comment.manual;
|
||||
commentScriptList.push_back(scriptComment);
|
||||
|
|
|
@ -10,13 +10,14 @@ namespace Script
|
|||
struct CommentInfo
|
||||
{
|
||||
char mod[MAX_MODULE_SIZE];
|
||||
duint addr;
|
||||
duint rva;
|
||||
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 Set(const CommentInfo* info);
|
||||
SCRIPT_EXPORT bool Get(duint addr, char* text); //text[MAX_COMMENT_SIZE]
|
||||
SCRIPT_EXPORT bool GetInfo(duint addr, CommentInfo* info);
|
||||
SCRIPT_EXPORT bool Delete(duint addr);
|
||||
SCRIPT_EXPORT void DeleteRange(duint start, duint end);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "_scriptapi_function.h"
|
||||
#include "_scriptapi_module.h"
|
||||
#include "function.h"
|
||||
|
||||
SCRIPT_EXPORT bool Script::Function::Add(duint start, duint end, bool manual, duint instructionCount)
|
||||
|
@ -6,6 +7,16 @@ SCRIPT_EXPORT bool Script::Function::Add(duint start, duint end, bool manual, du
|
|||
return FunctionAdd(start, end, manual, instructionCount);
|
||||
}
|
||||
|
||||
bool Script::Function::Add(const FunctionInfo* info)
|
||||
{
|
||||
if(!info)
|
||||
return false;
|
||||
auto base = Module::BaseFromName(info->mod);
|
||||
if(!base)
|
||||
return false;
|
||||
return Add(base + info->rvaStart, base + info->rvaEnd, info->manual, info->instructioncount);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Function::Get(duint addr, duint* start, duint* end, duint* instructionCount)
|
||||
{
|
||||
return FunctionGet(addr, start, end, instructionCount);
|
||||
|
@ -19,8 +30,8 @@ SCRIPT_EXPORT bool Script::Function::GetInfo(duint addr, FunctionInfo* info)
|
|||
if(info)
|
||||
{
|
||||
strcpy_s(info->mod, function.mod);
|
||||
info->start = function.start;
|
||||
info->end = function.end;
|
||||
info->rvaStart = function.start;
|
||||
info->rvaEnd = function.end;
|
||||
info->manual = function.manual;
|
||||
info->instructioncount = function.instructioncount;
|
||||
}
|
||||
|
@ -57,8 +68,8 @@ SCRIPT_EXPORT bool Script::Function::GetList(ListOf(FunctionInfo) listInfo)
|
|||
{
|
||||
FunctionInfo scriptFunction;
|
||||
strcpy_s(scriptFunction.mod, function.mod);
|
||||
scriptFunction.start = function.start;
|
||||
scriptFunction.end = function.end;
|
||||
scriptFunction.rvaStart = function.start;
|
||||
scriptFunction.rvaEnd = function.end;
|
||||
scriptFunction.manual = function.manual;
|
||||
scriptFunction.instructioncount = function.instructioncount;
|
||||
functionScriptList.push_back(scriptFunction);
|
||||
|
|
|
@ -10,13 +10,14 @@ namespace Script
|
|||
struct FunctionInfo
|
||||
{
|
||||
char mod[MAX_MODULE_SIZE];
|
||||
duint start;
|
||||
duint end;
|
||||
duint rvaStart;
|
||||
duint rvaEnd;
|
||||
bool manual;
|
||||
duint instructioncount;
|
||||
};
|
||||
|
||||
SCRIPT_EXPORT bool Add(duint start, duint end, bool manual, duint instructionCount = 0);
|
||||
SCRIPT_EXPORT bool Add(const FunctionInfo* info);
|
||||
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);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "_scriptapi_label.h"
|
||||
#include "_scriptapi_module.h"
|
||||
#include "label.h"
|
||||
|
||||
SCRIPT_EXPORT bool Script::Label::Set(duint addr, const char* text, bool manual)
|
||||
|
@ -6,6 +7,16 @@ SCRIPT_EXPORT bool Script::Label::Set(duint addr, const char* text, bool manual)
|
|||
return LabelSet(addr, text, manual);
|
||||
}
|
||||
|
||||
bool Script::Label::Set(const LabelInfo* info)
|
||||
{
|
||||
if(!info)
|
||||
return false;
|
||||
auto base = Module::BaseFromName(info->mod);
|
||||
if(!base)
|
||||
return false;
|
||||
return Set(base + info->rva, info->text, info->manual);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Label::FromString(const char* label, duint* addr)
|
||||
{
|
||||
return LabelFromString(label, addr);
|
||||
|
@ -24,7 +35,7 @@ SCRIPT_EXPORT bool Script::Label::GetInfo(duint addr, LabelInfo* info)
|
|||
if(info)
|
||||
{
|
||||
strcpy_s(info->mod, label.mod);
|
||||
info->addr = label.addr;
|
||||
info->rva = label.addr;
|
||||
strcpy_s(info->text, label.text);
|
||||
info->manual = label.manual;
|
||||
}
|
||||
|
@ -56,7 +67,7 @@ SCRIPT_EXPORT bool Script::Label::GetList(ListOf(LabelInfo) listInfo)
|
|||
{
|
||||
LabelInfo scriptLabel;
|
||||
strcpy_s(scriptLabel.mod, label.mod);
|
||||
scriptLabel.addr = label.addr;
|
||||
scriptLabel.rva = label.addr;
|
||||
strcpy_s(scriptLabel.text, label.text);
|
||||
scriptLabel.manual = label.manual;
|
||||
labelScriptList.push_back(scriptLabel);
|
||||
|
|
|
@ -10,14 +10,15 @@ namespace Script
|
|||
struct LabelInfo
|
||||
{
|
||||
char mod[MAX_MODULE_SIZE];
|
||||
duint addr;
|
||||
duint rva;
|
||||
char text[MAX_LABEL_SIZE];
|
||||
bool manual;
|
||||
};
|
||||
|
||||
SCRIPT_EXPORT bool Set(duint addr, const char* text, bool manual = false);
|
||||
SCRIPT_EXPORT bool Set(const LabelInfo* info);
|
||||
SCRIPT_EXPORT bool FromString(const char* label, duint* addr);
|
||||
SCRIPT_EXPORT bool Get(duint addr, char* text);
|
||||
SCRIPT_EXPORT bool Get(duint addr, char* text); //text[MAX_LABEL_SIZE]
|
||||
SCRIPT_EXPORT bool GetInfo(duint addr, LabelInfo* info);
|
||||
SCRIPT_EXPORT bool Delete(duint addr);
|
||||
SCRIPT_EXPORT void DeleteRange(duint start, duint end);
|
||||
|
|
|
@ -12,7 +12,8 @@ SCRIPT_EXPORT duint Script::Pattern::FindMem(duint start, duint size, const char
|
|||
Memory<unsigned char*> data(size, "Script::Pattern::FindMem::data");
|
||||
if(!MemRead(start, data(), size))
|
||||
return -1;
|
||||
return Pattern::Find(data(), data.size(), pattern) + start;
|
||||
auto found = Pattern::Find(data(), data.size(), pattern);
|
||||
return found == -1 ? 0 : found + start;
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT void Script::Pattern::Write(unsigned char* data, duint datasize, const char* pattern)
|
||||
|
|
Loading…
Reference in New Issue