1
0
mirror of synced 2024-11-30 20:24:27 +01:00

Do some tidying

This commit is contained in:
Bobby Dilley 2023-02-05 21:37:15 +00:00
parent bc800855ee
commit 6835590efc
6 changed files with 126 additions and 150 deletions

View File

@ -135,7 +135,6 @@ int baseboardIoctl(int fd, unsigned int request, void *data)
case BASEBOARD_INIT: case BASEBOARD_INIT:
{ {
printf("baseboard init\n");
// selectReply = -1; Considering adding this in // selectReply = -1; Considering adding this in
return 0; 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 case BASEBOARD_READY: // Not sure this is what it should be called
{ {
printf("baseboard read\n");
selectReply = 0; selectReply = 0;
return 0; return 0;
} }
@ -184,7 +181,6 @@ int baseboardIoctl(int fd, unsigned int request, void *data)
case BASEBOARD_GET_SERIAL: // bcCmdSysInfoGetReq case BASEBOARD_GET_SERIAL: // bcCmdSysInfoGetReq
{ {
printf("game asked for serial\n");
serialCommand.destAddress = _data[1]; serialCommand.destAddress = _data[1];
serialCommand.destSize = _data[2]; serialCommand.destSize = _data[2];
} }
@ -203,12 +199,6 @@ int baseboardIoctl(int fd, unsigned int request, void *data)
jvsCommand.destAddress = _data[3]; jvsCommand.destAddress = _data[3];
jvsCommand.destSize = _data[4]; jvsCommand.destSize = _data[4];
memcpy(inputBuffer, &sharedMemory[jvsCommand.srcAddress], jvsCommand.srcSize); 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) if (getConfig()->emulateJVS)
{ {
@ -235,10 +225,7 @@ int baseboardIoctl(int fd, unsigned int request, void *data)
break; break;
case BASEBOARD_GET_SENSE_LINE: case BASEBOARD_GET_SENSE_LINE:
{ break;
printf("REQUEST SENSE LINE\n");
}
break;
default: default:
printf("Error: Unknown baseboard command %X\n", _data[0]); 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: case BASEBOARD_GET_SERIAL:
{ {
printf("receive serial\n");
memcpy(&sharedMemory[serialCommand.destAddress + 96], SERIAL_STRING, strlen(SERIAL_STRING)); memcpy(&sharedMemory[serialCommand.destAddress + 96], SERIAL_STRING, strlen(SERIAL_STRING));
_data[1] = 1; // Set the status to success _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[2] = getSenseLine();
_data[1] = 1; // Set the status to success _data[1] = 1; // Set the status to success
printf("RECEIVE SENSE LINE\n");
} }
break; break;
@ -278,19 +263,10 @@ int baseboardIoctl(int fd, unsigned int request, void *data)
{ {
if (getConfig()->emulateJVS) if (getConfig()->emulateJVS)
{ {
printf("FROM OPENJVS\n");
memcpy(&sharedMemory[jvsCommand.destAddress], outputBuffer, outputPacket.length + 3); memcpy(&sharedMemory[jvsCommand.destAddress], outputBuffer, outputPacket.length + 3);
usleep(500);
_data[2] = jvsCommand.destAddress; _data[2] = jvsCommand.destAddress;
_data[3] = outputPacket.length + 3; _data[3] = outputPacket.length + 3;
_data[1] = 1; // Set the status to success _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) else if (jvsFileDescriptor >= 0)
{ {

View File

@ -109,7 +109,7 @@ ssize_t driveboardWrite(int fd, const void *buf, size_t count)
if (wheelTest) 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; steerValue += 0.09;
setAnalogue(ANALOGUE_1, (int)(steerValue * 1024)); setAnalogue(ANALOGUE_1, (int)(steerValue * 1024));
response = DRIVEBOARD_BUSY; response = DRIVEBOARD_BUSY;

View File

@ -13,7 +13,6 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/mman.h>
#include "hook.h" #include "hook.h"
@ -24,6 +23,7 @@
#include "jvs.h" #include "jvs.h"
#include "rideboard.h" #include "rideboard.h"
#include "securityboard.h" #include "securityboard.h"
#include "patch.h"
#define HOOK_FILE_NAME "/dev/zero" #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() void __attribute__((constructor)) hook_init()
{ {
@ -199,6 +121,9 @@ void __attribute__((constructor)) hook_init()
initConfig(); initConfig();
if(initPatch() != 0)
exit(1);
if (initEeprom() != 0) if (initEeprom() != 0)
exit(1); exit(1);
@ -226,45 +151,6 @@ void __attribute__((constructor)) hook_init()
securityBoardSetDipResolution(getConfig()->width, getConfig()->height); securityBoardSetDipResolution(getConfig()->width, getConfig()->height);
printf("Loader init success\n"); 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) int open(const char *pathname, int flags)

View File

@ -559,12 +559,6 @@ JVSStatus readPacket(JVSPacket *packet)
*/ */
JVSStatus writePacket(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 */ /* Get pointer to raw data in packet */
unsigned char *packetPointer = (unsigned char *)packet; unsigned char *packetPointer = (unsigned char *)packet;

119
src/lindbergh/patch.c Normal file
View File

@ -0,0 +1,119 @@
#include <string.h>
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#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;
}

1
src/lindbergh/patch.h Normal file
View File

@ -0,0 +1 @@
int initPatch();