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
|
||||
|
||||
sh setup.sh --buildtype=release
|
||||
ninja -C build
|
||||
meson compile -C build
|
||||
|
||||
mkdir 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 ./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')
|
||||
str_include_dir = join_paths(meson.current_source_dir(), 'include')
|
||||
|
||||
# Assemble the payload that will be injected into the launcher
|
||||
inj_payload_bin = asm_gen.process(
|
||||
'src/payload.asm',
|
||||
extra_args: [ str_include_dir ]
|
||||
# Assemble the payloads
|
||||
launcher_payload_bin = asm_gen.process(
|
||||
'src/launcher_p.asm',
|
||||
extra_args: [ '-i', str_include_dir ]
|
||||
)
|
||||
|
||||
# Embed it into the library
|
||||
inj_res_files = custom_target(
|
||||
'ipayload.[oh]',
|
||||
output: [ 'ipayload.o', 'ipayload.h' ],
|
||||
input: [ inj_payload_bin ],
|
||||
game_payload_bin = asm_gen.process(
|
||||
'src/game_p.asm',
|
||||
extra_args: [ '-i', str_include_dir ]
|
||||
)
|
||||
|
||||
# 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@' ]
|
||||
)
|
||||
|
||||
# Main injector exe
|
||||
executable(
|
||||
'jadeite',
|
||||
'src/injector.c',
|
||||
inj_res_files,
|
||||
'src/exe.c',
|
||||
'src/inject.c',
|
||||
exe_res_files,
|
||||
include_directories: include_dir,
|
||||
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 <injshared.h>
|
||||
#include <inject.h>
|
||||
|
||||
#include <lpayload.h>
|
||||
#include <game_p.h>
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
|
||||
// Only listen for attach
|
||||
@ -52,8 +52,8 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
|
||||
}
|
||||
|
||||
// Inject
|
||||
void *payloadStart = &_binary_lpayload_o_p_payload_bin_start;
|
||||
size_t payloadSize = (size_t)&_binary_lpayload_o_p_payload_bin_size;
|
||||
void *payloadStart = &_binary_game_p_o_p_game_p_bin_start;
|
||||
size_t payloadSize = (size_t)&_binary_game_p_o_p_game_p_bin_size;
|
||||
inject(pi.hProcess, payloadStart, payloadSize, injectDll);
|
||||
|
||||
// Optional: wait for user input before resuming (useful for debugging)
|
@ -1,8 +1,8 @@
|
||||
#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 GAME_INJECT_DLL[] = "game_payload.dll";
|
||||
@ -108,8 +108,8 @@ int main(int argc, char **argv) {
|
||||
printf("Started launcher process (%ld)\n", pi.dwProcessId);
|
||||
|
||||
// Inject
|
||||
void *payloadStart = &_binary_ipayload_o_p_payload_bin_start;
|
||||
size_t payloadSize = (size_t)&_binary_ipayload_o_p_payload_bin_size; // yes this is valid
|
||||
void *payloadStart = &_binary_launcher_p_o_p_launcher_p_bin_start;
|
||||
size_t payloadSize = (size_t)&_binary_launcher_p_o_p_launcher_p_bin_size; // yes this is valid
|
||||
inject(pi.hProcess, payloadStart, payloadSize, launcherPayloadPath);
|
||||
|
||||
// Resume the process
|
@ -63,7 +63,7 @@ main: ; Replacement entry point
|
||||
ret
|
||||
|
||||
|
||||
%include "gpa.inc"
|
||||
%include "gpa.asm"
|
||||
|
||||
|
||||
; Strings
|
@ -1,10 +1,4 @@
|
||||
#include <windows.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";
|
||||
#include <inject.h>
|
||||
|
||||
static inline void write_protected_process_memory(HANDLE process, void *address, const void *buf, size_t size) {
|
||||
DWORD oldProtect;
|
||||
@ -16,8 +10,8 @@ static inline void write_protected_process_memory(HANDLE process, void *address,
|
||||
VirtualProtectEx(process, address, size, oldProtect, &oldProtect);
|
||||
}
|
||||
|
||||
static inline void inject(HANDLE process, const void *payload, size_t payloadSize, const char *dllPath) {
|
||||
size_t _;
|
||||
void inject(HANDLE process, const void *payload, size_t payloadSize, const char *dllPath) {
|
||||
size_t _; // Contrary to the docs, {Write,Read}ProcessMemory likes to crash if the last arg is NULL
|
||||
|
||||
// Inject the loader into the module
|
||||
size_t dllPathLen = strlen(dllPath) + 1;
|
@ -28,7 +28,7 @@ main: ; Replacement entry point
|
||||
ret
|
||||
|
||||
|
||||
%include "gpa.inc"
|
||||
%include "gpa.asm"
|
||||
|
||||
|
||||
; Strings
|
@ -8,7 +8,7 @@ asm_gen = generator(
|
||||
nasm,
|
||||
output: '@BASENAME@.bin',
|
||||
arguments: [
|
||||
'-i', '@EXTRA_ARGS@',
|
||||
'@EXTRA_ARGS@',
|
||||
'-f', 'bin',
|
||||
'@INPUT@',
|
||||
'-o', '@OUTPUT@'
|
||||
|
Loading…
Reference in New Issue
Block a user