1
0
Fork 0

new jit and jet auto stuff improves, wow64 stuff and auto registry creation stuff

This commit is contained in:
dreg_fr33project 2014-08-08 15:31:17 +02:00
parent 24f2202f02
commit 41ddea139e
4 changed files with 108 additions and 63 deletions

View File

@ -109,14 +109,14 @@ static void _getcallstack(DBGCALLSTACK* callstack)
static bool _getjitauto(bool* jit_auto)
{
return dbggetjitauto(jit_auto, notfound, NULL);
return dbggetjitauto(jit_auto, notfound, NULL, NULL);
}
static bool _getjit(char* jit, bool jit64)
{
arch dummy;
char jit_tmp[JIT_ENTRY_MAX_SIZE] = "";
if(!dbggetjit(jit_tmp, jit64 ? x64 : x32, &dummy))
if(!dbggetjit(jit_tmp, jit64 ? x64 : x32, &dummy, NULL))
return false;
strcpy(jit, jit_tmp);
return true;

View File

@ -1510,8 +1510,15 @@ bool _readwritejitkey(char* jit_key_value, DWORD* jit_key_vale_size, char* key,
if(arch_in == x64)
{
#ifdef _WIN32
if(!IsWow64())
{
if(error != NULL)
* error = ERROR_RW_NOTWOW64;
return false;
}
#endif
#ifdef _WIN32
key_flags |= KEY_WOW64_64KEY;
@ -1553,7 +1560,7 @@ bool _readwritejitkey(char* jit_key_value, DWORD* jit_key_vale_size, char* key,
return true;
}
bool dbggetjitauto(bool* auto_on, arch arch_in, arch* arch_out)
bool dbggetjitauto(bool* auto_on, arch arch_in, arch* arch_out, readwritejitkey_error_t* rw_error_out)
{
char jit_entry[4];
DWORD jit_entry_size = sizeof(jit_entry) - 1;
@ -1562,7 +1569,12 @@ bool dbggetjitauto(bool* auto_on, arch arch_in, arch* arch_out)
if(_readwritejitkey(jit_entry, & jit_entry_size, "Auto", arch_in, arch_out, & rw_error, false) == false)
{
if(rw_error = ERROR_RW_FILE_NOT_FOUND)
{
if(rw_error_out != NULL)
* rw_error_out = rw_error;
return true;
}
return false;
}
@ -1576,17 +1588,47 @@ bool dbggetjitauto(bool* auto_on, arch arch_in, arch* arch_out)
return true;
}
bool dbgsetjitauto(bool auto_on, arch arch_in, arch* arch_out)
bool dbgsetjitauto(bool auto_on, arch arch_in, arch* arch_out, readwritejitkey_error_t* rw_error_out)
{
DWORD auto_string_size = sizeof("1");
readwritejitkey_error_t rw_error;
return _readwritejitkey(auto_on ? "1" : "0", & auto_string_size, "Auto", arch_in, arch_out, NULL, true);
if(auto_on == false)
{
char jit_entry[4];
DWORD jit_entry_size = sizeof(jit_entry) - 1;
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;
}
}
if(_readwritejitkey(auto_on ? "1" : "0", & auto_string_size, "Auto", arch_in, arch_out, & rw_error, true) == false)
{
if(rw_error_out != NULL)
* rw_error_out = rw_error;
return false;
}
return true;
}
bool dbggetjit(char jit_entry[JIT_ENTRY_MAX_SIZE], arch arch_in, arch* arch_out)
bool dbggetjit(char jit_entry[JIT_ENTRY_MAX_SIZE], arch arch_in, arch* arch_out, readwritejitkey_error_t* rw_error_out)
{
DWORD jit_entry_size = JIT_ENTRY_MAX_SIZE;
return _readwritejitkey(jit_entry, & jit_entry_size, "Debugger", arch_in, arch_out, NULL, false);
readwritejitkey_error_t rw_error;
if(_readwritejitkey(jit_entry, & jit_entry_size, "Debugger", arch_in, arch_out, & rw_error, false) == false)
{
if(rw_error_out != NULL)
* rw_error_out = rw_error;
return false;
}
return true;
}
bool dbggetdefjit(char* jit_entry)
@ -1600,10 +1642,19 @@ bool dbggetdefjit(char* jit_entry)
return true;
}
bool dbgsetjit(char* jit_cmd, arch arch_in, arch* arch_out)
bool dbgsetjit(char* jit_cmd, arch arch_in, arch* arch_out, readwritejitkey_error_t* rw_error_out)
{
DWORD jit_cmd_size = (DWORD)strlen(jit_cmd);
return _readwritejitkey(jit_cmd, & jit_cmd_size, "Debugger", arch_in, arch_out, NULL, true);
readwritejitkey_error_t rw_error;
if(_readwritejitkey(jit_cmd, & jit_cmd_size, "Debugger", arch_in, arch_out, & rw_error, true) == false)
{
if(rw_error_out != NULL)
* rw_error_out = rw_error;
return false;
}
return true;
}
bool dbglistprocesses(std::vector<PROCESSENTRY32>* list)

View File

@ -14,7 +14,8 @@
typedef enum
{
ERROR_RW = 0,
ERROR_RW_FILE_NOT_FOUND
ERROR_RW_FILE_NOT_FOUND,
ERROR_RW_NOTWOW64
} readwritejitkey_error_t;
//structures
@ -60,12 +61,12 @@ void dbgaddignoredexception(ExceptionRange range);
bool dbgisignoredexception(unsigned int exception);
bool dbgcmdnew(const char* name, CBCOMMAND cbCommand, bool debugonly);
bool dbgcmddel(const char* name);
bool dbggetjit(char jit_entry[JIT_ENTRY_MAX_SIZE], arch arch_in, arch* arch_out);
bool dbgsetjit(char* jit_cmd, arch arch_in, arch* arch_out);
bool dbggetjit(char jit_entry[JIT_ENTRY_MAX_SIZE], arch arch_in, arch* arch_out, readwritejitkey_error_t*);
bool dbgsetjit(char* jit_cmd, arch arch_in, arch* arch_out, readwritejitkey_error_t*);
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 dbggetjitauto(bool*, arch, arch*, readwritejitkey_error_t*);
bool dbgsetjitauto(bool, arch, arch*, readwritejitkey_error_t*);
bool dbglistprocesses(std::vector<PROCESSENTRY32>* list);
void cbStep();

View File

@ -1395,7 +1395,7 @@ CMDRESULT cbDebugGetJITAuto(int argc, char* argv[])
if(argc == 1)
{
if(!dbggetjitauto(&jit_auto, notfound, & actual_arch))
if(!dbggetjitauto(&jit_auto, notfound, & actual_arch, NULL))
{
dprintf("Error getting JIT auto %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
@ -1403,16 +1403,9 @@ CMDRESULT cbDebugGetJITAuto(int argc, char* argv[])
}
else if(argc == 2)
{
readwritejitkey_error_t rw_error;
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
@ -1421,9 +1414,12 @@ CMDRESULT cbDebugGetJITAuto(int argc, char* argv[])
return STATUS_ERROR;
}
if(!dbggetjitauto(& jit_auto, actual_arch, NULL))
if(!dbggetjitauto(& jit_auto, actual_arch, NULL, & rw_error))
{
dprintf("Error getting JIT auto %s\n", argv[1]);
if(rw_error == ERROR_RW_NOTWOW64)
dprintf("Error using x64 arg the debugger is not a WOW64 process\n");
else
dprintf("Error getting JIT auto %s\n", argv[1]);
return STATUS_ERROR;
}
}
@ -1443,7 +1439,7 @@ CMDRESULT cbDebugSetJITAuto(int argc, char* argv[])
bool set_jit_auto;
if(argc < 2)
{
dprintf("Error setting JIT Auto use ON/1 or OFF/0 arg\n");
dprintf("Error setting JIT Auto use ON/1 or OFF/0 arg or x64/x32, ON/1 or OFF/0 args\n");
return STATUS_ERROR;
}
else if(argc == 2)
@ -1454,11 +1450,11 @@ CMDRESULT cbDebugSetJITAuto(int argc, char* argv[])
set_jit_auto = false;
else
{
dputs("Error unkown parameters use ON/1 or OFF/0");
return STATUS_ERROR;
dputs("Error unkown parameters use x86 or x64, ON/1 or OFF/0");
}
if(!dbgsetjitauto(set_jit_auto, notfound, & actual_arch))
if(!dbgsetjitauto(set_jit_auto, notfound, & actual_arch, NULL))
{
dprintf("Error setting JIT auto %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
@ -1466,16 +1462,11 @@ CMDRESULT cbDebugSetJITAuto(int argc, char* argv[])
}
else if(argc == 3)
{
readwritejitkey_error_t rw_error;
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;
}
}
actual_arch = x64;
else if(_strcmpi(argv[1], "x32") == 0)
actual_arch = x32;
else
@ -1494,9 +1485,13 @@ CMDRESULT cbDebugSetJITAuto(int argc, char* argv[])
dputs("Error unkown parameters use x86 or x64, ON/1 or OFF/0\n");
}
if(!dbgsetjitauto(set_jit_auto, actual_arch, NULL))
if(!dbgsetjitauto(set_jit_auto, actual_arch, NULL, & rw_error))
{
dprintf("Error getting JIT auto %s\n", (actual_arch == x64) ? "x64" : "x32");
if(rw_error == ERROR_RW_NOTWOW64)
dprintf("Error using x64 arg the debugger is not a WOW64 process\n");
else
dprintf("Error getting JIT auto %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
}
}
@ -1522,7 +1517,7 @@ CMDRESULT cbDebugSetJIT(int argc, char* argv[])
char path[JIT_ENTRY_DEF_SIZE];
dbggetdefjit(path);
char get_entry[JIT_ENTRY_MAX_SIZE] = "";
if(!dbggetjit(get_entry, notfound, & actual_arch))
if(!dbggetjit(get_entry, notfound, & actual_arch, NULL))
{
dprintf("Error getting JIT %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
@ -1530,7 +1525,7 @@ CMDRESULT cbDebugSetJIT(int argc, char* argv[])
strcpy_s(oldjit, get_entry);
jit_debugger_cmd = path;
if(!dbgsetjit(jit_debugger_cmd, notfound, & actual_arch))
if(!dbgsetjit(jit_debugger_cmd, notfound, & actual_arch, NULL))
{
dprintf("Error setting JIT %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
@ -1543,9 +1538,14 @@ CMDRESULT cbDebugSetJIT(int argc, char* argv[])
if(!_strcmpi(argv[1], "restore"))
{
jit_debugger_cmd = oldjit;
if(!BridgeSettingGet("JIT", "Old", jit_debugger_cmd))
return STATUS_CONTINUE; //nothing to restore
if(!dbgsetjit(jit_debugger_cmd, notfound, & actual_arch))
{
dputs(" Error dont exist an OLD JIT, please use setjit command");
return STATUS_ERROR; //nothing to restore
}
if(!dbgsetjit(jit_debugger_cmd, notfound, & actual_arch, NULL))
{
dprintf("Error setting JIT %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
@ -1555,7 +1555,7 @@ CMDRESULT cbDebugSetJIT(int argc, char* argv[])
else
{
jit_debugger_cmd = argv[1];
if(!dbgsetjit(jit_debugger_cmd, notfound, & actual_arch))
if(!dbgsetjit(jit_debugger_cmd, notfound, & actual_arch, NULL))
{
dprintf("Error setting JIT %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
@ -1564,16 +1564,10 @@ CMDRESULT cbDebugSetJIT(int argc, char* argv[])
}
else if(argc == 3)
{
actual_arch = x64;
readwritejitkey_error_t rw_error;
if(_strcmpi(argv[1], "x64") == 0)
{
if(!IsWow64())
{
dprintf("Error using x64 arg the debugger is not a WOW64 process", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
}
}
actual_arch = x64;
else if(_strcmpi(argv[1], "x32") == 0)
actual_arch = x32;
else
@ -1583,9 +1577,12 @@ CMDRESULT cbDebugSetJIT(int argc, char* argv[])
}
jit_debugger_cmd = argv[2];
if(!dbgsetjit(jit_debugger_cmd, actual_arch, NULL))
if(!dbgsetjit(jit_debugger_cmd, actual_arch, NULL, & rw_error))
{
dprintf("Error getting JIT %s\n", (actual_arch == x64) ? "x64" : "x32");
if(rw_error == ERROR_RW_NOTWOW64)
dprintf("Error using x64 arg the debugger is not a WOW64 process\n");
else
dprintf("Error getting JIT %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
}
}
@ -1607,7 +1604,7 @@ CMDRESULT cbDebugGetJIT(int argc, char* argv[])
if(argc < 2)
{
if(!dbggetjit(get_entry, notfound, & actual_arch))
if(!dbggetjit(get_entry, notfound, & actual_arch, NULL))
{
dprintf("Error getting JIT %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
@ -1615,16 +1612,9 @@ CMDRESULT cbDebugGetJIT(int argc, char* argv[])
}
else
{
readwritejitkey_error_t rw_error;
if(_strcmpi(argv[1], "x64") == 0)
{
actual_arch = x64;
if(!IsWow64())
{
dprintf("Error using x64 arg the debugger is not a WOW64 process", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
}
}
else if(_strcmpi(argv[1], "x32") == 0)
actual_arch = x32;
else
@ -1633,9 +1623,12 @@ CMDRESULT cbDebugGetJIT(int argc, char* argv[])
return STATUS_ERROR;
}
if(!dbggetjit(get_entry, actual_arch, NULL))
if(!dbggetjit(get_entry, actual_arch, NULL, & rw_error))
{
dprintf("Error getting JIT %s\n", argv[1]);
if(rw_error == ERROR_RW_NOTWOW64)
dprintf("Error using x64 arg the debugger is not a WOW64 process\n");
else
dprintf("Error getting JIT %s\n", argv[1]);
return STATUS_ERROR;
}
}