void qtDLGAssembler::InsertNewInstructions() { if(lineEdit->text().length() <= 0) { close(); return; } QMap<QString,DisAsDataRow>::const_iterator i = _pDisAs->SectionDisAs.constFind(QString("%1").arg(_InstructionOffset,16,16,QChar('0')).toUpper()); if((QMapData::Node *)i == (QMapData::Node *)_pDisAs->SectionDisAs.constEnd()) { close(); return; } QString oldOpcodes = i.value().OpCodes; DWORD oldOpcodeLen = oldOpcodes.replace(" ", "").length() / 2, newOpcodeLen = NULL; QFile tempOutput("nanomite.asm"); tempOutput.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&tempOutput); if(_Is64Bit) out << "BITS 64\r\n"; else out << "BITS 32\r\n"; out << lineEdit->text(); tempOutput.close(); STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si,sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi,sizeof(pi)); TCHAR szCommandLine[] = L"nasm.exe -o nanomite.bin nanomite.asm"; if(!CreateProcess(NULL,szCommandLine,NULL,NULL,FALSE,CREATE_NO_WINDOW,NULL,NULL,&si,&pi)) { MessageBoxW(NULL,L"Error, unable to launch assembler!",L"Nanomite",MB_OK); close(); return; } WaitForSingleObject(pi.hProcess,INFINITE); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); DeleteFile(L"nanomite.asm"); HANDLE hFile = CreateFileW(L"nanomite.bin",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,NULL,NULL); if(hFile == INVALID_HANDLE_VALUE) { close(); return; } int iLen = GetFileSize(hFile,NULL); LPVOID pFileBuffer = clsMemManager::CAlloc(iLen); DWORD BytesRead = NULL; if(!ReadFile(hFile,pFileBuffer,iLen,&BytesRead,NULL)) { CloseHandle(hFile); DeleteFile(L"nanomite.bin"); clsMemManager::CFree(pFileBuffer); MessageBoxW(NULL,L"Error, no valid opcodes found!",L"Nanomite",MB_OK); close(); return; } CloseHandle(hFile); DeleteFile(L"nanomite.bin"); if(BytesRead <= 0) { clsMemManager::CFree(pFileBuffer); MessageBoxW(NULL,L"Error, no valid opcodes found!",L"Nanomite",MB_OK); close(); return; } if(oldOpcodeLen >= BytesRead) newOpcodeLen = oldOpcodeLen; else if(oldOpcodeLen < BytesRead) { newOpcodeLen = oldOpcodeLen; while(newOpcodeLen < BytesRead) { ++i; if((QMapData::Node *)i == (QMapData::Node *)_pDisAs->SectionDisAs.constEnd()) return; oldOpcodes = i.value().OpCodes; newOpcodeLen += oldOpcodes.replace(" ", "").length() / 2; } } LPVOID pBuffer = clsMemManager::CAlloc(newOpcodeLen); memset(pBuffer,0x90,newOpcodeLen); memcpy(pBuffer,pFileBuffer,BytesRead); qtDLGPatchManager::AddNewPatch(0,_hProc,_InstructionOffset,newOpcodeLen,pBuffer); clsMemManager::CFree(pBuffer); clsMemManager::CFree(pFileBuffer); _pDisAs->SectionDisAs.clear(); emit OnReloadDebugger(); lineEdit->clear(); close(); return; }
qtDLGNanomite::qtDLGNanomite(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags), m_IsRestart(false) { setupUi(this); setAcceptDrops(true); QApplication::setStyle(new QPlastiqueStyle); QFontDatabase::addApplicationFont(":/Fonts/Fonts/consola.ttf"); this->setStyleSheet(clsHelperClass::LoadStyleSheet()); qRegisterMetaType<DWORD>("DWORD"); qRegisterMetaType<quint64>("quint64"); qRegisterMetaType<BPStruct>("BPStruct"); qRegisterMetaType<HANDLE>("HANDLE"); clsAPIImport::LoadFunctions(); coreBPManager = new clsBreakpointManager; coreDebugger = new clsDebugger(coreBPManager); coreDisAs = new clsDisassembler; PEManager = new clsPEManager; dlgDetInfo = new qtDLGDetailInfo(this,Qt::Window); dlgDbgStr = new qtDLGDebugStrings(this,Qt::Window); dlgBPManager = new qtDLGBreakPointManager(this,Qt::Window); dlgTraceWindow = new qtDLGTrace(this,Qt::Window); dlgPatchManager = new qtDLGPatchManager(this,Qt::Window); dlgBookmark = new qtDLGBookmark(this, Qt::Window); qtNanomiteDisAsColor = new qtNanomiteDisAsColorSettings; qtDLGMyWindow = this; lExceptionCount = 0; LoadWidgets(); settings->CheckIfFirstRun(); settings->LoadDebuggerSettings(coreDebugger); settings->LoadDisassemblerColor(qtNanomiteDisAsColor); settings->LoadRecentDebuggedFiles(m_recentDebuggedFiles); LoadRecentFileMenu(true); DisAsGUI = new qtDLGDisassembler(this); this->setCentralWidget(DisAsGUI); // Callbacks from Debugger Thread to GUI connect(coreDebugger,SIGNAL(OnThread(DWORD,DWORD,quint64,bool,DWORD,bool)), dlgDetInfo,SLOT(OnThread(DWORD,DWORD,quint64,bool,DWORD,bool)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnPID(DWORD,QString,DWORD,quint64,bool)), dlgDetInfo,SLOT(OnPID(DWORD,QString,DWORD,quint64,bool)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnException(QString,QString,quint64,quint64,DWORD,DWORD)), dlgDetInfo,SLOT(OnException(QString,QString,quint64,quint64,DWORD,DWORD)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnDbgString(QString,DWORD)), dlgDbgStr,SLOT(OnDbgString(QString,DWORD)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnDll(QString,DWORD,quint64,bool)), dlgDetInfo,SLOT(OnDll(QString,DWORD,quint64,bool)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnLog(QString)), logView,SLOT(OnLog(QString)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(AskForException(DWORD)),this,SLOT(AskForException(DWORD)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnDebuggerBreak()),this,SLOT(OnDebuggerBreak()),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnDebuggerTerminated()),this,SLOT(OnDebuggerTerminated()),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnNewPID(QString,int)),dlgBPManager,SLOT(UpdateCompleter(QString,int)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnNewPID(QString,int)),dlgBookmark,SLOT(UpdateBookmarks(QString,int)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(UpdateOffsetsPatches(HANDLE,int)),dlgPatchManager,SLOT(UpdateOffsetPatch(HANDLE,int)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(UpdateOffsetsPatches(HANDLE,int)),dlgBookmark,SLOT(BookmarkUpdateOffsets(HANDLE,int)),Qt::QueuedConnection); connect(coreBPManager,SIGNAL(OnBreakpointAdded(BPStruct,int)),dlgBPManager,SLOT(OnUpdate(BPStruct,int)),Qt::QueuedConnection); connect(coreBPManager,SIGNAL(OnBreakpointDeleted(quint64)),dlgBPManager,SLOT(OnDelete(quint64)),Qt::QueuedConnection); // Callbacks from Debugger to PEManager connect(coreDebugger,SIGNAL(OnNewPID(QString,int)),PEManager,SLOT(InsertPIDForFile(QString,int)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(DeletePEManagerObject(QString,int)),PEManager,SLOT(CloseFile(QString,int)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(CleanPEManager()),PEManager,SLOT(CleanPEManager()),Qt::QueuedConnection); // Actions for the MainMenu and Toolbar connect(actionFile_OpenNew, SIGNAL(triggered()), this, SLOT(action_FileOpenNewFile())); connect(actionFile_AttachTo, SIGNAL(triggered()), this, SLOT(action_FileAttachTo())); connect(actionFile_Detach, SIGNAL(triggered()), this, SLOT(action_FileDetach())); connect(actionFile_Exit, SIGNAL(triggered()), this, SLOT(action_FileTerminateGUI())); connect(actionFile_Load, SIGNAL(triggered()), this, SLOT(action_FileLoad())); connect(actionFile_Save, SIGNAL(triggered()), this, SLOT(action_FileSave())); connect(actionDebug_Start, SIGNAL(triggered()), this, SLOT(action_DebugStart())); connect(actionDebug_Stop, SIGNAL(triggered()), this, SLOT(action_DebugStop())); connect(actionDebug_Restart, SIGNAL(triggered()), this, SLOT(action_DebugRestart())); connect(actionDebug_Suspend, SIGNAL(triggered()), this, SLOT(action_DebugSuspend())); connect(actionDebug_Step_In, SIGNAL(triggered()), this, SLOT(action_DebugStepIn())); connect(actionDebug_Step_Out, SIGNAL(triggered()), this, SLOT(action_DebugStepOut())); connect(actionDebug_Step_Over, SIGNAL(triggered()), this, SLOT(action_DebugStepOver())); connect(actionOptions_About, SIGNAL(triggered()), this, SLOT(action_OptionsAbout())); connect(actionOptions_Options, SIGNAL(triggered()), this, SLOT(action_OptionsOptions())); connect(actionOptions_Update, SIGNAL(triggered()), this, SLOT(action_OptionsUpdate())); connect(actionWindow_Detail_Information, SIGNAL(triggered()), this, SLOT(action_WindowDetailInformation())); connect(actionWindow_Breakpoint_Manager, SIGNAL(triggered()), this, SLOT(action_WindowBreakpointManager())); connect(actionWindow_Show_Patches, SIGNAL(triggered()), this, SLOT(action_WindowPatches())); connect(actionWindow_Show_Memory, SIGNAL(triggered()), this, SLOT(action_WindowShowMemory())); connect(actionWindow_Show_Heap, SIGNAL(triggered()), this, SLOT(action_WindowShowHeap())); connect(actionWindow_Show_Strings, SIGNAL(triggered()), this, SLOT(action_WindowShowStrings())); connect(actionWindow_Show_Debug_Output, SIGNAL(triggered()), this, SLOT(action_WindowShowDebugOutput())); connect(actionWindow_Show_Handles, SIGNAL(triggered()), this, SLOT(action_WindowShowHandles())); connect(actionWindow_Show_Windows, SIGNAL(triggered()), this, SLOT(action_WindowShowWindows())); connect(actionWindow_Show_Functions, SIGNAL(triggered()), this, SLOT(action_WindowShowFunctions())); connect(actionWindow_Show_Privileges, SIGNAL(triggered()), this, SLOT(action_WindowShowPrivileges())); connect(actionWindow_Show_Bookmarks, SIGNAL(triggered()), this, SLOT(action_WindowShowBookmarks())); connect(action_Debug_Run_to_UserCode,SIGNAL(triggered()), this, SLOT(action_DebugRunToUserCode())); connect(actionDebug_Trace_Start, SIGNAL(triggered()), this, SLOT(action_DebugTraceStart())); connect(actionDebug_Trace_Stop, SIGNAL(triggered()), this, SLOT(action_DebugTraceStop())); connect(actionDebug_Trace_Show, SIGNAL(triggered()), this, SLOT(action_DebugTraceShow())); connect(actionWindow_Show_PEEditor, SIGNAL(triggered()), this, SLOT(action_WindowShowPEEditor())); // Callbacks to display disassembly connect(dlgTraceWindow,SIGNAL(OnDisplayDisassembly(quint64)),DisAsGUI,SLOT(OnDisplayDisassembly(quint64))); connect(cpuRegView,SIGNAL(OnDisplayDisassembly(quint64)),DisAsGUI,SLOT(OnDisplayDisassembly(quint64))); connect(dlgDetInfo,SIGNAL(ShowInDisassembler(quint64)),DisAsGUI,SLOT(OnDisplayDisassembly(quint64))); connect(coreDisAs,SIGNAL(DisAsFinished(quint64)),DisAsGUI,SLOT(OnDisplayDisassembly(quint64)),Qt::QueuedConnection); connect(dlgBPManager,SIGNAL(OnDisplayDisassembly(quint64)),DisAsGUI,SLOT(OnDisplayDisassembly(quint64))); connect(dlgBookmark,SIGNAL(ShowInDisassembler(quint64)),DisAsGUI,SLOT(OnDisplayDisassembly(quint64))); // Callbacks from PatchManager to GUI connect(dlgPatchManager,SIGNAL(OnReloadDebugger()),this,SLOT(OnDebuggerBreak())); // Callbacks from Disassembler GUI to GUI connect(DisAsGUI,SIGNAL(OnDebuggerBreak()),this,SLOT(OnDebuggerBreak())); // Callbacks to StateBar connect(dlgTraceWindow,SIGNAL(OnUpdateStatusBar(int,quint64)),this,SLOT(UpdateStateBar(int,quint64))); actionDebug_Trace_Stop->setDisabled(true); ParseCommandLineArgs(); }