in java/com/facebook/soloader/SoLoader.java [483:566]
private static synchronized void initSoLoader(@Nullable SoFileLoader soFileLoader) {
if (soFileLoader == null && sSoFileLoader != null) {
return;
}
if (soFileLoader != null) {
sSoFileLoader = soFileLoader;
return;
}
final Runtime runtime = Runtime.getRuntime();
final Method nativeLoadRuntimeMethod = getNativeLoadRuntimeMethod();
final boolean hasNativeLoadMethod = nativeLoadRuntimeMethod != null;
final String localLdLibraryPath =
hasNativeLoadMethod ? Api14Utils.getClassLoaderLdLoadLibrary() : null;
final String localLdLibraryPathNoZips = makeNonZipPath(localLdLibraryPath);
sSoFileLoader =
new SoFileLoader() {
@Override
public void loadBytes(String pathName, ElfByteChannel bytes, int loadFlags) {
throw new UnsupportedOperationException();
}
@Override
public void load(final String pathToSoFile, final int loadFlags) {
String error = null;
if (hasNativeLoadMethod) {
final boolean inZip = (loadFlags & SOLOADER_LOOK_IN_ZIP) == SOLOADER_LOOK_IN_ZIP;
final String path = inZip ? localLdLibraryPath : localLdLibraryPathNoZips;
try {
synchronized (runtime) {
error =
(String)
nativeLoadRuntimeMethod.invoke(
runtime, pathToSoFile, SoLoader.class.getClassLoader(), path);
if (error != null) {
throw new UnsatisfiedLinkError(error);
}
}
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException e) {
error = "Error: Cannot load " + pathToSoFile;
throw new RuntimeException(error, e);
} finally {
if (error != null) {
Log.e(
TAG,
"Error when loading lib: "
+ error
+ " lib hash: "
+ getLibHash(pathToSoFile)
+ " search path is "
+ path);
}
}
} else {
System.load(pathToSoFile);
}
}
/** * Logs MD5 of lib that failed loading */
private String getLibHash(String libPath) {
String digestStr;
try {
File libFile = new File(libPath);
MessageDigest digest = MessageDigest.getInstance("MD5");
try (InputStream libInStream = new FileInputStream(libFile)) {
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = libInStream.read(buffer)) > 0) {
digest.update(buffer, 0, bytesRead);
}
digestStr = String.format("%32x", new BigInteger(1, digest.digest()));
}
} catch (IOException | SecurityException | NoSuchAlgorithmException e) {
digestStr = e.toString();
}
return digestStr;
}
};
}