From eae049b193d9f1b0a5217854e654b113eb2b7f66 Mon Sep 17 00:00:00 2001 From: Splamy Date: Thu, 16 Nov 2017 07:08:58 +0100 Subject: [PATCH] New callback mode, added colors --- TS3Hook/asmhook.asm | 35 ++++++++++++++++------------------- TS3Hook/dllmain.cpp | 31 ++++++++++++++++++++++++++----- TS3Hook/main.h | 3 +++ 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/TS3Hook/asmhook.asm b/TS3Hook/asmhook.asm index 540dfd8..3a6ed3c 100644 --- a/TS3Hook/asmhook.asm +++ b/TS3Hook/asmhook.asm @@ -3,9 +3,8 @@ .code -EXTERN printf: PROC -EXTERN print_in_format: QWORD -EXTERN print_out_format: QWORD +EXTERN log_in_packet: PROC +EXTERN log_out_packet: PROC EXTERN packet_in_hook_return: QWORD EXTERN packet_out_hook_return: QWORD @@ -60,12 +59,11 @@ packet_in_hook1 proc SUB rsp, 32 ; Log in-packet - MOV r8, QWORD PTR [rdx+8] - ADD r8, 11 ; str + MOV rcx, QWORD PTR [rdx+8] + ADD rcx, 11 ; str MOV edx, DWORD PTR [rdx+16] SUB edx, 11 ; len - MOV rcx, print_in_format - CALL printf + CALL log_in_packet ADD rsp, 32 popaq @@ -78,12 +76,11 @@ packet_out_hook1 proc SUB rsp, 32 ; Log out-packet - MOV r8, QWORD PTR [rdi] - ADD r8, 13 ; str + MOV rcx, QWORD PTR [rdi] + ADD rcx, 13 ; str MOV edx, DWORD PTR [rdi+8] SUB edx, 13 ; len - MOV rcx, print_out_format - CALL printf + CALL log_out_packet ADD rsp, 32 popaq @@ -103,12 +100,11 @@ packet_out_hook2 proc SUB rsp, 32 ; Log out-packet - MOV r8, QWORD PTR [rdi] - ADD r8, 13 ; str + MOV rcx, QWORD PTR [rdi] + ADD rcx, 13 ; str MOV edx, DWORD PTR [rdi+8] SUB edx, 13 ; len - MOV rcx, print_out_format - CALL printf + CALL log_out_packet ADD rsp, 32 popaq @@ -139,13 +135,14 @@ packet_out_hook3 proc JNZ _skip_packet SUB rsp, 32 + ; Log out-packet - MOV r8, QWORD PTR [rsi] - ADD r8, 13 ; str + MOV rcx, QWORD PTR [rsi] + ADD rcx, 13 ; str MOV edx, DWORD PTR [rsi+8] SUB edx, 13 ; len - MOV rcx, print_out_format - CALL printf + CALL log_out_packet + ADD rsp, 32 _skip_packet: diff --git a/TS3Hook/dllmain.cpp b/TS3Hook/dllmain.cpp index 3b074ec..9b28052 100644 --- a/TS3Hook/dllmain.cpp +++ b/TS3Hook/dllmain.cpp @@ -30,6 +30,8 @@ hookpt OUT_HOOKS[] = { }; #endif +HANDLE hConsole = NULL; + // RUNTIME CALCED extern "C" { @@ -43,19 +45,30 @@ BOOL APIENTRY DllMain(HMODULE hModule, const DWORD ul_reason_for_call, LPVOID lp { case DLL_PROCESS_ATTACH: + hConsole = GetStdHandle(STD_OUTPUT_HANDLE); + + if (hConsole != NULL) + SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY); printf("-==== TS3HOOK 1.0 ====-\n"); printf("-= Written by Splamy =-\n"); if (!TryHook()) { + if (hConsole != NULL) + SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY); printf("Packet dispatcher not found, aborting\n"); return FALSE; } else { + if (hConsole != NULL) + SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_INTENSITY); printf("Hook successful!\n"); } + if (hConsole != NULL) + SetConsoleTextAttribute(hConsole, 0); + CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)idle_loop, nullptr, NULL, nullptr); break; @@ -67,10 +80,18 @@ BOOL APIENTRY DllMain(HMODULE hModule, const DWORD ul_reason_for_call, LPVOID lp return TRUE; } -extern "C" +void log_in_packet(char* packet, int length) +{ + if (hConsole != NULL) + SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY); + printf("[ IN] %.*s\n", length, packet); +} + +void log_out_packet(char* packet, int length) { - const char* print_in_format = "[ IN] %.*s\n"; - const char* print_out_format = "[OUT] %.*s\n"; + if (hConsole != NULL) + SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_INTENSITY); + printf("[OUT] %.*s\n", length, packet); } #ifdef ENV32 @@ -147,7 +168,7 @@ void __declspec(naked) packet_out_hook1() CMP DWORD PTR[ebp + 16], 1 SETZ BYTE PTR[ebp + 4] JMP packet_out_hook_return -} + } } #else bool TryHook() @@ -155,7 +176,7 @@ bool TryHook() const auto match_in_1 = FindPattern(mod, PATT_IN_1, MASK_IN_1); if (match_in_1 != NULL) printf("> Found PKGIN: %zX\n", match_in_1); - + SIZE_T match_out = NULL; hookpt* pt_out = nullptr; for (hookpt &pt : OUT_HOOKS) diff --git a/TS3Hook/main.h b/TS3Hook/main.h index 160ecc8..1f690b3 100644 --- a/TS3Hook/main.h +++ b/TS3Hook/main.h @@ -30,6 +30,9 @@ void idle_loop(); extern "C" { + void log_in_packet(char* packet, int length); + void log_out_packet(char* packet, int length); + void packet_in_hook1(); void packet_out_hook1(); #ifdef ENV64