summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/events.c15
-rw-r--r--src/main.c31
-rw-r--r--src/module.c9
-rw-r--r--src/parser.c13
-rw-r--r--src/pdb.c5
-rw-r--r--src/utils.c20
6 files changed, 59 insertions, 34 deletions
diff --git a/src/events.c b/src/events.c
index 61cc9dd..7ab5b53 100644
--- a/src/events.c
+++ b/src/events.c
@@ -1,4 +1,15 @@
-void read_name_uni(const void* name_addr, const char* name, size_t name_size) {
+#include <Windows.h>
+
+#include "types.h"
+#include "utils.h"
+#include "module.h"
+#include "pdb.h"
+
+u8 expect_single_step = FALSE;
+
+extern DEBUG_EVENT dbg_event;
+
+static void read_name_uni(const void* name_addr, const char* name, size_t name_size) {
u8* addr = NULL;
if (!read_memory(name_addr, (void*)&addr, 8U)) {
print("%s %u\n", "Loading DLL : error reading dll name : ", GetLastError());
@@ -143,6 +154,8 @@ void handle_create_thread() {
}
void handle_exception() {
+ extern DWORD continue_status;
+
print("%s : ", "ExceptionDebugEvent");
if (dbg_event.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_SINGLE_STEP && expect_single_step) {
diff --git a/src/main.c b/src/main.c
index e71b1b7..a747cb6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,29 +4,18 @@
#include "types.h"
-#include "utils.c"
+#include "utils.h"
+#include "events.h"
+#include "parser.h"
-static HANDLE h_input = NULL;
-static HANDLE h_output = NULL;
-static u8 is_open = TRUE;
-static u8 process_commands = TRUE;
-static u8 expect_single_step = FALSE;
-static DWORD continue_status = DBG_EXCEPTION_NOT_HANDLED;
-static DEBUG_EVENT dbg_event;
-static PROCESS_INFORMATION proc_info = { 0 };
+u8 is_open = TRUE;
+u8 process_commands = TRUE;
-/* Read debugged process memory at address */
-u8 read_memory(const void* addr, void* buffer, size_t size) {
- size_t b_read = 0U;
- HRESULT hr = ReadProcessMemory(proc_info.hProcess, addr, buffer, size, &b_read);
-
- return hr > 0 && b_read == size;
-}
-
-#include "module.c"
-#include "parser.c"
-#include "pdb.c"
-#include "events.c"
+HANDLE h_input = NULL;
+HANDLE h_output = NULL;
+DEBUG_EVENT dbg_event;
+PROCESS_INFORMATION proc_info = { 0 };
+DWORD continue_status = DBG_EXCEPTION_NOT_HANDLED;
void dbg_loop() {
while(is_open) {
diff --git a/src/module.c b/src/module.c
index 8188665..fde93fe 100644
--- a/src/module.c
+++ b/src/module.c
@@ -1,9 +1,6 @@
-struct module {
- void* base_addr;
- IMAGE_DOS_HEADER dos_header;
- IMAGE_NT_HEADERS64 nt_header;
- u8 name[256U];
-};
+#include "module.h"
+
+#include "utils.h"
struct module modules[64U] = { 0U };
u64 modules_list = ~0ULL;
diff --git a/src/parser.c b/src/parser.c
index 5ec6b0d..86f9563 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1,3 +1,12 @@
+#include <Windows.h>
+
+#include "types.h"
+#include "utils.h"
+#include "module.h"
+
+extern u8 expect_single_step;
+extern DWORD continue_status;
+
enum TOKEN_TYPE {
// Commands
TOKEN_CONTINUE,
@@ -183,6 +192,10 @@ u64 eval_number(const struct ast_node* node) {
}
void run(struct ast_node* root) {
+ extern DEBUG_EVENT dbg_event;
+ extern u8 process_commands;
+ extern u8 is_open;
+
struct ast_node cur_node = root[0];
CONTEXT ctx = {
.ContextFlags = CONTEXT_ALL,
diff --git a/src/pdb.c b/src/pdb.c
index f646a85..e99f0e3 100644
--- a/src/pdb.c
+++ b/src/pdb.c
@@ -1,5 +1,10 @@
+#include <Windows.h>
+#include <strsafe.h>
#include "cvinfo.h"
+#include "types.h"
+#include "utils.h"
+
enum STREAM_INDEX {
OLD_DIRECTORY,
PDB,
diff --git a/src/utils.c b/src/utils.c
index de719e9..440b9fb 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,9 +1,7 @@
-#if defined (_DEBUG)
-#define assert(x) if (!(x)) __debugbreak();
-#else
-#define assert(x) (x)
-#endif
-void print(const char* format, ...);
+#include "utils.h"
+
+#include <Windows.h>
+#include <strsafe.h>
u8 is_alpha(char c) {
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
@@ -155,3 +153,13 @@ void print(const char* format, ...) {
StringCchLengthA(formatted_str, sizeof(formatted_str), &length);
SUCCEEDED(WriteFile(standard_err, formatted_str, (DWORD)length, NULL, NULL));
}
+
+/* Read debugged process memory at address */
+u8 read_memory(const void* addr, void* buffer, size_t size) {
+ extern PROCESS_INFORMATION proc_info;
+
+ size_t b_read = 0U;
+ HRESULT hr = ReadProcessMemory(proc_info.hProcess, addr, buffer, size, &b_read);
+
+ return hr > 0 && b_read == size;
+}