mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
feat: add Injector module with Gradle build pipeline
- Add Injector subproject with JuiceAgent integration - Add build pipeline: cleanTmp, buildInjection, packInjection, buildAll - OrangeX shadowJar outputs to out/tmp/, Injector to out/ - packInjection bundles natives, resources and OrangeX.jar into injection.zip - Thanks to StaR4y (https://github.com/StaR4y) for contributing part of the Injector implementation
This commit is contained in:
1 parent
80307f6edc
commit
e854031e83
9 files changed
+214
-3
No files matched your search
Generated
+1
@@ -9,6 +9,7 @@
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/Injector" />
|
||||
<option value="$PROJECT_DIR$/Minecraft-1.8.8" />
|
||||
<option value="$PROJECT_DIR$/OrangeX" />
|
||||
</set>
|
||||
|
||||
Generated
+17
@@ -0,0 +1,17 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Run Injector" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="cn.xiaozhou233.orangex.injector.Main" />
|
||||
<module name="OrangeX-Client.Injector.main" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/out" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="cn.xiaozhou233.orangex.injector.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
<option name="RunConfigurationTask" enabled="true" run_configuration_name="OrangeX-Client [buildAll]" run_configuration_type="GradleRunConfiguration" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -0,0 +1,20 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id "com.gradleup.shadow" version "8.3.9"
|
||||
}
|
||||
|
||||
group = 'cn.xiaozhou233.orangex.injector'
|
||||
version = 'unspecified'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation files("libraries/JuiceAgent-JavaInjector-1.0-SNAPSHOT.jar")
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveFileName = 'Injector.jar'
|
||||
destinationDirectory = rootProject.layout.projectDirectory.dir('out')
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,38 @@
|
||||
package cn.xiaozhou233.orangex.injector;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
public static void unzip(InputStream zipInputStream, File destDir) throws IOException {
|
||||
if (!destDir.exists()) {
|
||||
destDir.mkdirs(); // 创建目标目录
|
||||
}
|
||||
|
||||
try (ZipInputStream zipIn = new ZipInputStream(zipInputStream)) {
|
||||
ZipEntry entry;
|
||||
while ((entry = zipIn.getNextEntry()) != null) {
|
||||
File outFile = new File(destDir, entry.getName());
|
||||
if (entry.isDirectory()) {
|
||||
outFile.mkdirs(); // 创建目录
|
||||
} else {
|
||||
File parent = outFile.getParentFile();
|
||||
if (!parent.exists()) {
|
||||
parent.mkdirs(); // 创建父目录
|
||||
}
|
||||
|
||||
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outFile))) {
|
||||
byte[] buffer = new byte[4096];
|
||||
int read;
|
||||
while ((read = zipIn.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
}
|
||||
zipIn.closeEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* OrangeX Injector
|
||||
* Thanks to StaR4y (https://github.com/StaR4y) for contributing part of the Injector implementation.
|
||||
*/
|
||||
|
||||
package cn.xiaozhou233.orangex.injector;
|
||||
|
||||
import cn.xiaozhou233.juiceagent.injector.Injector;
|
||||
import cn.xiaozhou233.juiceagent.injector.WindowInfo;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
public class Main {
|
||||
public static String orangexPath = System.getProperty("user.home") + "/.orangex";
|
||||
public static void main(String[] args) {
|
||||
System.out.println("OrangeX Injector");
|
||||
|
||||
int pid = -1;
|
||||
|
||||
System.out.println("Unzip injection.zip to " + orangexPath);
|
||||
|
||||
File zipFile = new File("injection.zip");
|
||||
|
||||
if (!zipFile.exists()) {
|
||||
System.err.println("injection.zip not found in runtime directory!");
|
||||
return;
|
||||
}
|
||||
|
||||
try (InputStream zipStream = new FileInputStream(zipFile)) {
|
||||
FileUtils.unzip(zipStream, new File(orangexPath));
|
||||
System.out.println("Done!");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Load Native Library
|
||||
System.load(orangexPath + "/libinject.dll");
|
||||
|
||||
// Find Minecraft
|
||||
ArrayList<Integer> pids = new ArrayList<>();
|
||||
ArrayList<String> windowTitles = new ArrayList<>();
|
||||
try {
|
||||
String[] titles = {"Minecraft", "minecraft", "1.8.9", "Badlion", "Lunar"};
|
||||
String[] ignoreTitles = {"Badlion Client", "Badlion Chat", "Home - Lunar Client"};
|
||||
for (String title : titles) {
|
||||
WindowInfo[] list = Injector.findWindowsByTitle(title);
|
||||
if (list == null || list.length == 0) {
|
||||
} else {
|
||||
for (WindowInfo w : list) {
|
||||
if (pids.contains(w.pid))
|
||||
continue;
|
||||
if (Arrays.stream(ignoreTitles).anyMatch(w.title::contains))
|
||||
continue;
|
||||
pids.add(w.pid);
|
||||
windowTitles.add(w.title);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
throw new RuntimeException("Native method findWindowsByTitle not available", ule);
|
||||
} catch (Exception ex) {
|
||||
System.out.println("[ERROR] Error while calling native findWindowsByTitle: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
// Print the result
|
||||
System.out.println("=======================");
|
||||
for (int i = 0; i < pids.size(); i++) {
|
||||
System.out.printf("[ %d ] %s (PID: %d)%n", i + 1, windowTitles.get(i), pids.get(i));
|
||||
}
|
||||
System.out.println("=======================");
|
||||
|
||||
if (pids.isEmpty()) {
|
||||
System.out.println("[ERROR] No Minecraft process found!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Input the sequence number
|
||||
try (Scanner scanner = new Scanner(System.in)) {
|
||||
System.out.printf("[INPUT] Select (1-%d): ", pids.size());
|
||||
int index = scanner.nextInt();
|
||||
if (index < 1 || index > pids.size()) {
|
||||
throw new RuntimeException("Invalid selection: " + index);
|
||||
}
|
||||
pid = pids.get(index - 1);
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Invalid input", e);
|
||||
}
|
||||
|
||||
// Inject
|
||||
String agentPath = orangexPath + "/libloader.dll";
|
||||
String configDir = orangexPath;
|
||||
Injector.inject(pid, agentPath, configDir);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,5 +17,5 @@ dependencies {
|
||||
|
||||
shadowJar {
|
||||
archiveFileName = 'OrangeX.jar'
|
||||
destinationDirectory = rootProject.layout.projectDirectory.dir('out/temp')
|
||||
}
|
||||
destinationDirectory = rootProject.layout.projectDirectory.dir('out/tmp')
|
||||
}
|
||||
+30
-1
@@ -2,16 +2,45 @@ plugins {
|
||||
id 'lifecycle-base'
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Variables
|
||||
// ============================
|
||||
def outDir = layout.projectDirectory.dir("out")
|
||||
def tmpDir = layout.projectDirectory.dir("out/tmp")
|
||||
|
||||
tasks.register("cleanTmp", Delete) {
|
||||
delete tmpDir
|
||||
}
|
||||
|
||||
tasks.register("buildInjection", Copy) {
|
||||
outputs.upToDateWhen { false }
|
||||
|
||||
dependsOn(
|
||||
project(':OrangeX').tasks.named('shadowJar')
|
||||
tasks.named("cleanTmp"),
|
||||
project(':OrangeX').tasks.named('shadowJar'),
|
||||
project(':Injector').tasks.named('shadowJar')
|
||||
)
|
||||
|
||||
from(rootProject.layout.projectDirectory.dir('natives'))
|
||||
from(rootProject.layout.projectDirectory.dir('resources'))
|
||||
into(tmpDir)
|
||||
}
|
||||
|
||||
tasks.register("packInjection", Zip) {
|
||||
group = 'build'
|
||||
description = 'Package all files from tmp into injection.zip'
|
||||
|
||||
dependsOn(tasks.named("buildInjection"))
|
||||
|
||||
destinationDirectory.set(outDir)
|
||||
archiveFileName.set("injection.zip")
|
||||
|
||||
from(tmpDir)
|
||||
}
|
||||
|
||||
tasks.register("buildAll") {
|
||||
dependsOn(tasks.named("buildInjection"))
|
||||
dependsOn(tasks.named("packInjection"))
|
||||
|
||||
doFirst {
|
||||
println("Building OrangeX-Client...")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
rootProject.name = 'OrangeX-Client'
|
||||
include 'Minecraft-1.8.8'
|
||||
include 'OrangeX'
|
||||
include 'Injector'
|
||||
|
||||
Reference in new issue
Block a user