Compare commits

...

No commits in common. "main" and "packetlog" have entirely different histories.

6 changed files with 115 additions and 11 deletions

View File

@ -16,6 +16,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
add_executable(PythonWhiteFin
packetlog.c
pcap.c
)
target_link_libraries(PythonWhiteFin

View File

@ -1,14 +1,6 @@
# PythonWhiteFin
revert cobra blackfin patches added in 3.60
cmd56 packet logger, oh it also
enables cobra blackfin on 3.60+
Cobra Blakfin patch is as follows:
```
time = sceKernelGetSystemTimeWide()
// do the gc authentication
time2 = sceKernelGetSystemTimeWide()
if((time2 - time) > 50000) goto fail;
```
or tl;dr if gc authentication takes longer than 50000 microseconds, then the authentication fails.
saves logs to ux0:/data/GC.PCAP

1
config.h Normal file
View File

@ -0,0 +1 @@
//#define PACKET_LOGGING 1

View File

@ -3,6 +3,14 @@
#include <vitasdkkern.h>
#include <taihen.h>
#include "pcap.h"
static int sendHook = -1;
static tai_hook_ref_t sendHookRef;
static int recvHook = -1;
static tai_hook_ref_t recvHookRef;
static int kernelGetSysTime = -1;
static tai_hook_ref_t kernelGetSysTimeRef;
@ -10,10 +18,40 @@ uint64_t sceKernelGetSystemTimeWide_Patched(){
return 0;
}
int SceSdifSendGcPacket_Patched(void* instance, char* buffer, int bufferSz) {
write_pcap_packet(buffer, bufferSz, 1);
int ret = TAI_CONTINUE(int, sendHookRef, instance, buffer, bufferSz);
return ret;
}
int SceSdifReceiveGcPacket_Patched(void* instance, char* buffer, int bufferSz) {
int ret = TAI_CONTINUE(int, recvHookRef, instance, buffer, bufferSz);
write_pcap_packet(buffer, bufferSz, 0);
return ret;
}
void _start() __attribute__ ((weak, alias ("module_start")));
int module_start(SceSize argc, const void *args)
{
write_pcap_hdr();
sendHook = taiHookFunctionImportForKernel(KERNEL_PID,
&sendHookRef,
"SceSblGcAuthMgr",
0x96D306FA, // SceSdifForDriver
0xB0996641, // SceSdifSendGcPacket
SceSdifSendGcPacket_Patched);
ksceKernelPrintf("[started] %x %x\n", sendHook, sendHookRef);
recvHook = taiHookFunctionImportForKernel(KERNEL_PID,
&recvHookRef,
"SceSblGcAuthMgr",
0x96D306FA, // SceSdifForDriver
0x134E06C4, // SceSdifReceiveGcPacket
SceSdifReceiveGcPacket_Patched);
ksceKernelPrintf("[started] %x %x\n", recvHook, recvHookRef);
// undo cobra blackfin patch
kernelGetSysTime = taiHookFunctionImportForKernel(KERNEL_PID,
&kernelGetSysTimeRef,
@ -28,6 +66,8 @@ int module_start(SceSize argc, const void *args)
int module_stop(SceSize argc, const void *args)
{
if (recvHook >= 0) taiHookReleaseForKernel(recvHook, recvHookRef);
if (sendHook >= 0) taiHookReleaseForKernel(sendHook, sendHookRef);
if (kernelGetSysTime >= 0) taiHookReleaseForKernel(kernelGetSysTime, kernelGetSysTimeRef);
return SCE_KERNEL_STOP_SUCCESS;

46
pcap.c Normal file
View File

@ -0,0 +1,46 @@
#include "pcap.h"
#include <vitasdkkern.h>
static char* pcapFile = "ux0:/data/gc.pcap";
void write_pcap_hdr() {
SceUID pcapfd = ksceIoOpen(pcapFile, SCE_O_WRONLY | SCE_O_CREAT , 0777);
pcap_hdr_t pcapHdr;
pcapHdr.magic_number = 0xa1b2c3d4;
pcapHdr.version_major = 0x2;
pcapHdr.version_minor = 0x4;
pcapHdr.thiszone = 0;
pcapHdr.sigfigs = 0;
pcapHdr.snaplen = 65535;
pcapHdr.network = 147;
ksceIoWrite(pcapfd, &pcapHdr, sizeof(pcap_hdr_t));
ksceIoClose(pcapfd);
return;
}
void write_pcap_packet(char* packetData, size_t packetLength, int direction) {
if(packetData == NULL) return;
SceRtcTick time;
ksceRtcGetCurrentSecureTick(&time);
SceUID pcapfd = ksceIoOpen(pcapFile, SCE_O_WRONLY | SCE_O_APPEND , 0777);
pcaprec_hdr_t packetHdr;
packetHdr.incl_len = packetLength + sizeof(int);
packetHdr.orig_len = packetLength + sizeof(int);
packetHdr.ts_sec = (uint32_t)((time.tick / 1000000) - 62135596800);
packetHdr.ts_usec = (uint32_t)(time.tick % 1000000);
ksceIoWrite(pcapfd, &packetHdr, sizeof(pcaprec_hdr_t));
ksceIoWrite(pcapfd, &direction, sizeof(int));
ksceIoWrite(pcapfd, packetData, packetLength);
ksceIoClose(pcapfd);
return;
}

24
pcap.h Normal file
View File

@ -0,0 +1,24 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
typedef struct pcap_hdr_s {
uint32_t magic_number; /* magic number */
uint16_t version_major; /* major version number */
uint16_t version_minor; /* minor version number */
int32_t thiszone; /* GMT to local correction */
uint32_t sigfigs; /* accuracy of timestamps */
uint32_t snaplen; /* max length of captured packets, in octets */
uint32_t network; /* data link type */
} pcap_hdr_t;
typedef struct pcaprec_hdr_s {
uint32_t ts_sec; /* timestamp seconds */
uint32_t ts_usec; /* timestamp microseconds */
uint32_t incl_len; /* number of octets of packet saved in file */
uint32_t orig_len; /* actual length of packet */
} pcaprec_hdr_t;
void write_pcap_hdr();
void write_pcap_packet(char* packetData, size_t packetLength, int direction);