Major injector refactoring
This commit is contained in:
parent
55fd21feef
commit
a0e79dcea0
4
build.sh
4
build.sh
@ -13,12 +13,12 @@ rm -f jadeite.zip
|
|||||||
rm -rf out
|
rm -rf out
|
||||||
|
|
||||||
sh setup.sh --buildtype=release
|
sh setup.sh --buildtype=release
|
||||||
ninja -C build
|
meson compile -C build
|
||||||
|
|
||||||
mkdir out
|
mkdir out
|
||||||
|
|
||||||
cp ./build/injector/jadeite.exe ./out
|
cp ./build/injector/jadeite.exe ./out
|
||||||
cp ./build/injector/launcher_payload/launcher_payload.dll ./out
|
cp ./build/injector/launcher_payload.dll ./out
|
||||||
cp ./build/game_payload/game_payload.dll ./out
|
cp ./build/game_payload/game_payload.dll ./out
|
||||||
cp ./LICENSE.txt ./out
|
cp ./LICENSE.txt ./out
|
||||||
|
|
||||||
|
11
injector/include/inject.h
Normal file
11
injector/include/inject.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#define EPFX "__JADEITE_"
|
||||||
|
|
||||||
|
#define ENV_EXE_PATH EPFX"TARGET_EXE_PATH"
|
||||||
|
#define ENV_DLL_PATH EPFX"INJECT_DLL_PATH"
|
||||||
|
#define ENV_PROC_CMD EPFX"PROCESS_COMMAND"
|
||||||
|
|
||||||
|
void inject(HANDLE process, const void *payload, size_t payloadSize, const char *dllPath);
|
@ -1,21 +0,0 @@
|
|||||||
# Assemble the payload that will be injected into the game
|
|
||||||
l_payload_bin = asm_gen.process(
|
|
||||||
'src/payload.asm',
|
|
||||||
extra_args: [ str_include_dir ]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Embed it into the library
|
|
||||||
l_res_files = custom_target(
|
|
||||||
'lpayload.[oh]',
|
|
||||||
output: [ 'lpayload.o', 'lpayload.h' ],
|
|
||||||
input: [ l_payload_bin ],
|
|
||||||
command: [ gen_res, './injector/launcher_payload', '@OUTPUT0@', '@OUTPUT1@', '@INPUT@' ]
|
|
||||||
)
|
|
||||||
|
|
||||||
shared_library(
|
|
||||||
'launcher_payload',
|
|
||||||
'src/dll.c',
|
|
||||||
l_res_files,
|
|
||||||
include_directories: include_dir,
|
|
||||||
name_prefix: ''
|
|
||||||
)
|
|
@ -1,27 +1,48 @@
|
|||||||
include_dir = include_directories('include')
|
include_dir = include_directories('include')
|
||||||
str_include_dir = join_paths(meson.current_source_dir(), 'include')
|
str_include_dir = join_paths(meson.current_source_dir(), 'include')
|
||||||
|
|
||||||
# Assemble the payload that will be injected into the launcher
|
# Assemble the payloads
|
||||||
inj_payload_bin = asm_gen.process(
|
launcher_payload_bin = asm_gen.process(
|
||||||
'src/payload.asm',
|
'src/launcher_p.asm',
|
||||||
extra_args: [ str_include_dir ]
|
extra_args: [ '-i', str_include_dir ]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Embed it into the library
|
game_payload_bin = asm_gen.process(
|
||||||
inj_res_files = custom_target(
|
'src/game_p.asm',
|
||||||
'ipayload.[oh]',
|
extra_args: [ '-i', str_include_dir ]
|
||||||
output: [ 'ipayload.o', 'ipayload.h' ],
|
)
|
||||||
input: [ inj_payload_bin ],
|
|
||||||
|
# Embed them into .o files
|
||||||
|
exe_res_files = custom_target(
|
||||||
|
'launcher_p.[oh]',
|
||||||
|
output: [ 'launcher_p.o', 'launcher_p.h' ],
|
||||||
|
input: [ launcher_payload_bin ],
|
||||||
|
command: [ gen_res, './injector', '@OUTPUT0@', '@OUTPUT1@', '@INPUT@' ]
|
||||||
|
)
|
||||||
|
|
||||||
|
dll_res_files = custom_target(
|
||||||
|
'game_p.[oh]',
|
||||||
|
output: [ 'game_p.o', 'game_p.h' ],
|
||||||
|
input: [ game_payload_bin ],
|
||||||
command: [ gen_res, './injector', '@OUTPUT0@', '@OUTPUT1@', '@INPUT@' ]
|
command: [ gen_res, './injector', '@OUTPUT0@', '@OUTPUT1@', '@INPUT@' ]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Main injector exe
|
# Main injector exe
|
||||||
executable(
|
executable(
|
||||||
'jadeite',
|
'jadeite',
|
||||||
'src/injector.c',
|
'src/exe.c',
|
||||||
inj_res_files,
|
'src/inject.c',
|
||||||
|
exe_res_files,
|
||||||
include_directories: include_dir,
|
include_directories: include_dir,
|
||||||
name_prefix: ''
|
name_prefix: ''
|
||||||
)
|
)
|
||||||
|
|
||||||
subdir('launcher_payload')
|
# Dll that will be injected into the launcher
|
||||||
|
shared_library(
|
||||||
|
'launcher_payload',
|
||||||
|
'src/dll.c',
|
||||||
|
'src/inject.c',
|
||||||
|
dll_res_files,
|
||||||
|
include_directories: include_dir,
|
||||||
|
name_prefix: ''
|
||||||
|
)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <injshared.h>
|
#include <inject.h>
|
||||||
|
|
||||||
#include <lpayload.h>
|
#include <game_p.h>
|
||||||
|
|
||||||
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
|
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
|
||||||
// Only listen for attach
|
// Only listen for attach
|
||||||
@ -52,8 +52,8 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inject
|
// Inject
|
||||||
void *payloadStart = &_binary_lpayload_o_p_payload_bin_start;
|
void *payloadStart = &_binary_game_p_o_p_game_p_bin_start;
|
||||||
size_t payloadSize = (size_t)&_binary_lpayload_o_p_payload_bin_size;
|
size_t payloadSize = (size_t)&_binary_game_p_o_p_game_p_bin_size;
|
||||||
inject(pi.hProcess, payloadStart, payloadSize, injectDll);
|
inject(pi.hProcess, payloadStart, payloadSize, injectDll);
|
||||||
|
|
||||||
// Optional: wait for user input before resuming (useful for debugging)
|
// Optional: wait for user input before resuming (useful for debugging)
|
@ -1,8 +1,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <injshared.h>
|
#include <inject.h>
|
||||||
|
|
||||||
#include <ipayload.h>
|
#include <launcher_p.h>
|
||||||
|
|
||||||
const char LAUNCHER_INJECT_DLL[] = "launcher_payload.dll";
|
const char LAUNCHER_INJECT_DLL[] = "launcher_payload.dll";
|
||||||
const char GAME_INJECT_DLL[] = "game_payload.dll";
|
const char GAME_INJECT_DLL[] = "game_payload.dll";
|
||||||
@ -108,8 +108,8 @@ int main(int argc, char **argv) {
|
|||||||
printf("Started launcher process (%ld)\n", pi.dwProcessId);
|
printf("Started launcher process (%ld)\n", pi.dwProcessId);
|
||||||
|
|
||||||
// Inject
|
// Inject
|
||||||
void *payloadStart = &_binary_ipayload_o_p_payload_bin_start;
|
void *payloadStart = &_binary_launcher_p_o_p_launcher_p_bin_start;
|
||||||
size_t payloadSize = (size_t)&_binary_ipayload_o_p_payload_bin_size; // yes this is valid
|
size_t payloadSize = (size_t)&_binary_launcher_p_o_p_launcher_p_bin_size; // yes this is valid
|
||||||
inject(pi.hProcess, payloadStart, payloadSize, launcherPayloadPath);
|
inject(pi.hProcess, payloadStart, payloadSize, launcherPayloadPath);
|
||||||
|
|
||||||
// Resume the process
|
// Resume the process
|
@ -63,7 +63,7 @@ main: ; Replacement entry point
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
%include "gpa.inc"
|
%include "gpa.asm"
|
||||||
|
|
||||||
|
|
||||||
; Strings
|
; Strings
|
@ -1,10 +1,4 @@
|
|||||||
#include <windows.h>
|
#include <inject.h>
|
||||||
|
|
||||||
#define EPFX "__JADEITE_"
|
|
||||||
|
|
||||||
const char ENV_EXE_PATH[] = EPFX"TARGET_EXE_PATH";
|
|
||||||
const char ENV_DLL_PATH[] = EPFX"INJECT_DLL_PATH";
|
|
||||||
const char ENV_PROC_CMD[] = EPFX"PROCESS_COMMAND";
|
|
||||||
|
|
||||||
static inline void write_protected_process_memory(HANDLE process, void *address, const void *buf, size_t size) {
|
static inline void write_protected_process_memory(HANDLE process, void *address, const void *buf, size_t size) {
|
||||||
DWORD oldProtect;
|
DWORD oldProtect;
|
||||||
@ -16,8 +10,8 @@ static inline void write_protected_process_memory(HANDLE process, void *address,
|
|||||||
VirtualProtectEx(process, address, size, oldProtect, &oldProtect);
|
VirtualProtectEx(process, address, size, oldProtect, &oldProtect);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void inject(HANDLE process, const void *payload, size_t payloadSize, const char *dllPath) {
|
void inject(HANDLE process, const void *payload, size_t payloadSize, const char *dllPath) {
|
||||||
size_t _;
|
size_t _; // Contrary to the docs, {Write,Read}ProcessMemory likes to crash if the last arg is NULL
|
||||||
|
|
||||||
// Inject the loader into the module
|
// Inject the loader into the module
|
||||||
size_t dllPathLen = strlen(dllPath) + 1;
|
size_t dllPathLen = strlen(dllPath) + 1;
|
@ -28,7 +28,7 @@ main: ; Replacement entry point
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
%include "gpa.inc"
|
%include "gpa.asm"
|
||||||
|
|
||||||
|
|
||||||
; Strings
|
; Strings
|
@ -8,7 +8,7 @@ asm_gen = generator(
|
|||||||
nasm,
|
nasm,
|
||||||
output: '@BASENAME@.bin',
|
output: '@BASENAME@.bin',
|
||||||
arguments: [
|
arguments: [
|
||||||
'-i', '@EXTRA_ARGS@',
|
'@EXTRA_ARGS@',
|
||||||
'-f', 'bin',
|
'-f', 'bin',
|
||||||
'@INPUT@',
|
'@INPUT@',
|
||||||
'-o', '@OUTPUT@'
|
'-o', '@OUTPUT@'
|
||||||
|
Loading…
Reference in New Issue
Block a user