2

I was wondering which is the best way to get the title from a disk image in .iso or .cue+.bin format, Is there any java library that can do this or should I read from the file header?

UPDATE: I managed to do it, i was particularly interested in PSX ISOs title. It's 10 bytes long and this is a sample code to read it:

File f = new File("cdimage2.bin");
FileInputStream fin = new FileInputStream(f);
fin.skip(37696);
int i = 0;
while (i < 10) {
    System.out.print((char) fin.read());
    i++;
}
System.out.println();

UPDATE2: This method is better:

private String getPSXId(File f) {
FileInputStream fin;
try {
    fin = new FileInputStream(f);
    fin.skip(32768);
    byte[] buffer = new byte[4096];
    long start = System.currentTimeMillis();
    while (fin.read(buffer) != -1) {
        String buffered = new String(buffer);

        if (buffered.contains("BOOT = cdrom:\\")) {
            String tmp = "";
            int lidx = buffered.lastIndexOf("BOOT = cdrom:\\") + 14;
            for (int i = 0; i < 11; i++) {
                tmp += buffered.charAt(lidx + i);
            }
            long elapsed = System.currentTimeMillis() - start;
            // System.out.println("BOOT = cdrom:\\" + tmp);
            tmp = tmp.toUpperCase().replace(".", "").replace("_", "-");
            fin.close();
            return tmp;
        }

    }
    fin.close();
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

return null;

}
Vektor88
  • 4,841
  • 11
  • 59
  • 111

1 Answers1

4

Just start reading after 32768 bytes (unused by ISO9660) in 2048 byte chunks (Volume Descriptor). The first byte determines the type of the descriptor, and 1 means Primary Volume Descriptor, which contain the title after the first 7 bytes (which are always \x01CD001\x01). The next byte is a NUL (\x00) and it is followed by 32 bytes of system and 32 bytes of volume identifier, the latter usually known and displayed as title. See http://alumnus.caltech.edu/~pje/iso9660.html for a more detailed description.

dnet
  • 1,411
  • 9
  • 19
  • I was interested particularly in PSX isos, and i found that the title is 10 bytes long and starts at byte 37696 – Vektor88 Aug 22 '13 at 10:30