From c45b7e611a953ae1e6a953cec739baa855f19b16 Mon Sep 17 00:00:00 2001 From: superturbocat2001 Date: Sun, 3 Jan 2021 18:15:53 +0000 Subject: [PATCH] - GameHack 0.1 alpha git-svn-id: svn://kolibrios.org@8507 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/other/GameHack/Makefile | 16 +++++ programs/other/GameHack/gh_core.c | 72 ++++++++++++++++++++++ programs/other/GameHack/gh_shell.c | 96 ++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+) create mode 100755 programs/other/GameHack/Makefile create mode 100644 programs/other/GameHack/gh_core.c create mode 100644 programs/other/GameHack/gh_shell.c diff --git a/programs/other/GameHack/Makefile b/programs/other/GameHack/Makefile new file mode 100755 index 0000000000..c9b6511f2c --- /dev/null +++ b/programs/other/GameHack/Makefile @@ -0,0 +1,16 @@ +KTCC_DIR=../../develop/ktcc/trunk + +NAME=gamehack + +KTCC=$(KTCC_DIR)/bin/kos32-tcc +KPACK=kpack + +SRC=gh_shell.c +CFLAGS=-I $(KTCC_DIR)/libc/include +LIBS = -lck + +all: + $(KTCC) $(CFLAGS) $(SRC) $(LIBS) -o $(NAME) + $(KPACK) $(NAME) +clean: + rm $(NAME) diff --git a/programs/other/GameHack/gh_core.c b/programs/other/GameHack/gh_core.c new file mode 100644 index 0000000000..a49a4cd4e6 --- /dev/null +++ b/programs/other/GameHack/gh_core.c @@ -0,0 +1,72 @@ +int PID=-1; + +int kdebugger_write(unsigned ID, unsigned n, unsigned addr, unsigned* buff) +{ + int num; + __asm__ __volatile__( + "int $0x40" + :"=a"(num) + :"a"(69), "b"(7), "c"(ID), "d"(n),"S"(addr),"D"(buff) + ); + return num; +} + +int kdebugger_read(unsigned ID, unsigned n, unsigned addr, unsigned* buff) +{ + int num; + __asm__ __volatile__( + "int $0x40" + :"=a"(num) + :"a"(69), "b"(6), "c"(ID), "d"(n),"S"(addr),"D"(buff) + ); + return num; +} + +void kdebugger_pause(unsigned ID) +{ + __asm__ __volatile__( + "int $0x40" + ::"a"(69), "b"(4), "c"(ID) + ); +} + +void kdebugger_play(unsigned ID) +{ + __asm__ __volatile__( + "int $0x40" + ::"a"(69), "b"(5), "c"(ID) + ); +} + +void kdebugger_disconnect(unsigned ID) +{ + __asm__ __volatile__( + "int $0x40" + ::"a"(69), "b"(3), "c"(ID) + ); +} + +int load_game(char *app_name, char *args) +{ + #pragma pack(push, 1) + struct file_op_t + { + unsigned fn; + unsigned flags; + char* args; + unsigned res1, res2; + char zero; + char* app_name __attribute__((packed)); + } file_op; + #pragma pack(pop) + + memset(&file_op, 0, sizeof(file_op)); + file_op.fn = 7; + file_op.flags = 1; + file_op.args = args; + file_op.app_name = app_name; + + register int val; + asm volatile ("int $0x40":"=a"(val):"a"(70), "b"(&file_op)); + return val; +} diff --git a/programs/other/GameHack/gh_shell.c b/programs/other/GameHack/gh_shell.c new file mode 100644 index 0000000000..bb32a97b1f --- /dev/null +++ b/programs/other/GameHack/gh_shell.c @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include "gh_core.c" + +#define CMD_LEN 255 +#define TITLE "GameHack 1.0 ALPHA " + +char cmd_line[CMD_LEN]; +char cmd_line_tmp[CMD_LEN]; + +void notify_show(char *text) +{ + start_app("/sys/@notify", text); +} + +void cmd_processing() +{ + strcpy(cmd_line_tmp, cmd_line); + char *cmd = strtok(cmd_line_tmp, " \n"); + if(!strcmp(cmd, "pause")){ + kdebugger_pause(PID); + } + else if(!strcmp(cmd, "play")){ + kdebugger_play(PID); + } + else if(!strcmp(cmd, "exit")){ + exit(0); + } + else if(!strcmp(cmd, "write")){ + unsigned addr=0; + int val =0; + if(sscanf(cmd_line, "%s %x %d %d",cmd_line, &addr, &val, &val)==3){ + if(kdebugger_write(PID, sizeof(int), addr, &val)==-1){ + puts("Memory write error!"); + } + }else{ + puts("Invalid arguments!"); + } + } + else if(!strcmp(cmd, "read")){ + unsigned addr=0; + int val =0; + if(sscanf(cmd_line, "%s %x %x",cmd_line, &addr, &addr)==2){ + if(kdebugger_read(PID, sizeof(int), addr, &val)==-1){ + puts("Memory read error!"); + } + printf("0x%.8X: %d\n", addr, val); + }else{ + puts("Invalid arguments!"); + } + } + + + else if(!strcmp(cmd, "help")) + { + puts("Commands:"); + puts(" write [addres] [value] - Write DWORD value by address."); + puts(" read [addres] [value] - Read DWORD value by address."); + puts(" pause - Suspend the game (process)." ); + puts(" play - Resume running the game(process)."); + puts(" find [value] - Search for DWORD value in memory(VIP)."); + } + else if(!strcmp(cmd, "find")) + { + puts("Not yet implemented ..."); + } + else if(cmd != NULL){ + puts("Unknown command!"); + } +} + +int main(int argc, char* argv[]) +{ + if (argc!=2 ){ + notify_show("'No game selected!' -E"); + exit(0); + } + con_init_console_dll(); + con_set_title(TITLE); + PID = load_game(argv[1], NULL); + PID = 2; + if(PID<0){ + notify_show("'Game not loaded!' -E"); + exit(0); + } + kdebugger_play(PID); + while (1){ + printf("GameHack> "); + con_gets(cmd_line, CMD_LEN); + cmd_processing(); + memset(cmd_line, '\n', CMD_LEN); + } +} \ No newline at end of file