From 4a7622807a756fef113c6936f46b3f6512bd90f4 Mon Sep 17 00:00:00 2001 From: rootacite <1498045907@qq.com> Date: Sat, 17 Aug 2024 17:09:05 +0800 Subject: [PATCH] 2024.8.17 --- .gitignore | 1 + .idea/.gitignore | 8 + .idea/aldbg.iml | 2 + .idea/misc.xml | 7 + .idea/modules.xml | 8 + CMakeLists.txt | 17 + aldbg.glade | 850 ++++++++++++++++++++++++++++++++++++++++++++++ core/attach.cpp | 26 ++ core/core.cpp | 4 + cpu/cpu.cpp | 39 +++ cpu/cpu.h | 20 ++ log/log.cpp | 33 ++ log/log.h | 12 + main.cpp | 149 ++++++++ 14 files changed, 1176 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/aldbg.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 CMakeLists.txt create mode 100644 aldbg.glade create mode 100644 core/attach.cpp create mode 100644 core/core.cpp create mode 100644 cpu/cpu.cpp create mode 100644 cpu/cpu.h create mode 100644 log/log.cpp create mode 100644 log/log.h create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/aldbg.iml b/.idea/aldbg.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/aldbg.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0b76fe5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..75f4fac --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..50886d1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.28) +project(aldbg) + +set(CMAKE_CXX_STANDARD 20) + +include_directories(.) + +find_package(PkgConfig) +pkg_check_modules(GTKMM gtkmm-3.0) + +include_directories(${GTKMM_INCLUDE_DIRS}) +link_directories(${GTKMM_LIBRARY_DIRS}) + +add_executable(aldbg + main.cpp cpu/cpu.cpp core/attach.cpp core/core.cpp log/log.cpp) + +target_link_libraries(aldbg ${GTKMM_LIBRARIES}) \ No newline at end of file diff --git a/aldbg.glade b/aldbg.glade new file mode 100644 index 0000000..048d2b7 --- /dev/null +++ b/aldbg.glade @@ -0,0 +1,850 @@ + + + + + + + + + + + + + + + + + + + + + False + False + True + center-on-parent + dialog + True + + + False + vertical + 2 + + + False + end + + + Attach + True + True + True + + + True + True + 0 + + + + + Cancel + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + + True + False + 6 + 5 + + + 30 + True + False + File Path: + + + 0 + 2 + + + + + 30 + True + False + Command Args: + + + 0 + 4 + + + + + 450 + 30 + True + True + + + 1 + 2 + 6 + + + + + 450 + 30 + True + True + + + 1 + 4 + 6 + + + + + True + False + + + 7 + 2 + + + + + True + False + + + 7 + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + False + True + 1 + + + + + + + + + + + + + + + + + + + + + False + center-always + 1280 + 720 + + + True + False + + + True + False + stack + + + False + True + 0 + + + + + True + False + True + + + + True + False + vertical + True + True + + + True + True + regView + + + + + + Registers + + + + + 13 + 0 + 2 + 13 + + + + + True + False + + + Restart + True + True + True + + + False + True + 0 + + + + + Stop + True + True + True + + + False + True + 1 + + + + + Pause + True + True + True + + + False + True + 2 + + + + + Continue + True + True + True + + + False + True + 3 + + + + + Goin + True + True + True + + + False + True + 4 + + + + + Next + True + True + True + + + False + True + 5 + + + + + Tracein + True + True + True + + + False + True + 6 + + + + + Point + True + True + True + + + False + True + 7 + + + + + Escape + True + True + True + + + False + True + 8 + + + + + 0 + 0 + 13 + + + + + True + True + in + + + True + True + codeView + 0 + True + + + + + + Status + + + + 3 + + + + + + + 100 + Address + + + + 0 + + + + + + + 100 + Data + + + + 1 + + + + + + + Disassembly + + + + 2 + + + + + + + + + 0 + 1 + 13 + 9 + + + + + True + True + in + + + True + True + 2 + + + + + + column + + + + + column + + + + + + + 0 + 10 + 13 + 3 + + + + + CPU + CPU + + + + + + True + False + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Memory + Memory + 1 + + + + + + True + False + + + True + True + True + True + in + + + True + True + True + True + logView + 0 + + + + + + 85 + Time + + + + 0 + + + + + + + Data + + + + 1 + + + + + + + + + 0 + 0 + + + + + Log + Log + 2 + + + + + + True + False + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Breakpoints + Breakpoints + 3 + + + + + + True + False + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Call Stack + Call Stack + 4 + + + + + + True + False + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Symbols + Symbols + 5 + + + + + False + True + 1 + + + + + + + True + False + Aldbg x64 + True + + + Attach + True + True + True + + + + + + diff --git a/core/attach.cpp b/core/attach.cpp new file mode 100644 index 0000000..c808328 --- /dev/null +++ b/core/attach.cpp @@ -0,0 +1,26 @@ +// +// Created by acite on 5/1/24. +// + +#include + +using namespace Gtk; + +extern Button* bAttach; +extern Dialog* dialogAttach; +extern Window* MainWindow; + +void button_attach() +{ + dialogAttach->show(); +} + +void button_exec() +{ + int fk = fork(); + if(fk == 0) + { + execl("/usr/bin/netstat", "netstat" ,"-tupln", NULL); + return; + } +} \ No newline at end of file diff --git a/core/core.cpp b/core/core.cpp new file mode 100644 index 0000000..3a0eb7e --- /dev/null +++ b/core/core.cpp @@ -0,0 +1,4 @@ +// +// Created by acite on 5/1/24. +// + diff --git a/cpu/cpu.cpp b/cpu/cpu.cpp new file mode 100644 index 0000000..68551e9 --- /dev/null +++ b/cpu/cpu.cpp @@ -0,0 +1,39 @@ +// +// Created by acite on 5/1/24. +// + +#include "cpu.h" + +using namespace std; +using namespace Gtk; + +extern TreeView* codeView; +extern Glib::RefPtr codeViewStore; + +void add_row(const string& addr, + const string& data, + const string& dasm, + const string& sts + ){ + auto mm = codeViewStore->append(); + Gtk::TreeModel::Row row = *mm; + + row.set_value(0, addr); + row.set_value(1, data); + row.set_value(2, dasm); + row.set_value(3, sts); +} + +void set_row_status(uint64_t index_addr, const string& sts) +{ + string addr; + for(auto i : codeViewStore->children()) + { + i.get_value(0, addr); + if(to_string(index_addr) == addr) + { + i.set_value(3, sts); + break; + } + } +} diff --git a/cpu/cpu.h b/cpu/cpu.h new file mode 100644 index 0000000..66711bc --- /dev/null +++ b/cpu/cpu.h @@ -0,0 +1,20 @@ +// +// Created by acite on 5/1/24. +// + +#ifndef ALDBG_CPU_H +#define ALDBG_CPU_H + +#include +#include +#include + +void add_row(const std::string &addr, + const std::string &data, + const std::string &dasm, + const std::string &sts +); + +void set_row_status(uint64_t index_addr, const std::string& sts); + +#endif //ALDBG_CPU_H diff --git a/log/log.cpp b/log/log.cpp new file mode 100644 index 0000000..4f68e39 --- /dev/null +++ b/log/log.cpp @@ -0,0 +1,33 @@ +// +// Created by acite on 5/1/24. +// + +#include +#include +#include +#include +#include +#include "log.h" +#include + +using namespace Gtk; +using namespace std; + +extern Glib::RefPtr logStore; + +void add_log_data(const std::string& data) +{ + auto mm = logStore->append(); + Gtk::TreeModel::Row row = *mm; + + time_t currentTime; + time(¤tTime); + tm* localTime = localtime(¤tTime); + + char time_str[64]; + sprintf(time_str, "[%d:%d:%d]", localTime->tm_hour, localTime->tm_min, localTime->tm_sec); + string cppstrtime = time_str; + + row.set_value(0, cppstrtime); + row.set_value(1, data); +} \ No newline at end of file diff --git a/log/log.h b/log/log.h new file mode 100644 index 0000000..ed39629 --- /dev/null +++ b/log/log.h @@ -0,0 +1,12 @@ +// +// Created by acite on 5/1/24. +// + +#ifndef ALDBG_LOG_H +#define ALDBG_LOG_H + +#include + +void add_log_data(const std::string& data); + +#endif //ALDBG_LOG_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e2668d1 --- /dev/null +++ b/main.cpp @@ -0,0 +1,149 @@ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "cpu/cpu.h" +#include "log/log.h" + +#define MAX_LOG_BUFFER_SIZE (1024*1024) + +using namespace std; +using namespace Gtk; + +extern void button_attach(); +extern void button_exec(); + +TreeView* codeView; +TreeView* logView; +Glib::RefPtr codeViewStore; +Glib::RefPtr logStore; +Button* bAttach; +Dialog* dialogAttach; +Button* dCancel; +Button* dAttach; +Button* bStop; +Window* MainWindow = nullptr; + +static Glib::RefPtr app; +static pthread_t threads[5]; + +epoll_event events[5] = { + { .events = EPOLLIN } // Event for pipe data +}; +epoll_event r_events[5] = {0}; +char buffer[MAX_LOG_BUFFER_SIZE]; +ssize_t sz = -1; +int pipefd[2] = {0}; + +void *aldbg_io_handler(void *arg) +{ + int r = pipe2(pipefd, O_CLOEXEC | O_NONBLOCK); + if(r == -1) + { + perror("pipe2()"); + return nullptr; + } + dup2(pipefd[1], 1); // dup pipe write port to stdout + + events[0].data.fd = pipefd[0]; + int efd = epoll_create1(0); + epoll_ctl(efd, EPOLL_CTL_ADD, pipefd[0], &events[0]); + + + while(1) + { + r = epoll_wait(efd, r_events, 5, 2000); + if(r == -1)perror("epoll_wait()"); + if(r == 0)continue; + + for(int i=0;ix; + double y = m->y; + std::cout << "Mouse moved to: (" << x << ", " << y << ")" << std::endl; + return false; // 事件已被处理 +} + +void window_init() +{ + ////////////////////////////////////////// register assemblies + auto builder = Builder::create_from_file("../aldbg.glade"); + builder->get_widget("MainWindow", MainWindow); + builder->get_widget("code", codeView); + builder->get_widget("log", logView); + builder->get_widget("bAttach", bAttach); + builder->get_widget("dialogAttach", dialogAttach); + builder->get_widget("dCancel", dCancel); + builder->get_widget("dAttach", dAttach); + builder->get_widget("bStop", bStop); + codeViewStore = Glib::RefPtr::cast_dynamic(codeView->get_model()); + logStore = Glib::RefPtr::cast_dynamic(logView->get_model()); + /////////////////////////////////////////// + + app->add_window(*MainWindow); + MainWindow->show(); // Show Window + + for(int i=0;i<35;i++) + add_row(to_string(i * 1000), "DAF", "Fuck", "->"); + set_row_status(2000, "*->"); + + ///////////////////////////////////////////////////// register events + bAttach->signal_clicked().connect([](){ + button_attach(); + }); + + dCancel->signal_clicked().connect([](){ + dialogAttach->close(); + }); + + dAttach->signal_clicked().connect([](){ + button_exec(); + }); + + bStop->signal_clicked().connect([](){ + + }); + + MainWindow->add_events(Gdk::POINTER_MOTION_MASK); + ///////////////////////////////////////////////////// + + pthread_create(&threads[0], nullptr, aldbg_io_handler, nullptr); +} + +int main() +{ + app = Application::create(); + app->signal_activate().connect([](){ + window_init(); + }); + + return app->run(); +} \ No newline at end of file