MCPcopy Create free account
hub / github.com/Bzi-Han/AndroidSurfaceImgui / ApiResolver

Class ApiResolver

modules/ANativeWindowCreator.h:1215–1303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1213 };
1214
1215 struct ApiResolver
1216 {
1217 struct ResolverImpl
1218 {
1219 void *(*Open)(const char *filename, int flag);
1220 void *(*Resolve)(void *handle, const char *symbol);
1221 int (*Close)(void *handle);
1222
1223 ResolverImpl()
1224 : Open(dlopen),
1225 Resolve(dlsym),
1226 Close(dlclose)
1227 {
1228 }
1229
1230 ResolverImpl(decltype(Open) open, decltype(Resolve) resolve, decltype(Close) close)
1231 : Open(open),
1232 Resolve(resolve),
1233 Close(close)
1234 {
1235 }
1236 };
1237
1238 static void Resolve(const ResolverImpl &resolver = {})
1239 {
1240 static bool resolved = false;
1241
1242 if (resolved)
1243 return;
1244
1245 std::string systemVersionString(128, 0);
1246 systemVersionString.resize(__system_property_get("ro.build.version.release", systemVersionString.data()));
1247 if (!systemVersionString.empty())
1248 compat::SystemVersion = std::stoi(systemVersionString);
1249
1250 if (compat::SupportedMinVersion > compat::SystemVersion)
1251 {
1252 LogError("[!] Unsupported system version: %zu", compat::SystemVersion);
1253 return;
1254 }
1255
1256 LogInfo("[*] Starting to resolve symbols for Android %zu", compat::SystemVersion);
1257
1258#ifdef __LP64__
1259 auto libgui = resolver.Open("/system/lib64/libgui.so", RTLD_LAZY);
1260 auto libutils = resolver.Open("/system/lib64/libutils.so", RTLD_LAZY);
1261#else
1262 auto libgui = resolver.Open("/system/lib/libgui.so", RTLD_LAZY);
1263 auto libutils = resolver.Open("/system/lib/libutils.so", RTLD_LAZY);
1264#endif
1265 if (nullptr == libgui || nullptr == libutils)
1266 {
1267 LogError("[!] Failed to open libgui.so or libutils.so");
1268 throw std::runtime_error("Failed to open libgui.so or libutils.so");
1269 }
1270
1271 const auto &[libutilsApis, libguiApis] = ApiTableDescriptor::GetDefaultDescriptors();
1272 for (const auto &descriptor : libutilsApis)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected