【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)
已标记关键词 清除标记
之前程序测试的时候能正常运行,现在加了点内容几个类,就报错了。!!! 具体错误如下; 04-09 00:25:55.687 8058-8058/com.samuel.schat W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40e2b258) 04-09 00:25:55.703 8058-8058/com.samuel.schat E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NullPointerException at android.widget.ListView.setupChild(ListView.java:1817) at android.widget.ListView.makeAndAddView(ListView.java:1795) at android.widget.ListView.fillDown(ListView.java:676) at android.widget.ListView.fillFromTop(ListView.java:736) at android.widget.ListView.layoutChildren(ListView.java:1637) at android.widget.AbsListView.onLayout(AbsListView.java:1924) at android.view.View.layout(View.java:11315) at android.view.ViewGroup.layout(ViewGroup.java:4314) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925) at android.view.View.layout(View.java:11315) at android.view.ViewGroup.layout(ViewGroup.java:4314) at android.widget.FrameLayout.onLayout(FrameLayout.java:431) at android.view.View.layout(View.java:11315) at android.view.ViewGroup.layout(ViewGroup.java:4314) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1633) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1491) at android.widget.LinearLayout.onLayout(LinearLayout.java:1404) at android.view.View.layout(View.java:11315) at android.view.ViewGroup.layout(ViewGroup.java:4314) at android.widget.FrameLayout.onLayout(FrameLayout.java:431) at android.view.View.layout(View.java:11315) at android.view.ViewGroup.layout(ViewGroup.java:4314) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1625) at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2642) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4624) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:965) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:732) at dalvik.system.NativeStart.main(Native Method)
©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页