Skip to content

Commit 0a25b32

Browse files
committed
Add support for XGD1
Use correct offset when rewriting from XDG ISO
1 parent f6d8223 commit 0a25b32

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

extract-xiso.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,9 @@
441441
#endif
442442

443443

444-
#define GLOBAL_LSEEK_OFFSET 0xFD90000ul
445-
#define XGD3_LSEEK_OFFSET 0x2080000ul
444+
#define GLOBAL_LSEEK_OFFSET 0x0FD90000ul
445+
#define XGD3_LSEEK_OFFSET 0x02080000ul
446+
#define XGD1_LSEEK_OFFSET 0x18300000ul
446447

447448
#define n_sectors( size ) ( ( size ) / XISO_SECTOR_SIZE + ( ( size ) % XISO_SECTOR_SIZE ? 1 : 0 ) )
448449

@@ -882,18 +883,25 @@ int verify_xiso( int in_xiso, int32_t *out_root_dir_sector, int32_t *out_root_di
882883
if ( ! err && read( in_xiso, buffer, XISO_HEADER_DATA_LENGTH ) != XISO_HEADER_DATA_LENGTH ) read_err();
883884
if ( ! err && memcmp( buffer, XISO_HEADER_DATA, XISO_HEADER_DATA_LENGTH ) )
884885
{
885-
if ( lseek( in_xiso, (xoff_t) XISO_HEADER_OFFSET + GLOBAL_LSEEK_OFFSET, SEEK_SET ) == -1 ) seek_err();
886-
if ( ! err && read( in_xiso, buffer, XISO_HEADER_DATA_LENGTH ) != XISO_HEADER_DATA_LENGTH ) read_err();
887-
if ( ! err && memcmp( buffer, XISO_HEADER_DATA, XISO_HEADER_DATA_LENGTH ) ) {
888-
889-
if ( lseek( in_xiso, (xoff_t) XISO_HEADER_OFFSET + XGD3_LSEEK_OFFSET, SEEK_SET ) == -1 ) seek_err();
886+
if ( lseek( in_xiso, (xoff_t) XISO_HEADER_OFFSET + GLOBAL_LSEEK_OFFSET, SEEK_SET ) == -1 ) seek_err();
890887
if ( ! err && read( in_xiso, buffer, XISO_HEADER_DATA_LENGTH ) != XISO_HEADER_DATA_LENGTH ) read_err();
891-
if ( ! err && memcmp( buffer, XISO_HEADER_DATA, XISO_HEADER_DATA_LENGTH ) ) misc_err( "%s does not appear to be a valid xbox iso image\n", in_iso_name, 0, 0 )
892-
else s_xbox_disc_lseek = XGD3_LSEEK_OFFSET;
888+
if ( ! err && memcmp( buffer, XISO_HEADER_DATA, XISO_HEADER_DATA_LENGTH ) ) {
889+
890+
if ( lseek( in_xiso, (xoff_t) XISO_HEADER_OFFSET + XGD3_LSEEK_OFFSET, SEEK_SET ) == -1 ) seek_err();
891+
if ( ! err && read( in_xiso, buffer, XISO_HEADER_DATA_LENGTH ) != XISO_HEADER_DATA_LENGTH ) read_err();
892+
if (!err && memcmp(buffer, XISO_HEADER_DATA, XISO_HEADER_DATA_LENGTH)) {
893+
894+
if (lseek(in_xiso, (xoff_t)XISO_HEADER_OFFSET + XGD1_LSEEK_OFFSET, SEEK_SET) == -1) seek_err();
895+
if (!err && read(in_xiso, buffer, XISO_HEADER_DATA_LENGTH) != XISO_HEADER_DATA_LENGTH) read_err();
896+
if (!err && memcmp(buffer, XISO_HEADER_DATA, XISO_HEADER_DATA_LENGTH)) misc_err("%s does not appear to be a valid xbox iso image\n", in_iso_name, 0, 0)
897+
else s_xbox_disc_lseek = XGD1_LSEEK_OFFSET;
898+
899+
}
900+
else s_xbox_disc_lseek = XGD3_LSEEK_OFFSET;
901+
}
902+
else s_xbox_disc_lseek = GLOBAL_LSEEK_OFFSET;
893903
}
894-
else s_xbox_disc_lseek = GLOBAL_LSEEK_OFFSET;
895-
}
896-
else s_xbox_disc_lseek = 0;
904+
else s_xbox_disc_lseek = 0;
897905

898906
// read root directory information
899907
if ( ! err && read( in_xiso, out_root_dir_sector, XISO_SECTOR_OFFSET_SIZE ) != XISO_SECTOR_OFFSET_SIZE ) read_err();
@@ -1022,7 +1030,7 @@ int create_xiso( char *in_root_directory, char *in_output_directory, dir_node_av
10221030
}
10231031
if ( ! err ) {
10241032
if ( in_root ) {
1025-
if ( lseek( in_xiso, (xoff_t) XISO_HEADER_OFFSET + XISO_HEADER_DATA_LENGTH + XISO_SECTOR_OFFSET_SIZE + XISO_DIRTABLE_SIZE, SEEK_SET ) == -1 ) seek_err();
1033+
if ( lseek( in_xiso, (xoff_t) XISO_HEADER_OFFSET + XISO_HEADER_DATA_LENGTH + XISO_SECTOR_OFFSET_SIZE + XISO_DIRTABLE_SIZE + s_xbox_disc_lseek, SEEK_SET ) == -1 ) seek_err();
10261034
if ( ! err && read( in_xiso, buf, XISO_FILETIME_SIZE ) != XISO_FILETIME_SIZE ) read_err();
10271035
if ( ! err && write( xiso, buf, XISO_FILETIME_SIZE ) != XISO_FILETIME_SIZE ) write_err();
10281036

@@ -1738,7 +1746,7 @@ int write_file( dir_node_avl *in_avl, write_tree_context *in_context, int in_dep
17381746
if ( in_context->from == -1 ) {
17391747
if ( ( fd = open( in_avl->filename, READFLAGS, 0 ) ) == -1 ) open_err( in_avl->filename );
17401748
} else {
1741-
if ( lseek( fd = in_context->from, (xoff_t) in_avl->old_start_sector * XISO_SECTOR_SIZE, SEEK_SET ) == -1 ) seek_err();
1749+
if ( lseek( fd = in_context->from, (xoff_t) in_avl->old_start_sector * XISO_SECTOR_SIZE + s_xbox_disc_lseek, SEEK_SET ) == -1 ) seek_err();
17421750
}
17431751
}
17441752

0 commit comments

Comments
 (0)