android 为什么FindLibrary返回0?

ztigrdn8  于 2023-11-15  发布在  Android
关注(0)|答案(1)|浏览(77)

我试图创建一个启动SAMP Android.一切都进行得很顺利,直到SAMP本身的集成(build69). libsamp.so无法找到相邻的libGTASA.so库的地址.
初始化所有库(Java)

static {
        vmVersion = null;
        System.out.println("**** Loading SO's");
        try
        {
            vmVersion = System.getProperty("java.vm.version");
            System.out.println("vmVersion " + vmVersion);
            System.out.println("**** Loading libImmEmulatorJ.so");
            System.loadLibrary("ImmEmulatorJ");
        } catch (ExceptionInInitializerError | UnsatisfiedLinkError e) {
        }
        System.out.println("**** Loading libGTASA.so");
        System.loadLibrary("GTASA");
        System.out.println("**** Loading libsamp.so");
        System.loadLibrary("samp");
    }

字符串
在libsamp.so中查找库(C++ JNI)

jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
  Log("SAMP library loaded! Build time: " __DATE__ " " __TIME__);

  g_libGTASA = FindLibrary("libGTASA.so");
  if(g_libGTASA == 0)
  {
    Log("ERROR: libGTASA.so address not found!");
    return 0;
  }

  Log("libGTASA.so image base address: 0x%X", g_libGTASA);

  srand(time(0));

  InitHookStuff();
  InitRenderWareFunctions();
  InstallSpecialHooks();

  pthread_t thread;
  pthread_create(&thread, 0, Init, 0);

  struct sigaction act;
  act.sa_sigaction = handler;
  sigemptyset(&act.sa_mask);
  act.sa_flags = SA_SIGINFO;
  sigaction(SIGSEGV, &act, 0);

  return JNI_VERSION_1_4;
}


FindLibrary:

uintptr_t FindLibrary(const char* library)
{
    char filename[0xFF] = {0},
    buffer[2048] = {0};
    FILE *fp = 0;
    uintptr_t address = 0;

    sprintf( filename, "/proc/%d/maps", getpid() );

    fp = fopen( filename, "rt" );
    if(fp == 0)
    {
        Log("ERROR: can't open file %s", filename);
        goto done;
    }

    while(fgets(buffer, sizeof(buffer), fp))
    {
        if( strstr( buffer, library ) )
        {
            address = (uintptr_t)strtoul( buffer, 0, 16 );
            break;
        }
    }

    done:

    if(fp)
      fclose(fp);

    return address;
}


应用程序日志:

2023-10-28 14:57:32.800 29054-29054 System.out              com.kalinovka.game                   I  **** Loading SO's
2023-10-28 14:57:32.800 29054-29054 System.out              com.kalinovka.game                   I  vmVersion 2.1.0
2023-10-28 14:57:32.800 29054-29054 System.out              com.kalinovka.game                   I  **** Loading libImmEmulatorJ.so
2023-10-28 14:57:32.804 29054-29054 System.out              com.kalinovka.game                   I  **** Loading libGTASA.so
2023-10-28 14:57:32.813 29054-29054 NVEvent                 com.kalinovka.game                   D  JNI_OnLoad called
2023-10-28 14:57:32.813 29054-29054 NVEvent                 com.kalinovka.game                   D  RegisterNatives 12
2023-10-28 14:57:32.813 29054-29054 System.out              com.kalinovka.game                   I  **** Loading libsamp.so
2023-10-28 14:57:32.815 29054-29054 AXL                     com.kalinovka.game                   I  SAMP library loaded! Build time: Oct 28 2023 14:47:20
2023-10-28 14:57:32.819 29054-29054 AXL                     com.kalinovka.game                   I  ERROR: libGTASA.so address not found!
2023-10-28 14:57:32.820 29054-29054 AndroidRuntime          com.kalinovka.game                   D  Shutting down VM
2023-10-28 14:57:32.823 29054-29054 AndroidRuntime          com.kalinovka.game                   E  FATAL EXCEPTION: main
                                                                                                    Process: com.kalinovka.game, PID: 29054
                                                                                                    java.lang.UnsatisfiedLinkError: Bad JNI version returned from JNI_OnLoad in "/data/app/~~AIt22YvJlsdkRyH_N_WAEw==/com.kalinovka.game-G93aBwDihlPGnVBadiHFkQ==/base.apk!/lib/armeabi-v7a/libsamp.so": 0
                                                                                                        at java.lang.Runtime.loadLibrary0(Runtime.java:1082)
                                                                                                        at java.lang.Runtime.loadLibrary0(Runtime.java:1003)
                                                                                                        at java.lang.System.loadLibrary(System.java:1661)
                                                                                                        at com.kalinovka.game.core.GTASA.<clinit>(GTASA.java:28)
                                                                                                        at java.lang.Class.newInstance(Native Method)
                                                                                                        at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
                                                                                                        at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
                                                                                                        at android.app.Instrumentation.newActivity(Instrumentation.java:1287)
                                                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3701)
                                                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3977)
                                                                                                        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:109)
                                                                                                        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
                                                                                                        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2374)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:233)
                                                                                                        at android.os.Looper.loop(Looper.java:344)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8249)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:589)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1071)
2023-10-28 14:57:32.894 29054-29054 Process                 com.kalinovka.game                   I  Sending signal. PID: 29054 SIG: 9


错误:从JNI_OnLoad返回的JNI版本无效-由于libsamp.so发送了0,您可以忽略此错误
我删除了所有对libsamp.so的引用,应用程序工作正常,GTASA本身由ID初始化,这意味着libGTASA.so已加载并工作。
我在FindLibrary中更改了库名称,它也返回了零。表示由于Android API级别,访问出现了问题。
我在一个俄语网站上也发现了同样的问题,但是没有解决方案,但是问题表明这个错误只发生在Android API 30+上

bq9c1y66

bq9c1y661#

最有可能的是,问题出在SDK版本上
可能超过28个版本。

相关问题