Created
August 11, 2024 02:43
-
-
Save bakueikozo/4c6f89bcf99c3d18be567167503339a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<string.h> | |
#pragma pack(1) | |
typedef struct _romheader { | |
char unknown[32]; | |
char mark[11]; | |
char flag[5]; | |
char unknown2[16]; | |
} ROMHEADER; | |
typedef struct _fileheader { | |
char filename[11]; | |
char flag[1]; | |
unsigned short flag2[2]; | |
unsigned short flag3[8]; | |
} FILEHEADER; | |
int main(int argc,char **argv){ | |
if(argc!=2){ fprintf(stderr,"filename.\n"); } | |
printf("input=%s",argv[1]); | |
FILE *fin=fopen(argv[1],"rb"); | |
if( fin ==NULL ){ fprintf(stderr,"input file error\n"); } | |
ROMHEADER romheader={0}; | |
char buf[128]; | |
memset(buf,0,128); | |
printf("sizeof(ROMHEADER)=%d,sizeof(FILEHEADER)=%d\n",sizeof(ROMHEADER),sizeof(FILEHEADER)); | |
fread(&romheader,1,sizeof(ROMHEADER),fin); | |
if(memcmp(romheader.mark,"BLTROM",6)){ | |
fprintf(stderr,"not BLTROM,but %s\n",romheader.mark); | |
exit(1); | |
} | |
FILEHEADER fhead={0}; | |
while(!feof(fin)){ | |
printf("fin pos=0x%x\n",fin); | |
fread(&fhead,1,sizeof(fhead),fin); | |
if( (fhead.filename[0] & 0xff ) == 0xff ){ | |
printf("end @0x%x\n",ftell(fin)); | |
break; | |
} | |
printf("filename:%.11s flag=0x%02x\n",fhead.filename,fhead.flag[0]); | |
printf("bodysize=%d(%x)\n",fhead.flag3[6],fhead.flag3[6]); | |
char outfile[128]; | |
for(int n=0;n<8;n++){ | |
if( fhead.filename[n] == ' ' ) { fhead.filename[n] = 0; } | |
} | |
mkdir("ROMEXT"); | |
sprintf(outfile,"ROMEXT/%.8s.%.3s",fhead.filename,fhead.filename+8); | |
printf("%s\n",outfile); | |
FILE *fout=fopen(outfile,"wb"); | |
int cnt=0; | |
int breakcnt= (fhead.flag3[6]+16) & 0xfffffff0; | |
while(!feof(fin)){ | |
int c=fgetc(fin); | |
cnt++; | |
if( cnt <= fhead.flag3[6] ){ | |
fputc(c,fout); | |
} | |
if( cnt == breakcnt ){ | |
printf("readbreak on 0x%x\n",ftell(fin)); | |
break; | |
} | |
} | |
fclose(fout); | |
} | |
fclose(fin); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment