@@ -23,16 +23,29 @@ bool set_layer_paths() {
2323 LAYER_ERROR (" Cannot open libgraphicsenv.so" );
2424 }
2525
26- #define FIND (var, sig, name ) auto var = sig (dlsym(handle, name)); \
26+ #define FIND (var, sig, name ) var = sig (dlsym(handle, name)); \
2727 if (!var) { \
2828 LAYER_ERROR (" Cannot find symbol in libgraphicsenv.so: " #name); \
2929 } \
3030 WLOGD (" Found " #name " in libgraphicsenv.so at %p" , var);
3131
32- FIND (getInstance, (void * (*)()), " _ZN7android11GraphicsEnv11getInstanceEv" );
33- FIND (getLayerPaths, (const std::string&(*)(void *)), " _ZN7android11GraphicsEnv13getLayerPathsEv" );
34- FIND (getAppNamespace, (void * (*)(void *)), " _ZN7android11GraphicsEnv15getAppNamespaceEv" );
35- FIND (setLayerPaths, (void (*)(void *, void *, const std::string)), " _ZN7android11GraphicsEnv13setLayerPathsEPNS_21NativeLoaderNamespaceENSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEE" );
32+ #define FIND2 (var, sig, name ) var = sig (dlsym(handle, name)); \
33+ if (!var) { \
34+ WLOGD (" Cannot find " #name " in libgraphicsenv.so" ); \
35+ } else { \
36+ WLOGD (" Found " #name " in libgraphicsenv.so at %p" , var); \
37+ }
38+
39+ auto FIND (getInstance, (void * (*)()), " _ZN7android11GraphicsEnv11getInstanceEv" );
40+ auto FIND (getLayerPaths, (const std::string&(*)(void *)), " _ZN7android11GraphicsEnv13getLayerPathsEv" );
41+ auto FIND (getAppNamespace, (void * (*)(void *)), " _ZN7android11GraphicsEnv15getAppNamespaceEv" );
42+ auto FIND2 (setLayerPaths, (void (*)(void *, void *, const std::string)), " _ZN7android11GraphicsEnv13setLayerPathsEPNS_21NativeLoaderNamespaceENSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEE" );
43+ // Later versions of Android uses this signature instead
44+ auto FIND2 (setLayerPaths2, (void (*)(void *, void *, const std::string&)), " _ZN7android11GraphicsEnv13setLayerPathsEPNS_21NativeLoaderNamespaceERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEE" );
45+
46+ if (!setLayerPaths && !setLayerPaths2) {
47+ LAYER_ERROR (" Could not find android::GraphicsEnv::setLayerPaths(android::NativeLoaderNamespace*, const std::string[&])" );
48+ }
3649
3750 void * instance = getInstance ();
3851 if (!instance) {
@@ -49,7 +62,11 @@ bool set_layer_paths() {
4962 LAYER_ERROR (" GraphicsEnv::mLayerPaths is already set to %s, cannot perform hijacking" , path.c_str ());
5063 }
5164 void * app_namespace = getAppNamespace (instance);
52- setLayerPaths (instance, app_namespace, PATH);
65+ if (setLayerPaths) {
66+ setLayerPaths (instance, app_namespace, PATH);
67+ } else {
68+ setLayerPaths2 (instance, app_namespace, PATH);
69+ }
5370 path = getLayerPaths (instance);
5471 if (path != PATH) {
5572 LAYER_ERROR (" GraphicsEnv::mLayerPaths failed to be set correctly, found %s" , path.c_str ());
0 commit comments