Support pop'n music 15-18
* popnhook1 for pop'n 15 - 18 has been added * popnio has been added * inject.exe has new syntax for loading hook DLLs, `real.dll=hook.dll`. This will trigger an early IAT hook where it will load the EXE suspended without resolving imports, replace the reference to real.dll in the import table with hook.dll, and then resolve everything before launching. This allows for ezusb.dll to be hooked properly. * launcher.exe also has a new early IAT hook feature now. Use `-I real.dll=hook.dll`. The idea is the same as described above for inject.exe. * Updated ezusb constant namings based on what is visible in ezusb.dll's debug statements. The launcher.exe implementation of early IAT hooking means that someone can implement popnhook2.dll for 19 and above. I have tried pop'n music Sunny Park using a modified version of popnhook1 and it seems to work to some degree: the I/O check and security check returns OK which means the ezusb hooking used in popnhook1 is also working for the later games using `launcher.exe -I ezusb.dll=ezusb2-popn-shim.dll ...`. The process is rather invasive (manually resolving all imports means more chances to fail) so it has been implemented in such a way that the launcher will work the same as it has before as long as `-I` isn't specified. One questionable thing I am not confident about is the `texture_usage_fix` hack flag I added in the conf. As the comment says, pop'n music 16 will work in Windows XP without the flag being set, but the game will immediately crash on later OSes without the flag being set in my experience. No other games had this issue in my experience. Enabling it in other games doesn't seem to have any negative effects.
This commit is contained in:
@@ -220,3 +220,96 @@ HRESULT pe_patch(void *dest, const void *src, size_t nbytes)
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
const pe_thunk_t *pe_thunk_get_first(HMODULE pe, const pe_iid_t *iid)
|
||||
{
|
||||
pe_thunk_t *thunk;
|
||||
|
||||
assert(pe != NULL);
|
||||
assert(iid != NULL);
|
||||
|
||||
thunk = pe_offset(pe, iid->FirstThunk);
|
||||
|
||||
if (thunk == NULL || thunk->u1.AddressOfData == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return thunk;
|
||||
}
|
||||
|
||||
const pe_thunk_t *pe_thunk_get_next(const pe_thunk_t *thunk)
|
||||
{
|
||||
const IMAGE_THUNK_DATA *thunk_next;
|
||||
|
||||
assert(thunk != NULL);
|
||||
|
||||
thunk_next = thunk + 1;
|
||||
|
||||
if (thunk_next == NULL || thunk_next->u1.AddressOfData == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return thunk_next;
|
||||
}
|
||||
|
||||
void *pe_thunk_get_resolved_function(HMODULE target_pe, HMODULE import_pe, const pe_thunk_t *thunk)
|
||||
{
|
||||
void *addr;
|
||||
|
||||
assert(target_pe != NULL);
|
||||
assert(import_pe != NULL);
|
||||
assert(thunk != NULL);
|
||||
|
||||
if (thunk->u1.AddressOfData != 0) {
|
||||
if (IMAGE_SNAP_BY_ORDINAL(thunk->u1.Ordinal)) {
|
||||
LPCSTR functionOrdinal = (LPCSTR)IMAGE_ORDINAL(thunk->u1.Ordinal);
|
||||
addr = (void *)GetProcAddress(import_pe, functionOrdinal);
|
||||
} else {
|
||||
PIMAGE_IMPORT_BY_NAME functionName = pe_offset(target_pe, thunk->u1.AddressOfData);
|
||||
addr = (void *)GetProcAddress(import_pe, functionName->Name);
|
||||
}
|
||||
} else {
|
||||
addr = NULL;
|
||||
}
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
void pe_resolve_imports(HMODULE target_pe)
|
||||
{
|
||||
for (const pe_iid_t *iid = pe_iid_get_first(target_pe); iid != NULL; iid = pe_iid_get_next(target_pe, iid)) {
|
||||
const char *iid_name;
|
||||
HMODULE imported_pe;
|
||||
|
||||
iid_name = pe_iid_get_name(target_pe, iid);
|
||||
imported_pe = LoadLibraryA(iid_name);
|
||||
assert(imported_pe != NULL);
|
||||
|
||||
for (const pe_thunk_t *thunk = pe_thunk_get_first(target_pe, iid); thunk != NULL; thunk = pe_thunk_get_next(thunk)) {
|
||||
void *addr;
|
||||
|
||||
addr = pe_thunk_get_resolved_function(target_pe, imported_pe, thunk);
|
||||
|
||||
if (addr != NULL) {
|
||||
pe_patch((void*)&thunk->u1.Function, &addr, sizeof(PDWORD));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT pe_hijack_entrypoint(const char *filename, dll_entry_t *orig_entry)
|
||||
{
|
||||
HMODULE pe;
|
||||
|
||||
pe = LoadLibraryExA(filename, NULL, DONT_RESOLVE_DLL_REFERENCES);
|
||||
|
||||
if (!pe) {
|
||||
return HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
|
||||
pe_resolve_imports(pe);
|
||||
|
||||
*orig_entry = pe_get_entry_point(pe);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#include <stdint.h>
|
||||
|
||||
typedef IMAGE_IMPORT_DESCRIPTOR pe_iid_t;
|
||||
typedef IMAGE_THUNK_DATA pe_thunk_t;
|
||||
|
||||
typedef DWORD (CALLBACK *dll_entry_t)(HMODULE self, DWORD reason, void *ctx);
|
||||
|
||||
struct pe_iat_entry {
|
||||
const char *name;
|
||||
@@ -25,3 +28,6 @@ HRESULT pe_iid_get_iat_entry(
|
||||
void *pe_get_export(HMODULE pe, const char *name, uint16_t ord);
|
||||
void *pe_get_entry_point(HMODULE pe);
|
||||
HRESULT pe_patch(void *dest, const void *src, size_t nbytes);
|
||||
|
||||
HRESULT pe_hijack_entrypoint(const char *filename, dll_entry_t *orig_entry);
|
||||
void pe_resolve_imports(HMODULE target_pe);
|
||||
Reference in New Issue
Block a user