Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3cdc8ee2c | ||
|
|
2275ac5e27 | ||
|
|
6ed5f7c953 | ||
|
|
5067dba275 | ||
|
|
f446e11bd7 | ||
|
|
e6ccde2343 | ||
|
|
9514685337 |
No files matched your search
@@ -37,10 +37,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if(!Tools.checkStorageRoot(this)) {
|
||||
startActivity(new Intent(this, MissingStorageActivity.class));
|
||||
finish();
|
||||
}
|
||||
Tools.checkStorageInteractive(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,7 +39,12 @@ public class ImportControlActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Tools.initContextConstants(getApplicationContext());
|
||||
if(Tools.checkStorageInteractive(this)) {
|
||||
Tools.initStorageConstants(getApplicationContext());
|
||||
}else {
|
||||
// Return early, no initialization needed.
|
||||
return;
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_import_control);
|
||||
mEditText = findViewById(R.id.editText_import_control_file_name);
|
||||
@@ -61,6 +66,12 @@ public class ImportControlActivity extends Activity {
|
||||
@Override
|
||||
protected void onPostResume() {
|
||||
super.onPostResume();
|
||||
if(!Tools.checkStorageInteractive(this)) {
|
||||
// Don't try to read the file as when this check fails, external storage paths
|
||||
// are no longer valid (likely unmounted).
|
||||
// checkStorageInteractive() will finish this activity for us.
|
||||
return;
|
||||
}
|
||||
if(!mHasIntentChanged) return;
|
||||
mIsFileVerified = false;
|
||||
getUriData();
|
||||
|
||||
@@ -334,6 +334,9 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
|
||||
|
||||
if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
|
||||
// Reload PREF_DEFAULTCTRL_PATH
|
||||
// If the storage root got unmounted/unreadable we won't be able to load the file anyway,
|
||||
// and MissingStorageActivity will be started.
|
||||
if(!Tools.checkStorageRoot(this)) return;
|
||||
LauncherPreferences.loadPreferences(getApplicationContext());
|
||||
try {
|
||||
mControlLayout.loadLayout(LauncherPreferences.PREF_DEFAULTCTRL_PATH);
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.kdt.pojavlaunch.lifecycle.ContextExecutor;
|
||||
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||
import net.kdt.pojavlaunch.tasks.AsyncAssetManager;
|
||||
import net.kdt.pojavlaunch.utils.*;
|
||||
import net.kdt.pojavlaunch.utils.FileUtils;
|
||||
@@ -57,10 +58,15 @@ public class PojavApplication extends Application {
|
||||
|
||||
try {
|
||||
super.onCreate();
|
||||
|
||||
Tools.DIR_DATA = getDir("files", MODE_PRIVATE).getParent();
|
||||
Tools.DIR_CACHE = getCacheDir();
|
||||
Tools.DIR_ACCOUNT_NEW = Tools.DIR_DATA + "/accounts";
|
||||
if(Tools.checkStorageRoot(this)){
|
||||
// Implicitly initializes early constants and storage constants.
|
||||
// Required to run the main activity properly.
|
||||
LauncherPreferences.loadPreferences(this);
|
||||
} else {
|
||||
// In other cases, only initialize enough for the basicmost basics to work
|
||||
// and not explode.
|
||||
Tools.initEarlyConstants(this);
|
||||
}
|
||||
Tools.DEVICE_ARCHITECTURE = Architecture.getDeviceArchitecture();
|
||||
//Force x86 lib directory for Asus x86 based zenfones
|
||||
if(Architecture.isx86Device() && Architecture.is32BitsDevice()){
|
||||
|
||||
@@ -14,6 +14,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||
import net.kdt.pojavlaunch.tasks.AsyncAssetManager;
|
||||
|
||||
public class TestStorageActivity extends Activity {
|
||||
@@ -60,7 +61,8 @@ public class TestStorageActivity extends Activity {
|
||||
startActivity(new Intent(this, MissingStorageActivity.class));
|
||||
return;
|
||||
}
|
||||
//Only run them once we get a definitive green light to use storage
|
||||
//Initialize constants (implicitly) and preferences after we confirm that we have storage.
|
||||
LauncherPreferences.loadPreferences(this);
|
||||
AsyncAssetManager.unpackComponents(this);
|
||||
AsyncAssetManager.unpackSingleFiles(this);
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Process;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.util.ArrayMap;
|
||||
@@ -164,14 +163,42 @@ public final class Tools {
|
||||
}
|
||||
|
||||
/**
|
||||
* Since some constant requires the use of the Context object
|
||||
* You can call this function to initialize them.
|
||||
* Any value (in)directly dependant on DIR_DATA should be set only here.
|
||||
* Checks if the Pojav's storage root is accessible and read-writable. If it's not, starts
|
||||
* the MissingStorageActivity and finishes the supplied activity.
|
||||
* @param context the Activity that checks for storage availability
|
||||
* @return whether the storage is available or not.
|
||||
*/
|
||||
public static void initContextConstants(Context ctx){
|
||||
public static boolean checkStorageInteractive(Activity context) {
|
||||
if(!Tools.checkStorageRoot(context)) {
|
||||
context.startActivity(new Intent(context, MissingStorageActivity.class));
|
||||
context.finish();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize context constants most necessary for launcher's early startup phase
|
||||
* that are not dependent on user storage.
|
||||
* All values that depend on DIR_DATA and are not dependent on DIR_GAME_HOME must
|
||||
* be initialized here.
|
||||
* @param ctx the context for initialization.
|
||||
*/
|
||||
public static void initEarlyConstants(Context ctx) {
|
||||
DIR_CACHE = ctx.getCacheDir();
|
||||
DIR_DATA = ctx.getFilesDir().getParent();
|
||||
MULTIRT_HOME = DIR_DATA+"/runtimes";
|
||||
MULTIRT_HOME = DIR_DATA + "/runtimes";
|
||||
DIR_ACCOUNT_NEW = DIR_DATA + "/accounts";
|
||||
NATIVE_LIB_DIR = ctx.getApplicationInfo().nativeLibraryDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize context constants that depend on user storage.
|
||||
* Any value (in)directly dependent on DIR_GAME_HOME should be set only here.
|
||||
* You ABSOLUTELY MUST check for storage presence using checkStorageRoot() before calling this.
|
||||
*/
|
||||
public static void initStorageConstants(Context ctx){
|
||||
initEarlyConstants(ctx);
|
||||
DIR_GAME_HOME = getPojavStorageRoot(ctx).getAbsolutePath();
|
||||
DIR_GAME_NEW = DIR_GAME_HOME + "/.minecraft";
|
||||
DIR_HOME_VERSION = DIR_GAME_NEW + "/versions";
|
||||
@@ -181,7 +208,6 @@ public final class Tools {
|
||||
OBSOLETE_RESOURCES_PATH = DIR_GAME_NEW + "/resources";
|
||||
CTRLMAP_PATH = DIR_GAME_HOME + "/controlmap";
|
||||
CTRLDEF_FILE = DIR_GAME_HOME + "/controlmap/default.json";
|
||||
NATIVE_LIB_DIR = ctx.getApplicationInfo().nativeLibraryDir;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+44
-30
@@ -3,8 +3,9 @@ package net.kdt.pojavlaunch.customcontrols.keyboard;
|
||||
|
||||
import static android.content.Context.INPUT_METHOD_SERVICE;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.text.Editable;
|
||||
import android.text.Selection;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
@@ -34,31 +35,6 @@ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText
|
||||
private boolean mIsDoingInternalChanges = false;
|
||||
private CharacterSenderStrategy mCharacterSender;
|
||||
|
||||
/**
|
||||
* We take the new chars, and send them to the game.
|
||||
* If less chars are present, remove some.
|
||||
* The text is always cleaned up.
|
||||
*/
|
||||
@Override
|
||||
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
|
||||
super.onTextChanged(text, start, lengthBefore, lengthAfter);
|
||||
if(mIsDoingInternalChanges)return;
|
||||
if(mCharacterSender != null){
|
||||
for(int i=0; i < lengthBefore; ++i){
|
||||
mCharacterSender.sendBackspace();
|
||||
}
|
||||
|
||||
for(int i=start, count = 0; count < lengthAfter; ++i){
|
||||
mCharacterSender.sendChar(text.charAt(i));
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
//Reset the keyboard state
|
||||
if(text.length() < 1) clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* When we change from app to app, the keyboard gets disabled.
|
||||
* So, we disable the object
|
||||
@@ -102,13 +78,15 @@ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText
|
||||
* Clear the EditText from any leftover inputs
|
||||
* It does not affect the in-game input
|
||||
*/
|
||||
@SuppressLint("SetTextI18n")
|
||||
public void clear(){
|
||||
mIsDoingInternalChanges = true;
|
||||
// Edit the Editable directly as it doesn't affect the state
|
||||
// of the TextView.
|
||||
Editable editable = getEditableText();
|
||||
editable.clear();
|
||||
//Braille space, doesn't trigger keyboard auto-complete
|
||||
//replacing directly the text without though setText avoids notifying changes
|
||||
setText(TEXT_FILLER);
|
||||
setSelection(TEXT_FILLER.length());
|
||||
editable.append(TEXT_FILLER);
|
||||
Selection.setSelection(editable, TEXT_FILLER.length());
|
||||
mIsDoingInternalChanges = false;
|
||||
}
|
||||
|
||||
@@ -142,6 +120,9 @@ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText
|
||||
|
||||
/** This function deals with anything that has to be executed when the constructor is called */
|
||||
private void setup(){
|
||||
// Using TextWatcher instead of overriding onTextChanged because some Huawei firmware
|
||||
// calls setText in constructor, causing havoc for our listener
|
||||
addTextChangedListener(new InputTextWatcher());
|
||||
setOnEditorActionListener((textView, i, keyEvent) -> {
|
||||
sendEnter();
|
||||
clear();
|
||||
@@ -151,5 +132,38 @@ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText
|
||||
clear();
|
||||
disable();
|
||||
}
|
||||
private class InputTextWatcher implements android.text.TextWatcher {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* We take the new chars, and send them to the game.
|
||||
* If less chars are present, remove some.
|
||||
* The text is always cleaned up.
|
||||
*/
|
||||
@Override
|
||||
public void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
|
||||
if(mIsDoingInternalChanges) return;
|
||||
if(mCharacterSender != null){
|
||||
for(int i=0; i < lengthBefore; ++i){
|
||||
mCharacterSender.sendBackspace();
|
||||
}
|
||||
|
||||
for(int i=start, count = 0; count < lengthAfter; ++i){
|
||||
mCharacterSender.sendChar(text.charAt(i));
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if(mIsDoingInternalChanges) return;
|
||||
// Moved from onTextChanged because "It is an error to attempt to make changes to s from this callback."
|
||||
// reference: https://developer.android.com/reference/android/text/TextWatcher#onTextChanged(java.lang.CharSequence,%20int,%20int,%20int)
|
||||
if(editable.length() < 1) clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
@@ -239,6 +239,7 @@ public abstract class FabriclikeInstallFragment extends Fragment implements Modl
|
||||
}
|
||||
|
||||
private void updateLoaderSpinner() {
|
||||
if(mLoaderVersionArray == null) return;
|
||||
mLoaderVersionSpinner.setAdapter(createAdapter(mLoaderVersionArray, mOnlyStableCheckbox.isChecked()));
|
||||
}
|
||||
|
||||
@@ -285,6 +286,7 @@ public abstract class FabriclikeInstallFragment extends Fragment implements Modl
|
||||
}
|
||||
|
||||
private void updateGameSpinner() {
|
||||
if(mGameVersionArray == null) return;
|
||||
mGameVersionSpinner.setAdapter(createAdapter(mGameVersionArray, mOnlyStableCheckbox.isChecked()));
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,8 @@ public class LauncherPreferences {
|
||||
|
||||
|
||||
public static void loadPreferences(Context ctx) {
|
||||
//Required for the data folder.
|
||||
Tools.initContextConstants(ctx);
|
||||
//Required for CTRLDEF_FILE and MultiRT
|
||||
Tools.initStorageConstants(ctx);
|
||||
boolean isDevicePowerful = isDevicePowerful(ctx);
|
||||
|
||||
PREF_RENDERER = DEFAULT_PREF.getString("renderer", "opengles2");
|
||||
|
||||
@@ -47,7 +47,7 @@ public class FolderProvider extends DocumentsProvider {
|
||||
|
||||
private static final String ALL_MIME_TYPES = "*/*";
|
||||
|
||||
private static final File BASE_DIR = new File(Tools.DIR_GAME_HOME);
|
||||
private File BASE_DIR;
|
||||
|
||||
private ContentResolver mContentResolver;
|
||||
|
||||
@@ -138,6 +138,12 @@ public class FolderProvider extends DocumentsProvider {
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
if(Tools.checkStorageRoot(getContext())) {
|
||||
Tools.initStorageConstants(getContext());
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
BASE_DIR = new File(Tools.DIR_GAME_HOME);
|
||||
mContentResolver = getContext().getContentResolver();
|
||||
mStorageProviderAuthortiy = getContext().getString(R.string.storageProviderAuthorities);
|
||||
return true;
|
||||
|
||||
@@ -315,7 +315,8 @@ public class JREUtils {
|
||||
System.out.println(JVMArgs);
|
||||
|
||||
initJavaRuntime(runtimeHome);
|
||||
setupExitTrap(activity.getApplication());
|
||||
JREUtils.setupExitMethod(activity.getApplication());
|
||||
JREUtils.initializeGameExitHook();
|
||||
chdir(gameDirectory == null ? Tools.DIR_GAME_NEW : gameDirectory.getAbsolutePath());
|
||||
userArgs.add(0,"java"); //argv[0] is the program name according to C standard.
|
||||
|
||||
@@ -572,10 +573,12 @@ public class JREUtils {
|
||||
public static native void setLdLibraryPath(String ldLibraryPath);
|
||||
public static native void setupBridgeWindow(Object surface);
|
||||
public static native void releaseBridgeWindow();
|
||||
public static native void setupExitTrap(Context context);
|
||||
public static native void initializeGameExitHook();
|
||||
public static native void setupExitMethod(Context context);
|
||||
// Obtain AWT screen pixels to render on Android SurfaceView
|
||||
public static native int[] renderAWTScreenFrame(/* Object canvas, int width, int height */);
|
||||
static {
|
||||
System.loadLibrary("exithook");
|
||||
System.loadLibrary("pojavexec");
|
||||
System.loadLibrary("pojavexec_awt");
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import android.os.LocaleList;
|
||||
|
||||
import androidx.preference.*;
|
||||
import java.util.*;
|
||||
import net.kdt.pojavlaunch.prefs.*;
|
||||
|
||||
public class LocaleUtils extends ContextWrapper {
|
||||
|
||||
@@ -22,7 +21,10 @@ public class LocaleUtils extends ContextWrapper {
|
||||
public static ContextWrapper setLocale(Context context) {
|
||||
if (DEFAULT_PREF == null) {
|
||||
DEFAULT_PREF = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
LauncherPreferences.loadPreferences(context);
|
||||
// Too early to initialize all prefs here, as this is called by PojavApplication
|
||||
// before storage checks are done and before the storage paths are initialized.
|
||||
// So only initialize PREF_FORCE_ENGLISH for the check below.
|
||||
PREF_FORCE_ENGLISH = DEFAULT_PREF.getBoolean("force_english", false);
|
||||
}
|
||||
|
||||
if(PREF_FORCE_ENGLISH){
|
||||
|
||||
@@ -16,7 +16,6 @@ include $(CLEAR_VARS)
|
||||
LOCAL_LDLIBS := -ldl -llog -landroid
|
||||
# -lGLESv2
|
||||
LOCAL_MODULE := pojavexec
|
||||
LOCAL_SHARED_LIBRARIES := bytehook
|
||||
# LOCAL_CFLAGS += -DDEBUG
|
||||
# -DGLES_TEST
|
||||
LOCAL_SRC_FILES := \
|
||||
@@ -43,6 +42,13 @@ LOCAL_LDLIBS += -lEGL -lGLESv2
|
||||
endif
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := exithook
|
||||
LOCAL_LDLIBS := -ldl -llog
|
||||
LOCAL_SHARED_LIBRARIES := bytehook pojavexec
|
||||
LOCAL_SRC_FILES := exit_hook.c
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
#ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := linkerhook
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// Created by maks on 15.01.2025.
|
||||
//
|
||||
|
||||
#include <jni.h>
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
#include <bytehook.h>
|
||||
#include <dlfcn.h>
|
||||
#include <android/log.h>
|
||||
#include <stdlib.h>
|
||||
#include "stdio_is.h"
|
||||
|
||||
static _Atomic bool exit_tripped = false;
|
||||
|
||||
typedef void (*exit_func)(int);
|
||||
|
||||
static void custom_exit(int code) {
|
||||
// If the exit was already done (meaning it is recursive or from a different thread), pass the call through
|
||||
if(exit_tripped) {
|
||||
BYTEHOOK_CALL_PREV(custom_exit, exit_func, code);
|
||||
BYTEHOOK_POP_STACK();
|
||||
return;
|
||||
}
|
||||
exit_tripped = true;
|
||||
// Perform a nominal exit, as we expect.
|
||||
nominal_exit(code, false);
|
||||
BYTEHOOK_POP_STACK();
|
||||
}
|
||||
|
||||
static void custom_atexit() {
|
||||
// Same as custom_exit, but without the code or the exit passthrough.
|
||||
if(exit_tripped) {
|
||||
return;
|
||||
}
|
||||
exit_tripped = true;
|
||||
nominal_exit(0, false);
|
||||
}
|
||||
|
||||
static bool init_exit_hook() {
|
||||
void* bytehook_handle = dlopen("libbytehook.so", RTLD_NOW);
|
||||
if(bytehook_handle == NULL) {
|
||||
goto dlerror;
|
||||
}
|
||||
|
||||
bytehook_stub_t (*bytehook_hook_all_p)(const char *callee_path_name, const char *sym_name, void *new_func,
|
||||
bytehook_hooked_t hooked, void *hooked_arg);
|
||||
int (*bytehook_init_p)(int mode, bool debug);
|
||||
|
||||
bytehook_hook_all_p = dlsym(bytehook_handle, "bytehook_hook_all");
|
||||
bytehook_init_p = dlsym(bytehook_handle, "bytehook_init");
|
||||
|
||||
if(bytehook_hook_all_p == NULL || bytehook_init_p == NULL) {
|
||||
goto dlerror;
|
||||
}
|
||||
int bhook_status = bytehook_init_p(BYTEHOOK_MODE_AUTOMATIC, false);
|
||||
if(bhook_status == BYTEHOOK_STATUS_CODE_OK) {
|
||||
bytehook_stub_t stub = bytehook_hook_all_p(NULL, "exit", &custom_exit, NULL, NULL);
|
||||
__android_log_print(ANDROID_LOG_INFO, "exit_hook", "Successfully initialized exit hook, stub=%p", stub);
|
||||
return true;
|
||||
} else {
|
||||
__android_log_print(ANDROID_LOG_INFO, "exit_hook", "bytehook_init failed (%i)", bhook_status);
|
||||
dlclose(bytehook_handle);
|
||||
return false;
|
||||
}
|
||||
|
||||
dlerror:
|
||||
if(bytehook_handle != NULL) dlclose(bytehook_handle);
|
||||
__android_log_print(ANDROID_LOG_ERROR, "exit_hook", "Failed to load hook library: %s", dlerror());
|
||||
return false;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_net_kdt_pojavlaunch_utils_JREUtils_initializeGameExitHook(JNIEnv *env, jclass clazz) {
|
||||
bool hookReady = init_exit_hook();
|
||||
if(!hookReady){
|
||||
// If we can't hook, register atexit(). This won't report a proper error code,
|
||||
// but it will prevent a SIGSEGV or a SIGABRT from the depths of Dalvik that happens
|
||||
// on exit().
|
||||
atexit(custom_atexit);
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,10 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <bytehook.h>
|
||||
#include <environ/environ.h>
|
||||
|
||||
#include "stdio_is.h"
|
||||
|
||||
//
|
||||
// Created by maks on 17.02.21.
|
||||
//
|
||||
@@ -25,7 +26,6 @@ static pthread_t logger;
|
||||
static jmethodID logger_onEventLogged;
|
||||
static volatile jobject logListener = NULL;
|
||||
static int latestlog_fd = -1;
|
||||
static _Atomic bool exit_tripped = false;
|
||||
|
||||
|
||||
static bool recordBuffer(char* buf, ssize_t len) {
|
||||
@@ -100,11 +100,6 @@ Java_net_kdt_pojavlaunch_Logger_begin(JNIEnv *env, __attribute((unused)) jclass
|
||||
pthread_detach(logger);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
typedef void (*exit_func)(int);
|
||||
|
||||
_Noreturn void nominal_exit(int code, bool is_signal) {
|
||||
JNIEnv *env;
|
||||
jint errorCode = (*exitTrap_jvm)->GetEnv(exitTrap_jvm, (void**)&env, JNI_VERSION_1_6);
|
||||
@@ -142,48 +137,6 @@ _Noreturn void nominal_exit(int code, bool is_signal) {
|
||||
while(1) {}
|
||||
}
|
||||
|
||||
static void custom_exit(int code) {
|
||||
// If the exit was already done (meaning it is recursive or from a different thread), pass the call through
|
||||
if(exit_tripped) {
|
||||
BYTEHOOK_CALL_PREV(custom_exit, exit_func, code);
|
||||
BYTEHOOK_POP_STACK();
|
||||
return;
|
||||
}
|
||||
exit_tripped = true;
|
||||
// Perform a nominal exit, as we expect.
|
||||
nominal_exit(code, false);
|
||||
BYTEHOOK_POP_STACK();
|
||||
}
|
||||
|
||||
static void custom_atexit() {
|
||||
// Same as custom_exit, but without the code or the exit passthrough.
|
||||
if(exit_tripped) {
|
||||
return;
|
||||
}
|
||||
exit_tripped = true;
|
||||
nominal_exit(0, false);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setupExitTrap(JNIEnv *env, __attribute((unused)) jclass clazz, jobject context) {
|
||||
exitTrap_ctx = (*env)->NewGlobalRef(env,context);
|
||||
(*env)->GetJavaVM(env,&exitTrap_jvm);
|
||||
exitTrap_exitClass = (*env)->NewGlobalRef(env,(*env)->FindClass(env,"net/kdt/pojavlaunch/ExitActivity"));
|
||||
exitTrap_staticMethod = (*env)->GetStaticMethodID(env,exitTrap_exitClass,"showExitMessage","(Landroid/content/Context;IZ)V");
|
||||
|
||||
if(bytehook_init(BYTEHOOK_MODE_AUTOMATIC, false) == BYTEHOOK_STATUS_CODE_OK) {
|
||||
bytehook_hook_all(NULL,
|
||||
"exit",
|
||||
&custom_exit,
|
||||
NULL,
|
||||
NULL);
|
||||
}else {
|
||||
// If we can't hook, register atexit(). This won't report a proper error code,
|
||||
// but it will prevent a SIGSEGV or a SIGABRT from the depths of Dalvik that happens
|
||||
// on exit().
|
||||
atexit(custom_atexit);
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_Logger_appendToLog(JNIEnv *env, __attribute((unused)) jclass clazz, jstring text) {
|
||||
jsize appendStringLength = (*env)->GetStringUTFLength(env, text);
|
||||
char newChars[appendStringLength+2];
|
||||
@@ -205,3 +158,13 @@ Java_net_kdt_pojavlaunch_Logger_setLogListener(JNIEnv *env, __attribute((unused)
|
||||
}
|
||||
if(logListenerLocal != NULL) (*env)->DeleteGlobalRef(env, logListenerLocal);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_net_kdt_pojavlaunch_utils_JREUtils_setupExitMethod(JNIEnv *env, jclass clazz,
|
||||
jobject context) {
|
||||
exitTrap_ctx = (*env)->NewGlobalRef(env,context);
|
||||
(*env)->GetJavaVM(env,&exitTrap_jvm);
|
||||
exitTrap_exitClass = (*env)->NewGlobalRef(env,(*env)->FindClass(env,"net/kdt/pojavlaunch/ExitActivity"));
|
||||
exitTrap_staticMethod = (*env)->GetStaticMethodID(env,exitTrap_exitClass,"showExitMessage","(Landroid/content/Context;IZ)V");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// Created by maks on 15.01.2025.
|
||||
//
|
||||
|
||||
#ifndef POJAVLAUNCHER_STDIO_IS_H
|
||||
#define POJAVLAUNCHER_STDIO_IS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
_Noreturn void nominal_exit(int code, bool is_signal);
|
||||
|
||||
#endif //POJAVLAUNCHER_STDIO_IS_H
|
||||
Reference in new issue
Block a user