HOOK_DEF(void
*
, HookCallBackNoArgs) {
if
(!isFinish) {
return
orig_HookCallBackNoArgs();
}
if
(ALL_METHOD_LIST
=
=
nullptr) {
return
orig_HookCallBackNoArgs();
}
void
*
method_ptr
=
(void
*
) __builtin_return_address(
0
);
for
(const auto &method:
*
ALL_METHOD_LIST) {
if
(method
-
>methodPointer && method_ptr) {
if
(method
-
>methodPointer
=
=
method_ptr) {
const string &methodInfo
=
getMethodInfo(method);
if
(mOs
=
=
nullptr) {
mOs
=
new std::ofstream(saveDir);
}
LOGE(
"tracer method info %s il2cpp base -> %p"
, methodInfo.c_str(),
(void
*
) il2cpp_base)
*
mOs << methodInfo;
return
orig_HookCallBackNoArgs();
}
}
}
return
orig_HookCallBackNoArgs();
}
HOOK_DEF(void
*
, HookCallBack, va_list args) {
if
(!isFinish) {
return
orig_HookCallBack(args);
}
if
(ALL_METHOD_LIST
=
=
nullptr) {
return
orig_HookCallBack(args);
}
void
*
method_ptr
=
(void
*
) __builtin_return_address(
0
);
for
(const auto &method:
*
ALL_METHOD_LIST) {
if
(method
-
>methodPointer && method_ptr) {
if
(method
-
>methodPointer
=
=
method_ptr) {
const string &methodInfo
=
getMethodInfo(method);
if
(mOs
=
=
nullptr) {
mOs
=
new std::ofstream(saveDir);
}
LOGE(
"tracer method info %s il2cpp base -> %p"
, methodInfo.c_str(),
(void
*
) il2cpp_base)
*
mOs << methodInfo;
return
orig_HookCallBack(args);
}
}
}
return
orig_HookCallBack(args);
}
void il2cpp_tracer(const char
*
outDir) {
saveDir
=
std::string(outDir).append(
"FunIl2cpp_tracer.txt"
);
LOGI(
"il2cpp_tracer tracer... %s"
, saveDir.c_str())
if
(ALL_METHOD_LIST
=
=
nullptr) {
ALL_METHOD_LIST
=
new
list
<const MethodInfo
*
>;
}
size_t size;
auto domain
=
il2cpp_domain_get();
LOGI(
"il2cpp_tracer init domain finish "
)
auto assemblies
=
il2cpp_domain_get_assemblies(domain, &size);
LOGI(
"il2cpp_tracer init assemblies finish "
)
if
(il2cpp_image_get_class) {
LOGI(
"Version greater than 2018.3"
);
for
(
int
i
=
0
; i < size;
+
+
i) {
auto image
=
il2cpp_assembly_get_image(assemblies[i]);
auto imageName
=
il2cpp_image_get_name(image);
auto classCount
=
il2cpp_image_get_class_count(image);
for
(
int
j
=
0
; j < classCount;
+
+
j) {
auto tempKlass
=
il2cpp_image_get_class(image, j);
if
(tempKlass
=
=
nullptr) {
continue
;
}
auto
type
=
il2cpp_class_get_type(const_cast<Il2CppClass
*
>(tempKlass));
if
(
type
=
=
nullptr) {
continue
;
}
auto
*
klass
=
il2cpp_class_from_type(
type
);
if
(klass
=
=
nullptr) {
continue
;
}
void
*
iter
=
nullptr;
while
(auto method
=
il2cpp_class_get_methods(klass, &
iter
)) {
auto pointer
=
method
-
>methodPointer;
if
(pointer) {
const string &methodInfo
=
getMethodInfo(method);
/
/
hook
all
method
auto param_count
=
il2cpp_method_get_param_count(method);
if
(param_count >
0
) {
HookUtils::Hooker((void
*
) pointer,
(void
*
) new_HookCallBack,
(void
*
*
) &orig_HookCallBack
);
}
else
{
HookUtils::Hooker((void
*
) pointer,
(void
*
) new_HookCallBackNoArgs,
(void
*
*
) &orig_HookCallBackNoArgs
);
}
ALL_METHOD_LIST
-
>push_back(method);
LOGI(
"hook method success %lu %s "
, ALL_METHOD_LIST
-
>size(),
methodInfo.c_str());
}
if
(
iter
=
=
nullptr) {
break
;
}
}
}
}
isFinish
=
true;
LOGE(
"lister il2cpp finish method size %lu "
, ALL_METHOD_LIST
-
>size())
}
}