diff --git a/help/PLUG_SETUPSTRUCT.htm b/help/PLUG_SETUPSTRUCT.htm
index 1869c0f3..6192199f 100644
--- a/help/PLUG_SETUPSTRUCT.htm
+++ b/help/PLUG_SETUPSTRUCT.htm
@@ -12,18 +12,24 @@ html,body {
}
-
+
+
-
-plugsetup
This structure is used by the function that allows the
-creation of plugin menu entries:
-
- struct PLUG_SETUPSTRUCT
-
{
//data provided by the debugger to
-the plugin.
-
[IN] HWND hwndDlg; //GUI window
-handle
[IN]
-int hMenu; //plugin menu
-handle
+
+
+plugsetup
This structure is used by the function that allows the
+creation of plugin menu entries:
+
+ struct PLUG_SETUPSTRUCT
+
{
//data provided by the debugger to
+the plugin.
+
[IN] HWND hwndDlg; //GUI window
+handle
[IN]
+int hMenu; //plugin menu
+handle
[IN] int hMenuDisasm;
+//plugin disasm menu handle
[IN] int
+hMenuDump; //plugin dump menu handle
[IN]
+int hMenuStack; //plugin stack menu
+handle
};
diff --git a/release.bat b/release.bat
index daea1b06..a471eae0 100644
--- a/release.bat
+++ b/release.bat
@@ -31,6 +31,7 @@ copy bin\x32\jansson.dll %RELEASEDIR%\bin_base\x32\jansson.dll
copy bin\x32\lz4.dll %RELEASEDIR%\bin_base\x32\lz4.dll
copy bin\x32\TitanEngine.dll %RELEASEDIR%\bin_base\x32\TitanEngine.dll
copy bin\x32\XEDParse.dll %RELEASEDIR%\bin_base\x32\XEDParse.dll
+copy bin\x32\yara.dll %RELEASEDIR%\bin_base\x32\yara.dll
copy bin\x64\BeaEngine.dll %RELEASEDIR%\bin_base\x64\BeaEngine.dll
copy bin\x64\dbghelp.dll %RELEASEDIR%\bin_base\x64\dbghelp.dll
copy bin\x64\symsrv.dll %RELEASEDIR%\bin_base\x64\symsrv.dll
@@ -40,6 +41,7 @@ copy bin\x64\jansson.dll %RELEASEDIR%\bin_base\x64\jansson.dll
copy bin\x64\lz4.dll %RELEASEDIR%\bin_base\x64\lz4.dll
copy bin\x64\TitanEngine.dll %RELEASEDIR%\bin_base\x64\TitanEngine.dll
copy bin\x64\XEDParse.dll %RELEASEDIR%\bin_base\x64\XEDParse.dll
+copy bin\x64\yara.dll %RELEASEDIR%\bin_base\x64\yara.dll
echo help
@@ -57,6 +59,8 @@ mkdir %RELEASEDIR%\pluginsdk\jansson
mkdir %RELEASEDIR%\pluginsdk\lz4
mkdir %RELEASEDIR%\pluginsdk\TitanEngine
mkdir %RELEASEDIR%\pluginsdk\XEDParse
+mkdir %RELEASEDIR%\pluginsdk\yara
+mkdir %RELEASEDIR%\pluginsdk\yara\yara
xcopy x64_dbg_dbg\BeaEngine %RELEASEDIR%\pluginsdk\BeaEngine /S /Y
xcopy x64_dbg_dbg\dbghelp %RELEASEDIR%\pluginsdk\dbghelp /S /Y
@@ -66,6 +70,7 @@ xcopy x64_dbg_dbg\lz4 %RELEASEDIR%\pluginsdk\lz4 /S /Y
xcopy x64_dbg_dbg\TitanEngine %RELEASEDIR%\pluginsdk\TitanEngine /S /Y
del %RELEASEDIR%\pluginsdk\TitanEngine\TitanEngine.txt /F /Q
xcopy x64_dbg_dbg\XEDParse %RELEASEDIR%\pluginsdk\XEDParse /S /Y
+xcopy x64_dbg_dbg\yara %RELEASEDIR%\pluginsdk\yara /S /Y
copy x64_dbg_dbg\_plugin_types.h %RELEASEDIR%\pluginsdk\_plugin_types.h
copy x64_dbg_dbg\_plugins.h %RELEASEDIR%\pluginsdk\_plugins.h
copy x64_dbg_dbg\_dbgfunctions.h %RELEASEDIR%\pluginsdk\_dbgfunctions.h
diff --git a/rpm.cpp b/rpm.cpp
new file mode 100644
index 00000000..fc354e12
--- /dev/null
+++ b/rpm.cpp
@@ -0,0 +1,93 @@
+#include
+#include
+#include
+
+#define uint size_t
+#define PAGE_SIZE 0x1000
+
+#ifdef _WIN64
+#define HIGHEST_USER_ADDR 0x7FFFFFEFFFF
+#else //x86
+#define HIGHEST_USER_ADDR 0x7FFEFFFF
+#endif // _WIN64
+
+bool readblock(uint addr, unsigned char block[PAGE_SIZE])
+{
+ printf("readblock(%X[%X])\n", addr, PAGE_SIZE);
+ memset(block, 0xFF, PAGE_SIZE);
+ return true;
+}
+
+bool memread(uint addr, unsigned char* data, uint size)
+{
+ //check if the address is inside user space
+ if(addr > HIGHEST_USER_ADDR)
+ return false;
+
+ puts("-start-");
+ printf(" addr: %X\n size: %X\n", addr, size);
+
+ //calculate the start page
+ uint start = addr & ~(PAGE_SIZE - 1);
+ printf(" start: %X\n", start);
+
+ //calculate the end page
+ uint end = addr + size;
+ uint x = end & (PAGE_SIZE - 1);
+ if(x)
+ end += (PAGE_SIZE - x);
+ printf(" end: %X\n", end);
+
+ //calculate the number of pages to read
+ uint npages = (end - start) / PAGE_SIZE;
+ printf("npages: %d\n\n", npages);
+
+ //go over all pages
+ for(uint i = 0, j = start; i < npages; i++)
+ {
+ //read one page (j should always align with PAGE_SIZE)
+ unsigned char block[PAGE_SIZE];
+ if(!readblock(j, block))
+ {
+ return false;
+ }
+
+ //these are the offsets and sizes in the block to write to append to the output buffer
+ uint roffset = 0;
+ uint rsize = PAGE_SIZE;
+
+ if(i == npages - 1) //last page (first because there might only be one page)
+ {
+ rsize = size - (j - start); //remaining size
+ }
+ else if(i == 0) //first page
+ {
+ roffset = addr & (PAGE_SIZE - 1);
+ rsize = PAGE_SIZE - roffset;
+ }
+
+ printf("roffset: %X\n rsize: %X\n", roffset, rsize);
+ puts("");
+
+ //copy the required block data in the output buffer
+ memcpy(data, block + roffset, rsize);
+ data += rsize;
+
+ j += rsize;
+ }
+
+ puts("--end--\n");
+ return true;
+}
+
+int main()
+{
+ unsigned char out[0x10000] = {0};
+ memread(0x12A45, out, 0x3456);
+ memread(0x12000, out, 0x456);
+ memread(0x12000, out, 0x3456);
+ memread(0x12000, out, 0x4000);
+ memread(0x12ff0, out, 0x16);
+ memread(0x100, out, 0x3090);
+ return 0;
+}
\ No newline at end of file
diff --git a/x64_dbg_bridge/bridgemain.cpp b/x64_dbg_bridge/bridgemain.cpp
index 6a1559cf..79c0e56c 100644
--- a/x64_dbg_bridge/bridgemain.cpp
+++ b/x64_dbg_bridge/bridgemain.cpp
@@ -12,6 +12,7 @@
static HINSTANCE hInst;
static wchar_t szIniFile[MAX_PATH] = L"";
+static CRITICAL_SECTION csIni;
#ifdef _WIN64
#define dbg_lib "x64_dbg.dll"
@@ -37,6 +38,9 @@ static wchar_t szIniFile[MAX_PATH] = L"";
BRIDGE_IMPEXP const char* BridgeInit()
{
+ //Initialize critial section
+ InitializeCriticalSection(&csIni);
+
//Settings load
if(!GetModuleFileNameW(0, szIniFile, MAX_PATH))
return "Error getting module path!";
@@ -87,6 +91,7 @@ BRIDGE_IMPEXP const char* BridgeStart()
if(!_dbg_dbginit || !_gui_guiinit)
return "\"_dbg_dbginit\" || \"_gui_guiinit\" was not loaded yet, call BridgeInit!";
_gui_guiinit(0, 0); //remove arguments
+ DeleteCriticalSection(&csIni);
return 0;
}
@@ -111,14 +116,20 @@ BRIDGE_IMPEXP bool BridgeSettingGet(const char* section, const char* key, char*
{
if(!section || !key || !value)
return false;
+ EnterCriticalSection(&csIni);
CSimpleIniA inifile(true, false, false);
- if(inifile.LoadFile(szIniFile) < 0)
- return false;
- const char* szValue = inifile.GetValue(section, key);
- if(!szValue)
- return false;
- strcpy_s(value, MAX_SETTING_SIZE, szValue);
- return true;
+ bool success = false;
+ if(inifile.LoadFile(szIniFile) >= 0)
+ {
+ const char* szValue = inifile.GetValue(section, key);
+ if(szValue)
+ {
+ strcpy_s(value, MAX_SETTING_SIZE, szValue);
+ success = true;
+ }
+ }
+ LeaveCriticalSection(&csIni);
+ return success;
}
BRIDGE_IMPEXP bool BridgeSettingGetUint(const char* section, const char* key, duint* value)
@@ -140,15 +151,20 @@ BRIDGE_IMPEXP bool BridgeSettingGetUint(const char* section, const char* key, du
BRIDGE_IMPEXP bool BridgeSettingSet(const char* section, const char* key, const char* value)
{
- if(!section)
- return false;
- CSimpleIniA inifile(true, false, false);
- inifile.LoadFile(szIniFile);
- if(!key || !value) //delete value/key when 0
- inifile.Delete(section, key, true);
- else
- inifile.SetValue(section, key, value);
- return inifile.SaveFile(szIniFile, false) >= 0;
+ bool success = false;
+ if(section)
+ {
+ EnterCriticalSection(&csIni);
+ CSimpleIniA inifile(true, false, false);
+ inifile.LoadFile(szIniFile);
+ if(!key || !value) //delete value/key when 0
+ inifile.Delete(section, key, true);
+ else
+ inifile.SetValue(section, key, value);
+ success = inifile.SaveFile(szIniFile, false) >= 0;
+ LeaveCriticalSection(&csIni);
+ }
+ return success;
}
BRIDGE_IMPEXP bool BridgeSettingSetUint(const char* section, const char* key, duint value)
@@ -251,7 +267,7 @@ BRIDGE_IMPEXP bool DbgGetLabelAt(duint addr, SEGMENTREG segment, char* text) //(
return false;
sprintf_s(info.label, "&%s", ptrinfo.label);
}
- strcpy(text, info.label);
+ strcpy_s(text, MAX_LABEL_SIZE, info.label);
return true;
}
@@ -262,7 +278,7 @@ BRIDGE_IMPEXP bool DbgSetLabelAt(duint addr, const char* text)
ADDRINFO info;
memset(&info, 0, sizeof(info));
info.flags = flaglabel;
- strcpy(info.label, text);
+ strcpy_s(info.label, text);
if(!_dbg_addrinfoset(addr, &info))
return false;
return true;
@@ -278,7 +294,7 @@ BRIDGE_IMPEXP bool DbgGetCommentAt(duint addr, char* text) //comment (not live)
info.flags = flagcomment;
if(!_dbg_addrinfoget(addr, SEG_DEFAULT, &info))
return false;
- strcpy(text, info.comment);
+ strcpy_s(text, MAX_COMMENT_SIZE, info.comment);
return true;
}
@@ -289,7 +305,7 @@ BRIDGE_IMPEXP bool DbgSetCommentAt(duint addr, const char* text)
ADDRINFO info;
memset(&info, 0, sizeof(info));
info.flags = flagcomment;
- strcpy(info.comment, text);
+ strcpy_s(info.comment, MAX_COMMENT_SIZE, text);
if(!_dbg_addrinfoset(addr, &info))
return false;
return true;
@@ -305,7 +321,7 @@ BRIDGE_IMPEXP bool DbgGetModuleAt(duint addr, char* text)
info.flags = flagmodule;
if(!_dbg_addrinfoget(addr, SEG_DEFAULT, &info))
return false;
- strcpy(text, info.module);
+ strcpy_s(text, MAX_MODULE_SIZE, info.module);
return true;
}
@@ -1092,4 +1108,3 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
hInst = hinstDLL;
return TRUE;
}
-
diff --git a/x64_dbg_bridge/bridgemain.h b/x64_dbg_bridge/bridgemain.h
index 09f961f4..c64fe3c1 100644
--- a/x64_dbg_bridge/bridgemain.h
+++ b/x64_dbg_bridge/bridgemain.h
@@ -37,7 +37,7 @@ extern "C"
//Bridge defines
#define MAX_SETTING_SIZE 65536
-#define DBG_VERSION 23
+#define DBG_VERSION 24
//Bridge functions
BRIDGE_IMPEXP const char* BridgeInit();
@@ -60,6 +60,7 @@ BRIDGE_IMPEXP int BridgeGetDbgVersion();
#define MAX_STRING_SIZE 512
#define MAX_ERROR_SIZE 512
#define RIGHTS_STRING_SIZE (sizeof("ERWCG") + 1)
+#define MAX_SECTION_SIZE 10
#define TYPE_VALUE 1
#define TYPE_MEMORY 2
@@ -423,6 +424,18 @@ typedef struct
} X87CONTROLWORDFIELDS;
+typedef struct DECLSPEC_ALIGN(16) _XMMREGISTER
+{
+ ULONGLONG Low;
+ LONGLONG High;
+} XMMREGISTER;
+
+typedef struct
+{
+ XMMREGISTER Low; //XMM/SSE part
+ XMMREGISTER High; //AVX part
+} YMMREGISTER;
+
typedef struct
{
BYTE data[10];
@@ -480,11 +493,11 @@ typedef struct
X87FPU x87fpu;
DWORD MxCsr;
#ifdef _WIN64
- M128A XmmRegisters[16];
- BYTE YmmRegisters[32 * 16];
+ XMMREGISTER XmmRegisters[16];
+ YMMREGISTER YmmRegisters[16];
#else // x86
- M128A XmmRegisters[8];
- BYTE YmmRegisters[32 * 8];
+ XMMREGISTER XmmRegisters[8];
+ YMMREGISTER YmmRegisters[8];
#endif
} REGISTERCONTEXT;
@@ -666,6 +679,9 @@ BRIDGE_IMPEXP bool DbgWinEventGlobal(MSG* message);
//Gui defines
#define GUI_PLUGIN_MENU 0
+#define GUI_DISASM_MENU 1
+#define GUI_DUMP_MENU 2
+#define GUI_STACK_MENU 3
#define GUI_DISASSEMBLY 0
#define GUI_DUMP 1
diff --git a/x64_dbg_dbg/TitanEngine/TitanEngine.h b/x64_dbg_dbg/TitanEngine/TitanEngine.h
index 0576db7c..55d01c2b 100644
--- a/x64_dbg_dbg/TitanEngine/TitanEngine.h
+++ b/x64_dbg_dbg/TitanEngine/TitanEngine.h
@@ -10,14 +10,6 @@
#include
#include
-#ifdef __GNUC__
-typedef struct DECLSPEC_ALIGN(16) _M128A
-{
- ULONGLONG Low;
- LONGLONG High;
-} M128A, *PM128A;
-#endif //__GNUC__
-
#pragma pack(push, 1)
// Global.Constant.Structure.Declaration:
@@ -594,10 +586,16 @@ typedef struct
DWORD OriginalCOMTableSize;
} FILE_FIX_INFO, *PFILE_FIX_INFO;
+typedef struct DECLSPEC_ALIGN(16) _XmmRegister_t
+{
+ ULONGLONG Low;
+ LONGLONG High;
+} XmmRegister_t;
+
typedef struct
{
- M128A Low; //XMM/SSE part
- M128A High; //AVX part
+ XmmRegister_t Low; //XMM/SSE part
+ XmmRegister_t High; //AVX part
} YmmRegister_t;
typedef struct
@@ -657,10 +655,10 @@ typedef struct
x87FPU_t x87fpu;
DWORD MxCsr;
#ifdef _WIN64
- M128A XmmRegisters[16];
+ XmmRegister_t XmmRegisters[16];
YmmRegister_t YmmRegisters[16];
#else // x86
- M128A XmmRegisters[8];
+ XmmRegister_t XmmRegisters[8];
YmmRegister_t YmmRegisters[8];
#endif
} TITAN_ENGINE_CONTEXT_t;
diff --git a/x64_dbg_dbg/_dbgfunctions.cpp b/x64_dbg_dbg/_dbgfunctions.cpp
index 03237fb1..caf8165b 100644
--- a/x64_dbg_dbg/_dbgfunctions.cpp
+++ b/x64_dbg_dbg/_dbgfunctions.cpp
@@ -14,6 +14,7 @@
#include "disasm_fast.h"
#include "stackinfo.h"
#include "symbolinfo.h"
+#include "module.h"
static DBGFUNCTIONS _dbgfunctions;
@@ -47,7 +48,7 @@ static bool _sectionfromaddr(duint addr, char* section)
{
const char* name = (const char*)GetPE32DataFromMappedFile(FileMapVA, sectionNumber, UE_SECTIONNAME);
if(section)
- strcpy(section, name);
+ strcpy_s(section, MAX_SECTION_SIZE, name); //maxi
StaticFileUnloadW(curModPath, false, FileHandle, LoadedSize, FileMap, FileMapVA);
return true;
}
@@ -138,7 +139,7 @@ static bool _getjit(char* jit, bool jit64)
{
if(!dbggetjit(jit_tmp, jit64 ? x64 : x32, &dummy, NULL))
return false;
- strcpy(jit, jit_tmp);
+ strcpy_s(jit, MAX_SETTING_SIZE, jit_tmp);
}
else // if jit input == NULL: it returns false if there are not an OLD JIT STORED.
{
diff --git a/x64_dbg_dbg/_exports.cpp b/x64_dbg_dbg/_exports.cpp
index cb8b0fdc..3ec8a586 100644
--- a/x64_dbg_dbg/_exports.cpp
+++ b/x64_dbg_dbg/_exports.cpp
@@ -21,6 +21,12 @@
#include "disasm_fast.h"
#include "plugin_loader.h"
#include "_dbgfunctions.h"
+#include "module.h"
+#include "comment.h"
+#include "label.h"
+#include "bookmark.h"
+#include "function.h"
+#include "loop.h"
static bool bOnlyCipAutoComments = false;
@@ -107,10 +113,10 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
pSymbol->MaxNameLen = MAX_LABEL_SIZE;
- if(SymFromAddr(fdProcessInfo->hProcess, (DWORD64)addr, &displacement, pSymbol) and !displacement)
+ if(SafeSymFromAddr(fdProcessInfo->hProcess, (DWORD64)addr, &displacement, pSymbol) and !displacement)
{
pSymbol->Name[pSymbol->MaxNameLen - 1] = '\0';
- if(!bUndecorateSymbolNames or !UnDecorateSymbolName(pSymbol->Name, addrinfo->label, MAX_LABEL_SIZE, UNDNAME_COMPLETE))
+ if(!bUndecorateSymbolNames or !SafeUnDecorateSymbolName(pSymbol->Name, addrinfo->label, MAX_LABEL_SIZE, UNDNAME_COMPLETE))
strcpy_s(addrinfo->label, pSymbol->Name);
retval = true;
}
@@ -123,10 +129,10 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
uint val = 0;
if(memread(fdProcessInfo->hProcess, (const void*)basicinfo.memory.value, &val, sizeof(val), 0))
{
- if(SymFromAddr(fdProcessInfo->hProcess, (DWORD64)val, &displacement, pSymbol) and !displacement)
+ if(SafeSymFromAddr(fdProcessInfo->hProcess, (DWORD64)val, &displacement, pSymbol) and !displacement)
{
pSymbol->Name[pSymbol->MaxNameLen - 1] = '\0';
- if(!bUndecorateSymbolNames or !UnDecorateSymbolName(pSymbol->Name, addrinfo->label, MAX_LABEL_SIZE, UNDNAME_COMPLETE))
+ if(!bUndecorateSymbolNames or !SafeUnDecorateSymbolName(pSymbol->Name, addrinfo->label, MAX_LABEL_SIZE, UNDNAME_COMPLETE))
sprintf_s(addrinfo->label, "JMP.&%s", pSymbol->Name);
retval = true;
}
@@ -160,10 +166,10 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
DWORD dwDisplacement;
IMAGEHLP_LINE64 line;
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
- if(SymGetLineFromAddr64(fdProcessInfo->hProcess, (DWORD64)addr, &dwDisplacement, &line) and !dwDisplacement)
+ if(SafeSymGetLineFromAddr64(fdProcessInfo->hProcess, (DWORD64)addr, &dwDisplacement, &line) and !dwDisplacement)
{
char filename[deflen] = "";
- strcpy(filename, line.FileName);
+ strcpy_s(filename, line.FileName);
int len = (int)strlen(filename);
while(filename[len] != '\\' and len != 0)
len--;
@@ -568,8 +574,8 @@ extern "C" DLL_EXPORT int _dbg_getbplist(BPXTYPE type, BPMAP* bpmap)
//TODO: fix this
if(memisvalidreadptr(fdProcessInfo->hProcess, curBp.addr))
curBp.active = true;
- strcpy(curBp.mod, list[i].mod);
- strcpy(curBp.name, list[i].name);
+ strcpy_s(curBp.mod, list[i].mod);
+ strcpy_s(curBp.name, list[i].name);
curBp.singleshoot = list[i].singleshoot;
curBp.slot = slot;
if(curBp.active)
diff --git a/x64_dbg_dbg/_global.cpp b/x64_dbg_dbg/_global.cpp
index ce9375dc..3d650632 100644
--- a/x64_dbg_dbg/_global.cpp
+++ b/x64_dbg_dbg/_global.cpp
@@ -176,7 +176,7 @@ void formathex(char* string)
for(int i = 0, j = 0; i < len; i++)
if(isxdigit(string[i]))
j += sprintf(new_string + j, "%c", string[i]);
- strcpy(string, new_string);
+ strcpy_s(string, len + 1, new_string);
}
/**
@@ -192,7 +192,7 @@ void formatdec(char* string)
for(int i = 0, j = 0; i < len; i++)
if(isdigit(string[i]))
j += sprintf(new_string + j, "%c", string[i]);
- strcpy(string, new_string);
+ strcpy_s(string, len + 1, new_string);
}
/**
diff --git a/x64_dbg_dbg/_global.h b/x64_dbg_dbg/_global.h
index 92f7feed..505bf2a1 100644
--- a/x64_dbg_dbg/_global.h
+++ b/x64_dbg_dbg/_global.h
@@ -11,23 +11,19 @@
#include
#include
#include
+#include
#include
#include
-#include
#include
#include