 |
|

08.10.2024, 22:07
|
|
Познающий
Регистрация: 22.12.2018
Сообщений: 72
С нами:
3890632
Репутация:
63
|
|
код че:
Код:
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 бла бла бла, но игра после запуска просто крашится
|
|
|

08.10.2024, 22:09
|
|
Флудер
Регистрация: 02.02.2019
Сообщений: 5,070
С нами:
3831395
Репутация:
183
|
|
Сообщение от 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
|
|
|

08.10.2024, 22:14
|
|
Познающий
Регистрация: 22.12.2018
Сообщений: 72
С нами:
3890632
Репутация:
63
|
|
Сообщение от ARMOR
Потому что ты установил __thiscall но почему-то указываешь void* EDX. Или убери параметр EDX, или поставь соглашение о вызове __fastcall
оба твои варианта не сработали, крашнуло
|
|
|

08.10.2024, 22:20
|
|
Флудер
Регистрация: 02.02.2019
Сообщений: 5,070
С нами:
3831395
Репутация:
183
|
|
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
)
)
;
}
Если все равно крашит - проблема в адресе или функции для хука
|
|
|

08.10.2024, 22:22
|
|
Познающий
Регистрация: 22.12.2018
Сообщений: 72
С нами:
3890632
Репутация:
63
|
|
Сообщение от 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
также глянул в иде, адреса совпадают на р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
(
)
;
}
|
|
|

08.10.2024, 23:19
|
|
Познающий
Регистрация: 10.06.2020
Сообщений: 37
С нами:
3119285
Репутация:
63
|
|
У __fastcall'a в х86 архитектуре аргументы передаются в ecx, edx + стэк, тебе надо в хуке после объекта добавить ещё один аргумент любой(чтобы учесть edx). В оригинал соответственно edx передавать не надо, т.к у thiscall передача ecx + stack.
|
|
|

08.10.2024, 23:26
|
|
Познающий
Регистрация: 22.12.2018
Сообщений: 72
С нами:
3890632
Репутация:
63
|
|
Сообщение от 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 бла бла бла прошло, а когда начала выбиваться следующая строка(коннект на сервер) крашнуло
|
|
|

08.10.2024, 23:36
|
|
Познающий
Регистрация: 10.06.2020
Сообщений: 37
С нами:
3119285
Репутация:
63
|
|
Закоментируй свой вывод в хуке и посмотри что будет. И попробуй отладчиком посмотреть, где крашит.
|
|
|

08.10.2024, 23:42
|
|
Познающий
Регистрация: 22.12.2018
Сообщений: 72
С нами:
3890632
Репутация:
63
|
|
Сообщение от fuflexxxx
Закоментируй свой вывод в хуке и посмотри что будет. И попробуй отладчиком посмотреть, где крашит.
вывод в хуке не повлиял, крашнуло, щас попробовал дебагер прикрутить к аси, весь проект пошел по очку
|
|
|

08.10.2024, 23:53
|
|
Познавший АНТИЧАТ
Регистрация: 01.04.2018
Сообщений: 1,710
С нами:
4272230
Репутация:
183
|
|
Ты ставишь хук на пролог функции, а не на один из ее вызовов, да и по коду непонятно как у тебя вообще твоя функция вызывается, ибо ты даже не пишешь 0xE8 или 0xE9.
Второе, тебе нужен JMP hook (для него есть библиотека minhook например) в таком случае (если ты хукаешь пролог функции), иначе ты просто караптнешь стек и краш
|
|
|
|
 |
|
|
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
|
|
|
|