Initial commit
This commit is contained in:
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