阅读 135

代码混淆工具Allatori7.7配置和使用

背景

工作中Allatori6.1的版本存在一些问题, 混淆效果差, 正则支持存在一些缺陷, 到7.7版本的时候这些问题得到了改善, 官网的版本是非商用版, 可用于教育和个人学习

混淆效果对比

测试代码

import java.time.LocalDateTime;
public class Demo {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        System.out.println("date print" + now);
    }

    private Object timePrivate() {
        LocalDateTime now = LocalDateTime.now();
        System.out.println("date print" + now);
        return now;
    }

    private Object timePublic() {
        System.out.println(timePrivate());
        LocalDateTime now = LocalDateTime.now();
        System.out.println("date print" + now);
        return now;
    }
}

从下图的对比来看, 混淆的效果相差非常大, 7.7版本无疑更加优秀


6.1混淆效果

7.7混淆效果

maven插件配置

    <build>
        <finalName>allatori_demo</finalName>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>run-allatori</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includePluginDependencies>true</includePluginDependencies>
                    <executable>java</executable>
                    <arguments>
                        <argument>-jar</argument>
                        <argument>${build.outputDirectory}/allatori.jar</argument>
                        <argument>${build.outputDirectory}/allatori.xml</argument>
                    </arguments>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

工具配置

在任意目录放入allatori.jarallatori.xml, jar包可以从 官网下载 后解压出来, 文档的使用也有详细的说明

配置结构
allatori.xml
<config>
    <input>
        <jar in="../allatori_demo.jar" out="../obf-allatori_demo.jar"/>
    </input>
    <keep-names>
        <class template="class * instanceof java.io.Serializable"/>
        <class access="protected+">
            <field access="protected+"/>
            <method access="protected+"/>
        </class>
    </keep-names>
    <ignore-classes>
        <!--    以com.code1开头的类不进行混淆    -->
        <class template="class regex:^(?!com.code1).*"/>
    </ignore-classes>
    <property name="line-numbers" value="keep"/>
</config>

加上正则的忽略配置后, 相同的一份代码放在不同的路径, 可以更直观的对比处混淆的效果

对比

运行Idea中maven的package命令, 会生成obf-allatori_demo.jar, 便可查看包中混淆后的效果

作者:清蒸三文鱼_

原文链接:https://www.jianshu.com/p/6ba6585e5f58

文章分类
后端
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐