ANTICHAT

ANTICHAT (https://forum.antichat.xyz/index.php)
-   Общие вопросы программирования (https://forum.antichat.xyz/forumdisplay.php?f=206)
-   -   беда с аси (https://forum.antichat.xyz/showthread.php?t=1522114)

nonelike 08.10.2024 22:07

код че:





Код:

using
CChat__AddEntry
=
void
(
__thiscall
*
)
(
void
*
,
void
*
,
int
,
const
char
*
,
const
char
*
,
unsigned
long
,
unsigned
long
)
;
CChat__AddEntry pOriginalFunction
=
nullptr
;
void
*
SetCallHook
(
uintptr_t HookAddress
,
void
*
DetourFunction
)
{
uintptr_t OriginalFunction
=
*
reinterpret_cast

(
HookAddress
+
1
)
+
HookAddress
+
5
;
DWORD oldProt
;
VirtualProtect
(
reinterpret_cast

(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
PAGE_READWRITE
,
&
oldProt
)
;
*
reinterpret_cast

(
HookAddress
+
1
)
=
reinterpret_cast

(
DetourFunction
)
-
HookAddress
-
5
;
VirtualProtect
(
reinterpret_cast

(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
oldProt
,
&
oldProt
)
;
return
reinterpret_cast

(
OriginalFunction
)
;
}
void
__fastcall
HOOK_AddEntry
(
void
*
pChat
,
void
*
EDX
,
int
nType
,
const
char
*
szText
,
const
char
*
szPrefix
,
unsigned
long
textColor
,
unsigned
long
prefixColor
)
{
pOriginalFunction
(
pChat
,
EDX
,
nType
,
szText
,
szPrefix
,
textColor
,
prefixColor
)
;
}
if
(
uintptr_t dwSAMP
=
reinterpret_cast

(
GetModuleHandleA
(
"samp.dll"
)
)
;
dwSAMP
!=
0
)
{
pOriginalFunction
=
reinterpret_cast

(
SetCallHook
(
dwSAMP
+
0x67460
,
&
HOOK_AddEntry
)
)
;
}



пытаюсь хукнуть CChat__AddEntry, чтоб сменить текст samp started бла бла бла, но игра после запуска просто крашится

ARMOR 08.10.2024 22:09

Цитата:

Сообщение от nonelike

код че:





Код:

using
CChat__AddEntry
=
void
(
__thiscall
*
)
(
void
*
,
void
*
,
int
,
const
char
*
,
const
char
*
,
unsigned
long
,
unsigned
long
)
;
CChat__AddEntry pOriginalFunction
=
nullptr
;
void
*
SetCallHook
(
uintptr_t HookAddress
,
void
*
DetourFunction
)
{
uintptr_t OriginalFunction
=
*
reinterpret_cast

(
HookAddress
+
1
)
+
HookAddress
+
5
;
DWORD oldProt
;
VirtualProtect
(
reinterpret_cast

(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
PAGE_READWRITE
,
&
oldProt
)
;
*
reinterpret_cast

(
HookAddress
+
1
)
=
reinterpret_cast

(
DetourFunction
)
-
HookAddress
-
5
;
VirtualProtect
(
reinterpret_cast

(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
oldProt
,
&
oldProt
)
;
return
reinterpret_cast

(
OriginalFunction
)
;
}
void
__fastcall
HOOK_AddEntry
(
void
*
pChat
,
void
*
EDX
,
int
nType
,
const
char
*
szText
,
const
char
*
szPrefix
,
unsigned
long
textColor
,
unsigned
long
prefixColor
)
{
pOriginalFunction
(
pChat
,
EDX
,
nType
,
szText
,
szPrefix
,
textColor
,
prefixColor
)
;
}
if
(
uintptr_t dwSAMP
=
reinterpret_cast

(
GetModuleHandleA
(
"samp.dll"
)
)
;
dwSAMP
!=
0
)
{
pOriginalFunction
=
reinterpret_cast

(
SetCallHook
(
dwSAMP
+
0x67460
,
&
HOOK_AddEntry
)
)
;
}



пытаюсь хукнуть CChat__AddEntry, чтоб сменить текст samp started бла бла бла, но игра после запуска просто крашится

Потому что ты установил __thiscall но почему-то указываешь void* EDX. Или убери параметр EDX, или поставь соглашение о вызове __fastcall

nonelike 08.10.2024 22:14

Цитата:

Сообщение от ARMOR

Потому что ты установил __thiscall но почему-то указываешь void* EDX. Или убери параметр EDX, или поставь соглашение о вызове __fastcall

оба твои варианта не сработали, крашнуло

ARMOR 08.10.2024 22:20

C++:





Код:

using
CChat__AddEntry
=
void
(
__thiscall
*
)
(
void
*
,
int
,
const
char
*
,
const
char
*
,
unsigned
long
,
unsigned
long
)
;
CChat__AddEntry pOriginalFunction
=
nullptr
;
void
*
SetCallHook
(
uintptr_t HookAddress
,
void
*
DetourFunction
)
{
uintptr_t OriginalFunction
=
*
reinterpret_cast

(
HookAddress
+
1
)
+
HookAddress
+
5
;
DWORD oldProt
;
VirtualProtect
(
reinterpret_cast

(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
PAGE_READWRITE
,
&
oldProt
)
;
*
reinterpret_cast

(
HookAddress
+
1
)
=
reinterpret_cast

(
DetourFunction
)
-
HookAddress
-
5
;
VirtualProtect
(
reinterpret_cast

(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
oldProt
,
&
oldProt
)
;
return
reinterpret_cast

(
OriginalFunction
)
;
}
void
__fastcall
HOOK_AddEntry
(
void
*
pChat
,
int
nType
,
const
char
*
szText
,
const
char
*
szPrefix
,
unsigned
long
textColor
,
unsigned
long
prefixColor
)
{
pOriginalFunction
(
pChat
,
nType
,
szText
,
szPrefix
,
textColor
,
prefixColor
)
;
}
if
(
uintptr_t dwSAMP
=
reinterpret_cast

(
GetModuleHandleA
(
"samp.dll"
)
)
;
dwSAMP
!=
0
)
{
pOriginalFunction
=
reinterpret_cast

(
SetCallHook
(
dwSAMP
+
0x67460
,
&
HOOK_AddEntry
)
)
;
}



Если все равно крашит - проблема в адресе или функции для хука

nonelike 08.10.2024 22:22

Цитата:

Сообщение от ARMOR

C++:





Код:

using
CChat__AddEntry
=
void
(
__thiscall
*
)
(
void
*
,
int
,
const
char
*
,
const
char
*
,
unsigned
long
,
unsigned
long
)
;
CChat__AddEntry pOriginalFunction
=
nullptr
;
void
*
SetCallHook
(
uintptr_t HookAddress
,
void
*
DetourFunction
)
{
uintptr_t OriginalFunction
=
*
reinterpret_cast

(
HookAddress
+
1
)
+
HookAddress
+
5
;
DWORD oldProt
;
VirtualProtect
(
reinterpret_cast

(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
PAGE_READWRITE
,
&
oldProt
)
;
*
reinterpret_cast

(
HookAddress
+
1
)
=
reinterpret_cast

(
DetourFunction
)
-
HookAddress
-
5
;
VirtualProtect
(
reinterpret_cast

(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
oldProt
,
&
oldProt
)
;
return
reinterpret_cast

(
OriginalFunction
)
;
}
void
__fastcall
HOOK_AddEntry
(
void
*
pChat
,
int
nType
,
const
char
*
szText
,
const
char
*
szPrefix
,
unsigned
long
textColor
,
unsigned
long
prefixColor
)
{
pOriginalFunction
(
pChat
,
nType
,
szText
,
szPrefix
,
textColor
,
prefixColor
)
;
}
if
(
uintptr_t dwSAMP
=
reinterpret_cast

(
GetModuleHandleA
(
"samp.dll"
)
)
;
dwSAMP
!=
0
)
{
pOriginalFunction
=
reinterpret_cast

(
SetCallHook
(
dwSAMP
+
0x67460
,
&
HOOK_AddEntry
)
)
;
}



Если все равно крашит - проблема в адресе или функции для хука

адрес брал с https://github.com/BlastHackNet/SAMP...R3-1/CChat.cpp

https://forum.antichat.xyz/attachments/28547032/

также глянул в иде, адреса совпадают на р3

крашит до сих пор

плюс:





Код:

#include "plugin.h"
#include
using
CChat__AddEntry
=
void
(
__thiscall
*
)
(
void
*
,
int
,
const
char
*
,
const
char
*
,
unsigned
long
,
unsigned
long
)
;
CChat__AddEntry pOriginalFunction
=
nullptr
;
void
*
SetCallHook
(
uintptr_t HookAddress
,
void
*
DetourFunction
)
{
uintptr_t OriginalFunction
=
*
reinterpret_cast

(
HookAddress
+
1
)
+
HookAddress
+
5
;
DWORD oldProt
;
VirtualProtect
(
reinterpret_cast

(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
PAGE_READWRITE
,
&
oldProt
)
;
*
reinterpret_cast

(
HookAddress
+
1
)
=
reinterpret_cast

(
DetourFunction
)
-
HookAddress
-
5
;
VirtualProtect
(
reinterpret_cast

(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
oldProt
,
&
oldProt
)
;
return
reinterpret_cast

(
OriginalFunction
)
;
}
void
__fastcall
HOOK_AddEntry
(
void
*
pChat
,
int
nType
,
const
char
*
szText
,
const
char
*
szPrefix
,
unsigned
long
textColor
,
unsigned
long
prefixColor
)
{
std
::
cout
: "

ref
(
)
==
nullptr
)
return
game_loop_hook
.
call_original
(
)
;
initialized
=
true
;
if
(
uintptr_t dwSAMP
=
reinterpret_cast

(
GetModuleHandleA
(
"samp.dll"
)
)
;
dwSAMP
!=
0
)
{
pOriginalFunction
=
reinterpret_cast

(
SetCallHook
(
dwSAMP
+
0x67460
,
&
HOOK_AddEntry
)
)
;
}
return
game_loop_hook
.
call_original
(
)
;
}
void
c_plugin
::
attach_console
(
)
{
if
(
!
AllocConsole
(
)
)
return
;
FILE
*
f
;
freopen_s
(
&
f
,
"CONOUT$"
,
"w"
,
stdout
)
;
freopen_s
(
&
f
,
"CONOUT$"
,
"w"
,
stderr
)
;
freopen_s
(
&
f
,
"CONIN$"
,
"r"
,
stdin
)
;
}
c_plugin
::
c_plugin
(
HMODULE hmodule
)
:
hmodule
(
hmodule
)
{
attach_console
(
)
;
game_loop_hook
.
add
(
&
c_plugin
::
game_loop
)
;
}
c_plugin
::
~
c_plugin
(
)
{
rakhook
::
destroy
(
)
;
}


fuflexxxx 08.10.2024 23:19

У __fastcall'a в х86 архитектуре аргументы передаются в ecx, edx + стэк, тебе надо в хуке после объекта добавить ещё один аргумент любой(чтобы учесть edx). В оригинал соответственно edx передавать не надо, т.к у thiscall передача ecx + stack.

nonelike 08.10.2024 23:26

Цитата:

Сообщение от fuflexxxx

У __fastcall'a в х86 архитектуре аргументы передаются в ecx, edx + стэк, тебе надо в хуке после объекта добавить ещё один аргумент любой(чтобы учесть edx). В оригинал соответственно edx передавать не надо, т.к у thiscall передача ecx + stack.

C++:





[CODE]
void
__fastcall
HOOK_AddEntry
(
void
*
pChat
,
void
*
EDX
,
int
nType
,
const
char
*
szText
,
const
char
*
szPrefix
,
unsigned
long
textColor
,
unsigned
long
prefixColor
)
{
std
::
cout
: "



внес правки, samp started бла бла бла прошло, а когда начала выбиваться следующая строка(коннект на сервер) крашнуло

fuflexxxx 08.10.2024 23:36

Закоментируй свой вывод в хуке и посмотри что будет. И попробуй отладчиком посмотреть, где крашит.

nonelike 08.10.2024 23:42

Цитата:

Сообщение от fuflexxxx

Закоментируй свой вывод в хуке и посмотри что будет. И попробуй отладчиком посмотреть, где крашит.

вывод в хуке не повлиял, крашнуло, щас попробовал дебагер прикрутить к аси, весь проект пошел по очку

Musaigen 08.10.2024 23:53

Ты ставишь хук на пролог функции, а не на один из ее вызовов, да и по коду непонятно как у тебя вообще твоя функция вызывается, ибо ты даже не пишешь 0xE8 или 0xE9.

Второе, тебе нужен JMP hook (для него есть библиотека minhook например) в таком случае (если ты хукаешь пролог функции), иначе ты просто караптнешь стек и краш


Время: 21:24