• 【安卓学习之常见问题】jar文件中Class转java文件不准(不同软件打开的class文件不一样)


    █ jar文件中Class转java文件不准


    █ 系列文章目录

    提示:这里是收集了和文件分享有关的文章

    █ 文章目录


    █ 读前说明

    • 本文通过学习别人写demo,学习一些课件,参考一些博客,’学习相关知识,如果涉及侵权请告知
    • 本文只简单罗列相关的代码实现过程
    • 涉及到的逻辑以及说明也只是简单介绍,主要当做笔记,了解过程而已    

    █ 问题

    • SDK开发时,里面里面有依赖第三方库时,集成时,也需要外围再重新依赖一次

    • 如果我们直接将依赖的jar文件转成java文件保存进去,这样别人集成时就不需要再去依赖

    • jar文件里面都是class文件,怎么转java文件

    █ 解决问题

    • 使用jad命令将文件夹下的class文件转成java文件:
    Jad -d D:\Temp\com\ftdi\j2xx\protocol -sjava com\ftdi\j2xx\protocol\*.class
    
    • 1
    • 用工具打开jar文件后,将一个一个文件代码复制拷贝出来

    >>>>不同工具打开的class文件长不一样

    █ 异常问题(d2xx.jar-ProcessInCtrl.class-processBulkInData()):

    • 使用android studio打开d2xx.jar-ProcessInCtrl.class-processBulkInData()):
      在这里插入图片描述
        public void processBulkInData(InBuffer inBuffer) throws D2xxException {
            int bufSize = false;// 这个语法明显有问题
            short signalEvents = 0;
            short signalLineEvents = 0;
            boolean signalRxChar = false;
            。。。。。。
       }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 使用jd-gui-windows-1.4.0打开:

    在这里插入图片描述

     public void processBulkInData(InBuffer inBuffer)
        throws D2xxManager.D2xxException
      {
        int bufSize = 0;
        short signalEvents = 0;
        short signalLineEvents = 0;
        boolean signalRxChar = false;
        。。。。。。
       }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 使用jad.exe生成后再打开:

    在这里插入图片描述

        public void processBulkInData(InBuffer inBuffer)
            throws D2xxManager.D2xxException
        {
            int bufSize;
            short signalEvents;
            short signalLineEvents;
            boolean signalRxChar;
            bufSize = 0;
            signalEvents = 0;
            signalLineEvents = 0;
            signalRxChar = false;
            bufSize = inBuffer.getLength();
       }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    >>>>可以看出三种不同打开方式的代码都不一样

    • 此外jar文件也是可能引导安卓库:
    import android.support.v4.content.LocalBroadcastManager;
    // import androidx.localbroadcastmanager.content.LocalBroadcastManager;
    
    • 1
    • 2
    dependencies {
    	classpath 'androidx.legacy:legacy-support-v4:1.0.0'
    }
    
    • 1
    • 2
    • 3

    在这里插入图片描述

    █ 1.代码混淆打包成aar文件后,MySDKManager.kt 文件(可看到实现方法):

    • MySDKManager.kt 文件,原文件,使用AS打开:
    object MySDKManager {
    
        /**
         * 初始化App相关,在使用SDK各组件之前初始化context信息
         */
        fun initApp(application: Application): MySDKManager {
            XXXSDK.getInstance().initSDK(null, null)
            return this
        }
    
        /**
         * 连接上SDK
         */
        val isConnectedSDK: Boolean
            get() = XXXSDK.getInstance().isConnectedSDK
    
        /**
         * 开始连接 SDK
         */
        fun connectSDK(): Boolean {
            return XXXSDK.getInstance().connectSDK()
        }
    
        /**
         * 断开 SDK
         */
        fun disconnectSDK() {
            XXXSDK.getInstance().disconnectSDK()
        }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    在这里插入图片描述

    • MySDKManager.kt 文件,混淆后文件,使用AS打开:
    public object MySDKManager {
        public final val isConnectedSDK: kotlin.Boolean /* compiled code */
    
        public final fun connectSDK(): kotlin.Boolean { /* compiled code */ }
    
        public final fun disconnectSDK(): kotlin.Unit { /* compiled code */ }
    
        public final fun initApp(application: android.app.Application): com.xxx.xxx.MySDKManager { /* compiled code */ }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    在这里插入图片描述

    • MySDKManager.kt 文件,混淆后文件,使用jd-gui-windows-1.4.0打开:
    public final class MySDKManager{
      @NotNull
      public static final MySDKManager INSTANCE = new MySDKManager();
      
      @NotNull
      public final MySDKManager initApp(@NotNull Application application){
        Intrinsics.checkNotNullParameter(application, "application");d.e().a(null, null);
        return this;
      }
      
      public final boolean isConnectedSDK(){
        return d.e().f();
      }
      
      public final boolean connectSDK(){
        return d.e().a();
      }
      
      public final void disconnectSDK(){
        d.e().c();
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    在这里插入图片描述

    █ 2.代码混淆打包成aar文件后,MyClient.kt 文件(可看到实现方法):

    • MyClient.kt 文件,原文件,使用AS打开:
    class MyClient {
        private var mVideoView: XXXVideoSurface? = null//
        private var mConnectHelper: ConnectHelper? = null// 连接
    
        /**
         * 初始化View
         */
        fun initView(videoView: XXXVideoSurface?): MyClient {
            mVideoView = videoView
            mVideoView?.init()
            return this
        }
    
        /**
         * 打开连接
         */
        fun openConnection(): MyClient {
            mConnectHelper = ConnectHelper()
            mConnectHelper?.initConnection()
            return this
        }
    
        /**
         * 关闭连接
         */
        fun closeConnected(): MyClient {
            mConnectHelper?.closeConnected()
            mConnectHelper = null
            return this
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    在这里插入图片描述

    • MyClient .kt 文件,混淆后文件,使用AS打开:
    public final class MyClient public constructor() {
        private final var mConnectHelper: com.xxx.xxx.ConnectHelper? /* compiled code */
    
        private final var mVideoView: XXXVideoSurface? /* compiled code */
    
        public final fun closeConnected(): com.xxx.xxx.MyClient { /* compiled code */ }
    
        public final fun initView(videoView: XXXVideoSurface?): com.xxx.xxx.MyClient { /* compiled code */ }
    
        public final fun openConnection(): com.xxx.xxx.MyClient { /* compiled code */ }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    在这里插入图片描述

    • MyClient .kt 文件,混淆后文件,使用jd-gui-windows-1.4.0打开:
    public final class MyClient {
      @Nullable
      private XXXVideoSurface a;
      @Nullable
      private ConnectHelper b;
      
      @NotNull
      public final MyClient initView(@Nullable XXXVideoSurface videoView) {
        this.a = videoView;
        if (videoView != null) {
          videoView.init();
        }
        return this;
      }
      
      @NotNull
      public final MyClient openConnection()  {
        ConnectHelper tmp3_0 = new com/xxx/xxx/ConnectHelper;
        ConnectHelper localConnectHelper;
        (localConnectHelper = tmp3_0).<init>();this.b = localConnectHelper;
        if (tmp3_0 != null) {
          localConnectHelper.initConnection();
        }
        return this;
      }
      
      @NotNull
      public final MyClient closeConnected()  {
        ConnectHelper localConnectHelper;
        if ((localConnectHelper = this.b) != null) {
          localConnectHelper.closeConnected();
        }
        this.b = null;
        return this;
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    在这里插入图片描述

    █ 3.代码混淆打包成aar文件后,MyClient.kt 文件(带线程,看不到实现方法):

    • MyClient.kt 文件,原文件,使用AS打开:
    class MyClient {
        private var mVideoView: XXXVideoSurface? = null//
        private var mConnectHelper: ConnectHelper? = null// 连接
    
        /**
         * 初始化View
         */
        fun initView(videoView: XXXVideoSurface?): MyClient {
            mVideoView = videoView
            mVideoView?.init()
            return this
        }
    
        /**
         * 打开连接
         */
        fun openConnection(): MyClient {
            mConnectHelper = ConnectHelper()
            mConnectHelper?.initConnection()
            Thread(Runnable { Log.e("Thread","Thread start") }).start() // 重点
            return this
        }
    
        /**
         * 关闭连接
         */
        fun closeConnected(): MyClient {
            mConnectHelper?.closeConnected()
            mConnectHelper = null
            return this
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    在这里插入图片描述

    • MyClient .kt 文件,混淆后文件,使用AS打开:
    public final class MyClient public constructor() {
        private final var mConnectHelper: com.xxx.xxx.ConnectHelper? /* compiled code */
    
        private final var mVideoView: XXXVideoSurface? /* compiled code */
    
        public final fun closeConnected(): com.xxx.xxx.MyClient { /* compiled code */ }
    
        public final fun initView(videoView: XXXVideoSurface?): com.xxx.xxx.MyClient { /* compiled code */ }
    
        public final fun openConnection(): com.xxx.xxx.MyClient { /* compiled code */ }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    在这里插入图片描述

    • MyClient .kt 文件,混淆后文件,使用jd-gui-windows-1.4.0打开:
    // INTERNAL ERROR //
    
    • 1

    在这里插入图片描述

    █ 出现INTERNAL ERROR 后,使用luyten打开(可看到实现方法):

    • MyClient .kt 文件,混淆后文件,使用luyten-0.5.4.exe打开:
    public final class MyClient  {
        @Nullable
        private XXXVideoSurface a;
        @Nullable
        private ConnectHelper b;
        
        private static final void a() {
            Log.e("Thread", "Thread start");
        }
        
        @NotNull
        public final MyClient initView(@Nullable final XXXVideoSurface videoView) {
            this.a = videoView;
            if (videoView != null) {
                videoView.init();
            }
            return this;
        }
        
        @NotNull
        public final MyClient openConnection() {
            final ConnectHelper b;
            final ConnectHelper connectHelper = b = new ConnectHelper();
            this.b = b;
            if (connectHelper != null) {
                b.initConnection();
            }
            new Thread(MyClient::a).start();
            return this;
        }
        
        @NotNull
        public final MyClient closeConnected() {
            final ConnectHelper b;
            if ((b = this.b) != null) {
                b.closeConnected();
            }
            this.b = null;
            return this;
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42

    █ 相关资料

    提示:这里是参考的相关文章

    1. class文件太大 或者方法过多:jd-gui反编译报错// INTERNAL ERROR //_super wheat的博客-CSDN博客
    2. 安装Java反编译工具Luyten(Windows例)_RunFromHere的博客-CSDN博客_luyten

    █ 免责声明

    博主分享的所有文章内容,部分参考网上教程,引用大神高论,部分亲身实践,记下笔录,内容可能存在诸多不实之处,还望海涵,本内容仅供学习研究使用,切勿用于商业用途,若您是部分内容的作者,不喜欢此内容被分享出来,可联系博主说明相关情况通知删除,感谢您的理解与支持!

    转载请注明出处:
    https://blog.csdn.net/ljb568838953/article/details/126834000

  • 相关阅读:
    Edge Linux 正式版发布
    手写一个简单的Spring容器(原理+源码)
    vue 和 后端交互
    基于555定时器的LED电子骰子设计
    浅谈数据中心新型末端母线配电系统-Susie 周
    npm的基础
    MBR与GPT分区表
    赚麻了!!!
    LVI-SAM:配置环境、安装测试、适配自己采集数据集
    无代码和低代码平台:程序员的竞争优势
  • 原文地址:https://blog.csdn.net/ljb568838953/article/details/127408046