diff --git a/src/lindbergh/baseboard.c b/src/lindbergh/baseboard.c index 135326d..43e1478 100644 --- a/src/lindbergh/baseboard.c +++ b/src/lindbergh/baseboard.c @@ -135,7 +135,6 @@ int baseboardIoctl(int fd, unsigned int request, void *data) case BASEBOARD_INIT: { - printf("baseboard init\n"); // selectReply = -1; Considering adding this in return 0; } @@ -143,8 +142,6 @@ int baseboardIoctl(int fd, unsigned int request, void *data) case BASEBOARD_READY: // Not sure this is what it should be called { - printf("baseboard read\n"); - selectReply = 0; return 0; } @@ -184,7 +181,6 @@ int baseboardIoctl(int fd, unsigned int request, void *data) case BASEBOARD_GET_SERIAL: // bcCmdSysInfoGetReq { - printf("game asked for serial\n"); serialCommand.destAddress = _data[1]; serialCommand.destSize = _data[2]; } @@ -203,12 +199,6 @@ int baseboardIoctl(int fd, unsigned int request, void *data) jvsCommand.destAddress = _data[3]; jvsCommand.destSize = _data[4]; memcpy(inputBuffer, &sharedMemory[jvsCommand.srcAddress], jvsCommand.srcSize); - printf("TO OPENJVS\n"); - for (int i = 0; i < jvsCommand.srcSize; i++) - { - printf("%X ", sharedMemory[jvsCommand.srcAddress + i] & 0xFF); - } - printf("\n"); if (getConfig()->emulateJVS) { @@ -235,10 +225,7 @@ int baseboardIoctl(int fd, unsigned int request, void *data) break; case BASEBOARD_GET_SENSE_LINE: - { - printf("REQUEST SENSE LINE\n"); - } - break; + break; default: printf("Error: Unknown baseboard command %X\n", _data[0]); @@ -260,7 +247,6 @@ int baseboardIoctl(int fd, unsigned int request, void *data) case BASEBOARD_GET_SERIAL: { - printf("receive serial\n"); memcpy(&sharedMemory[serialCommand.destAddress + 96], SERIAL_STRING, strlen(SERIAL_STRING)); _data[1] = 1; // Set the status to success } @@ -270,7 +256,6 @@ int baseboardIoctl(int fd, unsigned int request, void *data) { _data[2] = getSenseLine(); _data[1] = 1; // Set the status to success - printf("RECEIVE SENSE LINE\n"); } break; @@ -278,19 +263,10 @@ int baseboardIoctl(int fd, unsigned int request, void *data) { if (getConfig()->emulateJVS) { - printf("FROM OPENJVS\n"); - memcpy(&sharedMemory[jvsCommand.destAddress], outputBuffer, outputPacket.length + 3); - usleep(500); _data[2] = jvsCommand.destAddress; _data[3] = outputPacket.length + 3; _data[1] = 1; // Set the status to success - - for (int i = 0; i < _data[3]; i++) - { - printf("%X ", sharedMemory[jvsCommand.destAddress + i] & 0xFF); - } - printf("\n"); } else if (jvsFileDescriptor >= 0) { diff --git a/src/lindbergh/driveboard.c b/src/lindbergh/driveboard.c index 0f8f6f7..64d0f4d 100644 --- a/src/lindbergh/driveboard.c +++ b/src/lindbergh/driveboard.c @@ -109,7 +109,7 @@ ssize_t driveboardWrite(int fd, const void *buf, size_t count) if (wheelTest) { - printf("Increment wheel until 0.9 -> %d\n", (int)(steerValue * 255)); + // printf("Increment wheel until 0.9 -> %d\n", (int)(steerValue * 255)); steerValue += 0.09; setAnalogue(ANALOGUE_1, (int)(steerValue * 1024)); response = DRIVEBOARD_BUSY; diff --git a/src/lindbergh/hook.c b/src/lindbergh/hook.c index edcbea8..d4b3eeb 100644 --- a/src/lindbergh/hook.c +++ b/src/lindbergh/hook.c @@ -13,7 +13,6 @@ #include #include #include -#include #include "hook.h" @@ -24,6 +23,7 @@ #include "jvs.h" #include "rideboard.h" #include "securityboard.h" +#include "patch.h" #define HOOK_FILE_NAME "/dev/zero" @@ -108,84 +108,6 @@ static void handleSegfault(int signal, siginfo_t *info, void *ptr) } } -void setVariable(uint32_t address, uint32_t value) -{ - int pagesize = sysconf(_SC_PAGE_SIZE); - - uint32_t *variable = (uint32_t *)address; - - void *toModify = (void *)(address - (address % pagesize)); - - int prot = mprotect(toModify, pagesize, PROT_WRITE); - if (prot != 0) - { - printf("Variable change error %d\n", prot); - abort(); - } - - *variable = value; -} - -/** - bool Detour(byte_t* src, byte_t* dst, size_t size) -{ - if(size < HOOK_MIN_SIZE) return false; - //mprotect(src, size, PROT_EXEC | PROT_READ | PROT_WRITE); - int out = ProtectMemory((mem_t)src, size, PROT_EXEC | PROT_READ | PROT_WRITE); - //std::cout << out << std::endl; - mem_t jmpAddr = ((mem_t)dst - (mem_t)src) - HOOK_MIN_SIZE; - byte_t CodeCave[] = { JMP, 0x0, 0x0, 0x0, 0x0 }; - *(mem_t*)((mem_t)CodeCave + sizeof(JMP)) = jmpAddr; - memcpy(src, CodeCave, sizeof(CodeCave)); - return true; -} -*/ - -void detourFunction(uint32_t address, void *function) -{ - int pagesize = sysconf(_SC_PAGE_SIZE); - - void *toModify = (void *)(address - (address % pagesize)); - - int prot = mprotect(toModify, pagesize, PROT_EXEC | PROT_WRITE | PROT_READ); - if (prot != 0) - { - printf("unprotect error %d\n", prot); - abort(); - } - - uint32_t jumpAddress = ((uint32_t)function - address) - 5; - - char cave[5] = {0xE9, 0x0, 0x00, 0x00, 0x00}; - memcpy(cave + 1, (void *)jumpAddress, 4); - for (int i = 0; i < 5; i++) - { - printf("%X ", cave[i] & 0xFF); - } - printf("\n"); - - memcpy((void *)address, cave, 5); - - return; -} - -int amDongleInit() -{ - printf("amDongleInit calld\n"); - return 0; -} - -int amDongleIsAvailable() -{ - printf("amDongleIsAvailable calld\n"); - return 1; -} - -int amDongleUpdate() -{ - printf("amDongleUpdate calld\n"); - return 0; -} void __attribute__((constructor)) hook_init() { @@ -199,6 +121,9 @@ void __attribute__((constructor)) hook_init() initConfig(); + if(initPatch() != 0) + exit(1); + if (initEeprom() != 0) exit(1); @@ -226,45 +151,6 @@ void __attribute__((constructor)) hook_init() securityBoardSetDipResolution(getConfig()->width, getConfig()->height); printf("Loader init success\n"); - - // The Hosue Of The Dead 4 C Set all Debug Variables; - /* - setVariable(0x0a737c60, 2); // amBackupDebugLevel - setVariable(0x0a737c64, 2); // amChunkDataDebugLevel - setVariable(0x0a737c80, 2); // amCreditDebugLevel - setVariable(0x0a737ed8, 2); // amDipswDebugLevel - setVariable(0x0a737edc, 2); // amDiskDebugLevel - setVariable(0x0a737ee0, 2); // amDongleDebugLevel - setVariable(0x0a737ee4, 2); // amEepromDebugLevel - setVariable(0x0a737ee8, 2); // amHmDebugLevel - setVariable(0x0a737ef0, 2); // amJvsDebugLevel - setVariable(0x0a737f14, 2); // amLibDebugLevel - setVariable(0x0a737f18, 2); // amMiscDebugLevel - setVariable(0x0a737f1c, 2); // amSysDataDebugLevel - setVariable(0x0a737f20, 2); // bcLibDebugLevel - setVariable(0x0a737f24, 0x0FFFFFFF); // s_logMask - */ - - if (getConfig()->game == OUTRUN) - { - printf("Enabling game debug features for outrun\n"); - setVariable(0x0893a24c, 2); // amBackupDebugLevel - setVariable(0x0893a260, 2); // amCreditDebugLevel - setVariable(0x0893a4b8, 2); // amDipswDebugLevel - setVariable(0x0893a4bc, 2); // amDongleDebugLevel - setVariable(0x0893a4c0, 2); // amEepromDebugLevel - setVariable(0x0893a4c4, 2); // amHwmonitorDebugLevel - setVariable(0x0893a4c8, 2); // amJvsDebugLevel - setVariable(0x0893a4cc, 2); // amLibDebugLevel - setVariable(0x0893a4d0, 2); // amMiscDebugLevel - setVariable(0x0893a4d4, 2); // amOsinfoDebugLevel - setVariable(0x0893a4d8, 2); // amSysDataDebugLevel - setVariable(0x0893a4e0, 2); // bcLibDebugLevel - - detourFunction(0x08190e80, amDongleInit); // amInit 08190e80 - detourFunction(0x08191201, amDongleIsAvailable); - detourFunction(0x08191125, amDongleUpdate); - } } int open(const char *pathname, int flags) diff --git a/src/lindbergh/jvs.c b/src/lindbergh/jvs.c index 8b01def..eaa1763 100644 --- a/src/lindbergh/jvs.c +++ b/src/lindbergh/jvs.c @@ -559,12 +559,6 @@ JVSStatus readPacket(JVSPacket *packet) */ JVSStatus writePacket(JVSPacket *packet) { - printf("packet\n"); - /* Don't return anything if there isn't anything to write! */ - - printf("sent a packet\n"); - - /* Get pointer to raw data in packet */ unsigned char *packetPointer = (unsigned char *)packet; diff --git a/src/lindbergh/patch.c b/src/lindbergh/patch.c new file mode 100644 index 0000000..15ec61a --- /dev/null +++ b/src/lindbergh/patch.c @@ -0,0 +1,119 @@ +#include +#include +#include +#include + +#include "patch.h" +#include "config.h" + +static void setVariable(uint32_t address, uint32_t value) +{ + int pagesize = sysconf(_SC_PAGE_SIZE); + + uint32_t *variable = (uint32_t *)address; + + void *toModify = (void *)(address - (address % pagesize)); + + int prot = mprotect(toModify, pagesize, PROT_WRITE); + if (prot != 0) + { + printf("Error: Cannot unprotect memory region to change variable (%d)\n", prot); + return; + } + + *variable = value; +} + +static void detourFunction(uint32_t address, void *function) +{ + int pagesize = sysconf(_SC_PAGE_SIZE); + + void *toModify = (void *)(address - (address % pagesize)); + + int prot = mprotect(toModify, pagesize, PROT_EXEC | PROT_WRITE); + if (prot != 0) + { + printf("Error: Cannot detour memory region to change variable (%d)\n", prot); + return; + } + + uint32_t jumpAddress = ((uint32_t)function - address) - 5; + + // Build the assembly to make the function jump + char cave[5] = {0xE9, 0x0, 0x00, 0x00, 0x00}; + cave[4] = (jumpAddress >> (8 * 3)) & 0xFF; + cave[3] = (jumpAddress >> (8 * 2)) & 0xFF; + cave[2] = (jumpAddress >> (8 * 1)) & 0xFF; + cave[1] = (jumpAddress)&0xFF; + + memcpy((void *)address, cave, 5); +} + +int amDongleInit() +{ + return 0; +} + +int amDongleIsAvailable() +{ + return 1; +} + +int amDongleUpdate() +{ + return 0; +} + +int initPatch() +{ + Game game = getConfig()->game; + + switch (game) + { + + case OUTRUN: + { + setVariable(0x0893a24c, 2); // amBackupDebugLevel + setVariable(0x0893a260, 2); // amCreditDebugLevel + setVariable(0x0893a4b8, 2); // amDipswDebugLevel + setVariable(0x0893a4bc, 2); // amDongleDebugLevel + setVariable(0x0893a4c0, 2); // amEepromDebugLevel + setVariable(0x0893a4c4, 2); // amHwmonitorDebugLevel + setVariable(0x0893a4c8, 2); // amJvsDebugLevel + setVariable(0x0893a4cc, 2); // amLibDebugLevel + setVariable(0x0893a4d0, 2); // amMiscDebugLevel + setVariable(0x0893a4d4, 2); // amOsinfoDebugLevel + setVariable(0x0893a4d8, 2); // amSysDataDebugLevel + setVariable(0x0893a4e0, 2); // bcLibDebugLevel + detourFunction(0x08190e80, amDongleInit); + detourFunction(0x08191201, amDongleIsAvailable); + detourFunction(0x08191125, amDongleUpdate); + } + break; + + case THE_HOUSE_OF_THE_DEAD_4: + { + setVariable(0x0a737c60, 2); // amBackupDebugLevel + setVariable(0x0a737c64, 2); // amChunkDataDebugLevel + setVariable(0x0a737c80, 2); // amCreditDebugLevel + setVariable(0x0a737ed8, 2); // amDipswDebugLevel + setVariable(0x0a737edc, 2); // amDiskDebugLevel + setVariable(0x0a737ee0, 2); // amDongleDebugLevel + setVariable(0x0a737ee4, 2); // amEepromDebugLevel + setVariable(0x0a737ee8, 2); // amHmDebugLevel + setVariable(0x0a737ef0, 2); // amJvsDebugLevel + setVariable(0x0a737f14, 2); // amLibDebugLevel + setVariable(0x0a737f18, 2); // amMiscDebugLevel + setVariable(0x0a737f1c, 2); // amSysDataDebugLevel + setVariable(0x0a737f20, 2); // bcLibDebugLevel + setVariable(0x0a737f24, 0x0FFFFFFF); // s_logMask + } + break; + + default: + // Don't do any patches for random games + break; + } + + return 0; +} \ No newline at end of file diff --git a/src/lindbergh/patch.h b/src/lindbergh/patch.h new file mode 100644 index 0000000..76eb405 --- /dev/null +++ b/src/lindbergh/patch.h @@ -0,0 +1 @@ +int initPatch(); \ No newline at end of file