Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int filesize( FILE * fp){
- int sz = 0;
- fseek(fp, 0L, SEEK_END);
- sz = ftell(fp);
- fseek(fp, 0L, SEEK_SET);
- return sz;
- }
- int GetFileNameDeb(FILE * fn, char ** filnamPtr){
- int i = 0, nstart = 0, nsize = 0, next = 0, estart = 0, esize = 0;
- char c = '0';
- int tabarr[4] = {0,0,0,0};
- char * filnam;
- if(*filnamPtr != NULL){free(*filnamPtr);}
- if(ftell(fn) > 0x143C0){return -1;}
- while(c != '\n'){
- fread(&c, 1, 1, fn);
- if((c == ' ') && (i < 4)){
- tabarr[i] = ftell(fn);
- i++;
- }
- }
- next = ftell(fn);
- nstart = tabarr[0];
- nsize = tabarr[1]-tabarr[0]-1;
- estart = tabarr[2];
- esize = tabarr[3]-tabarr[2]-1;
- *filnamPtr = (char *) malloc(nsize+esize+1);
- filnam = *filnamPtr;
- fseek(fn, nstart, SEEK_SET);
- fread(filnam, 1, nsize, fn);
- fseek(fn, estart, SEEK_SET);
- fread(&(filnam[nsize]), 1, esize, fn);
- filnam[nsize+esize] = '\0';
- fseek(fn, next, SEEK_SET);
- if(filnam[nsize+esize-1] == 'e'){return 1;} else {return 0;}
- }
- int main(){
- int fileindex = 0;
- int offset1 = 0;
- int offset2 = 0;
- int injectsize = 0;
- int injnum = 0;
- int excess = 0;
- int tablebase = 0;
- int dummy = 0;
- int status = 0;
- char * buffer = NULL;
- char * filename = NULL;
- FILE * rom = NULL;
- FILE * injection = NULL;
- FILE * fn = NULL;
- rom = fopen("ZELOOTMA.z64","rb+");
- fn = fopen("DebugList.txt", "rb");
- if((rom == NULL)||(fn == NULL)){
- printf("Failed to open ROM or DebugList.txt\n\r");
- printf("Make sure your ROM is named ZELOOTMA.z64\n\r");
- goto end;
- }
- //fseek(fn, 0x509C, SEEK_SET);
- printf("ROM and DebugList opened.\n\r");
- tablebase = 0x12F70;
- for(fileindex = 0 ; fileindex < 1532; fileindex++){
- status = GetFileNameDeb(fn, &filename);
- if(status == -1){
- printf("Ran out of fn");
- break;
- }
- injection = fopen(filename, "rb");
- if(injection == NULL){/*printf("Failed to open file %s %d",filename,fileindex);*/ continue;}
- printf("%s ", filename);
- fseek(rom, tablebase + 16*fileindex, SEEK_SET);
- printf("Table Slot %X\n\r", tablebase + 16*fileindex);
- dummy = fread(&offset1, 4, 1, rom);
- offset1 = _byteswap_ulong(offset1);
- fseek(rom, 12, SEEK_CUR);
- dummy = fread(&offset2, 4, 1, rom);
- offset2 = _byteswap_ulong(offset2);
- printf("Start %X End %X\n\r", offset1, offset2);
- injectsize = filesize(injection);
- excess = injectsize - (offset2 - offset1);
- if( excess > 0 ){
- printf("%s is %X bytes too large to inject.\n\r", filename, excess);
- continue;
- }
- offset2 = _byteswap_ulong(offset2 + excess);
- printf("New End %X\n\r",_byteswap_ulong(offset2));
- fseek(rom, tablebase + fileindex*16 + 4, SEEK_SET);
- fwrite(&offset2, 4, 1, rom);
- fseek(rom, offset1, SEEK_SET);
- buffer = (char *) malloc(injectsize);
- dummy = fread(buffer, 1, injectsize, injection);
- dummy = fwrite(buffer, 1, injectsize, rom);
- printf("%X bytes transferred\n\r\n\r", dummy);
- free(buffer);
- injnum++;
- dummy = fclose(injection);
- }
- dummy = fclose(fn);
- dummy = fclose(rom);
- end:
- printf("Injected %d files. Now fix the CRC and you're done.\n\r", injnum);
- printf("AutoInjector program by petrie911.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement