mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 21:15:56 +08:00
[Refactor] utils and library entry
This commit is contained in:
1 parent
5eff534dbd
commit
6f104145b4
5 files changed
+136
-103
No files matched your search
+1
-1
@@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
# version
|
||||
set(PROJECT_VERSION_MAJOR 1)
|
||||
set(PROJECT_VERSION_MINOR 0)
|
||||
set(PROJECT_BUILD_NUMBER 23)
|
||||
set(PROJECT_BUILD_NUMBER 24)
|
||||
set(PROJECT_VERSION_STRING "v${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}-b${PROJECT_BUILD_NUMBER}")
|
||||
message(STATUS " ======== Build version: ${PROJECT_VERSION_STRING} ======== ")
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# src/core/CMakeLists.txt
|
||||
# src/agent/CMakeLists.txt
|
||||
|
||||
target_include_directories(agent PRIVATE ${CMAKE_SOURCE_DIR}/includes/tomlc17)
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef DATAUTILS_H
|
||||
#define DATAUTILS_H
|
||||
|
||||
#include <string.h>
|
||||
#include "InjectParameters.h"
|
||||
#include "tomlc17.h"
|
||||
#include "log.h"
|
||||
|
||||
typedef struct _InjectionInfo {
|
||||
char BootstrapAPIPath[INJECT_PATH_MAX];
|
||||
char JuiceLoaderJarPath[INJECT_PATH_MAX];
|
||||
char JuiceLoaderLibPath[INJECT_PATH_MAX];
|
||||
char EntryJarPath[INJECT_PATH_MAX];
|
||||
char EntryClass[INJECT_PATH_MAX];
|
||||
char EntryMethod[INJECT_PATH_MAX];
|
||||
} InjectionInfoType;
|
||||
extern InjectionInfoType InjectionInfo;
|
||||
|
||||
void safe_copy(char *dest, const char *src, size_t dest_size);
|
||||
bool ReadInjectionInfo(toml_result_t result, InjectParameters* params);
|
||||
|
||||
#endif // DATAUTILS_H
|
||||
+8
-101
@@ -1,3 +1,9 @@
|
||||
/*
|
||||
Author: xiaozhou233 (xiaozhou233@vip.qq.com)
|
||||
File: libagent.c
|
||||
Desc: Entry point for the agent
|
||||
*/
|
||||
|
||||
#include "ReflectiveLoader.h"
|
||||
#include "windows.h"
|
||||
#include "unistd.h"
|
||||
@@ -9,111 +15,12 @@
|
||||
#include "GlobalUtils.h"
|
||||
#include "shlwapi.h"
|
||||
#include "tomlc17.h"
|
||||
#include "datautils.h"
|
||||
|
||||
#define WIN_X64
|
||||
extern HINSTANCE hAppInstance;
|
||||
|
||||
struct _InjectionInfo {
|
||||
char BootstrapAPIPath[INJECT_PATH_MAX];
|
||||
char JuiceLoaderJarPath[INJECT_PATH_MAX];
|
||||
char JuiceLoaderLibPath[INJECT_PATH_MAX];
|
||||
char EntryJarPath[INJECT_PATH_MAX];
|
||||
char EntryClass[INJECT_PATH_MAX];
|
||||
char EntryMethod[INJECT_PATH_MAX];
|
||||
} InjectionInfo;
|
||||
|
||||
void safe_copy(char *dest, const char *src, size_t dest_size) {
|
||||
if (!dest || dest_size == 0) return;
|
||||
strncpy(dest, src, dest_size - 1);
|
||||
dest[dest_size - 1] = '\0';
|
||||
}
|
||||
|
||||
static bool ReadInjectionInfo(toml_result_t result, InjectParameters* params) {
|
||||
toml_datum_t InjectionTree = toml_seek(result.toptab, "Injection");
|
||||
|
||||
// ======= BootstrapAPIPath =======
|
||||
toml_datum_t BootstrapAPIPath = toml_seek(InjectionTree, "BootstrapAPIPath");
|
||||
char BootstrapAPIPathStr[INJECT_PATH_MAX];
|
||||
if (BootstrapAPIPath.type != TOML_STRING) {
|
||||
log_error("BootstrapAPIPath is not a string.");
|
||||
return false;
|
||||
}
|
||||
if (BootstrapAPIPath.u.s == NULL || strlen(BootstrapAPIPath.u.s) == 0) {
|
||||
sprintf(BootstrapAPIPathStr, "%s\\bootstrap-api.jar", params->ConfigDir);
|
||||
} else {
|
||||
sprintf(BootstrapAPIPathStr, "%s", BootstrapAPIPath.u.s);
|
||||
}
|
||||
safe_copy(InjectionInfo.BootstrapAPIPath, BootstrapAPIPathStr, INJECT_PATH_MAX);
|
||||
// ======= BootstrapAPIPath =======
|
||||
|
||||
// ======= JuiceLoaderJarPath =======
|
||||
toml_datum_t JuiceLoaderJarPath = toml_seek(InjectionTree, "JuiceLoaderJarPath");
|
||||
char JuiceLoaderJarPathStr[INJECT_PATH_MAX];
|
||||
if (JuiceLoaderJarPath.type != TOML_STRING) {
|
||||
log_error("JuiceLoaderJarPath is not a string.");
|
||||
return false;
|
||||
}
|
||||
if (JuiceLoaderJarPath.u.s == NULL || strlen(JuiceLoaderJarPath.u.s) == 0) {
|
||||
sprintf(JuiceLoaderJarPathStr, "%s\\JuiceLoader.jar", params->ConfigDir);
|
||||
} else {
|
||||
sprintf(JuiceLoaderJarPathStr, "%s", JuiceLoaderJarPath.u.s);
|
||||
}
|
||||
safe_copy(InjectionInfo.JuiceLoaderJarPath, JuiceLoaderJarPathStr, INJECT_PATH_MAX);
|
||||
// ======= JuiceLoaderJarPath =======
|
||||
|
||||
// ======= JuiceLoaderLibPath =======
|
||||
toml_datum_t JuiceLoaderLibPath = toml_seek(InjectionTree, "JuiceLoaderLibPath");
|
||||
char JuiceLoaderLibPathStr[INJECT_PATH_MAX];
|
||||
if (JuiceLoaderLibPath.type != TOML_STRING) {
|
||||
log_error("JuiceLoaderLibPath is not a string.");
|
||||
return false;
|
||||
}
|
||||
if (JuiceLoaderLibPath.u.s == NULL || strlen(JuiceLoaderLibPath.u.s) == 0) {
|
||||
sprintf(JuiceLoaderLibPathStr, "%s\\libjuiceloader.dll", params->ConfigDir);
|
||||
} else {
|
||||
sprintf(JuiceLoaderLibPathStr, "%s", JuiceLoaderLibPath.u.s);
|
||||
}
|
||||
safe_copy(InjectionInfo.JuiceLoaderLibPath, JuiceLoaderLibPathStr, INJECT_PATH_MAX);
|
||||
// ======= JuiceLoaderLibPath =======
|
||||
|
||||
// ======= Entry =======
|
||||
toml_datum_t EntryJarPath = toml_seek(InjectionTree, "EntryJarPath");
|
||||
char EntryJarPathStr[INJECT_PATH_MAX];
|
||||
if (EntryJarPath.type != TOML_STRING) {
|
||||
log_error("EntryJarPath is not a string.");
|
||||
return false;
|
||||
}
|
||||
if (EntryJarPath.u.s == NULL || strlen(EntryJarPath.u.s) == 0) {
|
||||
sprintf(EntryJarPathStr, "%s\\entry.jar", params->ConfigDir);
|
||||
} else {
|
||||
sprintf(EntryJarPathStr, "%s", EntryJarPath.u.s);
|
||||
}
|
||||
safe_copy(InjectionInfo.EntryJarPath, EntryJarPathStr, INJECT_PATH_MAX);
|
||||
|
||||
toml_datum_t EntryClass = toml_seek(InjectionTree, "EntryClass");
|
||||
if (EntryClass.type != TOML_STRING) {
|
||||
log_error("EntryClass is not a string.");
|
||||
return false;
|
||||
}
|
||||
if (EntryClass.u.s == NULL || strlen(EntryClass.u.s) == 0) {
|
||||
safe_copy(InjectionInfo.EntryClass, "cn.xiaozhou233.juiceloader.entry.Entry", INJECT_PATH_MAX);
|
||||
} else {
|
||||
safe_copy(InjectionInfo.EntryClass, EntryClass.u.s, INJECT_PATH_MAX);
|
||||
}
|
||||
|
||||
toml_datum_t EntryMethod = toml_seek(InjectionTree, "EntryMethod");
|
||||
if (EntryMethod.type != TOML_STRING) {
|
||||
log_error("EntryMethod is not a string.");
|
||||
return false;
|
||||
}
|
||||
if (EntryMethod.u.s == NULL || strlen(EntryMethod.u.s) == 0) {
|
||||
safe_copy(InjectionInfo.EntryMethod, "start", INJECT_PATH_MAX);
|
||||
} else {
|
||||
safe_copy(InjectionInfo.EntryMethod, EntryMethod.u.s, INJECT_PATH_MAX);
|
||||
}
|
||||
// ======= Entry =======
|
||||
return true;
|
||||
}
|
||||
InjectionInfoType InjectionInfo;
|
||||
|
||||
DWORD WINAPI ThreadProc(LPVOID lpParam) {
|
||||
log_trace("New thread started.");
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
Author: xiaozhou233 (xiaozhou233@vip.qq.com)
|
||||
File: datautils.c
|
||||
Desc: data utils
|
||||
*/
|
||||
|
||||
|
||||
#include "datautils.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "tomlc17.h"
|
||||
|
||||
void safe_copy(char *dest, const char *src, size_t dest_size) {
|
||||
if (!dest || dest_size == 0) return;
|
||||
strncpy(dest, src, dest_size - 1);
|
||||
dest[dest_size - 1] = '\0';
|
||||
}
|
||||
|
||||
bool ReadInjectionInfo(toml_result_t result, InjectParameters* params) {
|
||||
toml_datum_t InjectionTree = toml_seek(result.toptab, "Injection");
|
||||
|
||||
// ======= BootstrapAPIPath =======
|
||||
toml_datum_t BootstrapAPIPath = toml_seek(InjectionTree, "BootstrapAPIPath");
|
||||
char BootstrapAPIPathStr[INJECT_PATH_MAX];
|
||||
if (BootstrapAPIPath.type != TOML_STRING) {
|
||||
log_error("BootstrapAPIPath is not a string.");
|
||||
return false;
|
||||
}
|
||||
if (BootstrapAPIPath.u.s == NULL || strlen(BootstrapAPIPath.u.s) == 0) {
|
||||
sprintf(BootstrapAPIPathStr, "%s\\bootstrap-api.jar", params->ConfigDir);
|
||||
} else {
|
||||
sprintf(BootstrapAPIPathStr, "%s", BootstrapAPIPath.u.s);
|
||||
}
|
||||
safe_copy(InjectionInfo.BootstrapAPIPath, BootstrapAPIPathStr, INJECT_PATH_MAX);
|
||||
// ======= BootstrapAPIPath =======
|
||||
|
||||
// ======= JuiceLoaderJarPath =======
|
||||
toml_datum_t JuiceLoaderJarPath = toml_seek(InjectionTree, "JuiceLoaderJarPath");
|
||||
char JuiceLoaderJarPathStr[INJECT_PATH_MAX];
|
||||
if (JuiceLoaderJarPath.type != TOML_STRING) {
|
||||
log_error("JuiceLoaderJarPath is not a string.");
|
||||
return false;
|
||||
}
|
||||
if (JuiceLoaderJarPath.u.s == NULL || strlen(JuiceLoaderJarPath.u.s) == 0) {
|
||||
sprintf(JuiceLoaderJarPathStr, "%s\\JuiceLoader.jar", params->ConfigDir);
|
||||
} else {
|
||||
sprintf(JuiceLoaderJarPathStr, "%s", JuiceLoaderJarPath.u.s);
|
||||
}
|
||||
safe_copy(InjectionInfo.JuiceLoaderJarPath, JuiceLoaderJarPathStr, INJECT_PATH_MAX);
|
||||
// ======= JuiceLoaderJarPath =======
|
||||
|
||||
// ======= JuiceLoaderLibPath =======
|
||||
toml_datum_t JuiceLoaderLibPath = toml_seek(InjectionTree, "JuiceLoaderLibPath");
|
||||
char JuiceLoaderLibPathStr[INJECT_PATH_MAX];
|
||||
if (JuiceLoaderLibPath.type != TOML_STRING) {
|
||||
log_error("JuiceLoaderLibPath is not a string.");
|
||||
return false;
|
||||
}
|
||||
if (JuiceLoaderLibPath.u.s == NULL || strlen(JuiceLoaderLibPath.u.s) == 0) {
|
||||
sprintf(JuiceLoaderLibPathStr, "%s\\libjuiceloader.dll", params->ConfigDir);
|
||||
} else {
|
||||
sprintf(JuiceLoaderLibPathStr, "%s", JuiceLoaderLibPath.u.s);
|
||||
}
|
||||
safe_copy(InjectionInfo.JuiceLoaderLibPath, JuiceLoaderLibPathStr, INJECT_PATH_MAX);
|
||||
// ======= JuiceLoaderLibPath =======
|
||||
|
||||
// ======= Entry =======
|
||||
toml_datum_t EntryJarPath = toml_seek(InjectionTree, "EntryJarPath");
|
||||
char EntryJarPathStr[INJECT_PATH_MAX];
|
||||
if (EntryJarPath.type != TOML_STRING) {
|
||||
log_error("EntryJarPath is not a string.");
|
||||
return false;
|
||||
}
|
||||
if (EntryJarPath.u.s == NULL || strlen(EntryJarPath.u.s) == 0) {
|
||||
sprintf(EntryJarPathStr, "%s\\entry.jar", params->ConfigDir);
|
||||
} else {
|
||||
sprintf(EntryJarPathStr, "%s", EntryJarPath.u.s);
|
||||
}
|
||||
safe_copy(InjectionInfo.EntryJarPath, EntryJarPathStr, INJECT_PATH_MAX);
|
||||
|
||||
toml_datum_t EntryClass = toml_seek(InjectionTree, "EntryClass");
|
||||
if (EntryClass.type != TOML_STRING) {
|
||||
log_error("EntryClass is not a string.");
|
||||
return false;
|
||||
}
|
||||
if (EntryClass.u.s == NULL || strlen(EntryClass.u.s) == 0) {
|
||||
safe_copy(InjectionInfo.EntryClass, "cn.xiaozhou233.juiceloader.entry.Entry", INJECT_PATH_MAX);
|
||||
} else {
|
||||
safe_copy(InjectionInfo.EntryClass, EntryClass.u.s, INJECT_PATH_MAX);
|
||||
}
|
||||
|
||||
toml_datum_t EntryMethod = toml_seek(InjectionTree, "EntryMethod");
|
||||
if (EntryMethod.type != TOML_STRING) {
|
||||
log_error("EntryMethod is not a string.");
|
||||
return false;
|
||||
}
|
||||
if (EntryMethod.u.s == NULL || strlen(EntryMethod.u.s) == 0) {
|
||||
safe_copy(InjectionInfo.EntryMethod, "start", INJECT_PATH_MAX);
|
||||
} else {
|
||||
safe_copy(InjectionInfo.EntryMethod, EntryMethod.u.s, INJECT_PATH_MAX);
|
||||
}
|
||||
// ======= Entry =======
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user