├── sha1.c ├── README.md ├── sha1.h └── main.c /sha1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MajorTomSec/fixreg_vita/HEAD/sha1.c -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fixreg_vita 2 | 3 | Fix registry tool for PSVita. Adapated from PSP registry fixing tool. 4 | This tool allows to edit the PSVita registry (system.dreg/system.ireg). 5 | It checks every block and patches the corrupted blocks by calculating a checksum. 6 | 7 | # Usage 8 | 9 | fixreg_vita is simple to use, just put your modded system.dreg, along with the original system.ireg file in the same directory as the executable. 10 | Run fixreg_vita to fix the registry. 11 | 12 | The tool will also extract each registry blocks in the directory 'seg'. The blocks can't be edited from this directory, you need to patch system.dreg directly. 13 | 14 | The patched system.dreg will be placed in the same directory, under the name "system_.dreg" 15 | 16 | # Credit 17 | 18 | Adapted from PSP to PSVita by **Major_Tom**. 19 | 20 | Original version by **skylark@mips.for.ever** 21 | -------------------------------------------------------------------------------- /sha1.h: -------------------------------------------------------------------------------- 1 | #ifndef MHASH_SHA1_H 2 | #define MHASH_SHA1_H 3 | 4 | #include 5 | 6 | typedef unsigned char word8; 7 | typedef unsigned long int word32; 8 | 9 | /* The SHA block size and message digest sizes, in bytes */ 10 | #define SHA_DATASIZE 64 11 | #define SHA_DATALEN 16 12 | #define SHA_DIGESTSIZE 20 13 | #define SHA_DIGESTLEN 5 14 | /* The structure for storing SHA info */ 15 | 16 | typedef struct sha_ctx { 17 | word32 digest[SHA_DIGESTLEN]; /* Message digest */ 18 | word32 count_l, count_h; /* 64-bit block count */ 19 | word8 block[SHA_DATASIZE]; /* SHA data buffer */ 20 | int index; /* index into buffer */ 21 | } SHA_CTX; 22 | 23 | void sha_init(struct sha_ctx *ctx); 24 | void sha_update(struct sha_ctx *ctx, word8 *buffer, word32 len); 25 | void sha_final(struct sha_ctx *ctx); 26 | void sha_digest(struct sha_ctx *ctx, word8 *s); 27 | void sha_copy(struct sha_ctx *dest, struct sha_ctx *src); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /* Fix registry tool adapted from PSP to PSVita by Major_Tom 2 | * Original version by skylark@mips.for.ever 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "sha1.h" 13 | 14 | typedef unsigned char uchar; 15 | 16 | void getcheck(uchar *block, int len, uchar *check) 17 | { 18 | uchar save[4]; 19 | uchar res[20]; 20 | struct sha_ctx ctx; 21 | 22 | memcpy(save, block+14, 4); 23 | memset(block+14, 0, 4); 24 | 25 | sha_init(&ctx); 26 | sha_update(&ctx, block, len); 27 | sha_final(&ctx); 28 | sha_digest(&ctx, res); 29 | 30 | memcpy(block+14, save, 4); 31 | 32 | check[0] = res[4] ^ res[3] ^ res[2] ^ res[1] ^ res[0]; 33 | check[1] = res[9] ^ res[8] ^ res[7] ^ res[6] ^ res[5]; 34 | check[2] = res[14] ^ res[13] ^ res[12] ^ res[11] ^ res[10]; 35 | check[3] = res[19] ^ res[18] ^ res[17] ^ res[16] ^ res[15]; 36 | } 37 | 38 | int checkcheck(uchar *block, int len) 39 | { 40 | uchar res[4]; 41 | getcheck(block, len, res); 42 | if(!memcmp(res, block+14, 4)) 43 | return 1; 44 | return 0; 45 | } 46 | 47 | void fixcheck(uchar *block, int len) 48 | { 49 | uchar res[4]; 50 | getcheck(block, len, res); 51 | memcpy(block+14, res, 4); 52 | } 53 | 54 | unsigned char d[524288]; 55 | struct { 56 | short _0; 57 | short _1; 58 | short parent; 59 | short _2; 60 | short _3; 61 | short nent; 62 | short nblk; 63 | char name[28]; 64 | short _4; 65 | short fat[7]; 66 | short _5; 67 | } a[1024]; 68 | 69 | void walk_fatents(void) 70 | { 71 | int i,j; 72 | for(i=0;i<1024;i++) 73 | if(a[i].nblk) { 74 | /* reassemble segments 75 | it can be done better in-place 76 | bleh i don't care foo */ 77 | uchar *buf=malloc(a[i].nblk*512); 78 | for(j=0;j FIXED\n",i,a[i].name); 92 | fixcheck(buf,a[i].nblk*512); 93 | memcpy(d+512*a[i].fat[0],buf,512); 94 | } 95 | free(buf); 96 | } 97 | } 98 | 99 | int main(void) 100 | { 101 | mkdir("seg", S_IRWXU); 102 | 103 | FILE *f=fopen("system.dreg","r"); 104 | fread(d,1024,512,f); 105 | fclose(f); 106 | f=fopen("system.ireg","r"); 107 | fseek(f,0xBC,SEEK_SET); 108 | fread(a,1024,60,f); 109 | fclose(f); 110 | walk_fatents(); 111 | f=fopen("system_.dreg","wb+"); 112 | fwrite(d,1024,512,f); 113 | fclose(f); 114 | return 0; 115 | } 116 | --------------------------------------------------------------------------------