CrackMe.apk

Download file
    package com.facebook.soloader;

import android.util.Log;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.ClosedByInterruptException;
import kotlin.UShort;
import okhttp3.internal.ws.WebSocketProtocol;

public final class MinElf {
    public static final int DT_NEEDED = 1;
    public static final int DT_NULL = 0;
    public static final int DT_STRTAB = 5;
    public static final int ELF_MAGIC = 1179403647;
    public static final int PN_XNUM = 65535;
    public static final int PT_DYNAMIC = 2;
    public static final int PT_LOAD = 1;
    private static final String TAG = "MinElf";

    public enum ISA {
        NOT_SO("not_so"),
        X86("x86"),
        ARM("armeabi-v7a"),
        X86_64("x86_64"),
        AARCH64("arm64-v8a"),
        OTHERS("others");
        
        private final String value;

        private ISA(String str) {
            this.value = str;
        }

        public String toString() {
            return this.value;
        }
    }

    public static String[] extract_DT_NEEDED(File file) throws IOException {
        ElfFileChannel elfFileChannel = new ElfFileChannel(file);
        try {
            String[] extract_DT_NEEDED = extract_DT_NEEDED((ElfByteChannel) elfFileChannel);
            elfFileChannel.close();
            return extract_DT_NEEDED;
        } catch (Throwable th) {
            th.addSuppressed(th);
        }
        throw th;
    }

    private static String[] extract_DT_NEEDED_with_retries(ElfFileChannel elfFileChannel) throws IOException {
        int i = 0;
        while (true) {
            try {
                return extract_DT_NEEDED_no_retries(elfFileChannel);
            } catch (ClosedByInterruptException e) {
                i++;
                if (i <= 4) {
                    Thread.interrupted();
                    Log.e(TAG, "retrying extract_DT_NEEDED due to ClosedByInterruptException", e);
                    elfFileChannel.openChannel();
                } else {
                    throw e;
                }
            }
        }
    }

    public static String[] extract_DT_NEEDED(ElfByteChannel elfByteChannel) throws IOException {
        if (elfByteChannel instanceof ElfFileChannel) {
            return extract_DT_NEEDED_with_retries((ElfFileChannel) elfByteChannel);
        }
        return extract_DT_NEEDED_no_retries(elfByteChannel);
    }

    private static String[] extract_DT_NEEDED_no_retries(ElfByteChannel elfByteChannel) throws IOException {
        long j;
        long j2;
        long j3;
        long j4;
        long j5;
        long j6;
        long j7;
        long j8;
        long j9;
        long j10;
        long j11;
        ElfByteChannel elfByteChannel2 = elfByteChannel;
        ByteBuffer allocate = ByteBuffer.allocate(8);
        allocate.order(ByteOrder.LITTLE_ENDIAN);
        long j12 = getu32(elfByteChannel2, allocate, 0);
        if (j12 == 1179403647) {
            boolean z = true;
            if (getu8(elfByteChannel2, allocate, 4) != 1) {
                z = false;
            }
            if (getu8(elfByteChannel2, allocate, 5) == 2) {
                allocate.order(ByteOrder.BIG_ENDIAN);
            }
            long r15 = z ? getu32(elfByteChannel2, allocate, 28) : get64(elfByteChannel2, allocate, 32);
            long j13 = z ? (long) getu16(elfByteChannel2, allocate, 44) : (long) getu16(elfByteChannel2, allocate, 56);
            int i = getu16(elfByteChannel2, allocate, z ? 42 : 54);
            if (j13 == WebSocketProtocol.PAYLOAD_SHORT_MAX) {
                long r3 = z ? getu32(elfByteChannel2, allocate, 32) : get64(elfByteChannel2, allocate, 40);
                if (z) {
                    j11 = getu32(elfByteChannel2, allocate, r3 + 28);
                } else {
                    j11 = getu32(elfByteChannel2, allocate, r3 + 44);
                }
                j13 = j11;
            }
            long j14 = r15;
            long j15 = 0;
            while (true) {
                if (j15 >= j13) {
                    j = 0;
                    break;
                }
                if (z) {
                    j10 = getu32(elfByteChannel2, allocate, j14 + 0);
                } else {
                    j10 = getu32(elfByteChannel2, allocate, j14 + 0);
                }
                if (j10 != 2) {
                    j14 += (long) i;
                    j15++;
                } else if (z) {
                    j = getu32(elfByteChannel2, allocate, j14 + 4);
                } else {
                    j = get64(elfByteChannel2, allocate, j14 + 8);
                }
            }
            long j16 = 0;
            if (j != 0) {
                long j17 = j;
                long j18 = 0;
                int i2 = 0;
                while (true) {
                    boolean z2 = z;
                    long r7 = z ? getu32(elfByteChannel2, allocate, j17 + j16) : get64(elfByteChannel2, allocate, j17 + j16);
                    if (r7 == 1) {
                        j2 = j;
                        if (i2 != Integer.MAX_VALUE) {
                            i2++;
                        } else {
                            throw new ElfError("malformed DT_NEEDED section");
                        }
                    } else {
                        j2 = j;
                        if (r7 == 5) {
                            if (z2) {
                                j9 = getu32(elfByteChannel2, allocate, j17 + 4);
                            } else {
                                j9 = get64(elfByteChannel2, allocate, j17 + 8);
                            }
                            j18 = j9;
                        }
                    }
                    long j19 = 16;
                    j17 += z2 ? 8 : 16;
                    j16 = 0;
                    if (r7 != 0) {
                        z = z2;
                        j = j2;
                    } else if (j18 != 0) {
                        int i3 = 0;
                        while (true) {
                            if (((long) i3) >= j13) {
                                j3 = 0;
                                break;
                            }
                            if (z2) {
                                j4 = getu32(elfByteChannel2, allocate, r15 + j16);
                            } else {
                                j4 = getu32(elfByteChannel2, allocate, r15 + j16);
                            }
                            if (j4 == 1) {
                                if (z2) {
                                    j6 = getu32(elfByteChannel2, allocate, r15 + 8);
                                } else {
                                    j6 = get64(elfByteChannel2, allocate, r15 + j19);
                                }
                                if (z2) {
                                    j5 = j13;
                                    j7 = getu32(elfByteChannel2, allocate, r15 + 20);
                                } else {
                                    j5 = j13;
                                    j7 = get64(elfByteChannel2, allocate, r15 + 40);
                                }
                                if (j6 <= j18 && j18 < j7 + j6) {
                                    if (z2) {
                                        j8 = getu32(elfByteChannel2, allocate, r15 + 4);
                                    } else {
                                        j8 = get64(elfByteChannel2, allocate, r15 + 8);
                                    }
                                    j3 = j8 + (j18 - j6);
                                }
                            } else {
                                j5 = j13;
                            }
                            r15 += (long) i;
                            i3++;
                            j13 = j5;
                            j19 = 16;
                            j16 = 0;
                        }
                        long j20 = 0;
                        if (j3 != 0) {
                            String[] strArr = new String[i2];
                            int i4 = 0;
                            while (true) {
                                long j21 = j2 + j20;
                                long r10 = z2 ? getu32(elfByteChannel2, allocate, j21) : get64(elfByteChannel2, allocate, j21);
                                if (r10 == 1) {
                                    strArr[i4] = getSz(elfByteChannel2, allocate, (z2 ? getu32(elfByteChannel2, allocate, j2 + 4) : get64(elfByteChannel2, allocate, j2 + 8)) + j3);
                                    if (i4 != Integer.MAX_VALUE) {
                                        i4++;
                                    } else {
                                        throw new ElfError("malformed DT_NEEDED section");
                                    }
                                }
                                j2 += z2 ? 8 : 16;
                                if (r10 != 0) {
                                    j20 = 0;
                                } else if (i4 == i2) {
                                    return strArr;
                                } else {
                                    throw new ElfError("malformed DT_NEEDED section");
                                }
                            }
                        } else {
                            throw new ElfError("did not find file offset of DT_STRTAB table");
                        }
                    } else {
                        throw new ElfError("Dynamic section string-table not found");
                    }
                }
            } else {
                throw new ElfError("ELF file does not contain dynamic linking information");
            }
        } else {
            throw new ElfError("file is not ELF: 0x" + Long.toHexString(j12));
        }
    }

    private static String getSz(ElfByteChannel elfByteChannel, ByteBuffer byteBuffer, long j) throws IOException {
        StringBuilder sb = new StringBuilder();
        while (true) {
            long j2 = 1 + j;
            short u8Var = getu8(elfByteChannel, byteBuffer, j);
            if (u8Var == 0) {
                return sb.toString();
            }
            sb.append((char) u8Var);
            j = j2;
        }
    }

    private static void read(ElfByteChannel elfByteChannel, ByteBuffer byteBuffer, int i, long j) throws IOException {
        int read;
        byteBuffer.position(0);
        byteBuffer.limit(i);
        while (byteBuffer.remaining() > 0 && (read = elfByteChannel.read(byteBuffer, j)) != -1) {
            j += (long) read;
        }
        if (byteBuffer.remaining() <= 0) {
            byteBuffer.position(0);
            return;
        }
        throw new ElfError("ELF file truncated");
    }

    private static long get64(ElfByteChannel elfByteChannel, ByteBuffer byteBuffer, long j) throws IOException {
        read(elfByteChannel, byteBuffer, 8, j);
        return byteBuffer.getLong();
    }

    private static long getu32(ElfByteChannel elfByteChannel, ByteBuffer byteBuffer, long j) throws IOException {
        read(elfByteChannel, byteBuffer, 4, j);
        return ((long) byteBuffer.getInt()) & 4294967295L;
    }

    private static int getu16(ElfByteChannel elfByteChannel, ByteBuffer byteBuffer, long j) throws IOException {
        read(elfByteChannel, byteBuffer, 2, j);
        return byteBuffer.getShort() & UShort.MAX_VALUE;
    }

    private static short getu8(ElfByteChannel elfByteChannel, ByteBuffer byteBuffer, long j) throws IOException {
        read(elfByteChannel, byteBuffer, 1, j);
        return (short) (byteBuffer.get() & 255);
    }

    private static class ElfError extends RuntimeException {
        ElfError(String str) {
            super(str);
        }
    }
}
    
Download file