Skip to content

Commit 9f5ccd9

Browse files
committed
custom exceptions option
1 parent 3661df2 commit 9f5ccd9

File tree

6 files changed

+81
-19
lines changed

6 files changed

+81
-19
lines changed

app/src/main/cpp/launcher-fix.cpp

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <dlfcn.h>
22
#include <jni.h>
3+
#include <fstream>
34
#include <string>
45
#include <cstdint>
56
#include <android/log.h>
@@ -17,16 +18,17 @@
1718

1819
class DataPaths {
1920
public:
20-
std::string original_data_path;
21-
std::string data_path;
21+
std::string original_data_path{};
22+
std::string data_path{};
23+
std::string load_symbols_from{};
2224

2325
static DataPaths& get_instance() {
2426
static auto paths_instance = DataPaths();
2527
return paths_instance;
2628
}
2729

2830
private:
29-
DataPaths() : original_data_path(), data_path() {}
31+
DataPaths() {}
3032
};
3133

3234
extern "C"
@@ -43,6 +45,20 @@ JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setDataPath(
4345
env->ReleaseStringUTFChars(data_path, data_path_str);
4446
}
4547

48+
extern "C"
49+
JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_enableCustomSymbolList(
50+
JNIEnv* env,
51+
jobject,
52+
jstring symbol_path
53+
) {
54+
auto is_copy = jboolean();
55+
auto symbol_path_str = env->GetStringUTFChars(symbol_path, &is_copy);
56+
57+
DataPaths::get_instance().load_symbols_from = std::string(symbol_path_str);
58+
59+
env->ReleaseStringUTFChars(symbol_path, symbol_path_str);
60+
}
61+
4662
#ifdef __arm__
4763
// 32bit code
4864
typedef Elf32_Dyn Elf_Dyn;
@@ -119,6 +135,43 @@ bool patch_symbol(std::uint32_t* hash_table, char* str_table, Elf_Sym* sym_table
119135
return false;
120136
}
121137

138+
std::vector<std::string> get_symbols_listing() {
139+
auto symbol_path = DataPaths::get_instance().load_symbols_from;
140+
if (symbol_path.empty()) {
141+
// this is every function that i thought would be relevant
142+
return {
143+
"__gxx_personality_v0",
144+
"__cxa_throw",
145+
"__cxa_rethrow",
146+
"__cxa_allocate_exception",
147+
"__cxa_end_catch",
148+
"__cxa_begin_catch",
149+
"__cxa_guard_abort",
150+
"__cxa_guard_acquire",
151+
"__cxa_guard_release",
152+
"__cxa_free_exception",
153+
"_Unwind_RaiseException",
154+
"_Unwind_Resume"
155+
};
156+
}
157+
158+
std::ifstream symbol_file{symbol_path};
159+
if (!symbol_file) {
160+
__android_log_print(ANDROID_LOG_WARN, "GeodeLauncher-fix", "failed to read symbol file at %s", symbol_path.c_str());
161+
return {};
162+
}
163+
164+
std::vector<std::string> symbols_list{};
165+
std::string current_line{};
166+
while (std::getline(symbol_file, current_line)) {
167+
if (!current_line.empty()) {
168+
symbols_list.push_back(current_line);
169+
}
170+
}
171+
172+
return symbols_list;
173+
}
174+
122175
int on_dl_iterate(dl_phdr_info* info, size_t size, void* data) {
123176
// this is probably going to be gd
124177
if (strstr(info->dlpi_name, "libcocos2dcpp.so") != nullptr) {
@@ -178,20 +231,11 @@ int on_dl_iterate(dl_phdr_info* info, size_t size, void* data) {
178231
auto str_table = reinterpret_cast<char*>(str_table_addr);
179232
auto sym_table = reinterpret_cast<Elf_Sym*>(sym_table_addr);
180233

181-
// this is every function that i thought would be relevant
182-
patch_symbol(hash_table, str_table, sym_table, "__gxx_personality_v0");
183-
patch_symbol(hash_table, str_table, sym_table, "__cxa_throw");
184-
patch_symbol(hash_table, str_table, sym_table, "__cxa_rethrow");
185-
patch_symbol(hash_table, str_table, sym_table, "__cxa_allocate_exception");
186-
patch_symbol(hash_table, str_table, sym_table, "__cxa_end_catch");
187-
patch_symbol(hash_table, str_table, sym_table, "__cxa_begin_catch");
188-
patch_symbol(hash_table, str_table, sym_table, "__cxa_guard_abort");
189-
patch_symbol(hash_table, str_table, sym_table, "__cxa_guard_acquire");
190-
patch_symbol(hash_table, str_table, sym_table, "__cxa_guard_release");
191-
patch_symbol(hash_table, str_table, sym_table, "__cxa_free_exception");
192-
193-
patch_symbol(hash_table, str_table, sym_table, "_Unwind_RaiseException");
194-
patch_symbol(hash_table, str_table, sym_table, "_Unwind_Resume");
234+
auto symbols_listing = get_symbols_listing();
235+
for (const auto& symbol : symbols_listing) {
236+
patch_symbol(hash_table, str_table, sym_table, symbol.c_str());
237+
}
238+
195239
return 1;
196240
}
197241

app/src/main/java/com/geode/launcher/GeometryDashActivity.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
146146
tryLoadLibrary(gdPackageInfo, Constants.COCOS_LIB_NAME)
147147

148148
if (GamePackageUtils.getGameVersionCode(packageManager) >= 39L) {
149+
val customSymbols = PreferenceUtils.get(this).getBoolean(PreferenceUtils.Key.CUSTOM_SYMBOL_LIST)
150+
if (customSymbols) {
151+
val symbolFile = File(LaunchUtils.getBaseDirectory(this), "exception_symbols.txt")
152+
LauncherFix.enableCustomSymbolList(symbolFile.path)
153+
}
154+
149155
// this fix requires geode v3, which is 2.206+
150156
// there is a short period in which 2.206 users will still have geode v2, but whatever. ig
151157
LauncherFix.performExceptionsRenaming()

app/src/main/java/com/geode/launcher/LauncherFix.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ object LauncherFix {
1414
external fun setOriginalDataPath(dataPath: String)
1515

1616
external fun performExceptionsRenaming()
17+
18+
external fun enableCustomSymbolList(symbolsPath: String)
1719
}

app/src/main/java/com/geode/launcher/preferences/DeveloperSettingsActivity.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ fun DeveloperSettingsScreen(onBackPressedDispatcher: OnBackPressedDispatcher?) {
134134
// if only there was a better way to define this!
135135
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*(){}<>[]?:;'\"~`-_+=\\| ".contains(c)
136136
}}
137-
)
137+
)
138+
SettingsCard(
139+
title = stringResource(R.string.preference_override_exceptions_name),
140+
description = stringResource(R.string.preference_override_exceptions_description),
141+
preferenceKey = PreferenceUtils.Key.CUSTOM_SYMBOL_LIST
142+
)
138143
}
139144

140145
OptionsGroup(title = stringResource(R.string.preference_category_updater)) {

app/src/main/java/com/geode/launcher/utils/PreferenceUtils.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
140140
ENABLE_REDESIGN,
141141
RELEASE_CHANNEL_TAG,
142142
DEVELOPER_MODE,
143-
CLEANUP_APKS
143+
CLEANUP_APKS,
144+
CUSTOM_SYMBOL_LIST
144145
}
145146

146147
private fun defaultValueForBooleanKey(key: Key): Boolean {
@@ -177,6 +178,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
177178
Key.RELEASE_CHANNEL_TAG -> "PreferenceReleaseChannelTag"
178179
Key.DEVELOPER_MODE -> "PreferenceDeveloperMode"
179180
Key.CLEANUP_APKS -> "PreferenceCleanupPackages"
181+
Key.CUSTOM_SYMBOL_LIST -> "PreferenceCustomSymbolList"
180182
}
181183
}
182184

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,7 @@
180180
<string name="preference_developer_mode">Enable developer options</string>
181181
<string name="preference_developer_mode_about">Developer mode enables some options that may make the game unstable. Please do not modify them unless you know what you\'re doing!\nThese options may change behavior, or be removed entirely in future updates.</string>
182182
<string name="preference_developer_update_notice">Enabling developer mode automatically disallows the updater from overwriting custom loader builds.</string>
183+
184+
<string name="preference_override_exceptions_name">Custom exceptions fix symbols</string>
185+
<string name="preference_override_exceptions_description">Uses exception_symbols.txt to patch</string>
183186
</resources>

0 commit comments

Comments
 (0)