mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
Feat: add inject-via-java-api example with JNI refactor
- Rename JNI class from InjectorNative to Injector in libinject.c - Add JNI header for cn.xiaozhou233.juiceagent.injector.Injector - Add inject-via-java-api example with HowToUse.txt and 如何使用.txt
This commit is contained in:
1 parent
32e9199d4a
commit
a1b0eb8b84
14 files changed
+391
-8
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import cn.xiaozhou233.juiceagent.injector.Injector;
|
||||
import cn.xiaozhou233.juiceagent.injector.WindowInfo;
|
||||
|
||||
import java.util.Scanner;
|
||||
import java.io.File;
|
||||
|
||||
public class JavaInjector {
|
||||
public static void main(String[] args) {
|
||||
// Load the native library
|
||||
System.load(new File("./libinject.dll").getAbsolutePath());
|
||||
|
||||
// Find windows by title
|
||||
for (WindowInfo window : Injector.findWindowsByTitle("cmd")) {
|
||||
System.out.println(window.toString());
|
||||
}
|
||||
System.out.println("----------------");
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
// Input
|
||||
System.out.println("PID: ");
|
||||
String pid = scanner.nextLine();
|
||||
System.out.println("Dll: ");
|
||||
String dll = scanner.nextLine();
|
||||
System.out.println("config_path: ");
|
||||
String config_path = scanner.nextLine();
|
||||
|
||||
if (config_path == null || config_path.isEmpty()) {
|
||||
// config_path is empty
|
||||
Injector.inject(Integer.parseInt(pid), dll);
|
||||
} else {
|
||||
Injector.inject(Integer.parseInt(pid), dll, config_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,51 @@
|
||||
@echo off
|
||||
setlocal
|
||||
|
||||
set "OUT=out"
|
||||
set "JAR=JuiceAgent-JavaInjector-1.0-SNAPSHOT.jar"
|
||||
set "TMP=tmp_jar"
|
||||
|
||||
if not exist "%JAR%" (
|
||||
echo Error: %JAR% not found. Please restore the original jar.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if exist "%OUT%" rmdir /s /q "%OUT%"
|
||||
if exist "%TMP%" rmdir /s /q "%TMP%"
|
||||
|
||||
mkdir "%OUT%"
|
||||
mkdir "%TMP%"
|
||||
|
||||
javac -encoding UTF-8 --release 8 -cp "%JAR%" -d "%OUT%" JavaInjector.java
|
||||
if errorlevel 1 goto :error
|
||||
|
||||
rem Extract existing jar (contains Injector/WindowInfo classes) into temp dir
|
||||
rem -J-XX:-UsePerfData prevents JVM from creating locked hsperfdata files in CWD
|
||||
pushd "%TMP%"
|
||||
jar -J-XX:-UsePerfData xf "..\%JAR%"
|
||||
popd
|
||||
if errorlevel 1 goto :error
|
||||
|
||||
rem Remove any hsperfdata folder that may have leaked into the jar
|
||||
for /d %%D in ("%TMP%\hsperfdata_*") do rmdir /s /q "%%D"
|
||||
|
||||
rem Merge compiled JavaInjector.class into temp dir
|
||||
copy /y "%OUT%\JavaInjector.class" "%TMP%\JavaInjector.class" >nul
|
||||
if errorlevel 1 goto :error
|
||||
|
||||
rem Repackage with Main-Class
|
||||
jar -J-XX:-UsePerfData --create --file "%JAR%" --main-class JavaInjector -C "%TMP%" .
|
||||
if errorlevel 1 goto :error
|
||||
|
||||
rmdir /s /q "%OUT%"
|
||||
rmdir /s /q "%TMP%"
|
||||
|
||||
echo Build succeeded: %JAR%
|
||||
goto :end
|
||||
|
||||
:error
|
||||
echo Build failed.
|
||||
exit /b 1
|
||||
|
||||
:end
|
||||
endlocal
|
||||
Reference in new issue
Block a user