Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

Commit

Permalink
New callback mode, added colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Splamy committed Nov 16, 2017
1 parent bd0ff02 commit eae049b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
35 changes: 16 additions & 19 deletions TS3Hook/asmhook.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
31 changes: 26 additions & 5 deletions TS3Hook/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ hookpt OUT_HOOKS[] = {
};
#endif

HANDLE hConsole = NULL;

// RUNTIME CALCED
extern "C"
{
Expand All @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -147,15 +168,15 @@ 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()
{
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)
Expand Down
3 changes: 3 additions & 0 deletions TS3Hook/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eae049b

Please sign in to comment.