+
Skip to content

增加方便使用的功能 #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@
</compilerArguments>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>io.xjar.XJar</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/xjar/XInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.loadkit.Resource;
import org.apache.commons.compress.archivers.jar.JarArchiveEntry;
import org.apache.commons.compress.archivers.jar.JarArchiveOutputStream;
import org.apache.commons.compress.utils.Sets;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -18,6 +19,9 @@
* 2018/11/25 10:34
*/
public class XInjector {

public static HashSet<String> ignoreClass = Sets.newHashSet("io/xjar/XInjector.class", "io/xjar/XGo.class",
"io/xjar/XJar.class");

/**
* 往JAR包中注入XJar框架的classes
Expand All @@ -31,6 +35,9 @@ public static void inject(JarArchiveOutputStream zos) throws IOException {
while (resources.hasMoreElements()) {
Resource resource = resources.nextElement();
String name = resource.getName();
if (ignoreClass.contains(name)) {
continue;
}
String directory = name.substring(0, name.lastIndexOf('/') + 1);
if (directories.add(directory)) {
JarArchiveEntry xDirEntry = new JarArchiveEntry(directory);
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/io/xjar/XJar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.xjar;

public class XJar {

public static void main(String[] args) throws Exception {
String sourceJar = System.getProperty("xjar.source");
if (stringIsEmpty(sourceJar)) {
System.err.println("请使用-Dxjar.source系统属性指定要加密的jar包。");
return;
}
String destJar = System.getProperty("xjar.dest");
if (stringIsEmpty(destJar)) {
System.err.println("请使用-Dxjar.dest系统属性指定加密后的jar包。");
return;
}
String password = System.getProperty("xjar.password");
if (stringIsEmpty(password)) {
System.err.println("请使用-Dxjar.password系统属性指定加密秘钥,长度小于256字节。");
return;
}
String algorithm = System.getProperty("xjar.algorithm");
String keysize = System.getProperty("xjar.keysize");
String ivsize = System.getProperty("xjar.ivsize");
String include = System.getProperty("xjar.include");
String exclude = System.getProperty("xjar.exclude");
XEncryption encryption = XCryptos.encryption().from(sourceJar);
if (stringIsEmpty(algorithm) || stringIsEmpty(keysize) || stringIsEmpty(ivsize)) {
encryption = encryption.use(password);
}
else {
encryption = encryption.use(algorithm, Integer.parseInt(keysize), Integer.parseInt(ivsize), password);
}
if (!stringIsEmpty(include)) {
encryption = encryption.include(include);
}
if (!stringIsEmpty(exclude)) {
encryption = encryption.exclude(exclude);
}
System.out.println("正在进行加密操作,请稍候...");
encryption.to(destJar);
}

private static boolean stringIsEmpty(String str) {
return str == null || str.trim().length() <= 0;
}

}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载