Skip to content

Commit

Permalink
1、新增代码
Browse files Browse the repository at this point in the history
  • Loading branch information
290044632 committed Jan 12, 2021
1 parent 8943388 commit d2d82af
Show file tree
Hide file tree
Showing 3 changed files with 331 additions and 7 deletions.
126 changes: 119 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,121 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pegg.maven.plugin</groupId>
<artifactId>obfuscator-maven-plugin</artifactId>
<version>1.0.0</version>

<!-- <packaging>maven-plugin</packaging> -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pegg.maven.plugin</groupId>
<artifactId>obfuscator-maven-plugin</artifactId>
<version>1.0.0</version>

<packaging>maven-plugin</packaging>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.pluging.version>3.6.3</maven.pluging.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.pluging.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.pluging.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>${maven.pluging.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven.pluging.version}</version>
</dependency>
<dependency>
<groupId>me.superblaubeere27</groupId>
<artifactId>obfuscator-core</artifactId>
<version>1.9.3.1</version>
</dependency>

</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

</build>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<distributionManagement>
<repository>
<id>releases</id>
<name>Thirdparty Dev Repository</name>
<url>http://www.16uke.com:8081/nexus/content/repositories/3rd-party-dev/</url>
</repository>
</distributionManagement>
</profile>
<profile>
<id>prod</id>
<distributionManagement>
<repository>
<id>releases</id>
<name>Thirdparty Repository</name>
<url>http://www.16uke.com:8081/nexus/content/repositories/thirdparty/</url>
</repository>
</distributionManagement>
</profile>
</profiles>

</project>
119 changes: 119 additions & 0 deletions src/main/java/com/pegg/maven/plugin/mojo/ObfuscatorMojo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.pegg.maven.plugin.mojo;

import java.io.File;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import org.apache.maven.model.Build;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

import com.google.common.io.ByteStreams;

import me.superblaubeere27.jobf.JObfImpl;
import me.superblaubeere27.jobf.utils.values.ConfigManager;
import me.superblaubeere27.jobf.utils.values.Configuration;

@Mojo(name = "obfus")
public class ObfuscatorMojo extends AbstractMojo {

@Parameter(defaultValue = "${project}", readonly = true, required = true)
protected MavenProject mavenProject;

@Parameter(property = "inputJar")
private String inputJar;

@Parameter(property = "outputJar")
private String outputJar;

@Parameter(property = "scriptFile")
private File scriptFile;

@Parameter(property = "config")
private File configFile;

@Parameter(property = "threads")
private int threads;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

Log log = getLog();
log.info("Start Obfuscator......");

try {
Configuration configuration = null;
String config = null;
if (this.configFile != null && this.configFile.isFile() && this.configFile.exists()) {
config = new String(Files.readAllBytes(this.configFile.toPath()));
} else {
try (InputStream in = this.getClass().getResourceAsStream("default.conf.json")) {
config = new String(ByteStreams.toByteArray(in), StandardCharsets.UTF_8);
}
}
log.info("Obfuscator configuration......");
log.info(config);
configuration = ConfigManager.loadConfig(config);

boolean defaultFlag = false;
String inputJar = configuration.getInput();
if (isBlank(inputJar)) {
if (!(defaultFlag = isBlank(this.inputJar))) {
inputJar = this.inputJar;
}
}
String outputJar = configuration.getOutput();
if (isBlank(outputJar)) {
if (!(defaultFlag = isBlank(this.outputJar))) {
outputJar = this.outputJar;
}
}
if (defaultFlag) {
Build build = mavenProject.getBuild();
String outputDirectory = build.getDirectory();
String jarFinalName = build.getFinalName();
String jarPackaging = this.mavenProject.getPackaging();

if (isBlank(inputJar)) {
inputJar = outputDirectory + File.separator + jarFinalName + "." + jarPackaging;
configuration.setInput(inputJar);
}
if (isBlank(outputJar)) {
outputJar = outputDirectory + File.separator + jarFinalName + ".obfus." + jarPackaging;
configuration.setOutput(outputJar);
}
}
log.info("InputJar: " + inputJar);
log.info("OutputJar: " + outputJar);

String script = null;
if (null != this.scriptFile && this.scriptFile.isFile() && this.scriptFile.exists()) {
script = new String(Files.readAllBytes(this.scriptFile.toPath()));
if (isBlank(script)) {
configuration.setScript(script);
}
}

if (this.threads > 0 && this.threads <= Runtime.getRuntime().availableProcessors()) {
JObfImpl.INSTANCE.setThreadCount(threads);
}

JObfImpl.INSTANCE.processJar(configuration);

log.info("End Obfuscator......");
} catch (Exception e) {
log.error("Obfuscated file exception", e);
}
}

private boolean isBlank(String inputJar) {
return null == inputJar || inputJar.isEmpty();
}

}
93 changes: 93 additions & 0 deletions src/main/java/com/pegg/maven/plugin/mojo/default.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"input": "",
"output": "",
"script": "function isRemappingEnabledForClass(node) {\n return true;\n}\nfunction isObfuscatorEnabledForClass(node) {\n return true;\n}",
"libraries": [],
"Crasher": {
"Enabled": false,
"Invalid Signatures": true,
"Empty annotation spam": true
},
"InvokeDynamic": {
"Enabled": false
},
"HWIDPRotection": {
"Enabled": false,
"HWID": "BCFC6192310C342F40243A6CB3CE7388"
},
"Optimizer": {
"Enabled": false,
"Replace String.equals()": false,
"Replace String.equalsIgnoreCase()": false,
"Optimize static string calls": false
},
"LineNumberRemover": {
"Enabled": true,
"Rename local variables": true,
"Remove Line Numbers": true,
"Remove Debug Names": true,
"Add Local Variables": true,
"New SourceFile Name": ""
},
"StringEncryption": {
"Enabled": true,
"HideStrings": false,
"AES": false
},
"NumberObfuscation": {
"Enabled": true,
"Extract to Array": true,
"Obfuscate Zero": true,
"Shift": false,
"And": false,
"Multiple Instructions": true
},
"ReferenceProxy": {
"Enabled": false
},
"ShuffleMembers": {
"Enabled": true
},
"InnerClassRemover": {
"Enabled": true,
"Remap": false,
"Remove Metadata": true
},
"NameObfuscation": {
"Enabled": false,
"Excluded classes": "me.name.Class\nme.name.*\nio.netty.**",
"Excluded methods": "me.name.Class.method\nme.name.Class**\nme.name.Class.*",
"Excluded fields": "me.name.Class.field\nme.name.Class.*\nme.name.**",
"Package": false,
"New Packages": ""
},
"General Settings": {
"Generator characters": "Il",
"Custom dictionary": false,
"Class Name dictionary": "",
"Name dictionary": "",
"Use STORE instead of DEFLATE (For e.g. SpringBoot)": true
},
"Packager": {
"Enabled": false,
"Use MainClass from the JAR manifest": true,
"Main class": "org.example.Main"
},
"FlowObfuscator": {
"Enabled": true,
"Mangle Comparisons": true,
"Replace GOTO": true,
"Replace If": true,
"Bad POP": true,
"Bad Concat": true,
"Mangle Switches": false,
"Mangle Return": false,
"Mangle Local Variables": false
},
"HideMembers": {
"Enabled": true
},
"Inlining": {
"Enabled": false
}
}

0 comments on commit d2d82af

Please sign in to comment.