NativeDeps.smali
.class public final Lcom/facebook/soloader/NativeDeps;
.super Ljava/lang/Object;
.source "SourceFile"
# static fields
.field private static final DEFAULT_LIBS_CAPACITY:I = 0x200
.field private static final INITIAL_HASH:I = 0x1505
.field private static final LIB_PREFIX_LEN:I = 0x3
.field private static final LIB_PREFIX_SUFFIX_LEN:I
.field private static final LIB_SUFFIX_LEN:I = 0x3
.field private static sEncodedDeps:[B = null
.field private static sInitialized:Z = false
.field private static sPrecomputedDeps:Ljava/util/Map;
.annotation system Ldalvik/annotation/Signature;
value = {
"Ljava/util/Map<",
"Ljava/lang/Integer;",
"Ljava/util/List<",
"Ljava/lang/Integer;",
">;>;"
}
.end annotation
.end field
.field private static sPrecomputedLibs:Ljava/util/List;
.annotation system Ldalvik/annotation/Signature;
value = {
"Ljava/util/List<",
"Ljava/lang/Integer;",
">;"
}
.end annotation
.end field
# direct methods
.method public static constructor <clinit>()V
.registers 1
const/4 v0, 0x3
add-int/2addr v0, v0
sput v0, Lcom/facebook/soloader/NativeDeps;->LIB_PREFIX_SUFFIX_LEN:I
return-void
.end method
.method public constructor <init>()V
.registers 1
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
.method public static getDependencies(Ljava/lang/String;Lcom/facebook/soloader/ElfByteChannel;)[Ljava/lang/String;
.registers 3
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 4
sget-object v0, Lcom/facebook/soloader/NativeDeps;->sPrecomputedDeps:Ljava/util/Map;
if-eqz v0, :cond_b
.line 5
invoke-static {p0}, Lcom/facebook/soloader/NativeDeps;->tryGetDepsFromPrecomputedDeps(Ljava/lang/String;)[Ljava/lang/String;
move-result-object p0
if-eqz p0, :cond_b
return-object p0
.line 6
:cond_b
invoke-static {p1}, Lcom/facebook/soloader/MinElf;->extract_DT_NEEDED(Lcom/facebook/soloader/ElfByteChannel;)[Ljava/lang/String;
move-result-object p0
return-object p0
.end method
.method public static getDependencies(Ljava/lang/String;Ljava/io/File;)[Ljava/lang/String;
.registers 3
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 1
sget-boolean v0, Lcom/facebook/soloader/NativeDeps;->sInitialized:Z
if-eqz v0, :cond_b
.line 2
invoke-static {p0}, Lcom/facebook/soloader/NativeDeps;->tryGetDepsFromPrecomputedDeps(Ljava/lang/String;)[Ljava/lang/String;
move-result-object p0
if-eqz p0, :cond_b
return-object p0
.line 3
:cond_b
invoke-static {p1}, Lcom/facebook/soloader/MinElf;->extract_DT_NEEDED(Ljava/io/File;)[Ljava/lang/String;
move-result-object p0
return-object p0
.end method
.method private static getDepsForLibAtOffset(II)[Ljava/lang/String;
.registers 8
.line 1
new-instance v0, Ljava/util/ArrayList;
invoke-direct {v0}, Ljava/util/ArrayList;-><init>()V
add-int/2addr p0, p1
.line 2
sget p1, Lcom/facebook/soloader/NativeDeps;->LIB_PREFIX_SUFFIX_LEN:I
sub-int/2addr p0, p1
const/4 p1, 0x0
const/4 v1, 0x0
const/4 v2, 0x0
.line 3
:goto_c
sget-object v3, Lcom/facebook/soloader/NativeDeps;->sEncodedDeps:[B
array-length v4, v3
const/4 v5, 0x0
if-ge p0, v4, :cond_3e
aget-byte v3, v3, p0
const/16 v4, 0xa
if-eq v3, v4, :cond_3e
const/16 v4, 0x20
if-ne v3, v4, :cond_2b
if-eqz v2, :cond_3a
.line 4
invoke-static {v1}, Lcom/facebook/soloader/NativeDeps;->getLibString(I)Ljava/lang/String;
move-result-object v1
if-nez v1, :cond_25
return-object v5
.line 5
:cond_25
invoke-virtual {v0, v1}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z
const/4 v1, 0x0
const/4 v2, 0x0
goto :goto_3a
:cond_2b
const/16 v2, 0x30
if-lt v3, v2, :cond_3d
const/16 v2, 0x39
if-le v3, v2, :cond_34
goto :goto_3d
:cond_34
mul-int/lit8 v1, v1, 0xa
add-int/lit8 v3, v3, -0x30
add-int/2addr v1, v3
const/4 v2, 0x1
:cond_3a
:goto_3a
add-int/lit8 p0, p0, 0x1
goto :goto_c
:cond_3d
:goto_3d
return-object v5
:cond_3e
if-eqz v2, :cond_4a
.line 6
invoke-static {v1}, Lcom/facebook/soloader/NativeDeps;->getLibString(I)Ljava/lang/String;
move-result-object p0
if-nez p0, :cond_47
return-object v5
.line 7
:cond_47
invoke-virtual {v0, p0}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z
.line 8
:cond_4a
invoke-virtual {v0}, Ljava/util/ArrayList;->size()I
move-result p0
if-nez p0, :cond_51
return-object v5
.line 9
:cond_51
invoke-virtual {v0}, Ljava/util/ArrayList;->size()I
move-result p0
new-array p0, p0, [Ljava/lang/String;
.line 10
invoke-virtual {v0, p0}, Ljava/util/ArrayList;->toArray([Ljava/lang/Object;)[Ljava/lang/Object;
move-result-object p0
check-cast p0, [Ljava/lang/String;
return-object p0
.end method
.method private static getLibString(I)Ljava/lang/String;
.registers 8
.line 1
sget-object v0, Lcom/facebook/soloader/NativeDeps;->sPrecomputedLibs:Ljava/util/List;
invoke-interface {v0}, Ljava/util/List;->size()I
move-result v0
if-lt p0, v0, :cond_a
const/4 p0, 0x0
return-object p0
.line 2
:cond_a
sget-object v0, Lcom/facebook/soloader/NativeDeps;->sPrecomputedLibs:Ljava/util/List;
invoke-interface {v0, p0}, Ljava/util/List;->get(I)Ljava/lang/Object;
move-result-object p0
check-cast p0, Ljava/lang/Integer;
invoke-virtual {p0}, Ljava/lang/Integer;->intValue()I
move-result p0
move v0, p0
.line 3
:goto_17
sget-object v1, Lcom/facebook/soloader/NativeDeps;->sEncodedDeps:[B
array-length v2, v1
if-ge v0, v2, :cond_25
aget-byte v1, v1, v0
const/16 v2, 0x20
if-le v1, v2, :cond_25
add-int/lit8 v0, v0, 0x1
goto :goto_17
:cond_25
sub-int/2addr v0, p0
.line 4
sget v1, Lcom/facebook/soloader/NativeDeps;->LIB_PREFIX_SUFFIX_LEN:I
add-int/2addr v0, v1
.line 5
new-array v1, v0, [C
const/16 v2, 0x6c
const/4 v3, 0x0
.line 6
aput-char v2, v1, v3
const/16 v2, 0x69
const/4 v4, 0x1
.line 7
aput-char v2, v1, v4
const/16 v2, 0x62
const/4 v5, 0x2
.line 8
aput-char v2, v1, v5
.line 9
:goto_3a
sget v2, Lcom/facebook/soloader/NativeDeps;->LIB_PREFIX_SUFFIX_LEN:I
sub-int v2, v0, v2
if-ge v3, v2, :cond_4f
.line 10
sget v2, Lcom/facebook/soloader/NativeDeps;->LIB_PREFIX_LEN:I
add-int/2addr v2, v3
sget-object v5, Lcom/facebook/soloader/NativeDeps;->sEncodedDeps:[B
add-int v6, p0, v3
aget-byte v5, v5, v6
int-to-char v5, v5
aput-char v5, v1, v2
add-int/lit8 v3, v3, 0x1
goto :goto_3a
:cond_4f
add-int/lit8 p0, v0, -0x3
const/16 v2, 0x2e
.line 11
aput-char v2, v1, p0
add-int/lit8 p0, v0, -0x2
const/16 v2, 0x73
.line 12
aput-char v2, v1, p0
sub-int/2addr v0, v4
const/16 p0, 0x6f
.line 13
aput-char p0, v1, v0
.line 14
new-instance p0, Ljava/lang/String;
invoke-direct {p0, v1}, Ljava/lang/String;-><init>([C)V
return-object p0
.end method
.method private static getOffsetForLib(Ljava/lang/String;)I
.registers 5
.line 1
invoke-static {p0}, Lcom/facebook/soloader/NativeDeps;->hashLib(Ljava/lang/String;)I
move-result v0
.line 2
sget-object v1, Lcom/facebook/soloader/NativeDeps;->sPrecomputedDeps:Ljava/util/Map;
invoke-static {v0}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object v0
invoke-interface {v1, v0}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;
move-result-object v0
check-cast v0, Ljava/util/List;
const/4 v1, -0x1
if-nez v0, :cond_14
return v1
.line 3
:cond_14
invoke-interface {v0}, Ljava/util/List;->iterator()Ljava/util/Iterator;
move-result-object v0
:cond_18
invoke-interface {v0}, Ljava/util/Iterator;->hasNext()Z
move-result v2
if-eqz v2, :cond_2f
invoke-interface {v0}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v2
check-cast v2, Ljava/lang/Integer;
invoke-virtual {v2}, Ljava/lang/Integer;->intValue()I
move-result v2
.line 4
invoke-static {p0, v2}, Lcom/facebook/soloader/NativeDeps;->libIsAtOffset(Ljava/lang/String;I)Z
move-result v3
if-eqz v3, :cond_18
return v2
:cond_2f
return v1
.end method
.method private static hashLib(Ljava/lang/String;)I
.registers 5
.line 1
sget v0, Lcom/facebook/soloader/NativeDeps;->LIB_PREFIX_LEN:I
const/16 v1, 0x1505
:goto_4
invoke-virtual {p0}, Ljava/lang/String;->length()I
move-result v2
sget v3, Lcom/facebook/soloader/NativeDeps;->LIB_SUFFIX_LEN:I
sub-int/2addr v2, v3
if-ge v0, v2, :cond_18
shl-int/lit8 v2, v1, 0x5
add-int/2addr v2, v1
.line 2
invoke-virtual {p0, v0}, Ljava/lang/String;->codePointAt(I)I
move-result v1
add-int/2addr v1, v2
add-int/lit8 v0, v0, 0x1
goto :goto_4
:cond_18
return v1
.end method
.method private static indexDepsBytes([BI)V
.registers 10
const/4 v0, 0x0
const/4 v1, 0x1
const/4 v2, 0x1
const/4 v3, 0x0
const/4 v4, 0x0
:goto_5
if-eqz v2, :cond_23
const/16 v3, 0x1505
move v4, p1
.line 1
:goto_a
:try_start_a
aget-byte v5, p0, v4
const/16 v6, 0x20
if-le v5, v6, :cond_18
shl-int/lit8 v6, v3, 0x5
add-int/2addr v6, v3
add-int v3, v6, v5
add-int/lit8 v4, v4, 0x1
goto :goto_a
.line 2
:cond_18
invoke-static {v3, p1}, Lcom/facebook/soloader/NativeDeps;->indexLib(II)V
:try_end_1b
.catch Ljava/lang/IndexOutOfBoundsException; {:try_start_a .. :try_end_1b} :catch_21
if-eq v5, v6, :cond_1f
const/4 v2, 0x1
goto :goto_30
:cond_1f
const/4 v2, 0x0
goto :goto_30
:catch_21
nop
goto :goto_36
.line 3
:cond_23
:goto_23
:try_start_23
aget-byte v5, p0, p1
:try_end_25
.catch Ljava/lang/IndexOutOfBoundsException; {:try_start_23 .. :try_end_25} :catch_35
const/16 v6, 0xa
if-eq v5, v6, :cond_2c
add-int/lit8 p1, p1, 0x1
goto :goto_23
:cond_2c
const/4 v2, 0x1
move v7, v4
move v4, p1
move p1, v7
:goto_30
add-int/2addr v4, v1
move v7, v4
move v4, p1
move p1, v7
goto :goto_5
:catch_35
move p1, v4
:goto_36
if-eqz v2, :cond_3b
.line 4
invoke-static {v3, p1}, Lcom/facebook/soloader/NativeDeps;->indexLib(II)V
:cond_3b
return-void
.end method
.method private static indexLib(II)V
.registers 4
.line 1
sget-object v0, Lcom/facebook/soloader/NativeDeps;->sPrecomputedLibs:Ljava/util/List;
invoke-static {p1}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object v1
invoke-interface {v0, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z
.line 2
sget-object v0, Lcom/facebook/soloader/NativeDeps;->sPrecomputedDeps:Ljava/util/Map;
invoke-static {p0}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object v1
invoke-interface {v0, v1}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;
move-result-object v0
check-cast v0, Ljava/util/List;
if-nez v0, :cond_25
.line 3
new-instance v0, Ljava/util/ArrayList;
invoke-direct {v0}, Ljava/util/ArrayList;-><init>()V
.line 4
sget-object v1, Lcom/facebook/soloader/NativeDeps;->sPrecomputedDeps:Ljava/util/Map;
invoke-static {p0}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object p0
invoke-interface {v1, p0, v0}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
.line 5
:cond_25
invoke-static {p1}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object p0
invoke-interface {v0, p0}, Ljava/util/List;->add(Ljava/lang/Object;)Z
return-void
.end method
.method private static libIsAtOffset(Ljava/lang/String;I)Z
.registers 6
.line 1
sget v0, Lcom/facebook/soloader/NativeDeps;->LIB_PREFIX_LEN:I
.line 2
:goto_2
invoke-virtual {p0}, Ljava/lang/String;->length()I
move-result v1
sget v2, Lcom/facebook/soloader/NativeDeps;->LIB_SUFFIX_LEN:I
sub-int/2addr v1, v2
if-ge v0, v1, :cond_22
sget-object v1, Lcom/facebook/soloader/NativeDeps;->sEncodedDeps:[B
array-length v1, v1
if-ge p1, v1, :cond_22
.line 3
invoke-virtual {p0, v0}, Ljava/lang/String;->codePointAt(I)I
move-result v1
and-int/lit16 v1, v1, 0xff
sget-object v3, Lcom/facebook/soloader/NativeDeps;->sEncodedDeps:[B
aget-byte v3, v3, p1
if-eq v1, v3, :cond_1d
goto :goto_22
:cond_1d
add-int/lit8 v0, v0, 0x1
add-int/lit8 p1, p1, 0x1
goto :goto_2
.line 4
:cond_22
:goto_22
invoke-virtual {p0}, Ljava/lang/String;->length()I
move-result p0
sub-int/2addr p0, v2
if-ne v0, p0, :cond_2b
const/4 p0, 0x1
goto :goto_2c
:cond_2b
const/4 p0, 0x0
:goto_2c
return p0
.end method
.method private static readDepsFromFile([BLjava/lang/String;)Z
.registers 5
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
const/4 v0, 0x0
.line 1
:try_start_1
new-instance v1, Ljava/io/FileInputStream;
invoke-direct {v1, p1}, Ljava/io/FileInputStream;-><init>(Ljava/lang/String;)V
:try_end_6
.catch Ljava/io/IOException; {:try_start_1 .. :try_end_6} :catch_47
.line 2
:try_start_6
invoke-virtual {v1}, Ljava/io/FileInputStream;->available()I
move-result p1
new-array p1, p1, [B
sput-object p1, Lcom/facebook/soloader/NativeDeps;->sEncodedDeps:[B
.line 3
invoke-virtual {v1, p1}, Ljava/io/FileInputStream;->read([B)I
.line 4
sget-object p1, Lcom/facebook/soloader/NativeDeps;->sEncodedDeps:[B
invoke-static {p0, p1}, Lcom/facebook/soloader/NativeDeps;->verifyBytesAndGetOffset([B[B)I
move-result p0
const/4 p1, -0x1
if-ne p0, p1, :cond_21
.line 5
sput-object v0, Lcom/facebook/soloader/NativeDeps;->sEncodedDeps:[B
:try_end_1c
.catchall {:try_start_6 .. :try_end_1c} :catchall_3d
const/4 p0, 0x0
.line 6
:try_start_1d
invoke-virtual {v1}, Ljava/io/FileInputStream;->close()V
:try_end_20
.catch Ljava/io/IOException; {:try_start_1d .. :try_end_20} :catch_47
return p0
.line 7
:cond_21
:try_start_21
new-instance p1, Ljava/util/HashMap;
const/16 v2, 0x200
invoke-direct {p1, v2}, Ljava/util/HashMap;-><init>(I)V
sput-object p1, Lcom/facebook/soloader/NativeDeps;->sPrecomputedDeps:Ljava/util/Map;
.line 8
new-instance p1, Ljava/util/ArrayList;
invoke-direct {p1, v2}, Ljava/util/ArrayList;-><init>(I)V
sput-object p1, Lcom/facebook/soloader/NativeDeps;->sPrecomputedLibs:Ljava/util/List;
.line 9
sget-object p1, Lcom/facebook/soloader/NativeDeps;->sEncodedDeps:[B
invoke-static {p1, p0}, Lcom/facebook/soloader/NativeDeps;->indexDepsBytes([BI)V
:try_end_36
.catchall {:try_start_21 .. :try_end_36} :catchall_3d
.line 10
:try_start_36
invoke-virtual {v1}, Ljava/io/FileInputStream;->close()V
:try_end_39
.catch Ljava/io/IOException; {:try_start_36 .. :try_end_39} :catch_47
const/4 p0, 0x1
.line 11
sput-boolean p0, Lcom/facebook/soloader/NativeDeps;->sInitialized:Z
return p0
:catchall_3d
move-exception p0
.line 12
:try_start_3e
invoke-virtual {v1}, Ljava/io/FileInputStream;->close()V
:try_end_41
.catchall {:try_start_3e .. :try_end_41} :catchall_42
goto :goto_46
:catchall_42
move-exception p1
:try_start_43
invoke-virtual {p0, p1}, Ljava/lang/Throwable;->addSuppressed(Ljava/lang/Throwable;)V
:goto_46
throw p0
:try_end_47
.catch Ljava/io/IOException; {:try_start_43 .. :try_end_47} :catch_47
:catch_47
move-exception p0
.line 13
sput-object v0, Lcom/facebook/soloader/NativeDeps;->sEncodedDeps:[B
.line 14
throw p0
.end method
.method public static tryGetDepsFromPrecomputedDeps(Ljava/lang/String;)[Ljava/lang/String;
.registers 4
.line 1
sget-boolean v0, Lcom/facebook/soloader/NativeDeps;->sInitialized:Z
const/4 v1, 0x0
if-nez v0, :cond_6
return-object v1
.line 2
:cond_6
invoke-virtual {p0}, Ljava/lang/String;->length()I
move-result v0
sget v2, Lcom/facebook/soloader/NativeDeps;->LIB_PREFIX_SUFFIX_LEN:I
if-gt v0, v2, :cond_f
return-object v1
.line 3
:cond_f
invoke-static {p0}, Lcom/facebook/soloader/NativeDeps;->getOffsetForLib(Ljava/lang/String;)I
move-result v0
const/4 v2, -0x1
if-ne v0, v2, :cond_17
return-object v1
.line 4
:cond_17
invoke-virtual {p0}, Ljava/lang/String;->length()I
move-result p0
invoke-static {v0, p0}, Lcom/facebook/soloader/NativeDeps;->getDepsForLibAtOffset(II)[Ljava/lang/String;
move-result-object p0
return-object p0
.end method
.method public static useDepsFile([BLjava/lang/String;)Z
.registers 4
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 1
sget-boolean v0, Lcom/facebook/soloader/NativeDeps;->sInitialized:Z
if-nez v0, :cond_16
.line 2
const-class v0, Lcom/facebook/soloader/NativeDeps;
monitor-enter v0
.line 3
:try_start_7
sget-boolean v1, Lcom/facebook/soloader/NativeDeps;->sInitialized:Z
if-nez v1, :cond_11
.line 4
invoke-static {p0, p1}, Lcom/facebook/soloader/NativeDeps;->readDepsFromFile([BLjava/lang/String;)Z
move-result p0
monitor-exit v0
return p0
.line 5
:cond_11
monitor-exit v0
goto :goto_16
:catchall_13
move-exception p0
monitor-exit v0
:try_end_15
.catchall {:try_start_7 .. :try_end_15} :catchall_13
throw p0
.line 6
:cond_16
:goto_16
new-instance p0, Ljava/lang/IllegalStateException;
const-string p1, "Trying to initialize NativeDeps but it was already initialized"
invoke-direct {p0, p1}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
throw p0
.end method
.method private static verifyBytesAndGetOffset([B[B)I
.registers 7
const/4 v0, -0x1
if-eqz p0, :cond_2f
.line 1
array-length v1, p0
if-nez v1, :cond_7
goto :goto_2f
.line 2
:cond_7
array-length v1, p1
array-length v2, p0
const/4 v3, 0x4
add-int/2addr v2, v3
if-ge v1, v2, :cond_e
return v0
.line 3
:cond_e
array-length v1, p0
invoke-static {p1, v1, v3}, Ljava/nio/ByteBuffer;->wrap([BII)Ljava/nio/ByteBuffer;
move-result-object v1
invoke-virtual {v1}, Ljava/nio/ByteBuffer;->getInt()I
move-result v1
.line 4
array-length v2, p1
array-length v4, p0
add-int/2addr v4, v3
add-int/2addr v4, v1
if-eq v2, v4, :cond_1e
return v0
:cond_1e
const/4 v1, 0x0
.line 5
:goto_1f
array-length v2, p0
if-ge v1, v2, :cond_2c
.line 6
aget-byte v2, p0, v1
aget-byte v4, p1, v1
if-eq v2, v4, :cond_29
return v0
:cond_29
add-int/lit8 v1, v1, 0x1
goto :goto_1f
.line 7
:cond_2c
array-length p0, p0
add-int/2addr p0, v3
return p0
:cond_2f
:goto_2f
return v0
.end method