Commit Graph

928 Commits

Author SHA1 Message Date
David Korth
7fa82f569f [rvthtool] list-banks.c: New function print_bank(), split out from print_bank_table().
This prints out information for an individual bank.

If the RvtH object only has one bank, it's assumed to be a standalone
disc image instead of an RVT-H HDD image.
2018-01-17 21:38:11 -05:00
David Korth
04ef2623c2 [rvthtool] Split the 'list-banks' and 'extract' commands into separate files. 2018-01-17 21:24:37 -05:00
David Korth
4f4ec894ee [rvthtool] extract(): Print the actual destination filename, not "Bank%u".
Forgot to change this when adding the gcm_filename parameter.
2018-01-17 21:23:28 -05:00
David Korth
a461bd7ee0 [rvthtool] main.c: Reworked the command line interface to take a command name and parameters.
Currently supported commands:
- list (or list-banks)
- extract
2018-01-17 21:11:10 -05:00
David Korth
a9656e9a7c [librvth] nhcd_structs.h: Added more LBA definitions and removed the byte definitions.
TODO: Verify the size of GameCube NR images.

rvth.h: Added a macro LBA_TO_BYTES() to convert LBA values to bytes.
2018-01-17 20:56:34 -05:00
David Korth
f9fc1a0119 Reverted back to the CheckC99CompilerFlag and CheckCXX11CompilerFlag macro files.
c_std_99 was added in CMake 3.8, which is a fairly recent version.
Ubuntu 17.04 has CMake 3.9, but 16.10 has 3.7.2. Hence, we shouldn't
use it in order to remain compatible with at least Ubuntu 16.04 LTS.
2018-01-17 20:53:55 -05:00
David Korth
231445a69b Use TCHAR for Unicode filename support on Windows.
[librvth] tcharx.h: Wrapper header that includes <tchar.h> on Windows
and defines macros on other operating systems.
2018-01-17 20:44:46 -05:00
David Korth
8b6b207376 [rvthtool] main.c: Fixed err vs. ret variable confusion and added an rvth_close() in an error path. 2018-01-17 19:57:25 -05:00
David Korth
fcbb936b66 [librvth] rvth.c: Added support for writing sparse files on Windows. 2018-01-17 19:52:11 -05:00
David Korth
2fc8580b0d [librvth] Detect encryption and signature types for Wii images.
This checks the ticket issuer and common key index in order to determine
the encryption key. In addition, if the hash verification and no-crypto
flags are set in the disc header, encryption is assumed to be disabled.
Ticket issuer is still checked to determine the certificate type.

[rvthtool] main.c: Print Wii encryption and signature types.
2018-01-17 00:22:33 -05:00
David Korth
645ee8d987 [librvth] rvth.c: Don't use ftruncate() if !HAVE_FTRUNCATE.
This fixes a regression from commit 2ce87305e1.
([librvth] rvth.c: Use sparse writes if supported.)
2018-01-16 23:59:17 -05:00
David Korth
dc1f104562 [librvth] rvth.c: Check type, not rvth_entry->type, when initializing the LBA values.
This error caused Wii DL and GameCube images to be ripped with the wrong
lengths.

This fixes a regression from commit e8bd9535a2.
([librvth] Split RVTH_BankEntry initialization into a separate function.)
2018-01-16 23:53:05 -05:00
David Korth
7ad7bc83c0 [librvth] rvth.c: Dynamically allocate the RvtH_BankEntry array.
This allows us to indicate how many banks are in the RvtH object,
which will let us use the same object for individual discs.

TODO: Detect individual discs vs. RVT-H images using heuristics.

[rvthtool] main.c: Use rvth_get_BankCount() to get the actual number
of banks in the RVT-H disk image instead of hard-coding 8.
2018-01-16 23:32:06 -05:00
David Korth
e8bd9535a2 [librvth] Split RVTH_BankEntry initialization into a separate function.
This should make it easier to support both RVT-H disk images and
standalone disc images.

TODO: Add a function to open a standalone disc image, and later add
support for CISO and WBFS.
2018-01-16 23:18:51 -05:00
David Korth
ca36421413 [librvth] Use a reference-counted FILE* container in RvtH_BankEntry.
This will allow us to reuse RvtH_BankEntry for standalone disc images.

When opening an RVT-H image, the FILE* pointer will be copied to each
bank entry. This includes "unknown" banks.

TODO: Support opening standalone disc images as if they're an RVT-H
disk image with a single bank.
2018-01-16 23:04:06 -05:00
David Korth
b7a09f57a2 README.md: Added more README stuff. 2018-01-16 22:40:35 -05:00
David Korth
66ea6ef47a [librvth] Added some more useful error codes.
rvth_open(), rvth_get_BankEntry(): Added an optional parameter to
retrieve the error code. This may either be a negative POSIX error code,
or a positive error code from RvtH_Errors.

rvth_open(): Check the NHCD bank table magic number. If it's incorrect,
fail and return RVTH_ERROR_NHCD_TABLE_MAGIC.

rvth_extract(): If the bank is empty, fail and return RVTH_ERROR_BANK_EMPTY.
2018-01-16 22:22:48 -05:00
David Korth
2ce87305e1 [librvth] rvth.c: Use sparse writes if supported.
Preset the file size using fallocate() if the function is available.

Note that this does not work on Windows. (The fseek will simply write
the blank data as normal data.) I'll have to implement sparse writing
on Windows using low-level file I/O instead.
2018-01-16 21:22:23 -05:00
David Korth
634b5e6b6d rvth_extract(): Only do the final fread()/fwrite() if we actually have LBAs to process.
We'd end up with 0-byte read/write calls, which shouldn't do anything,
but there's no point in doing it.
2018-01-16 00:36:45 -05:00
David Korth
5af31f1d74 Fixed issues compiling with 32-bit MSVC 2010.
- win32-msvc.cmake: Fix copy/paste errors from GCN MemCard Recover.
- stdbool.h was added in MSVC 2013, so define the boolean types manually
  if it isn't available.
- MSVC 2010 doesn't support C99, so we have to declare variables at the
  beginning of blocks.
- main() needs to be __cdecl. (Or, I could remove the /Gz option I added
  to rom-properties in order to reduce the binary size a bit, but I'd
  rather keep that in.)
2018-01-16 00:33:35 -05:00
David Korth
e1bef27e18 rvth.c: New function rvth_extract().
This function extracts the specified bank to the specified filename.
A callback may be specified to monitor progress.

main.c: Added a third command line parameter for "bank to extract".

If a third parameter, a bank number (1-8), is specified, that bank will
be extracted to BankX.gcm, where X is the bank number.

TODO: Use getopt() or popt for command line parsing.
2018-01-16 00:12:47 -05:00
David Korth
fd54b2168f Handle the second bank for dual-layer Wii images correctly.
TODO: A dual-layer Wii image cannot start in Bank 8.
2018-01-15 23:29:12 -05:00
David Korth
1d3dc01217 [librvth] CMakeLists.txt: Added rvth.h to ${librvth_H}. 2018-01-15 22:44:57 -05:00
David Korth
20fb383790 Initial reworking of main.c's code into librvth/rvth.c.
This provides a C interface for opening an RVT-H disk image and
retrieving bank information. rvth.c provides a higher-level abstraction
than the raw disk tables (now referred to as NHCD), which makes it
easier to e.g. print disc names and timestamps.

rvth_open() parses the RVT-H bank table and disc headers in order to get
all of the necessary information. It also checks for deleted disc images
and marks them as such.

Deleted images are identified and marked as such. Note that deleted
dual-layer Wii images are currently identified as single-layer, since
we aren't parsing the FST to determine the highest disc address.
2018-01-15 22:38:21 -05:00
David Korth
2f61ac5a06 Renamed rvth_structs.h to nhcd_structs.h.
Renamed the structures accordingly.

NHCD refers to the on-disk magic number. The RVTH_ structs will be used
for a higher-level interface.
2018-01-15 21:45:55 -05:00
David Korth
a8bc8a83ce Split headers from rvthtool into librvth.
This will eventually be rewritten to use an RVT-H "class" (in C)
instead of handling everything manually.

Renamed rvth.h to rvth_structs.h.
2018-01-15 21:39:22 -05:00
David Korth
76d1c4d477 Parse and print the RVT-H bank table.
This also prints some information from the GCN/Wii disc header,
even if the bank table says the bank is empty.
2018-01-15 07:48:12 -05:00
David Korth
f321fe5e65 Initial import of RVT-H Tool.
This program will allow for managing Nintendo RVT-H Reader devkits,
including dumping existing images and installing new images.

The current version doesn't actually do anything. It's mostly a copy
of the infrastructure from rom-properties, with some changes. In
particular, we're using CMake's TARGET_COMPILE_FEATURES() instead of
manually detecting C99 support.
2018-01-15 06:58:54 -05:00