QColor Configuration::colorFromConfig(const QString id) { char setting[MAX_SETTING_SIZE] = ""; if(!BridgeSettingGet("Colors", id.toUtf8().constData(), setting)) { if(defaultColors.contains(id)) { QColor ret = defaultColors.find(id).value(); colorToConfig(id, ret); return ret; } return Qt::black; //black is default } if(QString(setting).toUpper() == "#XXXXXX") //support custom transparent color name return Qt::transparent; QColor color(setting); if(!color.isValid()) { if(defaultColors.contains(id)) { QColor ret = defaultColors.find(id).value(); colorToConfig(id, ret); return ret; } return Qt::black; //black is default } return color; }
QString Configuration::shortcutFromConfig(const QString id) { QString _id = QString("%1").arg(id); char setting[MAX_SETTING_SIZE] = ""; if(BridgeSettingGet("Shortcuts", _id.toUtf8().constData(), setting)) { return QString(setting); } return ""; }
bool cbDebugGetJIT(int argc, char* argv[]) { char get_entry[JIT_ENTRY_MAX_SIZE] = ""; arch actual_arch; if(argc < 2) { if(!dbggetjit(get_entry, notfound, &actual_arch, NULL)) { dprintf(QT_TRANSLATE_NOOP("DBG", "Error getting JIT %s\n"), (actual_arch == x64) ? "x64" : "x32"); return false; } } else { readwritejitkey_error_t rw_error; Memory<char*> oldjit(MAX_SETTING_SIZE + 1); if(_strcmpi(argv[1], "OLD") == 0) { if(!BridgeSettingGet("JIT", "Old", oldjit())) { dputs(QT_TRANSLATE_NOOP("DBG", "Error: there is not an OLD JIT entry stored yet.")); return false; } else { dprintf(QT_TRANSLATE_NOOP("DBG", "OLD JIT entry stored: %s\n"), oldjit()); return true; } } else if(_strcmpi(argv[1], "x64") == 0) actual_arch = x64; else if(_strcmpi(argv[1], "x32") == 0) actual_arch = x32; else { dputs(QT_TRANSLATE_NOOP("DBG", "Unknown JIT entry type. Use OLD, x64 or x32 as parameter.")); return false; } if(!dbggetjit(get_entry, actual_arch, NULL, &rw_error)) { if(rw_error == ERROR_RW_NOTWOW64) dputs(QT_TRANSLATE_NOOP("DBG", "Error using x64 arg. The debugger is not a WOW64 process\n")); else dprintf(QT_TRANSLATE_NOOP("DBG", "Error getting JIT %s\n"), argv[1]); return false; } } dprintf(QT_TRANSLATE_NOOP("DBG", "JIT %s: %s\n"), (actual_arch == x64) ? "x64" : "x32", get_entry); return true; }
BRIDGE_IMPEXP bool BridgeSettingGetUint(const char* section, const char* key, duint* value) { if(!section || !key || !value) return false; char newvalue[MAX_SETTING_SIZE] = ""; if(!BridgeSettingGet(section, key, newvalue)) return false; #ifdef _WIN64 int ret = sscanf(newvalue, "%llX", value); #else int ret = sscanf(newvalue, "%X", value); #endif //_WIN64 if(ret) return true; return false; }
QFont Configuration::fontFromConfig(const QString id) { char setting[MAX_SETTING_SIZE] = ""; if(!BridgeSettingGet("Fonts", id.toUtf8().constData(), setting)) { if(defaultFonts.contains(id)) { QFont ret = defaultFonts.find(id).value(); fontToConfig(id, ret); return ret; } if(id == "Application") return QApplication::font(); QFont ret("Lucida Console", 8, QFont::Normal, false); ret.setFixedPitch(true); ret.setStyleHint(QFont::Monospace); return ret; } QFont font; if(!font.fromString(setting)) { if(defaultFonts.contains(id)) { QFont ret = defaultFonts.find(id).value(); fontToConfig(id, ret); return ret; } if(id == "Application") return QApplication::font(); QFont ret("Lucida Console", 8, QFont::Normal, false); ret.setFixedPitch(true); ret.setStyleHint(QFont::Monospace); return ret; } return font; }
extern "C" DLL_EXPORT const char* _dbg_dbginit() { if(!EngineCheckStructAlignment(UE_STRUCT_TITAN_ENGINE_CONTEXT, sizeof(TITAN_ENGINE_CONTEXT_t))) return "Invalid TITAN_ENGINE_CONTEXT_t alignment!"; if(sizeof(TITAN_ENGINE_CONTEXT_t) != sizeof(REGISTERCONTEXT)) return "Invalid REGISTERCONTEXT alignment!"; dputs("Initializing wait objects..."); waitinitialize(); dputs("Initializing debugger..."); dbginit(); dputs("Initializing debugger functions..."); dbgfunctionsinit(); dputs("Setting JSON memory management functions..."); json_set_alloc_funcs(json_malloc, json_free); dputs("Initializing capstone..."); Capstone::GlobalInitialize(); dputs("Initializing Yara..."); if(yr_initialize() != ERROR_SUCCESS) return "Failed to initialize Yara!"; dputs("Getting directory information..."); wchar_t wszDir[deflen] = L""; if(!GetModuleFileNameW(hInst, wszDir, deflen)) return "GetModuleFileNameW failed!"; char dir[deflen] = ""; strcpy_s(dir, StringUtils::Utf16ToUtf8(wszDir).c_str()); int len = (int)strlen(dir); while(dir[len] != '\\') len--; dir[len] = 0; strcpy_s(alloctrace, dir); strcat_s(alloctrace, "\\alloctrace.txt"); DeleteFileW(StringUtils::Utf8ToUtf16(alloctrace).c_str()); setalloctrace(alloctrace); strcpy_s(dbbasepath, dir); //debug directory strcat_s(dbbasepath, "\\db"); CreateDirectoryW(StringUtils::Utf8ToUtf16(dbbasepath).c_str(), 0); //create database directory char szLocalSymbolPath[MAX_PATH] = ""; strcpy_s(szLocalSymbolPath, dir); strcat_s(szLocalSymbolPath, "\\symbols"); char cachePath[MAX_SETTING_SIZE]; if(!BridgeSettingGet("Symbols", "CachePath", cachePath) || !*cachePath) { strcpy_s(szSymbolCachePath, szLocalSymbolPath); BridgeSettingSet("Symbols", "CachePath", ".\\symbols"); } else { if (_strnicmp(cachePath, ".\\", 2) == 0) { strncpy_s(szSymbolCachePath, dir, _TRUNCATE); strncat_s(szSymbolCachePath, cachePath + 1, _TRUNCATE); } else { // Trim the buffer to fit inside MAX_PATH strncpy_s(szSymbolCachePath, cachePath, _TRUNCATE); } if(strstr(szSymbolCachePath, "http://") || strstr(szSymbolCachePath, "https://")) { if(Script::Gui::MessageYesNo("It is strongly discouraged to use symbol servers in your path directly (use the store option instead).\n\nDo you want me to fix this?")) { strcpy_s(szSymbolCachePath, szLocalSymbolPath); BridgeSettingSet("Symbols", "CachePath", ".\\symbols"); } } } dputs(szSymbolCachePath); SetCurrentDirectoryW(StringUtils::Utf8ToUtf16(dir).c_str()); dputs("Allocating message stack..."); gMsgStack = MsgAllocStack(); if(!gMsgStack) return "Could not allocate message stack!"; dputs("Initializing global script variables..."); varinit(); dputs("Registering debugger commands..."); registercommands(); dputs("Starting command loop..."); hCommandLoopThread = CreateThread(0, 0, DbgCommandLoopThread, 0, 0, 0); char plugindir[deflen] = ""; strcpy_s(plugindir, dir); strcat_s(plugindir, "\\plugins"); CreateDirectoryW(StringUtils::Utf8ToUtf16(plugindir).c_str(), 0); dputs("Loading plugins..."); pluginload(plugindir); dputs("Handling command line..."); //handle command line int argc = 0; wchar_t** argv = CommandLineToArgvW(GetCommandLineW(), &argc); if(argc == 2) //we have an argument { String str = "init \""; str += StringUtils::Utf16ToUtf8(argv[1]); str += "\""; DbgCmdExec(str.c_str()); } else if(argc == 5) //4 arguments (JIT) { if(_wcsicmp(argv[1], L"-a") == 0 && !_wcsicmp(argv[3], L"-e")) { String str = "attach ."; str += StringUtils::Utf16ToUtf8(argv[2]); str += ", ."; str += StringUtils::Utf16ToUtf8(argv[4]); DbgCmdExec(str.c_str()); } } LocalFree(argv); dputs("Initialization successful!"); bIsStopped = false; return nullptr; }
bool cbDebugSetJIT(int argc, char* argv[]) { arch actual_arch = invalid; char* jit_debugger_cmd = ""; Memory<char*> oldjit(MAX_SETTING_SIZE + 1); char path[JIT_ENTRY_DEF_SIZE]; if(!IsProcessElevated()) { dputs(QT_TRANSLATE_NOOP("DBG", "Error run the debugger as Admin to setjit\n")); return false; } if(argc < 2) { dbggetdefjit(path); jit_debugger_cmd = path; if(!dbgsetjit(jit_debugger_cmd, notfound, &actual_arch, NULL)) { dprintf(QT_TRANSLATE_NOOP("DBG", "Error setting JIT %s\n"), (actual_arch == x64) ? "x64" : "x32"); return false; } } else if(argc == 2) { if(!_strcmpi(argv[1], "old")) { jit_debugger_cmd = oldjit(); if(!BridgeSettingGet("JIT", "Old", jit_debugger_cmd)) { dputs(QT_TRANSLATE_NOOP("DBG", "Error there is no old JIT entry stored.")); return false; } if(!dbgsetjit(jit_debugger_cmd, notfound, &actual_arch, NULL)) { dprintf(QT_TRANSLATE_NOOP("DBG", "Error setting JIT %s\n"), (actual_arch == x64) ? "x64" : "x32"); return false; } } else if(!_strcmpi(argv[1], "oldsave")) { dbggetdefjit(path); char get_entry[JIT_ENTRY_MAX_SIZE] = ""; bool get_last_jit = true; if(!dbggetjit(get_entry, notfound, &actual_arch, NULL)) { get_last_jit = false; } else strcpy_s(oldjit(), MAX_SETTING_SIZE, get_entry); jit_debugger_cmd = path; if(!dbgsetjit(jit_debugger_cmd, notfound, &actual_arch, NULL)) { dprintf(QT_TRANSLATE_NOOP("DBG", "Error setting JIT %s\n"), (actual_arch == x64) ? "x64" : "x32"); return false; } if(get_last_jit) { if(_stricmp(oldjit(), path)) BridgeSettingSet("JIT", "Old", oldjit()); } } else if(!_strcmpi(argv[1], "restore")) { jit_debugger_cmd = oldjit(); if(!BridgeSettingGet("JIT", "Old", jit_debugger_cmd)) { dputs(QT_TRANSLATE_NOOP("DBG", "Error there is no old JIT entry stored.")); return false; } if(!dbgsetjit(jit_debugger_cmd, notfound, &actual_arch, NULL)) { dprintf(QT_TRANSLATE_NOOP("DBG", "Error setting JIT %s\n"), (actual_arch == x64) ? "x64" : "x32"); return false; } BridgeSettingSet("JIT", 0, 0); } else { jit_debugger_cmd = argv[1]; if(!dbgsetjit(jit_debugger_cmd, notfound, &actual_arch, NULL)) { dprintf(QT_TRANSLATE_NOOP("DBG", "Error setting JIT %s\n"), (actual_arch == x64) ? "x64" : "x32"); return false; } } } else if(argc == 3) { readwritejitkey_error_t rw_error; if(!_strcmpi(argv[1], "old")) { BridgeSettingSet("JIT", "Old", argv[2]); dprintf(QT_TRANSLATE_NOOP("DBG", "New OLD JIT stored: %s\n"), argv[2]); return true; } else if(_strcmpi(argv[1], "x64") == 0) actual_arch = x64; else if(_strcmpi(argv[1], "x32") == 0) actual_arch = x32; else { dputs(QT_TRANSLATE_NOOP("DBG", "Unknown JIT entry type. Use OLD, x64 or x32 as parameter.")); return false; } jit_debugger_cmd = argv[2]; if(!dbgsetjit(jit_debugger_cmd, actual_arch, NULL, &rw_error)) { if(rw_error == ERROR_RW_NOTWOW64) dputs(QT_TRANSLATE_NOOP("DBG", "Error using x64 arg. The debugger is not a WOW64 process\n")); else dprintf(QT_TRANSLATE_NOOP("DBG", "Error setting JIT %s\n"), (actual_arch == x64) ? "x64" : "x32"); return false; } } else { dputs(QT_TRANSLATE_NOOP("DBG", "Error unknown parameters. Use old, oldsave, restore, x86 or x64 as parameter.")); return false; } dprintf(QT_TRANSLATE_NOOP("DBG", "New JIT %s: %s\n"), (actual_arch == x64) ? "x64" : "x32", jit_debugger_cmd); return true; }
int main(int argc, char* argv[]) { qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1"); MyApplication application(argc, argv); QFile f(QString("%1/style.css").arg(QCoreApplication::applicationDirPath())); if(f.open(QFile::ReadOnly | QFile::Text)) { QTextStream in(&f); auto style = in.readAll(); f.close(); application.setStyleSheet(style); } #if QT_VERSION < QT_VERSION_CHECK(5,0,0) QAbstractEventDispatcher::instance(application.thread())->setEventFilter(MyApplication::globalEventFilter); #else auto eventFilter = new MyEventFilter(); application.installNativeEventFilter(eventFilter); #endif // Get the hidden language setting (for testers) if(!BridgeSettingGet("Engine", "Language", currentLocale) || !isValidLocale(currentLocale)) { QStringList uiLanguages = QLocale::system().uiLanguages(); QString sysLocale = uiLanguages.size() ? QLocale(uiLanguages[0]).name() : QLocale::system().name(); strcpy_s(currentLocale, sysLocale.toUtf8().constData()); BridgeSettingSet("Engine", "Language", currentLocale); } // Load translations for Qt QTranslator qtTranslator; if(qtTranslator.load(QString("qt_%1").arg(currentLocale), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) application.installTranslator(&qtTranslator); //x64dbg and x32dbg can share the same translation QTranslator x64dbgTranslator; auto path = QString("%1/../translations").arg(QCoreApplication::applicationDirPath()); if(x64dbgTranslator.load(QString("x64dbg_%1").arg(currentLocale), path)) application.installTranslator(&x64dbgTranslator); TLS_TranslatedStringMap = new std::map<DWORD, TranslatedStringStorage>(); // initialize capstone Capstone::GlobalInitialize(); // load config file + set config font mConfiguration = new Configuration; application.setFont(ConfigFont("Application")); // Register custom data types qRegisterMetaType<dsint>("dsint"); qRegisterMetaType<duint>("duint"); qRegisterMetaType<byte_t>("byte_t"); qRegisterMetaType<DBGSTATE>("DBGSTATE"); // Set QString codec to UTF-8 QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); #if QT_VERSION < QT_VERSION_CHECK(5,0,0) QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); #endif // Init communication with debugger Bridge::initBridge(); // Start GUI MainWindow* mainWindow; mainWindow = new MainWindow(); mainWindow->show(); // Set some data Bridge::getBridge()->winId = (void*)mainWindow->winId(); // Init debugger const char* errormsg = DbgInit(); if(errormsg) { QMessageBox msg(QMessageBox::Critical, QObject::tr("DbgInit Error!"), QString(errormsg)); msg.setWindowIcon(DIcon("compile-error.png")); msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint)); msg.exec(); exit(1); } //execute the application int result = application.exec(); #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) application.removeNativeEventFilter(eventFilter); #else QAbstractEventDispatcher::instance(application.thread())->setEventFilter(nullptr); #endif delete mainWindow; mConfiguration->save(); //save config on exit { //delete tls auto temp = TLS_TranslatedStringMap; TLS_TranslatedStringMap = nullptr; delete temp; } //TODO free capstone/config/bridge and prevent use after free. return result; }
void SettingsDialog::LoadSettings() { //Defaults memset(&settings, 0, sizeof(SettingsStruct)); settings.eventSystemBreakpoint = true; settings.eventTlsCallbacks = true; settings.eventEntryBreakpoint = true; settings.eventAttachBreakpoint = true; settings.engineCalcType = calc_unsigned; settings.engineBreakpointType = break_int3short; settings.engineUndecorateSymbolNames = true; settings.engineEnableSourceDebugging = true; settings.exceptionRanges = &realExceptionRanges; settings.disasmArgumentSpaces = false; settings.disasmMemorySpaces = false; settings.disasmUppercase = false; settings.disasmOnlyCipAutoComments = false; settings.disasmTabBetweenMnemonicAndArguments = false; //Events tab GetSettingBool("Events", "SystemBreakpoint", &settings.eventSystemBreakpoint); GetSettingBool("Events", "TlsCallbacks", &settings.eventTlsCallbacks); GetSettingBool("Events", "EntryBreakpoint", &settings.eventEntryBreakpoint); GetSettingBool("Events", "DllEntry", &settings.eventDllEntry); GetSettingBool("Events", "ThreadEntry", &settings.eventThreadEntry); GetSettingBool("Events", "AttachBreakpoint", &settings.eventAttachBreakpoint); GetSettingBool("Events", "DllLoad", &settings.eventDllLoad); GetSettingBool("Events", "DllUnload", &settings.eventDllUnload); GetSettingBool("Events", "ThreadStart", &settings.eventThreadStart); GetSettingBool("Events", "ThreadEnd", &settings.eventThreadEnd); GetSettingBool("Events", "DebugStrings", &settings.eventDebugStrings); ui->chkSystemBreakpoint->setCheckState(bool2check(settings.eventSystemBreakpoint)); ui->chkTlsCallbacks->setCheckState(bool2check(settings.eventTlsCallbacks)); ui->chkEntryBreakpoint->setCheckState(bool2check(settings.eventEntryBreakpoint)); ui->chkDllEntry->setCheckState(bool2check(settings.eventDllEntry)); ui->chkThreadEntry->setCheckState(bool2check(settings.eventThreadEntry)); ui->chkAttachBreakpoint->setCheckState(bool2check(settings.eventAttachBreakpoint)); ui->chkDllLoad->setCheckState(bool2check(settings.eventDllLoad)); ui->chkDllUnload->setCheckState(bool2check(settings.eventDllUnload)); ui->chkThreadStart->setCheckState(bool2check(settings.eventThreadStart)); ui->chkThreadEnd->setCheckState(bool2check(settings.eventThreadEnd)); ui->chkDebugStrings->setCheckState(bool2check(settings.eventDebugStrings)); //Engine tab duint cur; if(BridgeSettingGetUint("Engine", "CalculationType", &cur)) { switch(cur) { case calc_signed: case calc_unsigned: settings.engineCalcType = (CalcType)cur; break; } } if(BridgeSettingGetUint("Engine", "BreakpointType", &cur)) { switch(cur) { case break_int3short: case break_int3long: case break_ud2: settings.engineBreakpointType = (BreakpointType)cur; break; } } GetSettingBool("Engine", "UndecorateSymbolNames", &settings.engineUndecorateSymbolNames); GetSettingBool("Engine", "EnableDebugPrivilege", &settings.engineEnableDebugPrivilege); GetSettingBool("Engine", "EnableSourceDebugging", &settings.engineEnableSourceDebugging); GetSettingBool("Engine", "SaveDatabaseInProgramDirectory", &settings.engineSaveDatabaseInProgramDirectory); GetSettingBool("Engine", "DisableDatabaseCompression", &settings.engineDisableDatabaseCompression); switch(settings.engineCalcType) { case calc_signed: ui->radioSigned->setChecked(true); break; case calc_unsigned: ui->radioUnsigned->setChecked(true); break; } switch(settings.engineBreakpointType) { case break_int3short: ui->radioInt3Short->setChecked(true); break; case break_int3long: ui->radioInt3Long->setChecked(true); break; case break_ud2: ui->radioUd2->setChecked(true); break; } ui->chkUndecorateSymbolNames->setChecked(settings.engineUndecorateSymbolNames); ui->chkEnableDebugPrivilege->setChecked(settings.engineEnableDebugPrivilege); ui->chkEnableSourceDebugging->setChecked(settings.engineEnableSourceDebugging); ui->chkSaveDatabaseInProgramDirectory->setChecked(settings.engineSaveDatabaseInProgramDirectory); ui->chkDisableDatabaseCompression->setChecked(settings.engineDisableDatabaseCompression); //Exceptions tab char exceptionRange[MAX_SETTING_SIZE] = ""; if(BridgeSettingGet("Exceptions", "IgnoreRange", exceptionRange)) { QStringList ranges = QString(exceptionRange).split(QString(","), QString::SkipEmptyParts); for(int i = 0; i < ranges.size(); i++) { unsigned long start; unsigned long end; if(sscanf_s(ranges.at(i).toUtf8().constData(), "%08X-%08X", &start, &end) == 2 && start <= end) { RangeStruct newRange; newRange.start = start; newRange.end = end; AddRangeToList(newRange); } } } //Disasm tab GetSettingBool("Disassembler", "ArgumentSpaces", &settings.disasmArgumentSpaces); GetSettingBool("Disassembler", "MemorySpaces", &settings.disasmMemorySpaces); GetSettingBool("Disassembler", "Uppercase", &settings.disasmUppercase); GetSettingBool("Disassembler", "OnlyCipAutoComments", &settings.disasmOnlyCipAutoComments); GetSettingBool("Disassembler", "TabbedMnemonic", &settings.disasmTabBetweenMnemonicAndArguments); ui->chkArgumentSpaces->setChecked(settings.disasmArgumentSpaces); ui->chkMemorySpaces->setChecked(settings.disasmMemorySpaces); ui->chkUppercase->setChecked(settings.disasmUppercase); ui->chkOnlyCipAutoComments->setChecked(settings.disasmOnlyCipAutoComments); ui->chkTabBetweenMnemonicAndArguments->setChecked(settings.disasmTabBetweenMnemonicAndArguments); //Misc tab if(DbgFunctions()->GetJit) { char jit_entry[MAX_SETTING_SIZE] = ""; char jit_def_entry[MAX_SETTING_SIZE] = ""; bool isx64 = true; #ifndef _WIN64 isx64 = false; #endif bool jit_auto_on; bool get_jit_works; get_jit_works = DbgFunctions()->GetJit(jit_entry, isx64); DbgFunctions()->GetDefJit(jit_def_entry); if(get_jit_works) { if(_strcmpi(jit_entry, jit_def_entry) == 0) settings.miscSetJIT = true; } else settings.miscSetJIT = false; ui->editJIT->setText(jit_entry); ui->editJIT->setCursorPosition(0); ui->chkSetJIT->setCheckState(bool2check(settings.miscSetJIT)); bool get_jit_auto_works = DbgFunctions()->GetJitAuto(&jit_auto_on); if(!get_jit_auto_works || !jit_auto_on) settings.miscSetJITAuto = true; else settings.miscSetJITAuto = false; ui->chkConfirmBeforeAtt->setCheckState(bool2check(settings.miscSetJITAuto)); if(!DbgFunctions()->IsProcessElevated()) { ui->chkSetJIT->setDisabled(true); ui->chkConfirmBeforeAtt->setDisabled(true); ui->lblAdminWarning->setText(QString("<font color=\"red\"><b>Warning</b></font>: Run the debugger as Admin to enable JIT.")); } else ui->lblAdminWarning->setText(""); } char setting[MAX_SETTING_SIZE] = ""; if(BridgeSettingGet("Symbols", "DefaultStore", setting)) ui->editSymbolStore->setText(QString(setting)); else { QString defaultStore = "http://msdl.microsoft.com/download/symbols"; ui->editSymbolStore->setText(defaultStore); BridgeSettingSet("Symbols", "DefaultStore", defaultStore.toUtf8().constData()); } if(BridgeSettingGet("Symbols", "CachePath", setting)) ui->editSymbolCache->setText(QString(setting)); bJitOld = settings.miscSetJIT; bJitAutoOld = settings.miscSetJITAuto; }
extern "C" DLL_EXPORT uint _dbg_sendmessage(DBGMSG type, void* param1, void* param2) { if(dbgisstopped()) { switch(type) //ignore win events { //these functions are safe to call when we did not initialize yet case DBG_DEINITIALIZE_LOCKS: case DBG_INITIALIZE_LOCKS: case DBG_GET_FUNCTIONS: case DBG_SETTINGS_UPDATED: case DBG_GET_THREAD_LIST: case DBG_WIN_EVENT: case DBG_WIN_EVENT_GLOBAL: break; //the rest is unsafe -> throw an exception when people try to call them default: __debugbreak(); //we cannot process messages when the debugger is stopped, this must be a bug } } switch(type) { case DBG_SCRIPT_LOAD: { scriptload((const char*)param1); } break; case DBG_SCRIPT_UNLOAD: { scriptunload(); } break; case DBG_SCRIPT_RUN: { scriptrun((int)(duint)param1); } break; case DBG_SCRIPT_STEP: { scriptstep(); } break; case DBG_SCRIPT_BPTOGGLE: { return scriptbptoggle((int)(duint)param1); } break; case DBG_SCRIPT_BPGET: { return scriptbpget((int)(duint)param1); } break; case DBG_SCRIPT_CMDEXEC: { return scriptcmdexec((const char*)param1); } break; case DBG_SCRIPT_ABORT: { scriptabort(); } break; case DBG_SCRIPT_GETLINETYPE: { return (duint)scriptgetlinetype((int)(duint)param1); } break; case DBG_SCRIPT_SETIP: { scriptsetip((int)(duint)param1); } break; case DBG_SCRIPT_GETBRANCHINFO: { return (duint)scriptgetbranchinfo((int)(duint)param1, (SCRIPTBRANCH*)param2); } break; case DBG_SYMBOL_ENUM: { SYMBOLCBINFO* cbInfo = (SYMBOLCBINFO*)param1; SymEnum(cbInfo->base, cbInfo->cbSymbolEnum, cbInfo->user); } break; case DBG_ASSEMBLE_AT: { return assembleat((duint)param1, (const char*)param2, 0, 0, false); } break; case DBG_MODBASE_FROM_NAME: { return ModBaseFromName((const char*)param1); } break; case DBG_DISASM_AT: { disasmget((uint)param1, (DISASM_INSTR*)param2); } break; case DBG_STACK_COMMENT_GET: { return stackcommentget((uint)param1, (STACK_COMMENT*)param2); } break; case DBG_GET_THREAD_LIST: { ThreadGetList((THREADLIST*)param1); } break; case DBG_SETTINGS_UPDATED: { valuesetsignedcalc(!settingboolget("Engine", "CalculationType")); //0:signed, 1:unsigned SetEngineVariable(UE_ENGINE_SET_DEBUG_PRIVILEGE, settingboolget("Engine", "EnableDebugPrivilege")); bOnlyCipAutoComments = settingboolget("Disassembler", "OnlyCipAutoComments"); bListAllPages = settingboolget("Engine", "ListAllPages"); bUndecorateSymbolNames = settingboolget("Engine", "UndecorateSymbolNames"); bEnableSourceDebugging = settingboolget("Engine", "EnableSourceDebugging"); uint setting; if(BridgeSettingGetUint("Engine", "BreakpointType", &setting)) { switch(setting) { case 0: //break_int3short SetBPXOptions(UE_BREAKPOINT_INT3); break; case 1: //break_int3long SetBPXOptions(UE_BREAKPOINT_LONG_INT3); break; case 2: //break_ud2 SetBPXOptions(UE_BREAKPOINT_UD2); break; } } char exceptionRange[MAX_SETTING_SIZE] = ""; dbgclearignoredexceptions(); if(BridgeSettingGet("Exceptions", "IgnoreRange", exceptionRange)) { char* entry = strtok(exceptionRange, ","); while(entry) { unsigned long start; unsigned long end; if(sscanf(entry, "%08X-%08X", &start, &end) == 2 && start <= end) { ExceptionRange range; range.start = start; range.end = end; dbgaddignoredexception(range); } entry = strtok(0, ","); } } char cachePath[MAX_SETTING_SIZE]; if(BridgeSettingGet("Symbols", "CachePath", cachePath)) { // Trim the buffer to fit inside MAX_PATH strncpy_s(szSymbolCachePath, cachePath, _TRUNCATE); } } break; case DBG_DISASM_FAST_AT: { if(!param1 || !param2) return 0; BASIC_INSTRUCTION_INFO* basicinfo = (BASIC_INSTRUCTION_INFO*)param2; if(!disasmfast((uint)param1, basicinfo)) basicinfo->size = 1; return 0; } break; case DBG_MENU_ENTRY_CLICKED: { int hEntry = (int)(uint)param1; pluginmenucall(hEntry); } break; case DBG_FUNCTION_GET: { FUNCTION_LOOP_INFO* info = (FUNCTION_LOOP_INFO*)param1; return (uint)FunctionGet(info->addr, &info->start, &info->end); } break; case DBG_FUNCTION_OVERLAPS: { FUNCTION_LOOP_INFO* info = (FUNCTION_LOOP_INFO*)param1; return (uint)FunctionOverlaps(info->start, info->end); } break; case DBG_FUNCTION_ADD: { FUNCTION_LOOP_INFO* info = (FUNCTION_LOOP_INFO*)param1; return (uint)FunctionAdd(info->start, info->end, info->manual); } break; case DBG_FUNCTION_DEL: { FUNCTION_LOOP_INFO* info = (FUNCTION_LOOP_INFO*)param1; return (uint)FunctionDelete(info->addr); } break; case DBG_LOOP_GET: { FUNCTION_LOOP_INFO* info = (FUNCTION_LOOP_INFO*)param1; return (uint)LoopGet(info->depth, info->addr, &info->start, &info->end); } break; case DBG_LOOP_OVERLAPS: { FUNCTION_LOOP_INFO* info = (FUNCTION_LOOP_INFO*)param1; return (uint)LoopOverlaps(info->depth, info->start, info->end, 0); } break; case DBG_LOOP_ADD: { FUNCTION_LOOP_INFO* info = (FUNCTION_LOOP_INFO*)param1; return (uint)LoopAdd(info->start, info->end, info->manual); } break; case DBG_LOOP_DEL: { FUNCTION_LOOP_INFO* info = (FUNCTION_LOOP_INFO*)param1; return (uint)LoopDelete(info->depth, info->addr); } break; case DBG_IS_RUN_LOCKED: { return (uint)waitislocked(WAITID_RUN); } break; case DBG_IS_BP_DISABLED: { BREAKPOINT bp; if(BpGet((uint)param1, BPNORMAL, 0, &bp)) return !(uint)bp.enabled; return (uint)false; } break; case DBG_SET_AUTO_COMMENT_AT: { return (uint)CommentSet((uint)param1, (const char*)param2, false); } break; case DBG_DELETE_AUTO_COMMENT_RANGE: { CommentDelRange((uint)param1, (uint)param2); } break; case DBG_SET_AUTO_LABEL_AT: { return (uint)LabelSet((uint)param1, (const char*)param2, false); } break; case DBG_DELETE_AUTO_LABEL_RANGE: { LabelDelRange((uint)param1, (uint)param2); } break; case DBG_SET_AUTO_BOOKMARK_AT: { return (uint)BookmarkSet((uint)param1, false); } break; case DBG_DELETE_AUTO_BOOKMARK_RANGE: { BookmarkDelRange((uint)param1, (uint)param2); } break; case DBG_SET_AUTO_FUNCTION_AT: { return (uint)FunctionAdd((uint)param1, (uint)param2, false); } break; case DBG_DELETE_AUTO_FUNCTION_RANGE: { FunctionDelRange((uint)param1, (uint)param2); } break; case DBG_GET_STRING_AT: { STRING_TYPE strtype; char string[MAX_STRING_SIZE]; if(disasmgetstringat((uint)param1, &strtype, string, string, MAX_STRING_SIZE-3)) { if(strtype == str_ascii) sprintf((char*)param2, "\"%s\"", string); else //unicode sprintf((char*)param2, "L\"%s\"", string); return true; } return false; } break; case DBG_GET_FUNCTIONS: { return (uint)dbgfunctionsget(); } break; case DBG_WIN_EVENT: { return (uint)pluginwinevent((MSG*)param1, (long*)param2); } break; case DBG_WIN_EVENT_GLOBAL: { return (uint)pluginwineventglobal((MSG*)param1); } break; case DBG_INITIALIZE_LOCKS: { SectionLockerGlobal::Initialize(); } break; case DBG_DEINITIALIZE_LOCKS: { SectionLockerGlobal::Deinitialize(); } break; case DBG_GET_TIME_WASTED_COUNTER: return dbggettimewastedcounter(); } return 0; }