📄 hdl_dump.cpp
字号:
"hdd1: \"Gran Turismo 3\" c:\\gt3.iso SCES_xxx.xx", 1 },
{ CMD_CDVD_INFO, "iin_input",
"Displays signature (startup file), volume label and data size\n"
"for a CD-/DVD-drive or image file.",
"c:\\gt3.gi", "\"hdd2:Gran Turismo 3\"", 0 },
{ CMD_POWER_OFF, "ip",
"Powers-off Playstation 2.",
"192.168.0.10", NULL, 0 },
#if defined (INCLUDE_READ_TEST_CMD)
{ CMD_READ_TEST, "iin_input",
"Consecutively reads all sectors from the specified input.",
"cd0:", NULL, 0 },
#endif /* INCLUDE_READ_TEST_CMD defined? */
#if defined (INCLUDE_CHECK_CMD)
{ CMD_CHECK, "device",
"Attempts to locate and display partition errors.",
"hdd1:", "192.168.0.10", 0 },
#endif /* INCLUDE_CHECK_CMD defined? */
{ NULL, NULL,
NULL,
NULL, NULL, 0 }
};
const char *app;
if (strrchr (app_path, '/') != NULL)
app = strrchr (app_path, '/') + 1;
else if (strrchr (app_path, '\\') != NULL)
app = strrchr (app_path, '\\') + 1;
else
app = app_path;
fprintf (stderr,
"hdl_dump- %02X.%02X.%02X by The W1zard 0f 0z (AKA b...)\n"
"http://hdldump.ps2-scene.org/ w1zard0f07@yahoo.com\n"
"\n", VER_MAJOR,VER_MINOR,VER_PATCH);
command_found = 0;
if (command != NULL)
{ /* display particular command help */
const struct help_entry_t *h = help;
while (h->command_name != NULL)
{
if (strcmp (command, h->command_name) == 0)
{
fprintf (stdout,
"Usage:\t%s %s\n"
"\n"
"%s\n",
h->command_name, h->command_arguments,
h->description);
if (h->example1 != NULL)
fprintf (stdout,
"\n"
"Example:\n"
"%s %s %s\n",
app, h->command_name, h->example1);
if (h->example2 != NULL)
fprintf (stdout,
"\tor\n"
"%s %s %s\n",
app, h->command_name, h->example2);
if (h->dangerous)
fprintf (stdout,
"\n"
"Warning: This command does write on the HDD\n"
" and could cause corruption. Use with care.\n");
command_found = 1;
break;
}
++h;
}
}
if (command == NULL ||
!command_found)
{ /* display all commands only */
const struct help_entry_t *h = help;
int is_first = 1, count = 0;
fprintf (stdout,
"Usage:\n"
"%s command arguments\n"
"\n"
"Where command is one of:\n",
app);
while (h->command_name != NULL)
{
if (!is_first)
{
if ((count % 5) == 0)
fprintf (stdout, ",\n");
else
fprintf (stdout, ", ");
}
else
is_first = 0;
fprintf (stdout, "%s", h->command_name);
if (h->dangerous)
fprintf (stdout, "*");
++h;
++count;
}
fprintf (stdout, "\n");
fprintf (stdout,
"\n"
"Use: %s command\n"
"to show \"command\" help.\n"
"\n"
"Warning: Commands, marked with * (asterisk) does write on the HDD\n"
" and could cause corruption. Use with care.\n"
"\n"
"License: You are only allowed to use this program with a software\n"
" you legally own. Use at your own risk.\n",
app);
if (command != NULL && !command_found)
{
fprintf (stdout,
"\n"
"%s: unrecognized command.\n",
command);
}
}
exit (100);
}
void
map_device_name_or_exit (const char *input,
char output [MAX_PATH])
{
int result = osal_map_device_name (input, output);
switch (result)
{
case RET_OK: return;
case RET_BAD_FORMAT: fprintf (stderr, "%s: bad format.\n", input); exit (100 + RET_BAD_FORMAT);
case RET_BAD_DEVICE: fprintf (stderr, "%s: bad device.\n", input); exit (100 + RET_BAD_DEVICE);
}
}
void
handle_result_and_exit (int result,
const char *device,
const char *partition)
{
switch (result)
{
case RET_OK:
exit (0);
case RET_ERR:
{
unsigned long err_code = osal_get_last_error_code ();
char *error = osal_get_last_error_msg ();
if (error != NULL)
{
fprintf (stderr, "%08lx (%lu): %s\n", err_code, err_code, error);
osal_dispose_error_msg (error);
}
else
fprintf (stderr, "%08lx (%lu): Unknown error.\n", err_code, err_code);
}
exit (1);
case RET_NO_MEM:
fprintf (stderr, "Out of memory.\n");
exit (2);
case RET_NOT_APA:
fprintf (stderr, "%s: not a PlayStation 2 HDD.\n", device);
exit (100 + RET_NOT_APA);
case RET_NOT_HDL_PART:
fprintf (stderr, "%s: not a HD Loader partition", device);
if (partition != NULL)
fprintf (stderr, ": \"%s\".\n", partition);
else
fprintf (stderr, ".\n");
exit (100 + RET_NOT_HDL_PART);
case RET_NOT_FOUND:
fprintf (stderr, "%s: partition not found", device);
if (partition != NULL)
fprintf (stderr, ": \"%s\".\n", partition);
else
fprintf (stderr, ".\n");
exit (100 + RET_NOT_FOUND);
case RET_NO_SPACE:
fprintf (stderr, "%s: not enough free space.\n", device);
exit (100 + RET_NO_SPACE);
case RET_BAD_APA:
fprintf (stderr, "%s: APA partition is broken; aborting.\n", device);
exit (100 + RET_BAD_APA);
case RET_DIFFERENT:
fprintf (stderr, "Contents are different.\n");
exit (100 + RET_DIFFERENT);
case RET_PART_EXISTS:
fprintf (stderr, "%s: partition with such name already exists: \"%s\".\n",
device, partition);
exit (100 + RET_PART_EXISTS);
case RET_BAD_ISOFS:
fprintf (stderr, "%s: bad ISOFS.\n", device);
exit (100 + RET_BAD_ISOFS);
case RET_NOT_PS_CDVD:
fprintf (stderr, "%s: not a Playstation CD-ROM/DVD-ROM.\n", device);
exit (100 + RET_NOT_PS_CDVD);
case RET_BAD_SYSCNF:
fprintf (stderr, "%s: SYSTEM.CNF is not in the expected format.\n", device);
exit (100 + RET_BAD_SYSCNF);
case RET_NOT_COMPAT:
fprintf (stderr, "Input or output is unsupported.\n");
exit (100 + RET_NOT_COMPAT);
case RET_NOT_ALLOWED:
fprintf (stderr, "Operation is not allowed.\n");
exit (100 + RET_NOT_ALLOWED);
case RET_BAD_COMPAT:
fprintf (stderr, "Input or output is supported, but invalid.\n");
exit (100 + RET_BAD_COMPAT);
case RET_SVR_ERR:
fprintf (stderr, "Server reported error.\n");
exit (100 + RET_SVR_ERR);
case RET_1ST_LONGER:
fprintf (stderr, "First input is longer, but until then the contents are the same.\n");
exit (100 + RET_1ST_LONGER);
case RET_2ND_LONGER:
fprintf (stderr, "Second input is longer, but until then the contents are the same.\n");
exit (100 + RET_2ND_LONGER);
case RET_FILE_NOT_FOUND:
fprintf (stderr, "File not found.\n");
exit (100 + RET_FILE_NOT_FOUND);
case RET_BROKEN_LINK:
fprintf (stderr, "Broken link (linked file not found).\n");
exit (100 + RET_BROKEN_LINK);
case RET_CROSS_128GB:
fprintf (stderr, "Unable to limit HDD size to 128GB - data behind 128GB mark.\n");
exit (100 + RET_CROSS_128GB);
default:
fprintf (stderr, "%s: don't know what the error is: %d.\n", device, result);
exit (200);
}
}
int
main (int argc, char *argv [])
{
/*
go_aspi ();
return (0);
*/
if (argc > 1)
{
const char *command_name = argv [1];
if (caseless_compare (command_name, CMD_QUERY))
{ /* show all devices */
handle_result_and_exit (query_devices (), NULL, NULL);
}
#if defined (INCLUDE_DUMP_CMD)
else if (caseless_compare (command_name, CMD_DUMP))
{ /* dump CD/DVD-ROM to the HDD */
char device_name [MAX_PATH];
if (argc != 4)
show_usage_and_exit (argv [0], CMD_DUMP);
map_device_name_or_exit (argv [2], device_name);
handle_result_and_exit (dump_device (device_name, argv [3], 0, get_progress ()),
argv [2], NULL);
}
#endif /* INCLUDE_DUMP_CMD defined? */
#if defined (INCLUDE_COMPARE_CMD)
else if (caseless_compare (command_name, CMD_COMPARE))
{ /* compare two files or devices or etc. */
char device_name_1 [MAX_PATH];
char device_name_2 [MAX_PATH];
int is_device_1 = 0, is_device_2 = 0;
if (argc != 4)
show_usage_and_exit (argv [0], CMD_COMPARE);
is_device_1 = osal_map_device_name (argv [2], device_name_1) == RET_OK ? 1 : 0;
is_device_2 = osal_map_device_name (argv [3], device_name_2) == RET_OK ? 1 : 0;
handle_result_and_exit (compare (is_device_1 ? device_name_1 : argv [2], is_device_1,
is_device_2 ? device_name_2 : argv [3], is_device_2),
NULL, NULL);
}
#endif /* INCLUDE_COMPARE_CMD defined? */
#if defined (INCLUDE_COMPARE_IIN_CMD)
else if (caseless_compare (command_name, CMD_COMPARE_IIN))
{ /* compare two iso inputs */
if (argc != 4)
show_usage_and_exit (argv [0], CMD_COMPARE_IIN);
handle_result_and_exit (compare_iin (argv [2], argv [3], get_progress ()),
NULL, NULL);
}
#endif /* INCLUDE_COMPARE_IIN_CMD defined? */
else if (caseless_compare (command_name, CMD_TOC))
{ /* show TOC of a PlayStation 2 HDD */
if (argc != 3)
show_usage_and_exit (argv [0], CMD_TOC);
handle_result_and_exit (show_toc (argv [2]), argv [2], NULL);
}
else if (caseless_compare (command_name, CMD_HDL_TOC))
{ /* show a TOC of HD Loader games only */
if (argc != 3)
show_usage_and_exit (argv [0], CMD_HDL_TOC);
handle_result_and_exit (show_hdl_toc (argv [2]), argv [2], NULL);
}
#if defined (INCLUDE_MAP_CMD)
else if (caseless_compare (command_name, CMD_MAP))
{ /* show map of a PlayStation 2 HDD */
if (argc != 3)
show_usage_and_exit (argv [0], CMD_MAP);
handle_result_and_exit (show_map (argv [2]), argv [2], NULL);
}
#endif /* INCLUDE_MAP_CMD defined? */
else if (caseless_compare (command_name, CMD_DELETE))
{ /* delete partition */
if (argc != 4)
show_usage_and_exit (argv [0], CMD_DELETE);
handle_result_and_exit (delete_partition (argv [2], argv [3]),
argv [2], argv [3]);
}
#if defined (INCLUDE_ZERO_CMD)
else if (caseless_compare (command_name, CMD_ZERO))
{ /* zero HDD */
char device_name [MAX_PATH];
if (argc != 3)
show_usage_and_exit (argv [0], CMD_ZERO);
map_device_name_or_exit (argv [2], device_name);
handle_result_and_exit (zero_device (device_name),
argv [2], NULL);
}
#endif /* INCLUDE_ZERO_CMD defined? */
#if defined (INCLUDE_INFO_CMD)
else if (caseless_compare (command_name, CMD_HDL_INFO))
{ /* show HD Loader game info */
if (argc != 4)
show_usage_and_exit (argv [0], CMD_HDL_INFO);
handle_result_and_exit (show_hdl_game_info (argv [2], argv [3]),
argv [2], argv [3]);
}
#endif /* INCLUDE_INFO_CMD defined? */
else if (caseless_compare (command_name, CMD_HDL_EXTRACT))
{ /* extract game image from a HD Loader partition */
if (argc != 5)
show_usage_and_exit (argv [0], CMD_HDL_EXTRACT);
handle_result_and_exit (hdl_extract (argv [2], argv [3], argv [4],
get_progress ()),
argv [2], argv [3]);
}
else if (caseless_compare (command_name, CMD_HDL_INJECT_CD))
{ /* inject game image into a new HD Loader partition */
if (argc != 6)
show_usage_and_exit (argv [0], CMD_HDL_INJECT_CD);
handle_result_and_exit (inject (argv [2], argv [3], argv [4],
argc == 6 ? argv [5] : NULL,
0 /* compat flags */, 0, get_progress ()),
argv [2], argv [3]);
}
else if (caseless_compare (command_name, CMD_HDL_INJECT_DVD))
{ /* inject game image into a new HD Loader partition */
if (argc != 6)
show_usage_and_exit (argv [0], CMD_HDL_INJECT_DVD);
handle_result_and_exit (inject (argv [2], argv [3], argv [4],
argc == 6 ? argv [5] : NULL,
0 /* compat flags */, 1, get_progress ()),
argv [2], argv [3]);
}
#if defined (INCLUDE_CUTOUT_CMD)
else if (caseless_compare (command_name, CMD_CUTOUT))
{ /* calculate and display how to arrange a new HD Loader partition */
char device_name [MAX_PATH];
if (argc != 4)
show_usage_and_exit (argv [0], CMD_CUTOUT);
map_device_name_or_exit (argv [2], device_name);
handle_result_and_exit (show_apa_cut_out_for_inject (device_name, atoi (argv [3])),
argv [2], NULL);
}
#endif /* INCLUDE_CUTOUT_CMD defined? */
else if (caseless_compare (command_name, CMD_CDVD_INFO))
{ /* try to display startup file and volume label for an iin */
if (argc != 3)
show_usage_and_exit (argv [0], CMD_CDVD_INFO);
handle_result_and_exit (cdvd_info (argv [2]), argv [2], NULL);
}
#if defined (INCLUDE_READ_TEST_CMD)
else if (caseless_compare (command_name, CMD_READ_TEST))
{
if (argc != 3)
show_usage_and_exit (argv [0], CMD_READ_TEST);
handle_result_and_exit (read_test (argv [2], get_progress ()), argv [2], NULL);
}
#endif /* INCLUDE_READ_TEST_CMD defined? */
else if (caseless_compare (command_name, CMD_POWER_OFF))
{ /* PS2 power-off */
if (argc != 3)
show_usage_and_exit (argv [0], CMD_POWER_OFF);
handle_result_and_exit (remote_poweroff (argv [2]), argv [2], NULL);
}
#if defined (INCLUDE_CHECK_CMD)
else if (caseless_compare (command_name, CMD_CHECK))
{ /* attempt to locate and display partition errors */
if (argc != 3)
show_usage_and_exit (argv [0], CMD_CHECK);
handle_result_and_exit (check (argv [2]), argv [2], NULL);
}
#endif /* INCLUDE_CHECK_CMD defined? */
else
{ /* something else... -h perhaps? */
show_usage_and_exit (argv [0], command_name);
}
}
else
{
show_usage_and_exit (argv [0], NULL);
}
return (0); /* please compiler */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -