Initial commit
This commit is contained in:
244
sources/com/getkeepsafe/relinker/ApkLibraryInstaller.java
Normal file
244
sources/com/getkeepsafe/relinker/ApkLibraryInstaller.java
Normal file
@@ -0,0 +1,244 @@
|
||||
package com.getkeepsafe.relinker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.os.Build;
|
||||
import com.getkeepsafe.relinker.ReLinker;
|
||||
import com.ubt.jimu.base.util.FileUtil;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ApkLibraryInstaller implements ReLinker.LibraryInstaller {
|
||||
|
||||
private static class ZipFileInZipEntry {
|
||||
public ZipFile a;
|
||||
public ZipEntry b;
|
||||
|
||||
public ZipFileInZipEntry(ZipFile zipFile, ZipEntry zipEntry) {
|
||||
this.a = zipFile;
|
||||
this.b = zipEntry;
|
||||
}
|
||||
}
|
||||
|
||||
private String[] a(Context context) {
|
||||
String[] strArr;
|
||||
ApplicationInfo applicationInfo = context.getApplicationInfo();
|
||||
if (Build.VERSION.SDK_INT < 21 || (strArr = applicationInfo.splitSourceDirs) == null || strArr.length == 0) {
|
||||
return new String[]{applicationInfo.sourceDir};
|
||||
}
|
||||
String[] strArr2 = new String[strArr.length + 1];
|
||||
strArr2[0] = applicationInfo.sourceDir;
|
||||
System.arraycopy(strArr, 0, strArr2, 1, strArr.length);
|
||||
return strArr2;
|
||||
}
|
||||
|
||||
private ZipFileInZipEntry a(Context context, String[] strArr, String str, ReLinkerInstance reLinkerInstance) {
|
||||
int i;
|
||||
String[] a = a(context);
|
||||
int length = a.length;
|
||||
char c = 0;
|
||||
ZipFile zipFile = null;
|
||||
int i2 = 0;
|
||||
while (i2 < length) {
|
||||
String str2 = a[i2];
|
||||
int i3 = 0;
|
||||
while (true) {
|
||||
int i4 = i3 + 1;
|
||||
i = 5;
|
||||
if (i3 >= 5) {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
zipFile = new ZipFile(new File(str2), 1);
|
||||
break;
|
||||
} catch (IOException unused) {
|
||||
i3 = i4;
|
||||
}
|
||||
}
|
||||
if (zipFile != null) {
|
||||
int i5 = 0;
|
||||
while (true) {
|
||||
int i6 = i5 + 1;
|
||||
if (i5 < i) {
|
||||
int length2 = strArr.length;
|
||||
int i7 = 0;
|
||||
while (i7 < length2) {
|
||||
String str3 = "lib" + File.separatorChar + strArr[i7] + File.separatorChar + str;
|
||||
Object[] objArr = new Object[2];
|
||||
objArr[c] = str3;
|
||||
objArr[1] = str2;
|
||||
reLinkerInstance.a("Looking for %s in APK %s...", objArr);
|
||||
ZipEntry entry = zipFile.getEntry(str3);
|
||||
if (entry != null) {
|
||||
return new ZipFileInZipEntry(zipFile, entry);
|
||||
}
|
||||
i7++;
|
||||
c = 0;
|
||||
}
|
||||
i5 = i6;
|
||||
i = 5;
|
||||
} else {
|
||||
try {
|
||||
zipFile.close();
|
||||
break;
|
||||
} catch (IOException unused2) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
i2++;
|
||||
c = 0;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override // com.getkeepsafe.relinker.ReLinker.LibraryInstaller
|
||||
public void a(Context context, String[] strArr, String str, File file, ReLinkerInstance reLinkerInstance) {
|
||||
ZipFileInZipEntry zipFileInZipEntry;
|
||||
InputStream inputStream;
|
||||
FileOutputStream fileOutputStream;
|
||||
long a;
|
||||
Closeable closeable = null;
|
||||
try {
|
||||
zipFileInZipEntry = a(context, strArr, str, reLinkerInstance);
|
||||
try {
|
||||
if (zipFileInZipEntry == null) {
|
||||
throw new MissingLibraryException(str);
|
||||
}
|
||||
int i = 0;
|
||||
while (true) {
|
||||
int i2 = i + 1;
|
||||
if (i < 5) {
|
||||
reLinkerInstance.a("Found %s! Extracting...", str);
|
||||
try {
|
||||
if (file.exists() || file.createNewFile()) {
|
||||
try {
|
||||
inputStream = zipFileInZipEntry.a.getInputStream(zipFileInZipEntry.b);
|
||||
try {
|
||||
fileOutputStream = new FileOutputStream(file);
|
||||
try {
|
||||
a = a(inputStream, fileOutputStream);
|
||||
fileOutputStream.getFD().sync();
|
||||
} catch (FileNotFoundException unused) {
|
||||
a(inputStream);
|
||||
a(fileOutputStream);
|
||||
i = i2;
|
||||
} catch (IOException unused2) {
|
||||
a(inputStream);
|
||||
a(fileOutputStream);
|
||||
i = i2;
|
||||
} catch (Throwable th) {
|
||||
th = th;
|
||||
closeable = fileOutputStream;
|
||||
a(inputStream);
|
||||
a(closeable);
|
||||
throw th;
|
||||
}
|
||||
} catch (FileNotFoundException unused3) {
|
||||
fileOutputStream = null;
|
||||
} catch (IOException unused4) {
|
||||
fileOutputStream = null;
|
||||
} catch (Throwable th2) {
|
||||
th = th2;
|
||||
}
|
||||
} catch (FileNotFoundException unused5) {
|
||||
inputStream = null;
|
||||
fileOutputStream = null;
|
||||
} catch (IOException unused6) {
|
||||
inputStream = null;
|
||||
fileOutputStream = null;
|
||||
} catch (Throwable th3) {
|
||||
th = th3;
|
||||
inputStream = null;
|
||||
}
|
||||
if (a != file.length()) {
|
||||
a(inputStream);
|
||||
a(fileOutputStream);
|
||||
} else {
|
||||
a(inputStream);
|
||||
a(fileOutputStream);
|
||||
file.setReadable(true, false);
|
||||
file.setExecutable(true, false);
|
||||
file.setWritable(true);
|
||||
if (zipFileInZipEntry != null) {
|
||||
try {
|
||||
if (zipFileInZipEntry.a != null) {
|
||||
zipFileInZipEntry.a.close();
|
||||
return;
|
||||
}
|
||||
return;
|
||||
} catch (IOException unused7) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (IOException unused8) {
|
||||
}
|
||||
i = i2;
|
||||
} else {
|
||||
reLinkerInstance.a("FATAL! Couldn't extract the library from the APK!");
|
||||
if (zipFileInZipEntry != null) {
|
||||
try {
|
||||
if (zipFileInZipEntry.a != null) {
|
||||
zipFileInZipEntry.a.close();
|
||||
return;
|
||||
}
|
||||
return;
|
||||
} catch (IOException unused9) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Throwable th4) {
|
||||
th = th4;
|
||||
if (zipFileInZipEntry != null) {
|
||||
try {
|
||||
if (zipFileInZipEntry.a != null) {
|
||||
zipFileInZipEntry.a.close();
|
||||
}
|
||||
} catch (IOException unused10) {
|
||||
}
|
||||
}
|
||||
throw th;
|
||||
}
|
||||
} catch (Throwable th5) {
|
||||
th = th5;
|
||||
zipFileInZipEntry = null;
|
||||
}
|
||||
}
|
||||
|
||||
private long a(InputStream inputStream, OutputStream outputStream) throws IOException {
|
||||
byte[] bArr = new byte[FileUtil.ZIP_BUFFER_SIZE];
|
||||
long j = 0;
|
||||
while (true) {
|
||||
int read = inputStream.read(bArr);
|
||||
if (read == -1) {
|
||||
outputStream.flush();
|
||||
return j;
|
||||
}
|
||||
outputStream.write(bArr, 0, read);
|
||||
j += read;
|
||||
}
|
||||
}
|
||||
|
||||
private void a(Closeable closeable) {
|
||||
if (closeable != null) {
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (IOException unused) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.getkeepsafe.relinker;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class MissingLibraryException extends RuntimeException {
|
||||
public MissingLibraryException(String str) {
|
||||
super(str);
|
||||
}
|
||||
}
|
42
sources/com/getkeepsafe/relinker/ReLinker.java
Normal file
42
sources/com/getkeepsafe/relinker/ReLinker.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.getkeepsafe.relinker;
|
||||
|
||||
import android.content.Context;
|
||||
import java.io.File;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ReLinker {
|
||||
|
||||
public interface LibraryInstaller {
|
||||
void a(Context context, String[] strArr, String str, File file, ReLinkerInstance reLinkerInstance);
|
||||
}
|
||||
|
||||
public interface LibraryLoader {
|
||||
String a(String str);
|
||||
|
||||
String[] a();
|
||||
|
||||
String b(String str);
|
||||
|
||||
void c(String str);
|
||||
|
||||
void loadLibrary(String str);
|
||||
}
|
||||
|
||||
public interface LoadListener {
|
||||
void a();
|
||||
|
||||
void a(Throwable th);
|
||||
}
|
||||
|
||||
public interface Logger {
|
||||
void log(String str);
|
||||
}
|
||||
|
||||
public static void a(Context context, String str) {
|
||||
a(context, str, null, null);
|
||||
}
|
||||
|
||||
public static void a(Context context, String str, String str2, LoadListener loadListener) {
|
||||
new ReLinkerInstance().a(context, str, str2, loadListener);
|
||||
}
|
||||
}
|
168
sources/com/getkeepsafe/relinker/ReLinkerInstance.java
Normal file
168
sources/com/getkeepsafe/relinker/ReLinkerInstance.java
Normal file
@@ -0,0 +1,168 @@
|
||||
package com.getkeepsafe.relinker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import com.getkeepsafe.relinker.ReLinker;
|
||||
import com.getkeepsafe.relinker.elf.ElfParser;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ReLinkerInstance {
|
||||
protected final Set<String> a;
|
||||
protected final ReLinker.LibraryLoader b;
|
||||
protected final ReLinker.LibraryInstaller c;
|
||||
protected boolean d;
|
||||
protected boolean e;
|
||||
protected ReLinker.Logger f;
|
||||
|
||||
protected ReLinkerInstance() {
|
||||
this(new SystemLibraryLoader(), new ApkLibraryInstaller());
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void c(Context context, String str, String str2) {
|
||||
ElfParser elfParser;
|
||||
if (this.a.contains(str) && !this.d) {
|
||||
a("%s already loaded previously!", str);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.b.loadLibrary(str);
|
||||
this.a.add(str);
|
||||
a("%s (%s) was loaded normally!", str, str2);
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
a("Loading the library normally failed: %s", Log.getStackTraceString(e));
|
||||
a("%s (%s) was not loaded normally, re-linking...", str, str2);
|
||||
File b = b(context, str, str2);
|
||||
if (!b.exists() || this.d) {
|
||||
if (this.d) {
|
||||
a("Forcing a re-link of %s (%s)...", str, str2);
|
||||
}
|
||||
a(context, str, str2);
|
||||
this.c.a(context, this.b.a(), this.b.a(str), b, this);
|
||||
}
|
||||
try {
|
||||
if (this.e) {
|
||||
ElfParser elfParser2 = null;
|
||||
try {
|
||||
elfParser = new ElfParser(b);
|
||||
} catch (Throwable th) {
|
||||
th = th;
|
||||
}
|
||||
try {
|
||||
List<String> b2 = elfParser.b();
|
||||
elfParser.close();
|
||||
Iterator<String> it = b2.iterator();
|
||||
while (it.hasNext()) {
|
||||
a(context, this.b.b(it.next()));
|
||||
}
|
||||
} catch (Throwable th2) {
|
||||
th = th2;
|
||||
elfParser2 = elfParser;
|
||||
elfParser2.close();
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
} catch (IOException unused) {
|
||||
}
|
||||
this.b.c(b.getAbsolutePath());
|
||||
this.a.add(str);
|
||||
a("%s (%s) was re-linked!", str, str2);
|
||||
}
|
||||
}
|
||||
|
||||
protected File b(Context context, String str, String str2) {
|
||||
String a = this.b.a(str);
|
||||
if (TextUtils.a(str2)) {
|
||||
return new File(a(context), a);
|
||||
}
|
||||
return new File(a(context), a + "." + str2);
|
||||
}
|
||||
|
||||
protected ReLinkerInstance(ReLinker.LibraryLoader libraryLoader, ReLinker.LibraryInstaller libraryInstaller) {
|
||||
this.a = new HashSet();
|
||||
if (libraryLoader == null) {
|
||||
throw new IllegalArgumentException("Cannot pass null library loader");
|
||||
}
|
||||
if (libraryInstaller == null) {
|
||||
throw new IllegalArgumentException("Cannot pass null library installer");
|
||||
}
|
||||
this.b = libraryLoader;
|
||||
this.c = libraryInstaller;
|
||||
}
|
||||
|
||||
public void a(Context context, String str) {
|
||||
a(context, str, (String) null, (ReLinker.LoadListener) null);
|
||||
}
|
||||
|
||||
public void a(final Context context, final String str, final String str2, final ReLinker.LoadListener loadListener) {
|
||||
if (context != null) {
|
||||
if (!TextUtils.a(str)) {
|
||||
a("Beginning load of %s...", str);
|
||||
if (loadListener == null) {
|
||||
c(context, str, str2);
|
||||
return;
|
||||
} else {
|
||||
new Thread(new Runnable() { // from class: com.getkeepsafe.relinker.ReLinkerInstance.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
try {
|
||||
ReLinkerInstance.this.c(context, str, str2);
|
||||
loadListener.a();
|
||||
} catch (MissingLibraryException e) {
|
||||
loadListener.a(e);
|
||||
} catch (UnsatisfiedLinkError e2) {
|
||||
loadListener.a(e2);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Given library is either null or empty");
|
||||
}
|
||||
throw new IllegalArgumentException("Given context is null");
|
||||
}
|
||||
|
||||
protected File a(Context context) {
|
||||
return context.getDir("lib", 0);
|
||||
}
|
||||
|
||||
protected void a(Context context, String str, String str2) {
|
||||
File a = a(context);
|
||||
File b = b(context, str, str2);
|
||||
final String a2 = this.b.a(str);
|
||||
File[] listFiles = a.listFiles(new FilenameFilter(this) { // from class: com.getkeepsafe.relinker.ReLinkerInstance.2
|
||||
@Override // java.io.FilenameFilter
|
||||
public boolean accept(File file, String str3) {
|
||||
return str3.startsWith(a2);
|
||||
}
|
||||
});
|
||||
if (listFiles == null) {
|
||||
return;
|
||||
}
|
||||
for (File file : listFiles) {
|
||||
if (this.d || !file.getAbsolutePath().equals(b.getAbsolutePath())) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void a(String str, Object... objArr) {
|
||||
a(String.format(Locale.US, str, objArr));
|
||||
}
|
||||
|
||||
public void a(String str) {
|
||||
ReLinker.Logger logger = this.f;
|
||||
if (logger != null) {
|
||||
logger.log(str);
|
||||
}
|
||||
}
|
||||
}
|
41
sources/com/getkeepsafe/relinker/SystemLibraryLoader.java
Normal file
41
sources/com/getkeepsafe/relinker/SystemLibraryLoader.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.getkeepsafe.relinker;
|
||||
|
||||
import android.os.Build;
|
||||
import com.getkeepsafe.relinker.ReLinker;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class SystemLibraryLoader implements ReLinker.LibraryLoader {
|
||||
SystemLibraryLoader() {
|
||||
}
|
||||
|
||||
@Override // com.getkeepsafe.relinker.ReLinker.LibraryLoader
|
||||
public String a(String str) {
|
||||
return (str.startsWith("lib") && str.endsWith(".so")) ? str : System.mapLibraryName(str);
|
||||
}
|
||||
|
||||
@Override // com.getkeepsafe.relinker.ReLinker.LibraryLoader
|
||||
public String b(String str) {
|
||||
return str.substring(3, str.length() - 3);
|
||||
}
|
||||
|
||||
@Override // com.getkeepsafe.relinker.ReLinker.LibraryLoader
|
||||
public void c(String str) {
|
||||
System.load(str);
|
||||
}
|
||||
|
||||
@Override // com.getkeepsafe.relinker.ReLinker.LibraryLoader
|
||||
public void loadLibrary(String str) {
|
||||
System.loadLibrary(str);
|
||||
}
|
||||
|
||||
@Override // com.getkeepsafe.relinker.ReLinker.LibraryLoader
|
||||
public String[] a() {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
String[] strArr = Build.SUPPORTED_ABIS;
|
||||
if (strArr.length > 0) {
|
||||
return strArr;
|
||||
}
|
||||
}
|
||||
return !TextUtils.a(Build.CPU_ABI2) ? new String[]{Build.CPU_ABI, Build.CPU_ABI2} : new String[]{Build.CPU_ABI};
|
||||
}
|
||||
}
|
8
sources/com/getkeepsafe/relinker/TextUtils.java
Normal file
8
sources/com/getkeepsafe/relinker/TextUtils.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.getkeepsafe.relinker;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class TextUtils {
|
||||
public static boolean a(CharSequence charSequence) {
|
||||
return charSequence == null || charSequence.length() == 0;
|
||||
}
|
||||
}
|
17
sources/com/getkeepsafe/relinker/elf/Dynamic32Structure.java
Normal file
17
sources/com/getkeepsafe/relinker/elf/Dynamic32Structure.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.getkeepsafe.relinker.elf;
|
||||
|
||||
import com.getkeepsafe.relinker.elf.Elf;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Dynamic32Structure extends Elf.DynamicStructure {
|
||||
public Dynamic32Structure(ElfParser elfParser, Elf.Header header, long j, int i) throws IOException {
|
||||
ByteBuffer allocate = ByteBuffer.allocate(4);
|
||||
allocate.order(header.a ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||
long j2 = j + (i * 8);
|
||||
this.a = elfParser.e(allocate, j2);
|
||||
this.b = elfParser.e(allocate, j2 + 4);
|
||||
}
|
||||
}
|
17
sources/com/getkeepsafe/relinker/elf/Dynamic64Structure.java
Normal file
17
sources/com/getkeepsafe/relinker/elf/Dynamic64Structure.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.getkeepsafe.relinker.elf;
|
||||
|
||||
import com.getkeepsafe.relinker.elf.Elf;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Dynamic64Structure extends Elf.DynamicStructure {
|
||||
public Dynamic64Structure(ElfParser elfParser, Elf.Header header, long j, int i) throws IOException {
|
||||
ByteBuffer allocate = ByteBuffer.allocate(8);
|
||||
allocate.order(header.a ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||
long j2 = j + (i * 16);
|
||||
this.a = elfParser.c(allocate, j2);
|
||||
this.b = elfParser.c(allocate, j2 + 8);
|
||||
}
|
||||
}
|
38
sources/com/getkeepsafe/relinker/elf/Elf.java
Normal file
38
sources/com/getkeepsafe/relinker/elf/Elf.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.getkeepsafe.relinker.elf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public interface Elf {
|
||||
|
||||
public static abstract class DynamicStructure {
|
||||
public long a;
|
||||
public long b;
|
||||
}
|
||||
|
||||
public static abstract class Header {
|
||||
public boolean a;
|
||||
public long b;
|
||||
public long c;
|
||||
public int d;
|
||||
public int e;
|
||||
public int f;
|
||||
|
||||
public abstract DynamicStructure a(long j, int i) throws IOException;
|
||||
|
||||
public abstract ProgramHeader a(long j) throws IOException;
|
||||
|
||||
public abstract SectionHeader a(int i) throws IOException;
|
||||
}
|
||||
|
||||
public static abstract class ProgramHeader {
|
||||
public long a;
|
||||
public long b;
|
||||
public long c;
|
||||
public long d;
|
||||
}
|
||||
|
||||
public static abstract class SectionHeader {
|
||||
public long a;
|
||||
}
|
||||
}
|
41
sources/com/getkeepsafe/relinker/elf/Elf32Header.java
Normal file
41
sources/com/getkeepsafe/relinker/elf/Elf32Header.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.getkeepsafe.relinker.elf;
|
||||
|
||||
import com.getkeepsafe.relinker.elf.Elf;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Elf32Header extends Elf.Header {
|
||||
private final ElfParser g;
|
||||
|
||||
public Elf32Header(boolean z, ElfParser elfParser) throws IOException {
|
||||
this.a = z;
|
||||
this.g = elfParser;
|
||||
ByteBuffer allocate = ByteBuffer.allocate(4);
|
||||
allocate.order(z ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||
elfParser.b(allocate, 16L);
|
||||
this.b = elfParser.e(allocate, 28L);
|
||||
this.c = elfParser.e(allocate, 32L);
|
||||
this.d = elfParser.b(allocate, 42L);
|
||||
this.e = elfParser.b(allocate, 44L);
|
||||
this.f = elfParser.b(allocate, 46L);
|
||||
elfParser.b(allocate, 48L);
|
||||
elfParser.b(allocate, 50L);
|
||||
}
|
||||
|
||||
@Override // com.getkeepsafe.relinker.elf.Elf.Header
|
||||
public Elf.SectionHeader a(int i) throws IOException {
|
||||
return new Section32Header(this.g, this, i);
|
||||
}
|
||||
|
||||
@Override // com.getkeepsafe.relinker.elf.Elf.Header
|
||||
public Elf.ProgramHeader a(long j) throws IOException {
|
||||
return new Program32Header(this.g, this, j);
|
||||
}
|
||||
|
||||
@Override // com.getkeepsafe.relinker.elf.Elf.Header
|
||||
public Elf.DynamicStructure a(long j, int i) throws IOException {
|
||||
return new Dynamic32Structure(this.g, this, j, i);
|
||||
}
|
||||
}
|
41
sources/com/getkeepsafe/relinker/elf/Elf64Header.java
Normal file
41
sources/com/getkeepsafe/relinker/elf/Elf64Header.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.getkeepsafe.relinker.elf;
|
||||
|
||||
import com.getkeepsafe.relinker.elf.Elf;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Elf64Header extends Elf.Header {
|
||||
private final ElfParser g;
|
||||
|
||||
public Elf64Header(boolean z, ElfParser elfParser) throws IOException {
|
||||
this.a = z;
|
||||
this.g = elfParser;
|
||||
ByteBuffer allocate = ByteBuffer.allocate(8);
|
||||
allocate.order(z ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||
elfParser.b(allocate, 16L);
|
||||
this.b = elfParser.c(allocate, 32L);
|
||||
this.c = elfParser.c(allocate, 40L);
|
||||
this.d = elfParser.b(allocate, 54L);
|
||||
this.e = elfParser.b(allocate, 56L);
|
||||
this.f = elfParser.b(allocate, 58L);
|
||||
elfParser.b(allocate, 60L);
|
||||
elfParser.b(allocate, 62L);
|
||||
}
|
||||
|
||||
@Override // com.getkeepsafe.relinker.elf.Elf.Header
|
||||
public Elf.SectionHeader a(int i) throws IOException {
|
||||
return new Section64Header(this.g, this, i);
|
||||
}
|
||||
|
||||
@Override // com.getkeepsafe.relinker.elf.Elf.Header
|
||||
public Elf.ProgramHeader a(long j) throws IOException {
|
||||
return new Program64Header(this.g, this, j);
|
||||
}
|
||||
|
||||
@Override // com.getkeepsafe.relinker.elf.Elf.Header
|
||||
public Elf.DynamicStructure a(long j, int i) throws IOException {
|
||||
return new Dynamic64Structure(this.g, this, j, i);
|
||||
}
|
||||
}
|
167
sources/com/getkeepsafe/relinker/elf/ElfParser.java
Normal file
167
sources/com/getkeepsafe/relinker/elf/ElfParser.java
Normal file
@@ -0,0 +1,167 @@
|
||||
package com.getkeepsafe.relinker.elf;
|
||||
|
||||
import com.getkeepsafe.relinker.elf.Elf;
|
||||
import java.io.Closeable;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ElfParser implements Closeable, Elf {
|
||||
private final FileChannel a;
|
||||
|
||||
public ElfParser(File file) throws FileNotFoundException {
|
||||
if (file == null || !file.exists()) {
|
||||
throw new IllegalArgumentException("File is null or does not exist");
|
||||
}
|
||||
this.a = new FileInputStream(file).getChannel();
|
||||
}
|
||||
|
||||
public Elf.Header a() throws IOException {
|
||||
this.a.position(0L);
|
||||
ByteBuffer allocate = ByteBuffer.allocate(8);
|
||||
allocate.order(ByteOrder.LITTLE_ENDIAN);
|
||||
if (e(allocate, 0L) != 1179403647) {
|
||||
throw new IllegalArgumentException("Invalid ELF Magic!");
|
||||
}
|
||||
short a = a(allocate, 4L);
|
||||
boolean z = a(allocate, 5L) == 2;
|
||||
if (a == 1) {
|
||||
return new Elf32Header(z, this);
|
||||
}
|
||||
if (a == 2) {
|
||||
return new Elf64Header(z, this);
|
||||
}
|
||||
throw new IllegalStateException("Invalid class type!");
|
||||
}
|
||||
|
||||
public List<String> b() throws IOException {
|
||||
long j;
|
||||
this.a.position(0L);
|
||||
ArrayList arrayList = new ArrayList();
|
||||
Elf.Header a = a();
|
||||
ByteBuffer allocate = ByteBuffer.allocate(8);
|
||||
allocate.order(a.a ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||
long j2 = a.e;
|
||||
int i = 0;
|
||||
if (j2 == 65535) {
|
||||
j2 = a.a(0).a;
|
||||
}
|
||||
long j3 = 0;
|
||||
while (true) {
|
||||
if (j3 >= j2) {
|
||||
j = 0;
|
||||
break;
|
||||
}
|
||||
Elf.ProgramHeader a2 = a.a(j3);
|
||||
if (a2.a == 2) {
|
||||
j = a2.b;
|
||||
break;
|
||||
}
|
||||
j3++;
|
||||
}
|
||||
if (j == 0) {
|
||||
return Collections.unmodifiableList(arrayList);
|
||||
}
|
||||
ArrayList arrayList2 = new ArrayList();
|
||||
long j4 = 0;
|
||||
while (true) {
|
||||
Elf.DynamicStructure a3 = a.a(j, i);
|
||||
long j5 = j;
|
||||
long j6 = a3.a;
|
||||
if (j6 == 1) {
|
||||
arrayList2.add(Long.valueOf(a3.b));
|
||||
} else if (j6 == 5) {
|
||||
j4 = a3.b;
|
||||
}
|
||||
i++;
|
||||
if (a3.a == 0) {
|
||||
break;
|
||||
}
|
||||
j = j5;
|
||||
}
|
||||
if (j4 == 0) {
|
||||
throw new IllegalStateException("String table offset not found!");
|
||||
}
|
||||
long a4 = a(a, j2, j4);
|
||||
Iterator it = arrayList2.iterator();
|
||||
while (it.hasNext()) {
|
||||
arrayList.add(d(allocate, ((Long) it.next()).longValue() + a4));
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
protected long c(ByteBuffer byteBuffer, long j) throws IOException {
|
||||
a(byteBuffer, j, 8);
|
||||
return byteBuffer.getLong();
|
||||
}
|
||||
|
||||
@Override // java.io.Closeable, java.lang.AutoCloseable
|
||||
public void close() throws IOException {
|
||||
this.a.close();
|
||||
}
|
||||
|
||||
protected String d(ByteBuffer byteBuffer, long j) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (true) {
|
||||
long j2 = 1 + j;
|
||||
short a = a(byteBuffer, j);
|
||||
if (a == 0) {
|
||||
return sb.toString();
|
||||
}
|
||||
sb.append((char) a);
|
||||
j = j2;
|
||||
}
|
||||
}
|
||||
|
||||
protected long e(ByteBuffer byteBuffer, long j) throws IOException {
|
||||
a(byteBuffer, j, 4);
|
||||
return byteBuffer.getInt() & 4294967295L;
|
||||
}
|
||||
|
||||
private long a(Elf.Header header, long j, long j2) throws IOException {
|
||||
for (long j3 = 0; j3 < j; j3++) {
|
||||
Elf.ProgramHeader a = header.a(j3);
|
||||
if (a.a == 1) {
|
||||
long j4 = a.c;
|
||||
if (j4 <= j2 && j2 <= a.d + j4) {
|
||||
return (j2 - j4) + a.b;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Could not map vma to file offset!");
|
||||
}
|
||||
|
||||
protected short a(ByteBuffer byteBuffer, long j) throws IOException {
|
||||
a(byteBuffer, j, 1);
|
||||
return (short) (byteBuffer.get() & 255);
|
||||
}
|
||||
|
||||
protected void a(ByteBuffer byteBuffer, long j, int i) throws IOException {
|
||||
byteBuffer.position(0);
|
||||
byteBuffer.limit(i);
|
||||
long j2 = 0;
|
||||
while (j2 < i) {
|
||||
int read = this.a.read(byteBuffer, j + j2);
|
||||
if (read == -1) {
|
||||
throw new EOFException();
|
||||
}
|
||||
j2 += read;
|
||||
}
|
||||
byteBuffer.position(0);
|
||||
}
|
||||
|
||||
protected int b(ByteBuffer byteBuffer, long j) throws IOException {
|
||||
a(byteBuffer, j, 2);
|
||||
return byteBuffer.getShort() & 65535;
|
||||
}
|
||||
}
|
19
sources/com/getkeepsafe/relinker/elf/Program32Header.java
Normal file
19
sources/com/getkeepsafe/relinker/elf/Program32Header.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.getkeepsafe.relinker.elf;
|
||||
|
||||
import com.getkeepsafe.relinker.elf.Elf;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Program32Header extends Elf.ProgramHeader {
|
||||
public Program32Header(ElfParser elfParser, Elf.Header header, long j) throws IOException {
|
||||
ByteBuffer allocate = ByteBuffer.allocate(4);
|
||||
allocate.order(header.a ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||
long j2 = header.b + (j * header.d);
|
||||
this.a = elfParser.e(allocate, j2);
|
||||
this.b = elfParser.e(allocate, 4 + j2);
|
||||
this.c = elfParser.e(allocate, 8 + j2);
|
||||
this.d = elfParser.e(allocate, j2 + 20);
|
||||
}
|
||||
}
|
19
sources/com/getkeepsafe/relinker/elf/Program64Header.java
Normal file
19
sources/com/getkeepsafe/relinker/elf/Program64Header.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.getkeepsafe.relinker.elf;
|
||||
|
||||
import com.getkeepsafe.relinker.elf.Elf;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Program64Header extends Elf.ProgramHeader {
|
||||
public Program64Header(ElfParser elfParser, Elf.Header header, long j) throws IOException {
|
||||
ByteBuffer allocate = ByteBuffer.allocate(8);
|
||||
allocate.order(header.a ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||
long j2 = header.b + (j * header.d);
|
||||
this.a = elfParser.e(allocate, j2);
|
||||
this.b = elfParser.c(allocate, 8 + j2);
|
||||
this.c = elfParser.c(allocate, 16 + j2);
|
||||
this.d = elfParser.c(allocate, j2 + 40);
|
||||
}
|
||||
}
|
15
sources/com/getkeepsafe/relinker/elf/Section32Header.java
Normal file
15
sources/com/getkeepsafe/relinker/elf/Section32Header.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.getkeepsafe.relinker.elf;
|
||||
|
||||
import com.getkeepsafe.relinker.elf.Elf;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Section32Header extends Elf.SectionHeader {
|
||||
public Section32Header(ElfParser elfParser, Elf.Header header, int i) throws IOException {
|
||||
ByteBuffer allocate = ByteBuffer.allocate(4);
|
||||
allocate.order(header.a ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||
this.a = elfParser.e(allocate, header.c + (i * header.f) + 28);
|
||||
}
|
||||
}
|
15
sources/com/getkeepsafe/relinker/elf/Section64Header.java
Normal file
15
sources/com/getkeepsafe/relinker/elf/Section64Header.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.getkeepsafe.relinker.elf;
|
||||
|
||||
import com.getkeepsafe.relinker.elf.Elf;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Section64Header extends Elf.SectionHeader {
|
||||
public Section64Header(ElfParser elfParser, Elf.Header header, int i) throws IOException {
|
||||
ByteBuffer allocate = ByteBuffer.allocate(8);
|
||||
allocate.order(header.a ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||
this.a = elfParser.e(allocate, header.c + (i * header.f) + 44);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user