Показать сообщение отдельно

  #4  
Старый 28.04.2024, 19:28
g305noobo
Постоянный
Регистрация: 24.09.2020
Сообщений: 364
С нами: 2966237

Репутация: 148
По умолчанию

Цитата:
Сообщение от why ega  

Мне кажется, хукать getfield не лучшая идея, поскольку не все скрипты имеют функцию main. На больную голову решил прохукать lua_newstate, но чет получил таз крашей, поэтому, возможно, кто-то доделает этот шедеврометод

C++:





Код:
LSHook
::
LSHook
(
)
{
auto
luaLibAddress
=
GetModuleHandleA
(
"lua51.dll"
)
;
if
(
!
luaLibAddress
)
return
;
luaL_loadstring
=
reinterpret_cast

(
GetProcAddress
(
luaLibAddress
,
"luaL_loadstring"
)
)
;
lua_pcall
=
reinterpret_cast

(
GetProcAddress
(
luaLibAddress
,
"lua_pcall"
)
)
;
auto
luaL_newstateAddress
=
GetProcAddress
(
luaLibAddress
,
"luaL_newstate"
)
;
luaL_newstateHook
.
set_dest
(
luaL_newstateAddress
)
;
luaL_newstateHook
.
set_cb
(
[
this
]
(
auto
&&
.
.
.
args
)
{
return
luaL_newstateHooked
(
args
.
.
.
)
;
}
)
;
luaL_newstateHook
.
install
(
)
;
}
LSHook
::
~
LSHook
(
)
{
luaL_newstateHook
.
remove
(
)
;
}
std
::
uintptr_t LSHook
::
luaL_newstateHooked
(
const
decltype
(
luaL_newstateHook
)
&
hook
)
{
auto
L
=
hook
.
get_trampoline
(
)
(
)
;
auto
result
=
luaL_loadstring
(
L
,
"print(\"HUY\")"
)
;
if
(
result
==
0
)
lua_pcall
(
L
,
0
,
0
,
0
)
;
return
L
;
}


header:





Код:
#include 
#include "kthook/kthook.hpp"
class
LSHook
{
private
:
using
luaL_newstate_t
=
std
::
uintptr_t
(
*
)
(
)
;
kthook
::
kthook_simple

luaL_newstateHook
;
std
::
uintptr_t
luaL_newstateHooked
(
const
decltype
(
luaL_newstateHook
)
&
hook
)
;
using
luaL_loadstring_t
=
int
(
*
)
(
std
::
uintptr_t
,
const
char
*
)
;
using
lua_pcall_t
=
int
(
*
)
(
std
::
uintptr_t L
,
int
nargs
,
int
nresults
,
int
errfunc
)
;
;
luaL_loadstring_t luaL_loadstring
=
nullptr
;
lua_pcall_t lua_pcall
=
nullptr
;
public
:
LSHook
(
/* args */
)
;
~
LSHook
(
)
;
}
lshook
;

это хорошая идея, но из-за того что мы хукаем самую начальную точку, moonloader не успевает сделать luaL_openlibs, соотвественно в хуке даже print не работает в luaL_loadstring, не говоря уже о функциях муна.

но если просто сохранить эти указатели и использовать попозже, все будет ок
 
Ответить с цитированием