1
0
Fork 0

JIT AUTO SUTFF - before attaching - and some code improves

This commit is contained in:
dreg_fr33project 2014-08-05 22:19:09 +02:00
parent cc4d1963ac
commit a68d95d77d
10 changed files with 260 additions and 51 deletions

View File

@ -107,6 +107,11 @@ static void _getcallstack(DBGCALLSTACK* callstack)
stackgetcallstack(GetContextDataEx(hActiveThread, UE_CSP), (CALLSTACK*)callstack);
}
static bool _getjitauto(bool * jit_auto)
{
return dbggetjitauto( jit_auto, notfound, NULL );
}
static bool _getjit(char* jit, bool jit64)
{
arch dummy;
@ -162,6 +167,7 @@ void dbgfunctionsinit()
_dbgfunctions.GetCallStack = _getcallstack;
_dbgfunctions.SymbolDownloadAllSymbols = symdownloadallsymbols;
_dbgfunctions.GetJit = _getjit;
_dbgfunctions.GetJitAuto = _getjitauto;
_dbgfunctions.GetDefJit = dbggetdefjit;
_dbgfunctions.GetProcessList = _getprocesslist;
}

View File

@ -54,6 +54,7 @@ typedef void (*MEMUPDATEMAP)(HANDLE hProcess);
typedef void (*GETCALLSTACK)(DBGCALLSTACK* callstack);
typedef void (*SYMBOLDOWNLOADALLSYMBOLS)(const char* szSymbolStore);
typedef bool (*GETJIT)(char* jit, bool x64);
typedef bool (*GETJITAUTO)(bool *);
typedef bool (*GETDEFJIT)(char*);
typedef bool (*GETPROCESSLIST)(DBGPROCESSINFO** entries, int* count);
@ -79,6 +80,7 @@ typedef struct DBGFUNCTIONS_
MEMUPDATEMAP MemUpdateMap;
GETCALLSTACK GetCallStack;
SYMBOLDOWNLOADALLSYMBOLS SymbolDownloadAllSymbols;
GETJITAUTO GetJitAuto;
GETJIT GetJit;
GETDEFJIT GetDefJit;
GETPROCESSLIST GetProcessList;

View File

@ -1487,13 +1487,20 @@ void cbDetach()
return;
}
#define JIT_REG_KEY TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug")
bool dbggetjit(char** jit_entry_out, arch arch_in, arch* arch_out)
bool _readwritejitkey( char * jit_key_value, DWORD * jit_key_vale_size, char * key, arch arch_in, arch* arch_out, readwritejitkey_error_t * error, bool write)
{
DWORD key_flags = KEY_READ;
DWORD key_flags;
DWORD lRv;
HKEY hKey;
DWORD dwDisposition;
if ( error != NULL )
* error = ERROR_RW;
if (write)
key_flags = KEY_WRITE;
else
key_flags = KEY_READ;
if(arch_out != NULL)
{
@ -1526,14 +1533,71 @@ bool dbggetjit(char** jit_entry_out, arch arch_in, arch* arch_out)
#endif
}
lRv = RegOpenKeyEx(HKEY_LOCAL_MACHINE, JIT_REG_KEY, 0, key_flags, &hKey);
if (write)
{
lRv = RegCreateKeyEx(HKEY_LOCAL_MACHINE, JIT_REG_KEY, 0, NULL, REG_OPTION_NON_VOLATILE, key_flags, NULL, &hKey, &dwDisposition);
if(lRv != ERROR_SUCCESS)
return false;
lRv = RegSetValueExA(hKey, key, 0, REG_SZ, (BYTE*) jit_key_value, (DWORD) (* jit_key_vale_size) + 1);
RegCloseKey(hKey);
}
else
{
lRv = RegOpenKeyEx(HKEY_LOCAL_MACHINE, JIT_REG_KEY, 0, key_flags, &hKey);
if(lRv != ERROR_SUCCESS)
{
if ( error != NULL )
* error = ERROR_RW_FILE_NOT_FOUND;
return false;
}
lRv = RegQueryValueExA(hKey, key, 0, NULL, (LPBYTE)jit_key_value, jit_key_vale_size);
}
if(lRv != ERROR_SUCCESS)
return false;
return true;
}
bool dbggetjitauto(bool * auto_on, arch arch_in, arch* arch_out)
{
char jit_entry[4];
DWORD jit_entry_size = sizeof(jit_entry) - 1;
readwritejitkey_error_t rw_error;
if ( _readwritejitkey(jit_entry, & jit_entry_size, "Auto", arch_in, arch_out, & rw_error, false ) == false )
{
if ( rw_error = ERROR_RW_FILE_NOT_FOUND )
return true;
return false;
}
if ( _strcmpi( jit_entry, "1") == 0 )
* auto_on = true;
else if ( _strcmpi( jit_entry, "0") == 0 )
* auto_on = false;
else
return false;
return true;
}
bool dbgsetjitauto(bool auto_on, arch arch_in, arch* arch_out)
{
DWORD auto_string_size = sizeof("1");
return _readwritejitkey( auto_on ? "1" : "0", & auto_string_size, "Auto", arch_in, arch_out, NULL, true );
}
bool dbggetjit(char** jit_entry_out, arch arch_in, arch* arch_out)
{
char jit_entry[512];
DWORD jit_entry_size = sizeof(jit_entry);
lRv = RegQueryValueExA(hKey, "Debugger", 0, NULL, (LPBYTE)jit_entry, & jit_entry_size);
if(lRv != ERROR_SUCCESS)
if ( _readwritejitkey(jit_entry, & jit_entry_size, "Debugger", arch_in, arch_out, NULL, false ) == false )
return false;
* jit_entry_out = (char*) emalloc(jit_entry_size, "dbggetjit:*jit_entry_out");
@ -1556,49 +1620,8 @@ bool dbggetdefjit(char* jit_entry)
bool dbgsetjit(char* jit_cmd, arch arch_in, arch* arch_out)
{
DWORD key_flags = KEY_WRITE;
DWORD lRv;
HKEY hKey;
DWORD dwDisposition;
if(arch_out != NULL)
{
if(arch_in != x64 && arch_in != x32)
{
#ifdef _WIN32
* arch_out = x32;
#endif
#ifdef _WIN64
* arch_out = x64;
#endif
}
else
* arch_out = arch_in;
}
if(arch_in == x64)
{
if(!IsWow64())
return false;
#ifdef _WIN32
key_flags |= KEY_WOW64_64KEY;
#endif
}
else if(arch_in == x32)
{
#ifdef _WIN64
key_flags |= KEY_WOW64_32KEY;
#endif
}
lRv = RegCreateKeyEx(HKEY_LOCAL_MACHINE, JIT_REG_KEY, 0, NULL, REG_OPTION_NON_VOLATILE, key_flags, NULL, &hKey, &dwDisposition);
if(lRv != ERROR_SUCCESS)
return false;
lRv = RegSetValueExA(hKey, "Debugger", 0, REG_SZ, (BYTE*) jit_cmd, (DWORD)strlen(jit_cmd) + 1);
RegCloseKey(hKey);
return (lRv == ERROR_SUCCESS);
DWORD jit_cmd_size = strlen( jit_cmd );
return _readwritejitkey(jit_cmd, & jit_cmd_size, "Debugger", arch_in, arch_out, NULL, true );
}
bool dbglistprocesses(std::vector<PROCESSENTRY32>* list)

View File

@ -8,6 +8,12 @@
#define ATTACH_CMD_LINE "\" -a %ld -e %ld"
#define JIT_ENTRY_DEF_SIZE (MAX_PATH + sizeof(ATTACH_CMD_LINE) + 2)
#define JIT_REG_KEY TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug")
typedef enum {
ERROR_RW = 0,
ERROR_RW_FILE_NOT_FOUND
} readwritejitkey_error_t;
//structures
struct INIT_STRUCT
@ -55,6 +61,9 @@ bool dbgcmddel(const char* name);
bool dbggetjit(char** jit_entry_out, arch arch_in, arch* arch_out);
bool dbgsetjit(char* jit_cmd, arch arch_in, arch* arch_out);
bool dbggetdefjit(char* jit_entry);
bool _readwritejitkey( char *, DWORD *, char *, arch, arch*, readwritejitkey_error_t *, bool );
bool dbggetjitauto(bool *, arch, arch*);
bool dbgsetjitauto(bool, arch, arch*);
bool dbglistprocesses(std::vector<PROCESSENTRY32>* list);
void cbStep();

View File

@ -1387,6 +1387,130 @@ CMDRESULT cbDebugDownloadSymbol(int argc, char* argv[])
return STATUS_CONTINUE;
}
CMDRESULT cbDebugGetJITAuto(int argc, char* argv[])
{
bool jit_auto;
arch actual_arch;
if(argc == 1)
{
if(!dbggetjitauto( &jit_auto, notfound, & actual_arch))
{
dprintf("Error getting JIT auto %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
}
}
else if ( argc == 2 )
{
if(_strcmpi(argv[1], "x64") == 0)
{
actual_arch = x64;
if(!IsWow64())
{
dprintf("Error using x64 arg the debugger is not a WOW64 process\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
}
}
else if(_strcmpi(argv[1], "x32") == 0)
actual_arch = x32;
else
{
dputs("Unkown jit auto entry type use x64 or x32 parameter");
return STATUS_ERROR;
}
if(!dbggetjitauto(& jit_auto, actual_arch, NULL))
{
dprintf("Error getting JIT auto %s\n", argv[1]);
return STATUS_ERROR;
}
}
else
{
dputs("Unkown jit auto entry type use x64 or x32 parameter");
}
dprintf(" JIT auto %s: %s\n", (actual_arch == x64) ? "x64" : "x32", jit_auto ? "ON" : "OFF" );
return STATUS_CONTINUE;
}
CMDRESULT cbDebugSetJITAuto(int argc, char* argv[])
{
arch actual_arch;
bool set_jit_auto;
if(argc < 2)
{
dprintf("Error setting JIT Auto use ON/1 or OFF/0 arg\n");
return STATUS_ERROR;
}
else if(argc == 2)
{
if (_strcmpi(argv[1], "1") == 0 || _strcmpi(argv[1], "ON") == 0 )
set_jit_auto = true;
else if (_strcmpi(argv[1], "0") == 0 || _strcmpi(argv[1], "OFF") == 0 )
set_jit_auto = false;
else
{
return STATUS_ERROR;
dputs("Error unkown parameters use x86 or x64, ON/1 or OFF/0");
}
if(!dbgsetjitauto(set_jit_auto, notfound, & actual_arch))
{
dprintf("Error setting JIT auto %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
}
}
else if(argc == 3)
{
actual_arch = x64;
if(_strcmpi(argv[1], "x64") == 0)
{
if(!IsWow64())
{
dprintf("Error using x64 arg the debugger is not a WOW64 process\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
}
}
else if(_strcmpi(argv[1], "x32") == 0)
actual_arch = x32;
else
{
dputs("Unkown jit auto entry type use x64 or x32 parameter");
return STATUS_ERROR;
}
if (_strcmpi(argv[2], "1") == 0 || _strcmpi(argv[2], "ON") == 0 )
set_jit_auto = true;
else if (_strcmpi(argv[2], "0") == 0 || _strcmpi(argv[2], "OFF") == 0 )
set_jit_auto = false;
else
{
return STATUS_ERROR;
dputs("Error unkown parameters use x86 or x64, ON/1 or OFF/0\n");
}
if(!dbgsetjitauto(set_jit_auto, actual_arch, NULL))
{
dprintf("Error getting JIT auto %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
}
}
else
{
dputs("Error unkown parameters use x86 or x64, ON/1 or OFF/0\n");
return STATUS_ERROR;
}
dprintf("New JIT auto %s: %s\n", (actual_arch == x64) ? "x64" : "x32", set_jit_auto ? "ON" : "OFF" );
return STATUS_CONTINUE;
}
CMDRESULT cbDebugSetJIT(int argc, char* argv[])
{
arch actual_arch;

View File

@ -45,6 +45,8 @@ CMDRESULT cbDebugSwitchthread(int argc, char* argv[]);
CMDRESULT cbDebugResumethread(int argc, char* argv[]);
CMDRESULT cbDebugSetJIT(int argc, char* argv[]);
CMDRESULT cbDebugGetJIT(int argc, char* argv[]);
CMDRESULT cbDebugGetJITAuto(int argc, char* argv[]);
CMDRESULT cbDebugSetJITAuto(int argc, char* argv[]);
CMDRESULT cbDebugSuspendthread(int argc, char* argv[]);
CMDRESULT cbDebugKillthread(int argc, char* argv[]);
CMDRESULT cbDebugSetPriority(int argc, char* argv[]);

View File

@ -104,6 +104,8 @@ static void registercommands()
dbgcmdnew("symdownload\1downloadsym", cbDebugDownloadSymbol, true); //download symbols
dbgcmdnew("setjit\1jitset", cbDebugSetJIT, false); //set JIT
dbgcmdnew("getjit\1jitget", cbDebugGetJIT, false); //get JIT
dbgcmdnew("getjitauto\1jitgetauto", cbDebugGetJITAuto, false); //get JIT Auto
dbgcmdnew("setjitauto\1jitsetauto", cbDebugSetJITAuto, false); //set JIT Auto
//breakpoints
dbgcmdnew("bplist", cbDebugBplist, true); //breakpoint list

View File

@ -169,6 +169,7 @@ void SettingsDialog::LoadSettings()
#endif
if(DbgFunctions()->GetJit)
{
bool jit_auto_on;
DbgFunctions()->GetJit(jit_entry, isx64);
DbgFunctions()->GetDefJit(jit_def_entry);
@ -178,7 +179,18 @@ void SettingsDialog::LoadSettings()
settings.eventSetJIT = false;
ui->editJIT->setText(jit_entry);
ui->editJIT->setCursorPosition(0);
ui->chkSetJIT->setCheckState(bool2check(settings.eventSetJIT));
if ( DbgFunctions()->GetJitAuto(&jit_auto_on) )
{
if (jit_auto_on)
settings.eventSetJITAuto = true;
else
settings.eventSetJITAuto = false;
ui->chkConfirmBeforeAtt->setCheckState(bool2check(settings.eventSetJITAuto));
}
}
}
}
@ -227,6 +239,11 @@ void SettingsDialog::SaveSettings()
DbgCmdExecDirect("setjit");
else
DbgCmdExecDirect("setjit restore");
if(settings.eventSetJITAuto)
DbgCmdExecDirect("setjitauto on");
else
DbgCmdExecDirect("setjitauto off");
}
Config()->load();
@ -321,6 +338,14 @@ void SettingsDialog::on_chkAttachBreakpoint_stateChanged(int arg1)
settings.eventAttachBreakpoint = true;
}
void SettingsDialog::on_chkConfirmBeforeAtt_stateChanged(int arg1)
{
if(arg1 == Qt::Unchecked)
settings.eventSetJITAuto = false;
else
settings.eventSetJITAuto = true;
}
void SettingsDialog::on_chkSetJIT_stateChanged(int arg1)
{
if(arg1 == Qt::Unchecked)

View File

@ -57,6 +57,8 @@ private slots:
void on_chkOnlyCipAutoComments_stateChanged(int arg1);
//Misc tab
void on_chkSetJIT_stateChanged(int arg1);
void on_chkConfirmBeforeAtt_stateChanged(int arg1);
private:
//enums
@ -116,6 +118,7 @@ private:
bool disasmOnlyCipAutoComments;
//Misc Tab
bool eventSetJIT;
bool eventSetJITAuto;
};
//variables

View File

@ -477,7 +477,7 @@
<string>Set x64_dbg as Just In Time Debugger</string>
</property>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
@ -503,6 +503,19 @@
</item>
</layout>
</widget>
<widget class="QCheckBox" name="chkConfirmBeforeAtt">
<property name="geometry">
<rect>
<x>150</x>
<y>60</y>
<width>141</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Confirm before attaching</string>
</property>
</widget>
</widget>
</widget>
<widget class="QPushButton" name="btnSave">