ulong CCmdLog::erase(ulong id) { EnterCriticalSection(&m_csShare); void *temp = Findsorteddata(&m_Table.sorted, id, 0); LPLOGGER plog = reinterpret_cast<LPLOGGER>(temp); if (plog != nullptr) { Deletesorteddata(&m_Table.sorted, plog->addr, 0); Updatetable(&m_Table, false); } else id = 0; LeaveCriticalSection(&m_csShare); return id ; }
// This optional function receives commands from plugin menu in window of type // origin. Argument action is menu identifier from ODBG_Pluginmenu(). If user // activates automatically created entry in main menu, action is 0. extc void _export cdecl ODBG_Pluginaction(int origin, int action, void *item) { t_bookmark mark, *pb; t_dump *pd; if (origin == PM_MAIN) { switch (action) { case 0: // Menu item "Bookmarks", creates bookmark window. //Createbookmarkwindow(); // Make launcher { t_table *table; t_sorted *sorted; t_patch *patches; t_patch *elem; int i; FILE *f; table = Plugingetvalue(VAL_PATCHES); sorted = &table->data; patches = sorted->data; if(patches != NULL) { char *exe_name; char *launcher_name; int exe_name_len; // remove full path and keep exe name exe_name = Plugingetvalue(VAL_EXEFILENAME); exe_name += strlen(exe_name) - 1; while(*exe_name != '\\') --exe_name; ++exe_name; exe_name_len = strlen(exe_name); // create launcher file launcher_name = malloc(exe_name_len + 2); launcher_name[0] = '_'; strcpy(launcher_name + 1, exe_name); CopyFile("launcher.exe", launcher_name, 0); f = fopen(launcher_name, "a"); if(f != NULL) { //void *base_address = Plugingetvalue(VAL_MAINBASE); elem = patches; for(i = 0; i < sorted->n; i++) { fwrite(elem->orig, elem->size, 1, f); fwrite(elem->mod, elem->size, 1, f); fwrite(&elem->addr, sizeof(elem->addr) + sizeof(elem->size), 1, f); ++elem; } fwrite(exe_name, exe_name_len, 1, f); fwrite(&exe_name_len, sizeof(exe_name_len), 1, f); fwrite(&sorted->n, sizeof(sorted->n), 1, f); fwrite(SIG, sizeof(SIG) - 1, 1, f); fclose(f); } free(launcher_name); } } break; case 1: // Menu item "About", displays plugin info. If you write your own code, // please replace with own copyright! MessageBox(hwmain, "Bookmark plugin v1.10\n" "(demonstration of plugin capabilities)\n" "Copyright (C) 2001-2004 Oleh Yuschuk & Piérrot", "Bookmark plugin", MB_OK | MB_ICONINFORMATION); break; default: break; }; } else if (origin == PM_DISASM) { pd = (t_dump *)item; if (action >= 0 && action < 10) // Insert bookmark { mark.index = action; mark.size = 1; mark.type = 0; mark.addr = pd->sel0; Addsorteddata(&(bookmark.data), &mark); if (bookmark.hw != NULL) InvalidateRect(bookmark.hw, NULL, FALSE); } else if (action >= 10 && action < 20) // Delete bookmark { pb = (t_bookmark *)Findsorteddata(&(bookmark.data), action - 10); if (pb != NULL) { Deletesorteddata(&(bookmark.data), action - 10); if (bookmark.hw != NULL) InvalidateRect(bookmark.hw, NULL, FALSE); }; } else if (action >= 20 && action < 30) //Go to bookmark { pb = (t_bookmark *)Findsorteddata(&(bookmark.data), action - 20); if (pb != NULL) { Setcpu(0, pb->addr, 0, 0, CPU_ASMHIST | CPU_ASMCENTER | CPU_ASMFOCUS); }; }; }; };
// Each window class needs its own window procedure. Both standard and custom // OllyDbg windows must pass some system and OllyDbg-defined messages to // Tablefunction(). See description of Tablefunction() for more details. LRESULT CALLBACK Bookmarkwinproc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) { int i, shiftkey, controlkey; HMENU menu; t_bookmark *pb; switch (msg) { // Standard messages. You can process them, but - unless absolutely sure - // always pass them to Tablefunction(). case WM_DESTROY: case WM_MOUSEMOVE: case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: case WM_LBUTTONUP: case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: case WM_HSCROLL: case WM_VSCROLL: case WM_TIMER: case WM_SYSKEYDOWN: Tablefunction(&bookmark, hw, msg, wp, lp); break; // Pass message to DefMDIChildProc() // Custom messages responsible for scrolling and selection. User-drawn // windows must process them, standard OllyDbg windows without extra // functionality pass them to Tablefunction(). case WM_USER_SCR: case WM_USER_VABS: case WM_USER_VREL: case WM_USER_VBYTE: case WM_USER_STS: case WM_USER_CNTS: case WM_USER_CHGS: return Tablefunction(&bookmark, hw, msg, wp, lp); // WM_WINDOWPOSCHANGED is responsible for always-on-top MDI windows. case WM_WINDOWPOSCHANGED: return Tablefunction(&bookmark, hw, msg, wp, lp); case WM_USER_MENU: menu = CreatePopupMenu(); // Find selected bookmark. Any operations with bookmarks make sense only // if at least one bookmark exists and is selected. Note that sorted data // has special sort index table which is updated only when necessary. // Getsortedbyselection() does this; some other sorted data functions // don't and you must call Sortsorteddata(). Read documentation! pb = (t_bookmark *)Getsortedbyselection( &(bookmark.data), bookmark.data.selected); if (menu != NULL && pb != NULL) { AppendMenu(menu, MF_STRING, 1, "&Follow\tEnter"); AppendMenu(menu, MF_STRING, 2, "&Delete\tDel"); }; // Even when menu is NULL, call to Tablefunction is still meaningful. i = Tablefunction(&bookmark, hw, WM_USER_MENU, 0, (LPARAM)menu); if (menu != NULL) DestroyMenu(menu); if (i == 1) // Follow bookmark in Disassembler Setcpu(0, pb->addr, 0, 0, CPU_ASMHIST | CPU_ASMCENTER | CPU_ASMFOCUS); else if (i == 2) // Delete bookmark { Deletesorteddata(&(bookmark.data), pb->index); // There is no automatical window update, do it yourself. InvalidateRect(hw, NULL, FALSE); }; return 0; case WM_KEYDOWN: // Processing of WM_KEYDOWN messages is - surprise, surprise - very // similar to that of corresponding menu entries. shiftkey = GetKeyState(VK_SHIFT) & 0x8000; controlkey = GetKeyState(VK_CONTROL) & 0x8000; if (wp == VK_RETURN && shiftkey == 0 && controlkey == 0) { // Return key follows bookmark in Disassembler. pb = (t_bookmark *)Getsortedbyselection( &(bookmark.data), bookmark.data.selected); if (pb != NULL) Setcpu(0, pb->addr, 0, 0, CPU_ASMHIST | CPU_ASMCENTER | CPU_ASMFOCUS); ; } else if (wp == VK_DELETE && shiftkey == 0 && controlkey == 0) { // DEL key deletes bookmark. pb = (t_bookmark *)Getsortedbyselection( &(bookmark.data), bookmark.data.selected); if (pb != NULL) { Deletesorteddata(&(bookmark.data), pb->index); InvalidateRect(hw, NULL, FALSE); }; } else // Add all this arrow, home and pageup functionality. Tablefunction(&bookmark, hw, msg, wp, lp); break; case WM_USER_DBLCLK: // Doubleclicking row follows bookmark in Disassembler. pb = (t_bookmark *)Getsortedbyselection( &(bookmark.data), bookmark.data.selected); if (pb != NULL) Setcpu(0, pb->addr, 0, 0, CPU_ASMHIST | CPU_ASMCENTER | CPU_ASMFOCUS); return 1; // Doubleclick processed case WM_USER_CHALL: case WM_USER_CHMEM: // Something is changed, redraw window. InvalidateRect(hw, NULL, FALSE); return 0; case WM_PAINT: // Painting of all OllyDbg windows is done by Painttable(). Make custom // drawing only if you have important reasons to do this. Painttable(hw, &bookmark, Bookmarkgettext); return 0; default: break; }; return DefMDIChildProc(hw, msg, wp, lp); };