Skip to content

Commit

Permalink
Fix[init]: unexpectedly preload LWJGL
Browse files Browse the repository at this point in the history
Migrating token storage to keychain accidentally causes LWJGL to be
preloaded, making Fabric fails to init.
Add JNI library PojavAccountJNI to do the task of sending access token
from keychain to JVM space.
  • Loading branch information
khanhduytran0 committed Apr 9, 2024
1 parent 41a0c8d commit f7163ce
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static MinecraftAccount load(String name) throws IOException, JsonSyntaxE
}

static {
System.load(System.getenv("BUNDLE_PATH") + "/PojavLauncher");
System.loadLibrary("PojavAccountJNI");
}
public static native String getAccessTokenFromKeychain(String xuid);
}
6 changes: 6 additions & 0 deletions Natives/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ target_link_libraries(AFNetworking
"-framework UIKit"
)

# MinecraftAccount JNI
add_library(PojavAccountJNI SHARED
authenticator/MinecraftAccountJNI.m
)
target_link_libraries(PojavAccountJNI)

# PojavLauncher
add_executable(PojavLauncher
dyld_bypass_validation.m
Expand Down
14 changes: 0 additions & 14 deletions Natives/authenticator/MicrosoftAuthenticator.m
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,3 @@ - (NSDictionary *)tokenData {
}

@end

JNIEXPORT jstring JNICALL Java_net_kdt_pojavlaunch_value_MinecraftAccount_getAccessTokenFromKeychain(JNIEnv *env, jclass clazz, jstring xuid) {
// This function should only be called once
static BOOL called = NO;
if (called) {
abort();
}
called = YES;

const char *xuidC = (*env)->GetStringUTFChars(env, xuid, 0);
NSString *accessToken = [MicrosoftAuthenticator tokenDataOfProfile:@(xuidC)][@"accessToken"];
(*env)->ReleaseStringUTFChars(env, xuid, xuidC);
return (*env)->NewStringUTF(env, accessToken.UTF8String);
}
16 changes: 16 additions & 0 deletions Natives/authenticator/MinecraftAccountJNI.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#import "BaseAuthenticator.h"
#include "jni.h"

JNIEXPORT jstring JNICALL Java_net_kdt_pojavlaunch_value_MinecraftAccount_getAccessTokenFromKeychain(JNIEnv *env, jclass clazz, jstring xuid) {
// This function should only be called once
static BOOL called = NO;
if (called) {
abort();
}
called = YES;

const char *xuidC = (*env)->GetStringUTFChars(env, xuid, 0);
NSString *accessToken = [NSClassFromString(@"MicrosoftAuthenticator") tokenDataOfProfile:@(xuidC)][@"accessToken"];
(*env)->ReleaseStringUTFChars(env, xuid, xuidC);
return (*env)->NewStringUTF(env, accessToken.UTF8String);
}

0 comments on commit f7163ce

Please sign in to comment.