Java 代码混淆工具 Allatori

大家都知道Java 编译为class 后可以通过反编译工具再编译为Java 文件.
常用的反编译工具:idea,jd,jad

如果,不希望别人看到自己人源代码,要怎么做?
在JavaScript 中可以通过压缩代码,代码混淆来避免.Java 里也有类似的工具.

allatori

用于将已有代码混淆,防止反编译.

工作原理:

读取 jar 文件,对其代码按照XML 中的配置进行重写.如:字符串替换,代码改写为内部类等等

maven方式代码:

pom.xml

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-and-filter-allatori-config</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${basedir}/lib</directory>
                                    <includes>
                                        <include>allatori.xml</include>
                                    </includes>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Running Allatori -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>run-allatori</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>java</executable>
                    <arguments>
                        <argument>-Xms128m</argument>
                        <argument>-Xmx512m</argument>
                        <argument>-jar</argument>

                        <!-- Copy allatori.jar to 'allatori' directory to use the commented line -->
                        <argument>${basedir}/lib/allatori.jar</argument>
                        <!-- <argument>${basedir}/allatori/allatori.jar</argument> -->

                        <argument>${basedir}/target/allatori.xml</argument>
                    </arguments>
                </configuration>
            </plugin>

配置文件:

<config>
    <input>
        <jar in="my-allatori.jar" out="my-allatori-encrypt.jar"/>
    </input>

    <keep-names>
        <class access="protected+">
            <field access="protected+"/>
            <method access="protected+"/>
        </class>
    </keep-names>

    <property name="log-file" value="log.xml"/>
</config>

混淆前代码:

混淆后代码:

注意事项:

  • 重写会改变类名,可以在配置文件中控制是否保持类名,以及重写完类名是否影响代码运行.
  • 需要测试,保证代码的重写不会影响使用

更多文档:

http://www.allatori.com/doc.html

转载于:https://my.oschina.net/zhouxiang/blog/3101854

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值