upload src

This commit is contained in:
Li 2024-01-15 00:21:54 +13:00
commit 69f72aa7cb
9 changed files with 256 additions and 0 deletions

55
.gitignore vendored Normal file
View File

@ -0,0 +1,55 @@
# ---> C
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
build/*

35
CMakeLists.txt Normal file
View File

@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 2.8)
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
if(DEFINED ENV{VITASDK})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file")
else()
message(FATAL_ERROR "Please define VITASDK to point to your SDK path!")
endif()
endif()
project(PythonWhiteFin)
include("${VITASDK}/share/vita.cmake" REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-q -Wall -O3 -nostdlib")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
add_executable(PythonWhiteFin
packetlog.c
pcap.c
)
target_link_libraries(PythonWhiteFin
taihenForKernel_stub
SceIofilemgrForDriver_stub
SceSdifForDriver_stub
SceNpDrmForDriver_stub
SceRtcForDriver_stub
SceRegMgrForDriver_stub
SceSblSsMgrForDriver_stub
SceSysclibForDriver_stub
SceDebugForDriver_stub
SceThreadmgrForDriver_stub
)
vita_create_self(PythonWhiteFin.skprx PythonWhiteFin CONFIG exports.yml UNSAFE)

9
LICENSE Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2024 Li
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

4
README.md Normal file
View File

@ -0,0 +1,4 @@
# PythonWhiteFin
cmd56 packet logger, oh it also
enables cobra blackfin on 3.60+

1
config.h Normal file
View File

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

8
exports.yml Normal file
View File

@ -0,0 +1,8 @@
packetlog:
attributes: 0
version:
major: 1
minor: 1
main:
start: module_start
stop: module_stop

74
packetlog.c Normal file
View File

@ -0,0 +1,74 @@
#include <stdio.h>
#include <stdarg.h>
#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;
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,
"SceSblGcAuthMgr",
0xE2C40624, // SceThreadmgrForDriver
0xF4EE4FA9, // sceKernelGetSystemTimeWide
sceKernelGetSystemTimeWide_Patched);
ksceKernelPrintf("[started] %x %x\n", kernelGetSysTime, kernelGetSysTimeRef);
return SCE_KERNEL_START_SUCCESS;
}
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);