mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
Feat: Add Injector and injection packaging
- Add Injector module, built to out/injector.jar - Add packageAll chain producing out/injection.zip from out/tmp - Copy resources and natives into out/tmp with a flat layout
This commit is contained in:
1 parent
60baa8d1ef
commit
faa84b14d0
9 files changed
+256
-3
No files matched your search
Generated
+1
@@ -8,6 +8,7 @@
|
|||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
|
<option value="$PROJECT_DIR$/Injector" />
|
||||||
<option value="$PROJECT_DIR$/Loader" />
|
<option value="$PROJECT_DIR$/Loader" />
|
||||||
<option value="$PROJECT_DIR$/Minecraft1.8.8" />
|
<option value="$PROJECT_DIR$/Minecraft1.8.8" />
|
||||||
<option value="$PROJECT_DIR$/OrangeX" />
|
<option value="$PROJECT_DIR$/OrangeX" />
|
||||||
|
|||||||
Generated
+17
@@ -0,0 +1,17 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="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 [packageAll]" run_configuration_type="GradleRunConfiguration" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'cn.xiaozhou233.orangex.injector'
|
||||||
|
version = 'unspecified'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation platform('org.junit:junit-bom:5.10.0')
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('jar') {
|
||||||
|
destinationDirectory = rootProject.layout.projectDirectory.dir('out')
|
||||||
|
archiveFileName = 'injector.jar'
|
||||||
|
manifest {
|
||||||
|
attributes 'Main-Class': 'cn.xiaozhou233.orangex.injector.Main'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package cn.xiaozhou233.juiceagent.injector;
|
||||||
|
|
||||||
|
public class Injector {
|
||||||
|
/*
|
||||||
|
* @param pid process id
|
||||||
|
* @param path libinject path
|
||||||
|
*/
|
||||||
|
public native static boolean inject(int pid, String path);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param pid process id
|
||||||
|
* @param path libinject path
|
||||||
|
* @param configDir config directory
|
||||||
|
*/
|
||||||
|
public native static boolean inject(int pid, String path, String configDir);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param keyword window title keyword
|
||||||
|
* @return windows with title containing keyword
|
||||||
|
*/
|
||||||
|
public static native WindowInfo[] findWindowsByTitle(String keyword);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package cn.xiaozhou233.juiceagent.injector;
|
||||||
|
|
||||||
|
public class WindowInfo {
|
||||||
|
public String title;
|
||||||
|
public int pid;
|
||||||
|
|
||||||
|
public WindowInfo(String title, int pid) {
|
||||||
|
this.title = title;
|
||||||
|
this.pid = pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("Title: %-30s | PID: %d", title, pid);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package cn.xiaozhou233.orangex.injector;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
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(Files.newOutputStream(outFile.toPath()))) {
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int read;
|
||||||
|
while ((read = zipIn.read(buffer)) != -1) {
|
||||||
|
bos.write(buffer, 0, read);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zipIn.closeEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
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 = new File(System.getProperty("user.home") + "/.orangex").getAbsolutePath();
|
||||||
|
private static int pid = -1;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("================");
|
||||||
|
System.out.println("OrangeX Injector v1.0.0");
|
||||||
|
System.out.println("OrangeX Path: " + orangexPath);
|
||||||
|
System.out.println("================");
|
||||||
|
|
||||||
|
// Unzip injection
|
||||||
|
File zipFile = new File("./injection.zip");
|
||||||
|
if (!zipFile.exists()) {
|
||||||
|
System.err.println("injection.zip not found!");
|
||||||
|
}
|
||||||
|
try (InputStream zipStream = new FileInputStream(zipFile)) {
|
||||||
|
FileUtils.unzip(zipStream, new File(orangexPath));
|
||||||
|
System.out.println("Done!");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load libinject native library
|
||||||
|
System.load(new File(orangexPath + "/libinject.dll").getAbsolutePath());
|
||||||
|
System.out.println("Loaded 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 results
|
||||||
|
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.err.println("[ERROR] No Minecraft process found!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
String agentPath = orangexPath + "/libloader.dll";
|
||||||
|
String configDir = orangexPath;
|
||||||
|
Injector.inject(pid, agentPath, configDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
-2
@@ -3,6 +3,9 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def outputDir = layout.projectDirectory.dir('out/tmp')
|
def outputDir = layout.projectDirectory.dir('out/tmp')
|
||||||
|
def distDir = layout.projectDirectory.dir('out')
|
||||||
|
def resourcesDir = layout.projectDirectory.dir('resources')
|
||||||
|
def nativesDir = layout.projectDirectory.dir('natives')
|
||||||
|
|
||||||
tasks.register('cleanOut') {
|
tasks.register('cleanOut') {
|
||||||
group = 'build'
|
group = 'build'
|
||||||
@@ -12,11 +15,39 @@ tasks.register('cleanOut') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register('packageAll') {
|
tasks.register('prepareInjection') {
|
||||||
group = 'build'
|
group = 'build'
|
||||||
description = 'Builds the shaded Loader and OrangeX jars into out/tmp'
|
description = 'Copies resources and natives into out/tmp (both flattened)'
|
||||||
dependsOn cleanOut
|
dependsOn cleanOut
|
||||||
dependsOn ':Loader:shadowJar', ':OrangeX:shadowJar'
|
dependsOn ':Loader:shadowJar', ':OrangeX:shadowJar'
|
||||||
|
doLast {
|
||||||
|
copy {
|
||||||
|
from resourcesDir
|
||||||
|
into outputDir
|
||||||
|
exclude '**/.gitkeep'
|
||||||
|
}
|
||||||
|
copy {
|
||||||
|
from nativesDir
|
||||||
|
into outputDir
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register('injectionZip', Zip) {
|
||||||
|
group = 'build'
|
||||||
|
description = 'Zips out/tmp into out/injection.zip'
|
||||||
|
dependsOn prepareInjection
|
||||||
|
destinationDirectory = distDir
|
||||||
|
archiveFileName = 'injection.zip'
|
||||||
|
from outputDir
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register('packageAll') {
|
||||||
|
group = 'build'
|
||||||
|
description = 'Builds Loader, OrangeX and Injector, then zips out/tmp into out/injection.zip'
|
||||||
|
dependsOn cleanOut
|
||||||
|
dependsOn ':Loader:shadowJar', ':OrangeX:shadowJar', ':Injector:jar'
|
||||||
|
dependsOn injectionZip
|
||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
rootProject.name = 'OrangeX-Client'
|
rootProject.name = 'OrangeX-Client'
|
||||||
include 'Loader'
|
include 'Loader'
|
||||||
include 'OrangeX'
|
include 'OrangeX'
|
||||||
include 'Minecraft1.8.8'
|
include 'Injector'
|
||||||
|
include 'Minecraft1.8.8'
|
||||||
Reference in new issue
Block a user