alexandroid/decompiled/jadx/sources/com/facebook/soloader/ExtractFromZipSoSource.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

216 lines
8 KiB
Java

package com.facebook.soloader;
import android.content.Context;
import com.facebook.soloader.UnpackingSoSource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.CRC32;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.annotation.Nullable;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes7.dex */
public class ExtractFromZipSoSource extends UnpackingSoSource {
private static final String TAG = "soloader.ExtractFromZipSoSource";
protected final File mZipFileName;
protected final String mZipSearchPattern;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static final class ZipDso extends UnpackingSoSource.Dso implements Comparable<ZipDso> {
final int abiScore;
final ZipEntry backingEntry;
public ZipDso(String str, ZipEntry zipEntry, int i) {
super(str, String.valueOf(zipEntry.getCrc()));
this.backingEntry = zipEntry;
this.abiScore = i;
}
@Override // java.lang.Comparable
public int compareTo(ZipDso zipDso) {
return this.name.compareTo(zipDso.name);
}
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj != null && ZipDso.class == obj.getClass()) {
ZipDso zipDso = (ZipDso) obj;
if (this.backingEntry.equals(zipDso.backingEntry) && this.abiScore == zipDso.abiScore) {
return true;
}
}
return false;
}
public int hashCode() {
return this.backingEntry.hashCode() + (this.abiScore * 31);
}
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public class ZipUnpacker extends UnpackingSoSource.Unpacker {
@Nullable
protected ZipDso[] mDsos;
private final UnpackingSoSource mSoSource;
private final ZipFile mZipFile;
public ZipUnpacker(UnpackingSoSource unpackingSoSource) throws IOException {
this.mZipFile = new ZipFile(ExtractFromZipSoSource.this.mZipFileName);
this.mSoSource = unpackingSoSource;
}
@Override // com.facebook.soloader.UnpackingSoSource.Unpacker, java.io.Closeable, java.lang.AutoCloseable
public void close() throws IOException {
this.mZipFile.close();
}
public ZipDso[] computeDsosFromZip() {
LinkedHashSet linkedHashSet = new LinkedHashSet();
HashMap hashMap = new HashMap();
Pattern compile = Pattern.compile(ExtractFromZipSoSource.this.mZipSearchPattern);
String[] supportedAbis = SysUtil.getSupportedAbis();
Enumeration<? extends ZipEntry> entries = this.mZipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry nextElement = entries.nextElement();
Matcher matcher = compile.matcher(nextElement.getName());
if (matcher.matches()) {
int groupCount = matcher.groupCount();
String group = matcher.group(groupCount - 1);
String group2 = matcher.group(groupCount);
int findAbiScore = SysUtil.findAbiScore(supportedAbis, group);
if (findAbiScore >= 0) {
linkedHashSet.add(group);
ZipDso zipDso = (ZipDso) hashMap.get(group2);
if (zipDso == null || findAbiScore < zipDso.abiScore) {
hashMap.put(group2, new ZipDso(group2, nextElement, findAbiScore));
}
}
}
}
this.mSoSource.setSoSourceAbis((String[]) linkedHashSet.toArray(new String[linkedHashSet.size()]));
ZipDso[] zipDsoArr = (ZipDso[]) hashMap.values().toArray(new ZipDso[hashMap.size()]);
Arrays.sort(zipDsoArr);
return zipDsoArr;
}
@Override // com.facebook.soloader.UnpackingSoSource.Unpacker
public final UnpackingSoSource.Dso[] getDsos() throws IOException {
return getExtractableDsosFromZip();
}
public ZipDso[] getExtractableDsosFromZip() {
ZipDso[] zipDsoArr = this.mDsos;
if (zipDsoArr != null) {
return zipDsoArr;
}
ZipDso[] computeDsosFromZip = computeDsosFromZip();
this.mDsos = computeDsosFromZip;
return computeDsosFromZip;
}
@Override // com.facebook.soloader.UnpackingSoSource.Unpacker
public void unpack(File file) throws IOException {
byte[] bArr = new byte[32768];
for (ZipDso zipDso : getExtractableDsosFromZip()) {
InputStream inputStream = this.mZipFile.getInputStream(zipDso.backingEntry);
try {
UnpackingSoSource.InputDso inputDso = new UnpackingSoSource.InputDso(zipDso, inputStream);
inputStream = null;
try {
extractDso(inputDso, bArr, file);
inputDso.close();
} finally {
}
} catch (Throwable th) {
if (inputStream != null) {
inputStream.close();
}
throw th;
}
}
}
}
public ExtractFromZipSoSource(Context context, String str, File file, String str2) {
super(context, str);
this.mZipFileName = file;
this.mZipSearchPattern = str2;
}
@Override // com.facebook.soloader.UnpackingSoSource
public String computeFileHash(File file) {
try {
FileInputStream fileInputStream = new FileInputStream(file);
try {
CRC32 crc32 = new CRC32();
byte[] bArr = new byte[1024];
while (true) {
int read = fileInputStream.read(bArr);
if (read == -1) {
String valueOf = String.valueOf(crc32.getValue());
fileInputStream.close();
return valueOf;
}
crc32.update(bArr, 0, read);
}
} finally {
}
} catch (IOException e) {
LogUtil.w(TAG, "Failed to compute file hash ", e);
return "";
}
}
@Override // com.facebook.soloader.DirectorySoSource, com.facebook.soloader.SoSource
public String getName() {
return "ExtractFromZipSoSource";
}
public boolean hasZippedLibs() throws IOException {
ZipUnpacker zipUnpacker = new ZipUnpacker(this);
try {
boolean z = zipUnpacker.computeDsosFromZip().length != 0;
zipUnpacker.close();
return z;
} catch (Throwable th) {
try {
zipUnpacker.close();
} catch (Throwable th2) {
th.addSuppressed(th2);
}
throw th;
}
}
@Override // com.facebook.soloader.UnpackingSoSource
public UnpackingSoSource.Unpacker makeUnpacker() throws IOException {
return new ZipUnpacker(this);
}
@Override // com.facebook.soloader.DirectorySoSource, com.facebook.soloader.SoSource
public String toString() {
try {
return this.mZipFileName.getCanonicalPath();
} catch (IOException unused) {
return this.mZipFileName.getName();
}
}
public ExtractFromZipSoSource(Context context, File file, File file2, String str) {
super(context, file);
this.mZipFileName = file2;
this.mZipSearchPattern = str;
}
}