add debug funcs
+ created debug funcs + created `registers` class + add it to build build not passed(
This commit is contained in:
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -5,7 +5,9 @@
|
|||||||
"stdlib.h": "c",
|
"stdlib.h": "c",
|
||||||
"ksys.h": "c",
|
"ksys.h": "c",
|
||||||
"socket.h": "c",
|
"socket.h": "c",
|
||||||
"graphic.h": "c"
|
"graphic.h": "c",
|
||||||
|
"syscalls.h": "c",
|
||||||
|
"registers.h": "c"
|
||||||
},
|
},
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"syscalls",
|
"syscalls",
|
||||||
|
7
Makefile
7
Makefile
@@ -31,8 +31,9 @@ MYOBJS =
|
|||||||
|
|
||||||
|
|
||||||
Socket_O = src/sockets/socket.o src/sockets/socket_lua.o src/sockets/sockaddr.o
|
Socket_O = src/sockets/socket.o src/sockets/socket_lua.o src/sockets/sockaddr.o
|
||||||
|
Debug_O = src/debug/debug.o src/debug/registers.o
|
||||||
|
|
||||||
ALL_O = src/syscalls.o src/ARP_entry.o src/systemColors.o src/graphic.o $(Socket_O)
|
ALL_O = src/syscalls.o src/ARP_entry.o src/systemColors.o src/graphic.o $(Socket_O) $(Debug_O)
|
||||||
|
|
||||||
syscalls.dll: $(ALL_O)
|
syscalls.dll: $(ALL_O)
|
||||||
$(CC) -shared -T dll.lds --entry _DllStartup -o $@ $(ALL_O) $(LIBS)
|
$(CC) -shared -T dll.lds --entry _DllStartup -o $@ $(ALL_O) $(LIBS)
|
||||||
@@ -51,10 +52,12 @@ src/sockets/socket.o: src/sockets/socket.c src/sockets/socket.h
|
|||||||
src/sockets/socket_lua.o: src/sockets/socket_lua.c src/sockets/socket_lua.h
|
src/sockets/socket_lua.o: src/sockets/socket_lua.c src/sockets/socket_lua.h
|
||||||
src/sockets/sockaddr.o: src/sockets/sockaddr.c src/sockets/sockaddr.h
|
src/sockets/sockaddr.o: src/sockets/sockaddr.c src/sockets/sockaddr.h
|
||||||
src/graphic.o: src/graphic.c src/graphic.h
|
src/graphic.o: src/graphic.c src/graphic.h
|
||||||
|
src/debug/debug.o: src/debug/debug.c src/debug/debug.h src/debug/registers.h
|
||||||
|
src/debug/registers.o: src/debug/registers.c src/debug/registers.h src/syscalls.h
|
||||||
|
|
||||||
## headers
|
## headers
|
||||||
|
|
||||||
src/graphic.h: src/syscalls.h
|
src/graphic.h: src/syscalls.h
|
||||||
src/sockets/socket_lua.h: src/syscalls.h src/sockets/socket.h
|
src/sockets/socket_lua.h: src/syscalls.h src/sockets/socket.h
|
||||||
src/sockets/sockaddr.h: src/sockets/socket.h src/syscalls.h
|
src/sockets/sockaddr.h: src/sockets/socket.h src/syscalls.h
|
||||||
|
src/debug/debug.h: src/syscalls.h
|
||||||
|
@@ -21,4 +21,5 @@
|
|||||||
|
|
||||||
#define DEBUG_LINE(msg) DEBUG_PRINT(msg); DEBUG_PRINT("\n")
|
#define DEBUG_LINE(msg) DEBUG_PRINT(msg); DEBUG_PRINT("\n")
|
||||||
|
|
||||||
|
|
||||||
#endif // __DEBUG_H__
|
#endif // __DEBUG_H__
|
||||||
|
175
src/debug/debug.c
Normal file
175
src/debug/debug.c
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
#include <sys/ksys.h>
|
||||||
|
#include "debug.h"
|
||||||
|
#include "registers.h"
|
||||||
|
|
||||||
|
int syscalls_DebugPuts(lua_State* L)
|
||||||
|
{
|
||||||
|
_ksys_debug_puts(luaL_checkstring(L, 1));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int syscalls_DebugPutc(lua_State* L)
|
||||||
|
{
|
||||||
|
_ksys_debug_putc(*luaL_checkstring(L, 1));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DebugMessageArea
|
||||||
|
{
|
||||||
|
int Size;
|
||||||
|
int Used;
|
||||||
|
char data[];
|
||||||
|
};
|
||||||
|
|
||||||
|
int syscalls_SetMessageArea(lua_State* L)
|
||||||
|
{
|
||||||
|
struct DebugMessageArea* p = luaL_checkinteger(L, 1);
|
||||||
|
|
||||||
|
asm_inline(
|
||||||
|
"int $0x40"
|
||||||
|
:: "a"(69), "b"(0), "c"(p)
|
||||||
|
);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int syscalls_GetRegisters(lua_State* L)
|
||||||
|
{
|
||||||
|
struct registers* r = syscalls_pushRegisters(L);
|
||||||
|
|
||||||
|
uint32_t pid = luaL_checkinteger(L, 1);
|
||||||
|
|
||||||
|
asm_inline(
|
||||||
|
"int $0x40"
|
||||||
|
:: "a"(69), "b"(1), "c"(pid), "d"(sizeof(struct registers)), "S"(r)
|
||||||
|
);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int syscalls_SetRegisters(lua_State* L)
|
||||||
|
{
|
||||||
|
uint32_t pid = luaL_checkinteger(L, 1);
|
||||||
|
struct registers* r = luaL_checkudata(L, 1, syscalls_registers_metatable_name);
|
||||||
|
|
||||||
|
asm_inline(
|
||||||
|
"int $0x40"
|
||||||
|
:: "a"(69), "b"(2), "c"(pid), "d"(sizeof(struct registers)), "S"(r)
|
||||||
|
);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int syscalls_Disconnect(lua_State* L)
|
||||||
|
{
|
||||||
|
uint32_t pid = luaL_checkinteger(L, 1);
|
||||||
|
|
||||||
|
asm_inline(
|
||||||
|
"int $0x40"
|
||||||
|
:: "a"(69), "b"(3), "c"(pid)
|
||||||
|
);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int syscalls_Stop(lua_State* L)
|
||||||
|
{
|
||||||
|
uint32_t pid = luaL_checkinteger(L, 1);
|
||||||
|
|
||||||
|
asm_inline(
|
||||||
|
"int $0x40"
|
||||||
|
:: "a"(69), "b"(4), "c"(pid)
|
||||||
|
);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int syscalls_Continue(lua_State* L)
|
||||||
|
{
|
||||||
|
uint32_t pid = luaL_checkinteger(L, 1);
|
||||||
|
|
||||||
|
asm_inline(
|
||||||
|
"int $0x40"
|
||||||
|
:: "a"(69), "b"(5), "c"(pid)
|
||||||
|
);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int syscalls_ReadFromMem(lua_State *L)
|
||||||
|
{
|
||||||
|
uint32_t pid = luaL_checkinteger(L, 1);
|
||||||
|
uint32_t bytes = luaL_checkinteger(L, 2);
|
||||||
|
uint32_t pointer = luaL_checkinteger(L, 3);
|
||||||
|
uint32_t buffer = luaL_checkinteger(L, 4);
|
||||||
|
uint32_t ret;
|
||||||
|
|
||||||
|
asm_inline(
|
||||||
|
"int $0x40"
|
||||||
|
: "=a"(ret)
|
||||||
|
: "a"(69), "b"(6), "c"(pid), "d"(bytes), "S"(pointer), "D"(buffer)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (ret == -1)
|
||||||
|
lua_pushnil(L);
|
||||||
|
else
|
||||||
|
lua_pushinteger(L, ret);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int syscalls_WriteToMem(lua_State* L)
|
||||||
|
{
|
||||||
|
uint32_t pid = luaL_checkinteger(L, 1);
|
||||||
|
uint32_t bytes = luaL_checkinteger(L, 2);
|
||||||
|
uint32_t pointer = luaL_checkinteger(L, 3);
|
||||||
|
uint32_t buffer = luaL_checkinteger(L, 4);
|
||||||
|
uint32_t ret;
|
||||||
|
|
||||||
|
asm_inline(
|
||||||
|
"int $0x40"
|
||||||
|
: "=a"(ret)
|
||||||
|
: "a"(69), "b"(7), "c"(pid), "d"(bytes), "S"(pointer), "D"(buffer)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (ret == -1)
|
||||||
|
lua_pushnil(L);
|
||||||
|
else
|
||||||
|
lua_pushinteger(L, ret);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int syscalls_Done(lua_State* L)
|
||||||
|
{
|
||||||
|
uint32_t pid = luaL_checkinteger(L, 1);
|
||||||
|
|
||||||
|
asm_inline(
|
||||||
|
"int $0x40"
|
||||||
|
:: "a"(69), "b"(8), "c"(pid)
|
||||||
|
);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int syscalls_DefineBreakpoint(lua_State* L)
|
||||||
|
{
|
||||||
|
uint32_t pid = luaL_checkinteger(L, 1);
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t flags = luaL_checkinteger(L, 2) & 0xFF | (luaL_checkinteger(L, 3) << 16) | (luaL_checkinteger(L, 4) << 18);
|
||||||
|
|
||||||
|
uint32_t ret;
|
||||||
|
|
||||||
|
asm_inline(
|
||||||
|
"int $0x40"
|
||||||
|
: "=a"(ret)
|
||||||
|
: "a"(69), "b"(9), "c"(pid), "d"(flags)
|
||||||
|
);
|
||||||
|
|
||||||
|
lua_pushinteger(L, ret);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
26
src/debug/debug.h
Normal file
26
src/debug/debug.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __DEBUG_LUA_H__
|
||||||
|
#define __DEBUG_LUA_H__
|
||||||
|
|
||||||
|
#include "../syscalls.h"
|
||||||
|
|
||||||
|
enum BreakpointCondition
|
||||||
|
{
|
||||||
|
Execute = 0,
|
||||||
|
Write = 1,
|
||||||
|
ReadWrite = 0b11
|
||||||
|
};
|
||||||
|
|
||||||
|
enum BreakpointLen
|
||||||
|
{
|
||||||
|
Byte = 0,
|
||||||
|
Word = 1,
|
||||||
|
Dword = 0b11
|
||||||
|
};
|
||||||
|
|
||||||
|
int syscalls_DebugPutc(lua_State* L);
|
||||||
|
|
||||||
|
int syscalls_DebugPuts(lua_State* L);
|
||||||
|
|
||||||
|
int syscalls_SetMessageArea(lua_State* L);
|
||||||
|
|
||||||
|
#endif // __DEBUG_LUA_H__
|
146
src/debug/registers.c
Normal file
146
src/debug/registers.c
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
#include "registers.h"
|
||||||
|
#include "../syscalls.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static int syscalls_indexRegisters(lua_State* L)
|
||||||
|
{
|
||||||
|
struct registers* r = luaL_checkudata(L, 1, syscalls_registers_metatable_name);
|
||||||
|
const char* index = luaL_checkstring(L, 2);
|
||||||
|
|
||||||
|
if (strcmp(index, "eax") == 0)
|
||||||
|
{
|
||||||
|
lua_pushinteger(L, r->eax);
|
||||||
|
}
|
||||||
|
else if (strcmp(index, "ebx") == 0)
|
||||||
|
{
|
||||||
|
lua_pushinteger(L, r->ebx);
|
||||||
|
}
|
||||||
|
else if (strcmp(index, "esp") == 0)
|
||||||
|
{
|
||||||
|
lua_pushinteger(L, r->esp);
|
||||||
|
}
|
||||||
|
else if (strcmp(index, "esi") == 0)
|
||||||
|
{
|
||||||
|
lua_pushinteger(L, r->esi);
|
||||||
|
}
|
||||||
|
else if (strcmp(index, "edi") == 0)
|
||||||
|
{
|
||||||
|
lua_pushinteger(L, r->edi);
|
||||||
|
}
|
||||||
|
else if (strcmp(index, "eip") == 0)
|
||||||
|
{
|
||||||
|
lua_pushinteger(L, r->eip);
|
||||||
|
}
|
||||||
|
else if (strcmp(index, "eflags") == 0)
|
||||||
|
{
|
||||||
|
lua_pushinteger(L, r->eflags);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int syscalls_newindexRegisters(lua_State* L)
|
||||||
|
{
|
||||||
|
struct registers* r = luaL_checkudata(L, 1, syscalls_registers_metatable_name);
|
||||||
|
const char* index = luaL_checkstring(L, 2);
|
||||||
|
uint32_t val = luaL_checkinteger(L, 3);
|
||||||
|
|
||||||
|
if (strcmp(index, "eax") == 0)
|
||||||
|
{
|
||||||
|
r->eax = val;
|
||||||
|
}
|
||||||
|
else if (strcmp(index, "ebx") == 0)
|
||||||
|
{
|
||||||
|
r->ebx = val;
|
||||||
|
}
|
||||||
|
else if (strcmp(index, "esp") == 0)
|
||||||
|
{
|
||||||
|
r->esp = val;
|
||||||
|
}
|
||||||
|
else if (strcmp(index, "esi") == 0)
|
||||||
|
{
|
||||||
|
r->esi = val;
|
||||||
|
}
|
||||||
|
else if (strcmp(index, "edi") == 0)
|
||||||
|
{
|
||||||
|
r->edi = val;
|
||||||
|
}
|
||||||
|
else if (strcmp(index, "eip") == 0)
|
||||||
|
{
|
||||||
|
r->eip = val;
|
||||||
|
}
|
||||||
|
else if (strcmp(index, "eflags") == 0)
|
||||||
|
{
|
||||||
|
r->eflags = val;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
luaL_pushfail(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int syscalls_eqRegisters(lua_State* L)
|
||||||
|
{
|
||||||
|
lua_pushboolean(
|
||||||
|
L,
|
||||||
|
memcmp(
|
||||||
|
luaL_checkudata(L, 1, syscalls_registers_metatable_name),
|
||||||
|
luaL_checkudata(L, 2, syscalls_registers_metatable_name),
|
||||||
|
sizeof(struct registers)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const luaL_Reg syscalls_registers_m[] = {
|
||||||
|
{"__index", syscalls_indexRegisters},
|
||||||
|
{"__newindex", syscalls_newindexRegisters},
|
||||||
|
{"__eq", syscalls_eqRegisters},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ARP_entry* syscalls_pushRegisters(lua_State* L)
|
||||||
|
{
|
||||||
|
DEBUG_LINE("push ARP entry");
|
||||||
|
|
||||||
|
struct ARP_entry* entry = lua_newuserdata(L, sizeof(struct registers));
|
||||||
|
|
||||||
|
luaL_setmetatable(L, syscalls_registers_metatable_name);
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int syscalls_newRegisters(lua_State* L)
|
||||||
|
{
|
||||||
|
struct registers* r = syscalls_pushRegisters(L);
|
||||||
|
memset(r, 0, sizeof(struct registers));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const luaL_Reg syscalls_registers_lib[] = {
|
||||||
|
{"new", syscalls_newRegisters},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
void syscalls_register_registers(lua_State* L)
|
||||||
|
{
|
||||||
|
DEBUG_LINE("register registers entry");
|
||||||
|
|
||||||
|
luaL_newlib(L, syscalls_registers_lib);
|
||||||
|
|
||||||
|
lua_setfield(L, -2, syscalls_registers_name);
|
||||||
|
|
||||||
|
|
||||||
|
luaL_newmetatable(L, syscalls_registers_metatable_name);
|
||||||
|
luaL_setfuncs(L, syscalls_registers_m, 0);
|
||||||
|
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
25
src/debug/registers.h
Normal file
25
src/debug/registers.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef __REGISTERS_H__
|
||||||
|
#define __REGISTERS_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct registers
|
||||||
|
{
|
||||||
|
uint32_t eip;
|
||||||
|
uint32_t eflags;
|
||||||
|
uint32_t eax;
|
||||||
|
uint32_t ebx;
|
||||||
|
uint32_t esp;
|
||||||
|
uint32_t esi;
|
||||||
|
uint32_t edi;
|
||||||
|
char zero[12];
|
||||||
|
};
|
||||||
|
|
||||||
|
#define syscalls_registers_name "Registers table"
|
||||||
|
#define syscalls_registers_metatable_name "Registers metatable"
|
||||||
|
|
||||||
|
struct registers* syscalls_pushRegisters(lua_State* L);
|
||||||
|
|
||||||
|
inline void syscalls_register_registers(lua_State* L);
|
||||||
|
|
||||||
|
#endif // __REGISTERS_H__
|
@@ -28,7 +28,7 @@ int syscalls_drawLine(lua_State* L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drawText(char* text, uint32_t x, uint32_t y, ksys_color_t color, size_t len, uint64_t backgroundColor)
|
static inline void drawText(char* text, uint32_t x, uint32_t y, ksys_color_t color, size_t len, uint64_t backgroundColor)
|
||||||
{
|
{
|
||||||
bool fillBackground = !(backgroundColor << 32);
|
bool fillBackground = !(backgroundColor << 32);
|
||||||
|
|
||||||
@@ -50,16 +50,14 @@ static void drawText(char* text, uint32_t x, uint32_t y, ksys_color_t color, siz
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void syscall_drawText(const char* text, uint32_t x, uint32_t y, ksys_color_t color, enum TextScale size, uint32_t len, uint64_t backgroundColor, enum DrawTextEncoding encoding)
|
static inline void syscall_drawText(const char* text, uint32_t x, uint32_t y, ksys_color_t color, enum TextScale size, uint32_t len, uint64_t backgroundColor, enum DrawTextEncoding encoding)
|
||||||
{
|
{
|
||||||
|
|
||||||
enum DrawTextEncoding_
|
enum DrawTextEncoding_
|
||||||
{
|
{
|
||||||
cp866_6x9 = 0,
|
cp866_6x9 = 0,
|
||||||
cp866_8x16 = 1
|
cp866_8x16 = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum scale
|
enum scale
|
||||||
{
|
{
|
||||||
scale_x1 = 0,
|
scale_x1 = 0,
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "systemColors.h"
|
#include "systemColors.h"
|
||||||
#include "sockets/socket_lua.h"
|
#include "sockets/socket_lua.h"
|
||||||
|
#include "debug/debug.h"
|
||||||
#include "graphic.h"
|
#include "graphic.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -1487,39 +1488,6 @@ static int syscalls_ReadARPConflicts(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int syscalls_DebugPuts(lua_State* L)
|
|
||||||
{
|
|
||||||
_ksys_debug_puts(luaL_checkstring(L, 1));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int syscalls_DebugPutc(lua_State* L)
|
|
||||||
{
|
|
||||||
_ksys_debug_putc(*luaL_checkstring(L, 1));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct DebugMessageArea
|
|
||||||
{
|
|
||||||
int Size;
|
|
||||||
int Used;
|
|
||||||
char data[];
|
|
||||||
};
|
|
||||||
|
|
||||||
static int syscalls_SetMessageArea(lua_State* L)
|
|
||||||
{
|
|
||||||
struct DebugMessageArea* p = luaL_checkinteger(L, 1);
|
|
||||||
|
|
||||||
asm_inline(
|
|
||||||
"int $0x40"
|
|
||||||
:: "a"(69), "b"(0)
|
|
||||||
);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** functions for 'syscalls' library
|
** functions for 'syscalls' library
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user