11#include < dlfcn.h>
22#include < jni.h>
3+ #include < fstream>
34#include < string>
45#include < cstdint>
56#include < android/log.h>
1718
1819class DataPaths {
1920public:
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
2830private:
29- DataPaths () : original_data_path(), data_path() {}
31+ DataPaths () {}
3032};
3133
3234extern " 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
4864typedef 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+
122175int 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
0 commit comments