launcher: Add before-hook support
Required to hook certain things that happen on module load / avs boot: - network adapter hooking for avs - envvar setting Note: the logging facilities are NOT setup yet at this point so these hooks cannot use avs for logging
This commit is contained in:
+29
-23
@@ -93,10 +93,34 @@ static AVS_LOG_WRITER(log_callback, chars, nchars, ctx)
|
|||||||
free(utf16);
|
free(utf16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void load_hook_dlls(struct array* hook_dlls) {
|
||||||
|
const char *hook_dll;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < hook_dlls->nitems; i++) {
|
||||||
|
hook_dll = *array_item(char *, hook_dlls, i);
|
||||||
|
|
||||||
|
if (LoadLibraryA(hook_dll) == NULL) {
|
||||||
|
LPSTR buffer;
|
||||||
|
|
||||||
|
FormatMessageA(
|
||||||
|
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
||||||
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
NULL,
|
||||||
|
GetLastError(),
|
||||||
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
(LPSTR) &buffer,
|
||||||
|
0,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
log_fatal("%s: Failed to load hook DLL: %s", hook_dll, buffer);
|
||||||
|
|
||||||
|
LocalFree(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
const char *hook_dll;
|
|
||||||
bool ok;
|
bool ok;
|
||||||
HANDLE logfile;
|
HANDLE logfile;
|
||||||
|
|
||||||
@@ -170,6 +194,8 @@ int main(int argc, const char **argv)
|
|||||||
log_fatal("%s: /config missing", options.avs_config_path);
|
log_fatal("%s: /config missing", options.avs_config_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
load_hook_dlls(&options.before_hook_dlls);
|
||||||
|
|
||||||
avs_context_init(
|
avs_context_init(
|
||||||
avs_config_root,
|
avs_config_root,
|
||||||
options.avs_heap_size,
|
options.avs_heap_size,
|
||||||
@@ -188,27 +214,7 @@ int main(int argc, const char **argv)
|
|||||||
|
|
||||||
/* Load hook DLLs */
|
/* Load hook DLLs */
|
||||||
|
|
||||||
for (i = 0; i < options.hook_dlls.nitems; i++) {
|
load_hook_dlls(&options.hook_dlls);
|
||||||
hook_dll = *array_item(char *, &options.hook_dlls, i);
|
|
||||||
|
|
||||||
if (LoadLibraryA(hook_dll) == NULL) {
|
|
||||||
LPSTR buffer;
|
|
||||||
|
|
||||||
FormatMessageA(
|
|
||||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
||||||
NULL,
|
|
||||||
GetLastError(),
|
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
||||||
(LPSTR) &buffer,
|
|
||||||
0,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
log_fatal("%s: Failed to load hook DLL: %s", hook_dll, buffer);
|
|
||||||
|
|
||||||
LocalFree(buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Inject GetModuleHandle hooks */
|
/* Inject GetModuleHandle hooks */
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ void options_init(struct options *options)
|
|||||||
options->logfile = NULL;
|
options->logfile = NULL;
|
||||||
options->remote_debugger = false;
|
options->remote_debugger = false;
|
||||||
array_init(&options->hook_dlls);
|
array_init(&options->hook_dlls);
|
||||||
|
array_init(&options->before_hook_dlls);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool options_read_cmdline(struct options *options, int argc, const char **argv)
|
bool options_read_cmdline(struct options *options, int argc, const char **argv)
|
||||||
@@ -115,6 +116,16 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'B':
|
||||||
|
if (i + 1 >= argc) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*array_append(const char *, &options->before_hook_dlls) =
|
||||||
|
argv[++i];
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case 'Y':
|
case 'Y':
|
||||||
if (i + 1 >= argc) {
|
if (i + 1 >= argc) {
|
||||||
return false;
|
return false;
|
||||||
@@ -170,6 +181,8 @@ void options_print_usage(void)
|
|||||||
" -R [pcbid] Specify Soft ID (default: use ea3 config)\n"
|
" -R [pcbid] Specify Soft ID (default: use ea3 config)\n"
|
||||||
" -K [filename] Load hook DLL (can be specified multiple "
|
" -K [filename] Load hook DLL (can be specified multiple "
|
||||||
"times)\n"
|
"times)\n"
|
||||||
|
" -B [filename] Load pre-hook DLL loaded before avs boot "
|
||||||
|
"(can be specified multiple times)\n"
|
||||||
" -Y [filename] Log to a file in addition to the console\n"
|
" -Y [filename] Log to a file in addition to the console\n"
|
||||||
" -D Halt the launcher before bootstrapping AVS "
|
" -D Halt the launcher before bootstrapping AVS "
|
||||||
"until a"
|
"until a"
|
||||||
@@ -179,4 +192,5 @@ void options_print_usage(void)
|
|||||||
void options_fini(struct options *options)
|
void options_fini(struct options *options)
|
||||||
{
|
{
|
||||||
array_fini(&options->hook_dlls);
|
array_fini(&options->hook_dlls);
|
||||||
|
array_fini(&options->before_hook_dlls);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ struct options {
|
|||||||
const char *module;
|
const char *module;
|
||||||
const char *logfile;
|
const char *logfile;
|
||||||
struct array hook_dlls;
|
struct array hook_dlls;
|
||||||
|
struct array before_hook_dlls;
|
||||||
bool remote_debugger;
|
bool remote_debugger;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user