mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 21:15:53 +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
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user