EncryptedFileDataSource.smali

.class public final Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;
.super Lcom/google/android/exoplayer2/upstream/BaseDataSource;
.source "EncryptedFileDataSource.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource$EncryptedFileDataSourceException;
    }
.end annotation


# instance fields
.field private bytesRemaining:J

.field private file:Ljava/io/RandomAccessFile;

.field private fileOffset:I

.field private iv:[B

.field private key:[B

.field private opened:Z

.field private uri:Landroid/net/Uri;


# direct methods
.method static constructor <clinit>()V
    .registers 1

    return-void
.end method

.method public constructor <init>()V
    .registers 2

    .line 40
    const/4 v0, 0x0

    invoke-direct {p0, v0}, Lcom/google/android/exoplayer2/upstream/BaseDataSource;-><init>(Z)V

    .line 35
    const/16 v0, 0x20

    new-array v0, v0, [B

    iput-object v0, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->key:[B

    .line 36
    const/16 v0, 0x10

    new-array v0, v0, [B

    iput-object v0, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->iv:[B

    .line 41
    return-void
.end method

.method public constructor <init>(Lcom/google/android/exoplayer2/upstream/TransferListener;)V
    .registers 2
    .param p1, "listener"    # Lcom/google/android/exoplayer2/upstream/TransferListener;
    .annotation runtime Ljava/lang/Deprecated;
    .end annotation

    .line 45
    invoke-direct {p0}, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;-><init>()V

    .line 46
    if-eqz p1, :cond_8

    .line 47
    invoke-virtual {p0, p1}, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->addTransferListener(Lcom/google/android/exoplayer2/upstream/TransferListener;)V

    .line 49
    :cond_8
    return-void
.end method


# virtual methods
.method public close()V
    .registers 5
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource$EncryptedFileDataSourceException;
        }
    .end annotation

    .line 112
    const/4 v0, 0x0

    iput-object v0, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->uri:Landroid/net/Uri;

    .line 113
    const/4 v1, 0x0

    iput v1, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->fileOffset:I

    .line 115
    :try_start_6
    iget-object v2, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->file:Ljava/io/RandomAccessFile;

    if-eqz v2, :cond_f

    .line 116
    iget-object v2, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->file:Ljava/io/RandomAccessFile;

    invoke-virtual {v2}, Ljava/io/RandomAccessFile;->close()V
    :try_end_f
    .catch Ljava/io/IOException; {:try_start_6 .. :try_end_f} :catch_1d
    .catchall {:try_start_6 .. :try_end_f} :catchall_1b

    .line 121
    :cond_f
    iput-object v0, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->file:Ljava/io/RandomAccessFile;

    .line 122
    iget-boolean v0, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->opened:Z

    if-eqz v0, :cond_1a

    .line 123
    iput-boolean v1, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->opened:Z

    .line 124
    invoke-virtual {p0}, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->transferEnded()V

    .line 127
    :cond_1a
    return-void

    .line 121
    :catchall_1b
    move-exception v2

    goto :goto_24

    .line 118
    :catch_1d
    move-exception v2

    .line 119
    .local v2, "e":Ljava/io/IOException;
    :try_start_1e
    new-instance v3, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource$EncryptedFileDataSourceException;

    invoke-direct {v3, v2}, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource$EncryptedFileDataSourceException;-><init>(Ljava/io/IOException;)V

    throw v3
    :try_end_24
    .catchall {:try_start_1e .. :try_end_24} :catchall_1b

    .line 121
    .end local v2    # "e":Ljava/io/IOException;
    :goto_24
    iput-object v0, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->file:Ljava/io/RandomAccessFile;

    .line 122
    iget-boolean v0, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->opened:Z

    if-eqz v0, :cond_2f

    .line 123
    iput-boolean v1, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->opened:Z

    .line 124
    invoke-virtual {p0}, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->transferEnded()V

    .line 126
    :cond_2f
    throw v2
.end method

.method public getUri()Landroid/net/Uri;
    .registers 2

    .line 107
    iget-object v0, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->uri:Landroid/net/Uri;

    return-object v0
.end method

.method public open(Lcom/google/android/exoplayer2/upstream/DataSpec;)J
    .registers 11
    .param p1, "dataSpec"    # Lcom/google/android/exoplayer2/upstream/DataSpec;
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource$EncryptedFileDataSourceException;
        }
    .end annotation

    .line 54
    const-string/jumbo v0, "r"

    :try_start_3
    iget-object v1, p1, Lcom/google/android/exoplayer2/upstream/DataSpec;->uri:Landroid/net/Uri;

    iput-object v1, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->uri:Landroid/net/Uri;

    .line 55
    new-instance v1, Ljava/io/File;

    iget-object v2, p1, Lcom/google/android/exoplayer2/upstream/DataSpec;->uri:Landroid/net/Uri;

    invoke-virtual {v2}, Landroid/net/Uri;->getPath()Ljava/lang/String;

    move-result-object v2

    invoke-direct {v1, v2}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    .line 56
    .local v1, "path":Ljava/io/File;
    invoke-virtual {v1}, Ljava/io/File;->getName()Ljava/lang/String;

    move-result-object v2

    .line 57
    .local v2, "name":Ljava/lang/String;
    new-instance v3, Ljava/io/File;

    invoke-static {}, Lim/tpelyyftgw/messenger/FileLoader;->getInternalCacheDir()Ljava/io/File;

    move-result-object v4

    new-instance v5, Ljava/lang/StringBuilder;

    invoke-direct {v5}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v5, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    const-string v6, ".key"

    invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v5

    invoke-direct {v3, v4, v5}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    .line 58
    .local v3, "keyPath":Ljava/io/File;
    new-instance v4, Ljava/io/RandomAccessFile;

    invoke-direct {v4, v3, v0}, Ljava/io/RandomAccessFile;-><init>(Ljava/io/File;Ljava/lang/String;)V

    .line 59
    .local v4, "keyFile":Ljava/io/RandomAccessFile;
    iget-object v5, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->key:[B

    invoke-virtual {v4, v5}, Ljava/io/RandomAccessFile;->read([B)I

    .line 60
    iget-object v5, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->iv:[B

    invoke-virtual {v4, v5}, Ljava/io/RandomAccessFile;->read([B)I

    .line 61
    invoke-virtual {v4}, Ljava/io/RandomAccessFile;->close()V

    .line 63
    new-instance v5, Ljava/io/RandomAccessFile;

    invoke-direct {v5, v1, v0}, Ljava/io/RandomAccessFile;-><init>(Ljava/io/File;Ljava/lang/String;)V

    iput-object v5, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->file:Ljava/io/RandomAccessFile;

    .line 64
    iget-wide v6, p1, Lcom/google/android/exoplayer2/upstream/DataSpec;->position:J

    invoke-virtual {v5, v6, v7}, Ljava/io/RandomAccessFile;->seek(J)V

    .line 65
    iget-wide v5, p1, Lcom/google/android/exoplayer2/upstream/DataSpec;->position:J

    long-to-int v0, v5

    iput v0, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->fileOffset:I

    .line 66
    iget-wide v5, p1, Lcom/google/android/exoplayer2/upstream/DataSpec;->length:J

    const-wide/16 v7, -0x1

    cmp-long v0, v5, v7

    if-nez v0, :cond_65

    iget-object v0, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->file:Ljava/io/RandomAccessFile;

    invoke-virtual {v0}, Ljava/io/RandomAccessFile;->length()J

    move-result-wide v5

    iget-wide v7, p1, Lcom/google/android/exoplayer2/upstream/DataSpec;->position:J

    sub-long/2addr v5, v7

    goto :goto_67

    :cond_65
    iget-wide v5, p1, Lcom/google/android/exoplayer2/upstream/DataSpec;->length:J

    :goto_67
    iput-wide v5, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->bytesRemaining:J
    :try_end_69
    .catch Ljava/io/IOException; {:try_start_3 .. :try_end_69} :catch_7f

    .line 67
    const-wide/16 v7, 0x0

    cmp-long v0, v5, v7

    if-ltz v0, :cond_79

    .line 72
    .end local v1    # "path":Ljava/io/File;
    .end local v2    # "name":Ljava/lang/String;
    .end local v3    # "keyPath":Ljava/io/File;
    .end local v4    # "keyFile":Ljava/io/RandomAccessFile;
    nop

    .line 74
    const/4 v0, 0x1

    iput-boolean v0, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->opened:Z

    .line 75
    invoke-virtual {p0, p1}, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->transferStarted(Lcom/google/android/exoplayer2/upstream/DataSpec;)V

    .line 77
    iget-wide v0, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->bytesRemaining:J

    return-wide v0

    .line 68
    .restart local v1    # "path":Ljava/io/File;
    .restart local v2    # "name":Ljava/lang/String;
    .restart local v3    # "keyPath":Ljava/io/File;
    .restart local v4    # "keyFile":Ljava/io/RandomAccessFile;
    :cond_79
    :try_start_79
    new-instance v0, Ljava/io/EOFException;

    invoke-direct {v0}, Ljava/io/EOFException;-><init>()V

    .end local p1    # "dataSpec":Lcom/google/android/exoplayer2/upstream/DataSpec;
    throw v0
    :try_end_7f
    .catch Ljava/io/IOException; {:try_start_79 .. :try_end_7f} :catch_7f

    .line 70
    .end local v1    # "path":Ljava/io/File;
    .end local v2    # "name":Ljava/lang/String;
    .end local v3    # "keyPath":Ljava/io/File;
    .end local v4    # "keyFile":Ljava/io/RandomAccessFile;
    .restart local p1    # "dataSpec":Lcom/google/android/exoplayer2/upstream/DataSpec;
    :catch_7f
    move-exception v0

    .line 71
    .local v0, "e":Ljava/io/IOException;
    new-instance v1, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource$EncryptedFileDataSourceException;

    invoke-direct {v1, v0}, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource$EncryptedFileDataSourceException;-><init>(Ljava/io/IOException;)V

    throw v1
.end method

.method public read([BII)I
    .registers 11
    .param p1, "buffer"    # [B
    .param p2, "offset"    # I
    .param p3, "readLength"    # I
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource$EncryptedFileDataSourceException;
        }
    .end annotation

    .line 82
    if-nez p3, :cond_4

    .line 83
    const/4 v0, 0x0

    return v0

    .line 84
    :cond_4
    iget-wide v0, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->bytesRemaining:J

    const-wide/16 v2, 0x0

    cmp-long v4, v0, v2

    if-nez v4, :cond_e

    .line 85
    const/4 v0, -0x1

    return v0

    .line 89
    :cond_e
    :try_start_e
    iget-object v2, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->file:Ljava/io/RandomAccessFile;

    int-to-long v3, p3

    invoke-static {v0, v1, v3, v4}, Ljava/lang/Math;->min(JJ)J

    move-result-wide v0

    long-to-int v1, v0

    invoke-virtual {v2, p1, p2, v1}, Ljava/io/RandomAccessFile;->read([BII)I

    move-result v0

    .line 90
    .local v0, "bytesRead":I
    iget-object v2, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->key:[B

    iget-object v3, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->iv:[B

    iget v6, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->fileOffset:I

    move-object v1, p1

    move v4, p2

    move v5, v0

    invoke-static/range {v1 .. v6}, Lim/tpelyyftgw/messenger/Utilities;->aesCtrDecryptionByteArray([B[B[BIII)V

    .line 91
    iget v1, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->fileOffset:I

    add-int/2addr v1, v0

    iput v1, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->fileOffset:I
    :try_end_2b
    .catch Ljava/io/IOException; {:try_start_e .. :try_end_2b} :catch_38

    .line 94
    nop

    .line 96
    if-lez v0, :cond_37

    .line 97
    iget-wide v1, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->bytesRemaining:J

    int-to-long v3, v0

    sub-long/2addr v1, v3

    iput-wide v1, p0, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->bytesRemaining:J

    .line 98
    invoke-virtual {p0, v0}, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource;->bytesTransferred(I)V

    .line 101
    :cond_37
    return v0

    .line 92
    .end local v0    # "bytesRead":I
    :catch_38
    move-exception v0

    .line 93
    .local v0, "e":Ljava/io/IOException;
    new-instance v1, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource$EncryptedFileDataSourceException;

    invoke-direct {v1, v0}, Lim/tpelyyftgw/messenger/secretmedia/EncryptedFileDataSource$EncryptedFileDataSourceException;-><init>(Ljava/io/IOException;)V

    throw v1
.end method