{"id":14979957,"url":"https://github.com/hydraxman/hibeaver","last_synced_at":"2025-04-04T13:13:50.878Z","repository":{"id":50301511,"uuid":"64758317","full_name":"hydraxman/hibeaver","owner":"hydraxman","description":"HiBeaver is a gradle plugin for java byte code manipulation and AOP design by modifying project byte code during build of the package, or modifying byte code within Jar independently.","archived":false,"fork":false,"pushed_at":"2022-12-27T04:05:31.000Z","size":906,"stargazers_count":706,"open_issues_count":15,"forks_count":90,"subscribers_count":64,"default_branch":"master","last_synced_at":"2025-03-28T12:09:44.338Z","etag":null,"topics":["aop","bytecode","gradle","java"],"latest_commit_sha":null,"homepage":"","language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hydraxman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-02T13:17:00.000Z","updated_at":"2025-03-27T05:41:22.000Z","dependencies_parsed_at":"2023-01-31T02:31:20.724Z","dependency_job_id":null,"html_url":"https://github.com/hydraxman/hibeaver","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hydraxman%2Fhibeaver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hydraxman%2Fhibeaver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hydraxman%2Fhibeaver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hydraxman%2Fhibeaver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hydraxman","download_url":"https://codeload.github.com/hydraxman/hibeaver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247182420,"owners_count":20897381,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aop","bytecode","gradle","java"],"created_at":"2024-09-24T14:01:00.286Z","updated_at":"2025-04-04T13:13:50.854Z","avatar_url":"https://github.com/hydraxman.png","language":"Groovy","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/BryanSharp/hibeaver.svg?branch=master)](https://travis-ci.org/BryanSharp/hibeaver)[ ![Download](https://api.bintray.com/packages/bsp0911932/maven/HiBeaver/images/download.svg) ](https://bintray.com/bsp0911932/maven/HiBeaver/_latestVersion) [![Gitter](https://badges.gitter.im/hibeaver/Lobby.svg)](https://gitter.im/hibeaver/Lobby?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\n# HiBeaver\n\n[Java字节码修改神器HiBeaver：黑掉你的SDK](https://segmentfault.com/a/1190000008491823)\n\n![cute animals always busy in building their river dam](https://github.com/BryanSharp/hibeaver/blob/master/beaver.jpeg?raw=true)\n\n### 简介\n\nHiBeaver是一个用于进行Java字节码插桩的Gradle插件，可以用来:\n\n1.修改Jar文件内部的代码实现，注入逻辑（同时还支持对Android的aar文件进行修改）。\n\n2.实现Java轻量级AOP设计，支持Android Gradle Plugin。\n\n结合强大的Java ASM字节码修改工具和Gradle Transform API，HiBeaver可以实现在Android应用编译阶段，依据使用者的配置，对工程内所包含的Java字节码进行修改，从而支持使用者仅通过Gradle配置对字节码进行代码注入和AOP设计，或对项目依赖的Jar包内的代码增加Hook节点。\n\n从1.2.7版本开始，HiBeaver不再依赖于Android编译插件，可以在Gradle环境下独立运行，随心所欲地修改Jar/Aar文件内的代码逻辑。\n\nBeaver，即河狸，是一种日日忙碌于在自己栖息河流上修建和装修大坝的可爱小动物。河狸的堤坝虽说不上像三峡那样“高峡出平湖”，却也为自然和生态做出了暖男般的贡献。\n\n### 快速上手\n\n该插件已经上传到Jcenter,可直接引用最新版本如下：\n\n    classpath 'com.bryansharp:hibeaver:1.2.7'\n\n在1.2.7及以上的版本中，hibeaverModifyFiles任务不再依赖Android的gradle插件，也就是说只要你有gradle和Java运行环境，建一个build.gradle就可以指定Jar/Aar文件进行修改了。详见testJarModify目录下的示例。\n\n[Link to Jcenter](https://bintray.com/bsp0911932/maven/HiBeaver)\n\n然后在工程的build.gradle里加入如下片段（或通过其他.gradle引入）：\n\n```groovy\n    apply plugin: 'hiBeaver'\n    import com.bryansharp.gradle.hibeaver.utils.MethodLogAdapter\n    import org.objectweb.asm.ClassVisitor\n    import org.objectweb.asm.MethodVisitor\n    import org.objectweb.asm.Opcodes\n    //or you can import like bellow:\n    //import org.objectweb.asm.*\n    hiBeaver {\n        //下面这个参数仅仅影响log输出，为本次修改命名，无实际意义，不配置也可以\n        hiBeaverModifyName = 'myHibeaverTest'\n        //设置为true可以显示帮助内容，默认为true\n        showHelp = true\n        //keepQuiet默认为false,为true时不会有字节码修改的log输出，建议为false\n        keepQuiet = false\n        //下面的参数设置为true时会输出工程编译耗时信息\n        watchTimeConsume = false\n        \n        //重头戏是配置下面的参数：modifyMatchMaps\n        //基础配置结构形如： ['class':[[:],[:]],'class':[[:],[:]]], 类型是 Map\u003cString, List\u003cMap\u003cString, Object\u003e\u003e\u003e\n        modifyMatchMaps = [\n                //此处可以进行模糊匹配，!表示排除，!android*即表示排除掉android开头的全类名。\n                //|符号不完全表示或，而仅仅是匹配的分隔符。*表示任意长度（\u003e0）的任意字符\n                '*Activity|*Receiver|!android*'             : [\n                        //methodDesc设置为空代表对methodDesc不进行限制\n                        //方法名也可以用模糊匹配 用javap -s 命令来查看类中方法的description\n                        ['methodName': 'on**', 'methodDesc': null, 'adapter': {\n                            ClassVisitor cv, int access, String name, String desc, String signature, String[] exceptions -\u003e\n                                MethodVisitor methodVisitor = cv.visitMethod(access, name, desc, signature, exceptions);\n                                MethodVisitor adapter = new MethodLogAdapter(methodVisitor) {\n                                    @Override\n                                    void visitCode() {\n                                        super.visitCode();\n                                        methodVisitor.visitLdcInsn(desc);\n                                        methodVisitor.visitLdcInsn(name);\n                                      //下面这行代码 为要调用的方法，请酌情修改\n                                        methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, \n                                            \"bruce/com/testhibeaver/MainActivity\", \n                                                \"hookXM\", \"(Ljava/lang/Object;Ljava/lang/Object;)V\");\n                                    }\n                                }\n                                return adapter;\n                        }]\n                ]\n                ,\n                //此处以r:开头，代表正则表达式匹配模式\n                'r:.*D[a-zA-Z]*Client'              : [\n                        ['methodName': 'on**', 'methodDesc': null, 'adapter': {\n                            ClassVisitor cv, int access, String name, String desc, String signature, String[] exceptions -\u003e\n                                MethodVisitor methodVisitor = cv.visitMethod(access, name, desc, signature, exceptions);\n                                MethodVisitor adapter = new MethodLogAdapter(methodVisitor) {\n                                    @Override\n                                    void visitCode() {\n                                        super.visitCode();\n                                    }\n                                }\n                                return adapter;\n                        }]\n                ]\n        ]\n        //下面为对Jar或Aar进行单独修改的配置，执行hibeaverModifyFiles的Gradle任务来对路径所指向的文件进行修改，\n        //产出物在build/HiBeaver目录下\n        modifyTasks = [\"${rootDir.absolutePath}/submodule/app/libs/MiPush_SDK_Client_3_2_2.jar\": modifyMatchMaps]\n    }\n```\n\n本repo项目中还包含一个submodule，里面有本插件的demo，可以使用git submodule来进行初始化，然后在项目根目录加入settings.gradle并编辑（include ':submodule:app'）来包含这个子项目（是一个app demo）。\n\n玩的愉快！有任何问题和bug请提issue，欢迎参与到本项目的完善中！\n\n## English Version\n\nBy applying the regular expression and wildcard features, HiBeaver now has been upgraded to a Java lightweight AOP design tool.\n\nBeaver means 河狸 in Chinese, cute animals always busy in building their cute river dam.\n\nBasically, HiBeaver is a Gradle plugin for modifying your java byte code.\n\nThis plugin has been uploaded to jcenter. You can use this by adding the following code to your buildScripts:\n\n```groovy\n    classpath 'com.bryansharp:HiBeaver:1.2.7'\n```\n\n[Link to Jcenter](https://bintray.com/bsp0911932/maven/HiBeaver)\n\nand then add this to you app build scripts:\n\n```groovy\n    import com.bryansharp.gradle.hibeaver.utils.MethodLogAdapter\n    import org.objectweb.asm.ClassVisitor\n    import org.objectweb.asm.MethodVisitor\n    import org.objectweb.asm.Opcodes\n    //or you can import like bellow:\n    //import org.objectweb.asm.*\n    hiBeaver {\n        //this will determine the name of this hibeaver transform, no practical use.\n        hiBeaverModifyName = 'myHibeaverTest'\n        //turn this on to make it print help content, default value is true\n        showHelp = true\n        //this flag will decide whether the log of the modifying process be printed or not, default value is false\n        keepQuiet = false\n        //this is a kit feature of the plugin, set it true to see the time consume of this build\n        watchTimeConsume = false\n\n        //this is the most important part\n        //basic structure is like ['class':[[:],[:]],'class':[[:],[:]]], type is Map\u003cString, List\u003cMap\u003cString, Object\u003e\u003e\u003e\n        //advanced structure is like: ['classMatchPattern':['classMatchType':'wildcard','modifyMethods':[[:],[:]]],'classMatchPattern':['classMatchType':'regEx','modifyMethods':[[:],[:]]]]\n        modifyMatchMaps = [\n                //this is the basic version\n                'classname of which to be modified': [\n                        // you can use javap -s command to get the description of one method\n                        // the adapter is a closure\n                        ['methodName': 'the name of the method', 'methodDesc': 'javap -s to get the description', 'adapter': {\n                            //the below args cannot be changed, to copy them entirely with nothing changed is recommended\n                            ClassVisitor cv, int access, String name, String desc, String signature, String[] exceptions -\u003e\n                                //return null to modify nothing\n                                return null;\n                        }]\n                        ,\n                        ['methodName': 'the name of the method2', 'methodDesc': 'javap -s to get the description', 'adapter': {\n                            ClassVisitor cv, int access, String name, String desc, String signature, String[] exceptions -\u003e\n                                return null;\n                        }]\n                ]\n                ,\n                //the latter ones are advanced cases\n                '*Activity'                       : [\n                        //the value of classMatchType can either be one of the three: all,regEx,wildcard\n                        //default value is all\n                        'classMatchType': 'wildcard',\n                        'modifyMethods' : [\n                                //methodMatchType会同时对methodName和methodDesc的匹配生效\n                                //methodDesc设置为空代表对methodDesc不进行限制\n                                ['methodName': 'on**', 'methodMatchType': 'wildcard', 'methodDesc': null, 'adapter': {\n                                    ClassVisitor cv, int access, String name, String desc, String signature, String[] exceptions -\u003e\n                                        MethodVisitor methodVisitor = cv.visitMethod(access, name, desc, signature, exceptions);\n                                        MethodVisitor adapter = new MethodLogAdapter(methodVisitor) {\n                                            @Override\n                                            void visitCode() {\n                                                super.visitCode();\n                                                methodVisitor.visitLdcInsn(desc);\n                                                methodVisitor.visitLdcInsn(name);\n                                                methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, \"bruce/com/testhibeaver/MainActivity\", \"hookXM\", \"(Ljava/lang/Object;Ljava/lang/Object;)V\");\n                                            }\n                                        }\n                                        return adapter;\n                                }]\n                        ]\n                ]\n                ,\n                '.*D[a-zA-Z]*Receiver'                       : [\n                        'classMatchType': 'regEx',\n                        'modifyMethods' : [\n                                ['methodName': 'on**', 'methodMatchType': 'wildcard', 'methodDesc': null, 'adapter': {\n                                    ClassVisitor cv, int access, String name, String desc, String signature, String[] exceptions -\u003e\n                                        MethodVisitor methodVisitor = cv.visitMethod(access, name, desc, signature, exceptions);\n                                        MethodVisitor adapter = new MethodLogAdapter(methodVisitor) {\n                                            @Override\n                                            void visitCode() {\n                                                super.visitCode();\n                                                methodVisitor.visitLdcInsn(desc);\n                                                methodVisitor.visitLdcInsn(name);\n                                                methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, \"bruce/com/testhibeaver/MainActivity\", \"hookXM\", \"(Ljava/lang/Object;Ljava/lang/Object;)V\");\n                                            }\n                                        }\n                                        return adapter;\n                                }]\n                        ]\n                ]\n        ]\n    }\n```\n\nYou can also see the content above in the build log outputs.\n\nThere is also a demo showing how to use it. You can either get it through git submodule and add a settings.gradle file to include the module, or get it by checking out [hiBeaverDemo](https://github.com/BryanSharp/hiBeaverDemo).\n\nHope you can enjoy it! Any comment and suggestion is welcomed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhydraxman%2Fhibeaver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhydraxman%2Fhibeaver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhydraxman%2Fhibeaver/lists"}