[rvthtool] extract: Allow the bank number to be omitted for standalone disc images.

This commit is contained in:
David Korth 2018-04-22 16:13:45 -04:00
parent 1229ff4562
commit a3384aa9fe
4 changed files with 36 additions and 16 deletions

View File

@ -76,10 +76,9 @@ extract bank 1.
* If the game is retail-encrypted, it will be converted to debug encryption * If the game is retail-encrypted, it will be converted to debug encryption
and signed using the debug keys. and signed using the debug keys.
* Convert an RVT-R disc image to retail fakesigned: * Convert an RVT-R disc image to retail fakesigned:
* `$ ./rvthtool extract --recrypt=retail RVT-R.gcm 1 RetailFakesigned.gcm` * `$ ./rvthtool extract --recrypt=retail RVT-R.gcm RetailFakesigned.gcm`
* NOTE: Currently, disc images are treated as if they're single-bank RVT-H * The bank number may be omitted if the source file is a standalone disc
HDD images. This is why a bank number is required, even though it will image instead of an RVT-H HDD image or RVT-H Reader device.
always be 1.
* Query available RVT-H Readers: * Query available RVT-H Readers:
``` ```
$ ./rvthtool query $ ./rvthtool query

View File

@ -74,7 +74,7 @@ static bool progress_callback(const RvtH_Progress_State *state)
/** /**
* 'extract' command. * 'extract' command.
* @param rvth_filename [in] RVT-H device or disk image filename. * @param rvth_filename [in] RVT-H device or disk image filename.
* @param s_bank [in] Bank number (as a string). * @param s_bank [in] Bank number (as a string). (If NULL, assumes bank 1.)
* @param gcm_filename [in] Filename for the extracted GCM image. * @param gcm_filename [in] Filename for the extracted GCM image.
* @param recrypt_key [in] Key for recryption. (-1 for default) * @param recrypt_key [in] Key for recryption. (-1 for default)
* @return 0 on success; non-zero on error. * @return 0 on success; non-zero on error.
@ -95,14 +95,27 @@ int extract(const TCHAR *rvth_filename, const TCHAR *s_bank, const TCHAR *gcm_fi
return ret; return ret;
} }
// Validate the bank number. if (s_bank) {
bank = (unsigned int)_tcstoul(s_bank, &endptr, 10) - 1; // Validate the bank number.
if (*endptr != 0 || bank > rvth_get_BankCount(rvth)) { bank = (unsigned int)_tcstoul(s_bank, &endptr, 10) - 1;
fputs("*** ERROR: Invalid bank number '", stderr); if (*endptr != 0 || bank > rvth_get_BankCount(rvth)) {
_fputts(s_bank, stderr); fputs("*** ERROR: Invalid bank number '", stderr);
fputs("'.\n", stderr); _fputts(s_bank, stderr);
rvth_close(rvth); fputs("'.\n", stderr);
return -EINVAL; rvth_close(rvth);
return -EINVAL;
}
} else {
// No bank number specified.
// Assume 1 bank if this is a standalone disc image.
// For HDD images or RVT-H Readers, this is an error.
if (rvth_get_BankCount(rvth) != 1) {
fprintf(stderr, "*** ERROR: Must specify a bank number for this RVT-H Reader%s.\n",
rvth_is_hdd(rvth) ? "" : " disk image");
rvth_close(rvth);
return -EINVAL;
}
bank = 0;
} }
// Print the bank information. // Print the bank information.

View File

@ -30,7 +30,7 @@ extern "C" {
/** /**
* 'extract' command. * 'extract' command.
* @param rvth_filename RVT-H device or disk image filename. * @param rvth_filename RVT-H device or disk image filename.
* @param s_bank Bank number (as a string). * @param s_bank Bank number (as a string). (If NULL, assumes bank 1.)
* @param gcm_filename Filename for the extracted GCM image. * @param gcm_filename Filename for the extracted GCM image.
* @param recrypt_key [in] Key for recryption. (-1 for default) * @param recrypt_key [in] Key for recryption. (-1 for default)
* @return 0 on success; non-zero on error. * @return 0 on success; non-zero on error.

View File

@ -222,11 +222,19 @@ int RVTH_CDECL _tmain(int argc, TCHAR *argv[])
ret = list_banks(argv[optind+1]); ret = list_banks(argv[optind+1]);
} else if (!_tcscmp(argv[optind], _T("extract"))) { } else if (!_tcscmp(argv[optind], _T("extract"))) {
// Extract a bank. // Extract a bank.
if (argc < optind+4) { if (argc < optind+3) {
print_error(argv[0], _T("missing parameters for 'extract'")); print_error(argv[0], _T("missing parameters for 'extract'"));
return EXIT_FAILURE; return EXIT_FAILURE;
} else if (argc == optind+3) {
// Two parameters specified.
// Pass NULL as the bank number, which will be
// interpreted as bank 1 for single-disc images
// and an error for HDD images.
ret = extract(argv[optind+1], NULL, argv[optind+2], recrypt_key);
} else {
// Three or more parameters specified.
ret = extract(argv[optind+1], argv[optind+2], argv[optind+3], recrypt_key);
} }
ret = extract(argv[optind+1], argv[optind+2], argv[optind+3], recrypt_key);
} else if (!_tcscmp(argv[optind], _T("import"))) { } else if (!_tcscmp(argv[optind], _T("import"))) {
// Import a bank. // Import a bank.
if (argc < optind+4) { if (argc < optind+4) {