diff --git a/x64_dbg_dbg/_scriptapi_gui.cpp b/x64_dbg_dbg/_scriptapi_gui.cpp index d5918cbb..6120f127 100644 --- a/x64_dbg_dbg/_scriptapi_gui.cpp +++ b/x64_dbg_dbg/_scriptapi_gui.cpp @@ -129,4 +129,9 @@ SCRIPT_EXPORT bool Script::Gui::InputValue(const char* title, duint* value) if(!GuiGetLineWindow(title, line())) return false; return Misc::ParseExpression(line(), value); +} + +SCRIPT_EXPORT void Script::Gui::Refresh() +{ + GuiUpdateAllViews(); } \ No newline at end of file diff --git a/x64_dbg_dbg/_scriptapi_gui.h b/x64_dbg_dbg/_scriptapi_gui.h index 63ab199f..e1548ecd 100644 --- a/x64_dbg_dbg/_scriptapi_gui.h +++ b/x64_dbg_dbg/_scriptapi_gui.h @@ -49,6 +49,7 @@ SCRIPT_EXPORT void Message(const char* message); SCRIPT_EXPORT bool MessageYesNo(const char* message); SCRIPT_EXPORT bool InputLine(const char* title, char* text); //text[GUI_MAX_LINE_SIZE] SCRIPT_EXPORT bool InputValue(const char* title, duint* value); +SCRIPT_EXPORT void Refresh(); }; //Gui }; //Script diff --git a/x64_dbg_dbg/_scriptapi_register.cpp b/x64_dbg_dbg/_scriptapi_register.cpp index 2abfab96..a005619b 100644 --- a/x64_dbg_dbg/_scriptapi_register.cpp +++ b/x64_dbg_dbg/_scriptapi_register.cpp @@ -9,6 +9,7 @@ static const char* regTable[] = "DR3", "DR6", "DR7", + "EAX", "AX", "AH", @@ -34,7 +35,7 @@ static const char* regTable[] = "ESP", "SP", "EIP", - "CIP", + #ifdef _WIN64 "RAX", "RBX", @@ -80,7 +81,15 @@ static const char* regTable[] = "R15", "R15D", "R15W", - "R15" + "R15", +#endif //_WIN64 + +#ifdef _WIN64 + "RIP", + "RSP" +#else //x32 + "EIP", + "ESP" #endif //_WIN64 }; @@ -96,6 +105,11 @@ SCRIPT_EXPORT bool Script::Register::Set(Script::Register::RegisterEnum reg, dui return setregister(regTable[reg], value); } +SCRIPT_EXPORT int Script::Register::Size() +{ + return (int)sizeof(duint); +} + SCRIPT_EXPORT duint Script::Register::GetDR0() { return Get(DR0); @@ -406,16 +420,6 @@ SCRIPT_EXPORT bool Script::Register::SetEIP(unsigned int value) return Set(EIP, value); } -SCRIPT_EXPORT duint Script::Register::GetCIP() -{ - return Get(CIP); -} - -SCRIPT_EXPORT bool Script::Register::SetCIP(duint value) -{ - return Set(CIP, value); -} - #ifdef _WIN64 SCRIPT_EXPORT unsigned long long Script::Register::GetRAX() { @@ -866,4 +870,24 @@ SCRIPT_EXPORT bool Script::Register::SetR15B(unsigned char value) { return Set(R15B, value); } -#endif //_WIN64 \ No newline at end of file +#endif //_WIN64 + +SCRIPT_EXPORT duint Script::Register::GetCIP() +{ + return Get(CIP); +} + +SCRIPT_EXPORT bool Script::Register::SetCIP(duint value) +{ + return Set(CIP, value); +} + +SCRIPT_EXPORT duint Script::Register::GetCSP() +{ + return Get(CSP); +} + +SCRIPT_EXPORT bool Script::Register::SetCSP(duint value) +{ + return Set(CSP, value); +} \ No newline at end of file diff --git a/x64_dbg_dbg/_scriptapi_register.h b/x64_dbg_dbg/_scriptapi_register.h index 1838ba75..657b24b0 100644 --- a/x64_dbg_dbg/_scriptapi_register.h +++ b/x64_dbg_dbg/_scriptapi_register.h @@ -15,6 +15,7 @@ enum RegisterEnum DR3, DR6, DR7, + EAX, AX, AH, @@ -40,7 +41,7 @@ enum RegisterEnum ESP, SP, EIP, - CIP, + #ifdef _WIN64 RAX, RBX, @@ -86,12 +87,16 @@ enum RegisterEnum R15, R15D, R15W, - R15B + R15B, #endif //_WIN64 + + CIP, + CSP, }; //RegisterEnum SCRIPT_EXPORT duint Get(RegisterEnum reg); SCRIPT_EXPORT bool Set(RegisterEnum reg, duint value); +SCRIPT_EXPORT int Size(); //gets architecture register size in bytes SCRIPT_EXPORT duint GetDR0(); SCRIPT_EXPORT bool SetDR0(duint value); @@ -105,6 +110,7 @@ SCRIPT_EXPORT duint GetDR6(); SCRIPT_EXPORT bool SetDR6(duint value); SCRIPT_EXPORT duint GetDR7(); SCRIPT_EXPORT bool SetDR7(duint value); + SCRIPT_EXPORT unsigned int GetEAX(); SCRIPT_EXPORT bool SetEAX(unsigned int value); SCRIPT_EXPORT unsigned short GetAX(); @@ -155,8 +161,7 @@ SCRIPT_EXPORT unsigned short GetSP(); SCRIPT_EXPORT bool SetSP(unsigned short value); SCRIPT_EXPORT unsigned int GetEIP(); SCRIPT_EXPORT bool SetEIP(unsigned int value); -SCRIPT_EXPORT duint GetCIP(); -SCRIPT_EXPORT bool SetCIP(duint value); + #ifdef _WIN64 SCRIPT_EXPORT unsigned long long GetRAX(); SCRIPT_EXPORT bool SetRAX(unsigned long long value); @@ -249,6 +254,11 @@ SCRIPT_EXPORT bool SetR15W(unsigned short value); SCRIPT_EXPORT unsigned char GetR15B(); SCRIPT_EXPORT bool SetR15B(unsigned char value); #endif //_WIN64 + +SCRIPT_EXPORT duint GetCIP(); +SCRIPT_EXPORT bool SetCIP(duint value); +SCRIPT_EXPORT duint GetCSP(); +SCRIPT_EXPORT bool SetCSP(duint value); }; //Register }; //Script diff --git a/x64_dbg_dbg/_scriptapi_stack.cpp b/x64_dbg_dbg/_scriptapi_stack.cpp new file mode 100644 index 00000000..528d8137 --- /dev/null +++ b/x64_dbg_dbg/_scriptapi_stack.cpp @@ -0,0 +1,24 @@ +#include "_scriptapi_stack.h" +#include "_scriptapi_memory.h" +#include "_scriptapi_register.h" + +SCRIPT_EXPORT duint Script::Stack::Pop() +{ + duint csp = Register::GetCSP(); + duint top = Memory::ReadPtr(csp); + Register::SetCSP(csp + sizeof(duint)); + return top; +} + +SCRIPT_EXPORT duint Script::Stack::Push(duint value) +{ + duint csp = Register::GetCSP(); + Register::SetCSP(csp - sizeof(duint)); + Memory::WritePtr(csp, value); + return Memory::ReadPtr(csp); +} + +SCRIPT_EXPORT duint Script::Stack::Peek(int offset) +{ + return Memory::ReadPtr(Register::GetCSP() + offset * sizeof(duint)); +} \ No newline at end of file diff --git a/x64_dbg_dbg/_scriptapi_stack.h b/x64_dbg_dbg/_scriptapi_stack.h new file mode 100644 index 00000000..47d714de --- /dev/null +++ b/x64_dbg_dbg/_scriptapi_stack.h @@ -0,0 +1,16 @@ +#ifndef _SCRIPTAPI_STACK_H +#define _SCRIPTAPI_STACK_H + +#include "_scriptapi.h" + +namespace Script +{ +namespace Stack +{ +SCRIPT_EXPORT duint Pop(); +SCRIPT_EXPORT duint Push(duint value); //returns the previous top, equal to Peek(1) +SCRIPT_EXPORT duint Peek(int offset = 0); //offset is in multiples of Register::Size(), for easy x32/x64 portability +}; //Stack +}; //Script + +#endif //_SCRIPTAPI_STACK_H \ No newline at end of file diff --git a/x64_dbg_dbg/x64_dbg_dbg.vcxproj b/x64_dbg_dbg/x64_dbg_dbg.vcxproj index dd3a6e76..39f34df7 100644 --- a/x64_dbg_dbg/x64_dbg_dbg.vcxproj +++ b/x64_dbg_dbg/x64_dbg_dbg.vcxproj @@ -75,6 +75,7 @@ + @@ -187,6 +188,7 @@ + {E6548308-401E-3A8A-5819-905DB90522A6} diff --git a/x64_dbg_dbg/x64_dbg_dbg.vcxproj.filters b/x64_dbg_dbg/x64_dbg_dbg.vcxproj.filters index 0abcc89f..2ea64af8 100644 --- a/x64_dbg_dbg/x64_dbg_dbg.vcxproj.filters +++ b/x64_dbg_dbg/x64_dbg_dbg.vcxproj.filters @@ -255,6 +255,9 @@ Source Files\Interfaces/Exports\_scriptapi + + Source Files\Interfaces/Exports\_scriptapi + @@ -587,5 +590,8 @@ Header Files\Interfaces/Exports\_scriptapi + + Header Files\Interfaces/Exports\_scriptapi + \ No newline at end of file