【Android 安全】DEX 加密 ( Proguard 混淆 | 将混淆后的报错信息转为原始报错信息 | retrace.bat 命令执行目录 | 暴露更少信息 )


更多 ProGuard 混淆配置参考 : https://www.guardsquare.com/en/products/proguard/manual/usage





一、将混淆后的报错信息转为原始报错信息



前提 : proguard-rules.pro 混淆配置中配置保留行数 ;

# 保留行数
-keepattributes SourceFile,LineNumberTable

混淆后的报错信息 :

2020-11-10 12:01:59.426 28142-28142/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: kim.hsl.handler, PID: 28142
    java.lang.RuntimeException: Unable to start activity ComponentInfo{kim.hsl.handler/kim.hsl.handler.MainActivity}: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3897)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:219)
        at android.app.ActivityThread.main(ActivityThread.java:8349)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
     Caused by: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
        at b.a.a.a.<init>(Handler.java:30)
        at kim.hsl.handler.MainActivity.onCreate(MainActivity.kt:24)
        at android.app.Activity.performCreate(Activity.java:8085)
        at android.app.Activity.performCreate(Activity.java:8073)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3870)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473) 
        at android.os.Handler.dispatchMessage(Handler.java:110) 
        at android.os.Looper.loop(Looper.java:219) 
        at android.app.ActivityThread.main(ActivityThread.java:8349) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055) 

将上述混淆后的报错信息 , 保存到 bug.txt 文件中 , 放在 app\build\outputs\mapping\debug 目录里 ;

Sdk\tools\proguard\bin 中找到 retrace.bat 工具 ;

在这里插入图片描述

使用上述 retrace.bat 命令 , 通过 Proguard 混淆映射文件 mapping.txt , 还原被混淆过的 报错信息 ;

进入 D:\001_Programs\001_Android\002_Sdk\Sdk\tools\proguard\lib 目录 , 然后在该目录执行上述命令 ;

D:\001_Programs\001_Android\002_Sdk\Sdk\tools\proguard\bin\retrace.bat -verbose D:\002_Project\002_Android_Learn\Handler\app\build\outputs\mapping\debug\mapping.txt D:\002_Project\002_Android_Learn\Handler\app\build\outputs\mapping\debug\bug.txt

一定要注意 , 必须在 D:\001_Programs\001_Android\002_Sdk\Sdk\tools\proguard\lib 目录中执行该命令 ;

还原结果 :

D:\001_Programs\001_Android\002_Sdk\Sdk\tools\proguard\lib>D:\001_Programs\001_Android\002_Sdk\Sdk\tools\proguard\bin\retrace.bat -verbose D:\002_Project\002_Android_Learn\Handler\app\build\outputs\mapping\debug\mapping.txt D:\002_Project\002_Android_Learn\Handler\app\build\outputs\mapping\debug\bug.txt
2020-11-10 12:01:59.426 28142-28142/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: kim.hsl.handler, PID: 28142
    java.lang.RuntimeException: Unable to start activity ComponentInfo{kim.hsl.handler/kim.hsl.handler.MainActivity}: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3897)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:219)
        at android.app.ActivityThread.main(ActivityThread.java:8349)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
     Caused by: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
        at kim.hsl.handler.Handler.void <init>()(Handler.java:30)
        at kim.hsl.handler.MainActivity.void onCreate(android.os.Bundle)(MainActivity.kt:24)
        at android.app.Activity.performCreate(Activity.java:8085)
        at android.app.Activity.performCreate(Activity.java:8073)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3870)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076)聽
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)聽
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)聽
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)聽
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)聽
        at android.os.Handler.dispatchMessage(Handler.java:110)聽
        at android.os.Looper.loop(Looper.java:219)聽
        at android.app.ActivityThread.main(ActivityThread.java:8349)聽
        at java.lang.reflect.Method.invoke(Native Method)聽
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)聽
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)聽

D:\001_Programs\001_Android\002_Sdk\Sdk\tools\proguard\lib>

在这里插入图片描述





二、retrace.bat 命令执行目录



必须在 D:\001_Programs\001_Android\002_Sdk\Sdk\tools\proguard\lib 目录中执行 retrace.bat 命令 , 如果在别的目录会报下面的错误 ;

Error: Unable to access jarfile ..\lib\retrace.jar




三、暴露更少信息



使用以下配置 , 可以暴露更少信息 ;

-renamesourcefileattribute H

完整配置如下 :

# 保留行数
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute H

报错信息如下 :

2020-11-10 12:15:41.634 29988-29988/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: kim.hsl.handler, PID: 29988
    java.lang.RuntimeException: Unable to start activity ComponentInfo{kim.hsl.handler/kim.hsl.handler.MainActivity}: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3897)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:219)
        at android.app.ActivityThread.main(ActivityThread.java:8349)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
     Caused by: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
        at b.a.a.a.<init>(H:30)
        at kim.hsl.handler.MainActivity.onCreate(H:24)
        at android.app.Activity.performCreate(Activity.java:8085)
        at android.app.Activity.performCreate(Activity.java:8073)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3870)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473) 
        at android.os.Handler.dispatchMessage(Handler.java:110) 
        at android.os.Looper.loop(Looper.java:219) 
        at android.app.ActivityThread.main(ActivityThread.java:8349) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055) 

使用 -renamesourcefileattribute H 配置 前后对比对比 :

之前报错时 , 会将 Handler 暴露出来 ;

     Caused by: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
        at b.a.a.a.<init>(Handler.java:30)
        at kim.hsl.handler.MainActivity.onCreate(MainActivity.kt:24)

使用 -renamesourcefileattribute H 配置后 , 报错信息如下 :

     Caused by: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
        at b.a.a.a.<init>(H:30)
        at kim.hsl.handler.MainActivity.onCreate(H:24)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值