Ответы

Помогите исправить ошибку компиляции .so из-за frida gum

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
#include <pthread.h>
#include <jni.h>
#include <unistd.h>
#include <thread>
#include <dlfcn.h>

#include "includes/logger.h"
#include "includes/utils.h"
#include "includes/il2cpp.h"
#include "includes/frida-gum.h"

bool isLoaded = false;


typedef void (*Building_Do_Add_t)(int _rID, int _sID, const char* _bType);
static Building_Do_Add_t Building_Do_Add_original = nullptr;


static void onEnter(GumInvocationContext* context){
	LOGI("Метод Building_Do_Add вызван.");
}

static void onLeave(GumInvocationContext* context){
	LOGI("Метод Building_Do_Add завершён.");
}

typedef struct {
    GObject parent;
    void (*on_enter)(GumInvocationContext* context);
    void (*on_leave)(GumInvocationContext* context);
} SimpleInvocationListener;

static SimpleInvocationListener simple_listener = {
    .on_enter = onEnter,
    .on_leave = onLeave
};


void init_frida_gum(){
	gum_init_embedded();
	
	LOGI("frida-gum инициализирован.");
	
	LOGI("Вычисляю адрес метода Building_Do_Add по оффсету.");
	
	GumAddress target_addr = Utils::getAbsoluteAddress("libil2cpp.so", 0x1288B6C);
	
	LOGI("Адрес вычислен, приступаю к перехвату.");
	
	GumInterceptor* interceptor = gum_interceptor_obtain();
  
    GumAttachReturn result = gum_interceptor_attach(
        interceptor,
        (gpointer)target_addr,
        (GumInvocationListener*)&simple_listener,
        (gpointer)&Building_Do_Add_original,
        0
    );
    
    if (result == GUM_ATTACH_OK) {
        LOGI("Хук успешно установлен! Оригинальная функция: %p", Building_Do_Add_original);
    } else {
        LOGE("Ошибка установки хука: %d", result);
    }
}


void* main_thread() {
	LOGI("main_thread запущен, жду загрузки libil2cpp.so.");
	
    do {
        sleep(1);
    } while (!Utils::isLibraryLoaded("libil2cpp.so"));

	LOGI("libil2cpp.so загружен в память!");
	
	sleep(2);

	LOGI("Инициализирую frida-gum.");
	
	init_frida_gum();
}

JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
	if (isLoaded==false){
		LOGI("НАТИВНАЯ БИБЛИОТЕКА ЗАПУЩЕНА!");
		
		isLoaded = true;
		
		std::thread worker(main_thread);
		worker.detach();
	}
	return JNI_VERSION_1_6;
	
}

Ошибка компилятора:

jni/src/il2cpp_hacking_so.cpp:58:30: error: no matching function for call to

'gum_interceptor_attach'

58 | GumAttachReturn result = gum_interceptor_attach(

| ^~~~~~~~~~~~~~~~~~~~~~

При этом функция gum_interceptor_attach есть внутри frida-gum.h, но компилятор её почему-то не видит:

12345
GUM_API GumAttachReturn gum_interceptor_attach (GumInterceptor * self,
    gpointer function_address, GumInvocationListener * listener,
    gpointer listener_function_data, GumAttachFlags flags);

По дате
По рейтингу
Аватар пользователя
Ученик
2мес

#include <pthread.h>

#include <jni.h>

#include <unistd.h>

#include <thread>

#include <dlfcn.h>

#include "includes/logger.h"

#include "includes/utils.h"

#include "includes/il2cpp.h"

#include "includes/frida-gum.h"

bool isLoaded = false;

typedef void (*Building_Do_Add_t)(int rID, int sID, const char* _bType);

static Building_Do_Add_t Building_Do_Add_original = nullptr;

static void onEnter(GumInvocationContext* context, gpointer user_data) {

LOGI("Метод Building_Do_Add вызван.");

}

static void onLeave(GumInvocationContext* context, gpointer user_data) {

LOGI("Метод Building_Do_Add завершён.");

}

void init_frida_gum() {

gum_init_embedded();

LOGI("frida-gum инициализирован.");

LOGI("Вычисляю адрес метода Building_Do_Add по оффсету.");

GumAddress target_addr = Utils::getAbsoluteAddress("libil2cpp.so", 0x1288B6C);

LOGI("Адрес вычислен: %p", (void*)target_addr);

GumInterceptor* interceptor = gum_interceptor_obtain();

// Создаём C-совместимый listener

GumCInvocationListener* listener = gum_c_invocation_listener_new(

onEnter,

onLeave,

nullptr, // user_data

nullptr // destroy_notify

);

GumAttachReturn result = gum_interceptor_attach(

interceptor,

(gpointer)target_addr,

GUM_INVOCATION_LISTENER(listener),

&Building_Do_Add_original

);

if (result == GUM_ATTACH_OK) {

LOGI("Хук успешно установлен! Оригинальная функция: %p", (void*)Building_Do_Add_original);

} else {

LOGE("Ошибка установки хука: %d", result);

}

g_object_unref(listener); // Освобождаем listener после attach

}

void* main_thread() {

LOGI("main_thread запущен, жду загрузки libil2cpp.so.");

do {

sleep(1);

} while (!Utils::isLibraryLoaded("libil2cpp.so"));

LOGI("libil2cpp.so загружен в память!");

sleep(2);

init_frida_gum();

return nullptr;

}

JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {

if (!isLoaded) {

LOGI("НАТИВНАЯ БИБЛИОТЕКА ЗАПУЩЕНА!");

isLoaded = true;

std::thread worker(main_thread);

worker.detach();

}

return JNI_VERSION_1_6;

}