Skip to content

Instantly share code, notes, and snippets.

@rofl0r
Created October 31, 2024 04:23
Show Gist options
  • Save rofl0r/68e6d112b52f00fa82f9237eb7e50607 to your computer and use it in GitHub Desktop.
Save rofl0r/68e6d112b52f00fa82f9237eb7e50607 to your computer and use it in GitHub Desktop.
convert mode 2 cdrom image files (iso) to mode 1 format
#include <stdio.h>
#include <string.h>
/* small program to convert mode 2 form 1 (XA) cdrom iso files, as produced
by some windows software - maybe nero - to regular mode 1 iso file format.
because for some reason, linux can only mount mode 1 iso files.
the format encountered is basically a raw dump of the disc, including
checksum bytes, sync markers and header.
the means that the \1CD001 header starts at offset 0x9318 instead of 0x8000.
the necessary information was gathered on
http://www.icdia.co.uk/faq/cdifaq3.html and
https://forums.virtualbox.org/viewtopic.php?t=102163
in order to write form 2 disk, define MODE2_FORM2 before compiling.
*/
#ifdef MODE2_FORM2
#define OUTBYTES 2324
#else
#define OUTBYTES 2048
#endif
int main() {
unsigned char buf[12+4+8+2048+280];
while(1) {
size_t l = fread(buf, sizeof(buf), 1, stdin);
if(!l) return 0;
if(memcmp("\0\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\0", buf, 12))
{
fprintf(stderr, "err: no sync bytes found!\n");
return 1;
}
if(buf[15] != '\002') {
fprintf(stderr, "err: not mode2!\n");
return 1;
}
fwrite(buf+24, OUTBYTES, 1, stdout);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment