Load plugins in usermode lv2 module_start#65
Load plugins in usermode lv2 module_start#65illusionyy wants to merge 3 commits intoEvilnat:masterfrom
module_start#65Conversation
bbaba7f to
add269c
Compare
This comment was marked as outdated.
This comment was marked as outdated.
add269c to
9dc793f
Compare
9dc793f to
33d6114
Compare
|
Updated to be able to modify argc/argv. Code (Click to expand)#if defined(__PRX__)
typedef union bigint
{
struct _c
{
char* hi;
char* lo;
} c;
} bigint;
#define pChar bigint
#define pChar2 bigint*
#else
#define pChar uint64_t
#define pChar2 uint32_t
#endif
typedef struct program_args
{
uint32_t argc;
pChar2 argv;
uint32_t replace_args_size;
uint32_t replace_args_per_buf_size;
pChar new_argv[max_args];
char replace_args[max_args][max_arg_buf + 1];
struct change_flag
{
uint64_t changed : 1;
} flag;
} program_args;
#if defined(__cplusplus)
static_assert(__builtin_offsetof(program_args, argc) == 0, "");
static_assert(__builtin_offsetof(program_args, argv) == 4, "");
static_assert(__builtin_offsetof(program_args, replace_args_size) == 8, "");
static_assert(__builtin_offsetof(program_args, replace_args_per_buf_size) == 12, "");
static_assert(__builtin_offsetof(program_args, new_argv) == 16, "");
static_assert(__builtin_offsetof(program_args, replace_args) == 272, "");
#endifextern "C" int module_start(unsigned int argc, program_args& arg)
{
printf("program_args size %d\n", sizeof(program_args));
printf("arg %p argc %d argv %p\n", &arg, arg.argc, arg.argv);
printf("replace_arg_buf %ld\n", arg.replace_args_size);
for (uint32_t i = 0; i < arg.argc; i++)
{
printf("arg[%d]: (%p) %s\n", i, &arg.argv[i].c.lo, arg.argv[i].c.lo ? arg.argv[i].c.lo : "");
}
#if defined(enable_arg_modify)
size_t diff_bytes = 0;
if (!check_bytes(arg.replace_args, 0, arg.replace_args_size, diff_bytes))
{
printf("WARNING: replacement arg buf contains %ld bytes that was not zero! was the stack ever truly cleared?\n", diff_bytes);
}
else
{
printf("checked replacement buf of %ld bytes and it was all clear!\n", arg.replace_args_size);
}
#endif
#if defined(enable_arg_modify)
bool no_copy = false;
if (!copy_main_args(&arg, arg.argc, arg.argv))
{
printf("failed to copy main argc/argv\n");
no_copy = true;
}
if (!no_copy)
{
append_arg(&arg, "-novsync");
}
printf("argc now %d\n", arg.argc);
for (uint32_t i = 0; i < arg.argc; i++)
{
printf("arg[%d]: (%p) %s\n", i, arg.new_argv[i].c.lo, arg.new_argv[i].c.lo ? arg.new_argv[i].c.lo : "");
}
#endif
sys_timer_sleep(5);
return SYS_PRX_NO_RESIDENT;
}Output (Click to expand) |
90c64ab to
9086236
Compare
cae669e to
f7d1471
Compare
|
Ported to 4.92 PEX. Checked CEX and DEX kernels and they seem to work. |
|
@Evilnat ready for merge. |
3f97160 to
2f9c1fa
Compare
For 4.84 REX only, can be easily ported to other fws. will look for `/dev_hdd0/game_plugin_bootloader.sprx` and start it. if you have exceptions enabled in shellcode, you'll get exceptions to find out any errors.
2f9c1fa to
525850b
Compare
|
Could you explain a little about what I could do with your new changes? Thanks in advance |
@Evilnat it can load plugins on app startup. Previously you'd have to patch game executable manually, resign it correctly for CEX or DEX and it was just a mess. Now it's just as simple as putting a plugin somewhere, adding it to Also this shellcode also sets up a struct for argc/argv to be edited by plugins, so users may add their own cmdline before |
That's a much needed feature :) |
Thanks mate! I need to check that the final size of stage2 doesn't exceed the maximum allowed, although I also want to increase it to avoid problems. Give me a few days so I can check and test it. Thank you very much for your contribution |
|
Even in debug, it doesn't exceed 127k for me in PEX build. In release it's about 110k I believe so it should be okay. |
For 4.84 REX and 4.92 PEX only, can be easily ported to other fws.
will look for
/dev_hdd0/game_plugin_bootloader.sprxand start it. if you have exceptions enabled in shellcode, you'll get exceptions to find out any errors.