Skip to content

Instantly share code, notes, and snippets.

@yekm
Created July 8, 2019 16:16
Show Gist options
  • Save yekm/3ce74a509e65da9d3d6005113be18986 to your computer and use it in GitHub Desktop.
Save yekm/3ce74a509e65da9d3d6005113be18986 to your computer and use it in GitHub Desktop.
extracting rom files from rombank.bin from imbnes psx iso image
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct
{
char name[0x1C];
unsigned short offset;
unsigned short size;
} gl_t;
size_t getFilesize(const char* filename) {
struct stat st;
stat(filename, &st);
return st.st_size;
}
int main(int argc, char** argv) {
size_t filesize = getFilesize(argv[1]);
int fd = open(argv[1], O_RDONLY, 0);
assert(fd != -1);
void* md = mmap(NULL, filesize, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd, 0);
char name[0x1C], fname[0x1c+16];
gl_t* gl = md;
for (int i=0; i<atoi(argv[2]); ++i)
{
strncpy(name, gl[i].name, 0x1c);
name[0x1c-1] = 0;
int j=0x1c-2;
while(j>1)
{
if (name[j] == ' ')
name[j] = 0;
else
break;
j--;
}
sprintf(fname, "%04d %s.nes", i, name);
printf("%d %hx %hx %s\n", i, gl[i].offset, gl[i].size, name);
fsync(1);
FILE *f = fopen(fname, "w");
fwrite(md+gl[i].offset*2048, gl[i].size*0x80, 1, f);
fclose(f);
}
int rc = munmap(md, filesize);
assert(rc == 0);
close(fd);
}
@josedelgadillo82
Copy link

Can you please explain to me how to use it?

@josedelgadillo82
Copy link

Do you have any videos on how to use it? Or the final executable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment