首页
社区
课程
招聘
[求助]smali 混淆代码还原问题
发表于: 2015-6-22 17:36 10065

[求助]smali 混淆代码还原问题

2015-6-22 17:36
10065
小弟逆了一个smali里面的反法 想找牛人帮忙看看 是不是逆的不对 因为结果有问题是一个AES的加密算法smali 如下: 这个算法我用了之后发现和app里面加密结果不一样 所以应该是逆错了 但是我又不知道哪里错了。。。。

    .locals 10
    .annotation build Landroid/annotation/SuppressLint;
        value = {
            "TrulyRandom"
        }
    .end annotation

    const/4 v0, 0x0

    const/4 v1, 0x0

    :try_start_0
    array-length v3, p3

    invoke-static {p0}, Ljavax/crypto/Cipher;->getInstance(Ljava/lang/String;)Ljavax/crypto/Cipher;

    move-result-object v4

    const/4 v2, 0x1

    invoke-virtual {v4, v2, p1, p2}, Ljavax/crypto/Cipher;->init(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;)V

    invoke-virtual {v4}, Ljavax/crypto/Cipher;->getBlockSize()I

    move-result v2

    array-length v5, p3

    rem-int/2addr v5, v2

    sub-int v5, v2, v5

    array-length v2, p3

    add-int/2addr v2, v5

    new-array v6, v2, [B

    const/4 v2, 0x0

    const/4 v7, 0x0

    array-length v8, p3

    invoke-static {p3, v2, v6, v7, v8}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V

    move v2, v1

    :goto_0
    if-ge v2, v5, :cond_0

    array-length v7, p3

    add-int/2addr v7, v2

    const-string v8, "0"

    invoke-virtual {v8}, Ljava/lang/String;->getBytes()[B

    move-result-object v8

    const/4 v9, 0x0

    aget-byte v8, v8, v9

    aput-byte v8, v6, v7

    add-int/lit8 v2, v2, 0x1

    goto :goto_0

    :cond_0
    array-length v2, v6

    sub-int/2addr v2, v3

    add-int/lit8 v2, v2, 0x10

    new-instance v3, Ljava/lang/StringBuilder;

    const-string v5, "00000000000000"

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

    invoke-static {v2}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v2

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

    move-result-object v2

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

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/String;->getBytes()[B

    move-result-object v3

    array-length v5, v6

    if-eqz v3, :cond_4

    array-length v1, v3

    move v2, v1

    :goto_1
    add-int v1, v5, v2

    if-lez v1, :cond_3

    add-int v1, v5, v2

    new-array v1, v1, [B

    :goto_2
    if-lez v5, :cond_1

    const/4 v7, 0x0

    const/4 v8, 0x0

    invoke-static {v6, v7, v1, v8, v5}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V

    :cond_1
    if-lez v2, :cond_2

    const/4 v6, 0x0

    invoke-static {v3, v6, v1, v5, v2}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V

    :cond_2
    invoke-virtual {v4, v1}, Ljavax/crypto/Cipher;->doFinal([B)[B
    :try_end_0
    .catch Ljava/security/NoSuchAlgorithmException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljavax/crypto/NoSuchPaddingException; {:try_start_0 .. :try_end_0} :catch_1
    .catch Ljava/security/InvalidKeyException; {:try_start_0 .. :try_end_0} :catch_2
    .catch Ljava/security/InvalidAlgorithmParameterException; {:try_start_0 .. :try_end_0} :catch_3
    .catch Ljavax/crypto/IllegalBlockSizeException; {:try_start_0 .. :try_end_0} :catch_4
    .catch Ljavax/crypto/BadPaddingException; {:try_start_0 .. :try_end_0} :catch_5

    move-result-object v0

    :goto_3
    return-object v0

    :catch_0
    move-exception v1

    const-string v2, "AES"

    new-instance v3, Ljava/lang/StringBuilder;

    const-string v4, "AES~~~"

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

    invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v1

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

    move-result-object v1

    invoke-static {v2, v1}, Lcom/bilin/huijiao/g/v;->d(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_3

    :catch_1
    move-exception v1

    const-string v2, "AES"

    new-instance v3, Ljava/lang/StringBuilder;

    const-string v4, "AES~~~"

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

    invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v1

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

    move-result-object v1

    invoke-static {v2, v1}, Lcom/bilin/huijiao/g/v;->d(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_3

    :catch_2
    move-exception v1

    const-string v2, "AES"

    new-instance v3, Ljava/lang/StringBuilder;

    const-string v4, "AES~~~"

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

    invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v1

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

    move-result-object v1

    invoke-static {v2, v1}, Lcom/bilin/huijiao/g/v;->d(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_3

    :catch_3
    move-exception v1

    const-string v2, "AES"

    new-instance v3, Ljava/lang/StringBuilder;

    const-string v4, "AES~~~"

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

    invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v1

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

    move-result-object v1

    invoke-static {v2, v1}, Lcom/bilin/huijiao/g/v;->d(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_3

    :catch_4
    move-exception v1

    const-string v2, "AES"

    new-instance v3, Ljava/lang/StringBuilder;

    const-string v4, "AES~~~"

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

    invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v1

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

    move-result-object v1

    invoke-static {v2, v1}, Lcom/bilin/huijiao/g/v;->d(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_3

    :catch_5
    move-exception v1

    const-string v2, "AES"

    new-instance v3, Ljava/lang/StringBuilder;

    const-string v4, "AES~~~"

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

    invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v1

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

    move-result-object v1

    invoke-static {v2, v1}, Lcom/bilin/huijiao/g/v;->d(Ljava/lang/String;Ljava/lang/String;)V

    goto/16 :goto_3

    :cond_3
    move-object v1, v0

    goto/16 :goto_2

    :cond_4
    move v2, v1

    goto/16 :goto_1
Java 代码:
    private byte[] a(String paramString,
                    SecretKey paramSecretKey,
                    IvParameterSpec paramIvParameterSpec,
                    byte[] paramArrayOfByte)
    {
          try
          {
                int i2 = 0;
                byte[] arrayOfByte3 = null;
            int i = paramArrayOfByte.length;
            Cipher localCipher = Cipher.getInstance(paramString);
            localCipher.init(1, paramSecretKey, paramIvParameterSpec);
            int j = localCipher.getBlockSize();
            int k = j - (paramArrayOfByte.length % j);
            byte[] arrayOfByte1 = new byte[k + paramArrayOfByte.length];
            System.arraycopy(paramArrayOfByte, 0, arrayOfByte1, 0, paramArrayOfByte.length);
            for (int m = 0; m <k; m++) {
                    arrayOfByte1[(m + paramArrayOfByte.length)] = "0".getBytes()[0];
                        }
            int n = 16 + (arrayOfByte1.length - i);
            StringBuilder stringBuilder = new StringBuilder("00000000000000");
            stringBuilder.append(String.valueOf(n));
            byte[] arrayOfByte2 = (stringBuilder.toString()).getBytes();
            int i1 = arrayOfByte1.length;
            byte[] arrayOfByte4;
            if (arrayOfByte2 != null){
                    if (i1 + i2 > 0)
                            arrayOfByte3 = new byte[i1 + i2];
                    if (i1 > 0)
                    System.arraycopy(arrayOfByte1, 0, arrayOfByte3, 0, i1);
                if (i2 > 0)
                    System.arraycopy(arrayOfByte2, 0, arrayOfByte3, i1, i2);
                arrayOfByte4 = localCipher.doFinal(arrayOfByte3);
                return arrayOfByte4;
            }
            i2 = arrayOfByte2.length;
            return null;
          }
          catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
          {
            System.out.println("AES~~~" + localNoSuchAlgorithmException);
            return null;
          }
          catch (NoSuchPaddingException localNoSuchPaddingException)
          {
                System.out.println("AES~~~" + localNoSuchPaddingException);
            return null;
          }
          catch (InvalidKeyException localInvalidKeyException)
          {
                System.out.println("AES~~~" + localInvalidKeyException);
            return null;
          }
          catch (InvalidAlgorithmParameterException localInvalidAlgorithmParameterException)
          {
                System.out.println("AES~~~" + localInvalidAlgorithmParameterException);
            return null;
          }
          catch (IllegalBlockSizeException localIllegalBlockSizeException)
          {
                System.out.println("AES~~~" + localIllegalBlockSizeException);
            return null;
          }
          catch (BadPaddingException localBadPaddingException)
          {
                System.out.println("AES~~~" + localBadPaddingException);
            return null;
          }
        }

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (9)
雪    币: 13
活跃值: (30)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
没人 知道吗?
2015-6-22 21:40
0
雪    币: 13
活跃值: (30)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
求各位大大帮忙看看
2015-6-23 07:19
0
雪    币: 12388
活跃值: (3825)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
知道两个加密码SecretKey paramSecretKey,
        IvParameterSpec paramIvParameterSpec是什么吗?
2015-6-23 08:59
0
雪    币: 13
活跃值: (30)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
知道这些信息都有
2015-6-23 09:06
0
雪    币: 13
活跃值: (30)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
它app里面使用的是pbe+aes的方式
2015-6-23 10:34
0
雪    币: 233
活跃值: (285)
能力值: ( LV12,RANK:270 )
在线值:
发帖
回帖
粉丝
7
关键是你怎么用的。很多时候可能是因为编码不同造成的结果不一样。
所以建议你先用Java还原这段代码,进行测试看看是否正确。
2015-6-23 10:40
0
雪    币: 13
活跃值: (30)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
对啊~我就是还原了~但是我发现app里面结果跟我的不一样,编码问题?能不能详细说说?
2015-6-23 12:05
0
雪    币: 13
活跃值: (30)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
求解惑
2015-6-25 22:50
0
雪    币: 13
活跃值: (30)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
自问自答吧~加出来了~但是密文还不是完全一样但是可以解出来了,但是我又发现了一个问题另一个参数加密的时候用了so 晕死
2015-6-30 11:47
0
游客
登录 | 注册 方可回帖
返回
//