Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
Fix file names being flipped with new generalized code
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaymar committed Mar 1, 2024
1 parent 8fe5576 commit 56fb59f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
6 changes: 6 additions & 0 deletions source/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@
#define htobe16(x) (x)
#define htobe32(x) (x)
#define htobe64(x) (x)
#define eflip16(x) htole16(x)
#define eflip32(x) htole32(x)
#define eflip64(x) htole64(x)
#else
#define htobe16(x) ((uint16_t)(((x) >> 8) & 0xFF) | ((uint16_t)((x)&0xFF) << 8))
#define htobe32(x) (((uint32_t)htobe16(((x) >> 16) & 0xFFFF)) | ((uint32_t)htobe16((x)&0xFFFF) << 16))
#define htobe64(x) (((uint64_t)htobe32(((x) >> 32) & 0xFFFFFFFF)) | ((uint64_t)htobe32((x)&0xFFFFFFFF) << 32))
#define htole16(x) (x)
#define htole32(x) (x)
#define htole64(x) (x)
#define eflip16(x) htobe16(x)
#define eflip32(x) htobe32(x)
#define eflip64(x) htobe64(x)
#endif

#define le16toh(x) htole16(x)
Expand Down
67 changes: 33 additions & 34 deletions source/mode_extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,6 @@ int32_t mode_extract(std::vector<std::string> const& args)
bool show_help = false;
if (args.size() == 1) {
show_help = true;
} else {
if ((args[1] == "-h") || (args[1] == "--help")) {
show_help = true;
}
}
if (show_help) {
auto self = std::filesystem::path(args[0]).filename();
std::cout << self.generic_string() << " " << name << " [options] data_file_or_path [...]" << std::endl;
std::cout << "Exports all data from the given " << std::endl;
std::cout << std::endl;
std::cout << "Options" << std::endl;
std::cout << " -h, --help Show this help" << std::endl;
std::cout << " -o, --output <path> Set output directory" << std::endl;
std::cout << " -i, --input <regex> Only include input files matching the regular expression. Default is to exclude any file with an extension." << std::endl;
std::cout << " -f, --filter <regex> Only include output files matching the regular expression. Will be run after any translation tables have been applied." << std::endl;
std::cout << " -t, --types <path> Add a database file to the Type Hash translation table. Will search the most recently added one first, then continue until there's none left, then search the Strings Hash translation tables." << std::endl;
std::cout << " -n, --names <path> Add a database file to the Name Hash translation table. Will search the most recently added one first, then continue until there's none left, then search the Strings Hash translation tables." << std::endl;
std::cout << " -s, --strings <path> Add a database file to the String Hash translation table." << std::endl;
std::cout << " -d, --dry-run Don't actually do anything." << std::endl;
std::cout << " -r, --rename Rename/Delete files with older or untranslated names or types." << std::endl;
std::cout << " -q, --quiet Decrease verbosity of output." << std::endl;
std::cout << " -v, --verbose Increase verbosity of output." << std::endl;
std::cout << " -x, --index <path> Generate an hash -> file index (csv) for use in external tools." << std::endl;
std::cout << std::endl;
return 1;
}

std::optional<std::regex> input_filter;
Expand All @@ -93,7 +68,9 @@ int32_t mode_extract(std::vector<std::string> const& args)
for (size_t edx = args.size(), idx = 1; idx < edx; ++idx) {
auto arg = args[idx];
if (arg[0] == '-') {
if ((arg == "-o") || (arg == "--output")) {
if ((arg == "-h") || (arg == "--help")) {
show_help = true;
} else if ((arg == "-o") || (arg == "--output")) {
if ((idx + 1) < edx) {
output_path = std::filesystem::absolute(args[idx + 1]);
++idx;
Expand Down Expand Up @@ -167,6 +144,28 @@ int32_t mode_extract(std::vector<std::string> const& args)
}
}

if (show_help) {
auto self = std::filesystem::path(args[0]).filename();
std::cout << self.generic_string() << " " << name << " [options] data_file_or_path [...]" << std::endl;
std::cout << "Exports all data from the given " << std::endl;
std::cout << std::endl;
std::cout << "Options" << std::endl;
std::cout << " -h, --help Show this help" << std::endl;
std::cout << " -o, --output <path> Set output directory" << std::endl;
std::cout << " -i, --input <regex> Only include input files matching the regular expression. Default is to exclude any file with an extension." << std::endl;
std::cout << " -f, --filter <regex> Only include output files matching the regular expression. Will be run after any translation tables have been applied." << std::endl;
std::cout << " -t, --types <path> Add a database file to the Type Hash translation table. Will search the most recently added one first, then continue until there's none left, then search the Strings Hash translation tables." << std::endl;
std::cout << " -n, --names <path> Add a database file to the Name Hash translation table. Will search the most recently added one first, then continue until there's none left, then search the Strings Hash translation tables." << std::endl;
std::cout << " -s, --strings <path> Add a database file to the String Hash translation table." << std::endl;
std::cout << " -d, --dry-run Don't actually do anything." << std::endl;
std::cout << " -r, --rename Rename/Delete files with older or untranslated names or types." << std::endl;
std::cout << " -q, --quiet Decrease verbosity of output." << std::endl;
std::cout << " -v, --verbose Increase verbosity of output." << std::endl;
std::cout << " -x, --index <path> Generate an hash -> file index (csv) for use in external tools." << std::endl;
std::cout << std::endl;
return 1;
}

// Load translation tables...
std::list<hellextractor::hash_db> typedbs;
std::list<hellextractor::hash_db> namedbs;
Expand Down Expand Up @@ -300,16 +299,16 @@ int32_t mode_extract(std::vector<std::string> const& args)
if (file_names.size() > 0) {
++stats_names;
}
file_names.emplace_back(string_printf("%016" PRIx64, htobe64((uint64_t)meta.file.id)));
file_names.emplace_back(string_printf("%016" PRIx64, htole64((uint64_t)meta.file.id)));
file_names.emplace_back(string_printf("%016" PRIx64, (uint64_t)meta.file.id));
file_names.emplace_back(string_printf("%016" PRIx64, eflip64((uint64_t)meta.file.id)));

// Match the type with the type databases.
auto file_types = translations(static_cast<uint64_t>(meta.file.type), typedbs, strings);
if (file_types.size() > 0) {
++stats_types;
}
file_types.emplace_back(string_printf("%016" PRIx64, htobe64((uint64_t)meta.file.type)));
file_types.emplace_back(string_printf("%016" PRIx64, htole64((uint64_t)meta.file.type)));
file_types.emplace_back(string_printf("%016" PRIx64, (uint64_t)meta.file.type));
file_types.emplace_back(string_printf("%016" PRIx64, eflip64((uint64_t)meta.file.type)));

// Generate all permutations.
std::vector<std::pair<std::string, std::string>> permutations;
Expand All @@ -329,8 +328,8 @@ int32_t mode_extract(std::vector<std::string> const& args)

if (index_stream.is_open() && !is_dry) {
index_stream //
<< string_printf("%016" PRIx64, htobe64((uint64_t)meta.file.id)) << "," //
<< string_printf("%016" PRIx64, htobe64((uint64_t)meta.file.type)) << "," //
<< string_printf("%016" PRIx64, (uint64_t)meta.file.id) << "," //
<< string_printf("%016" PRIx64, (uint64_t)meta.file.type) << "," //
<< base_file_name.generic_string() //
<< std::endl;
}
Expand Down Expand Up @@ -376,8 +375,8 @@ int32_t mode_extract(std::vector<std::string> const& args)

if (index_stream.is_open() && !is_dry) {
index_stream //
<< string_printf("%016" PRIx64, htobe64((uint64_t)meta.file.id)) << "," //
<< string_printf("%016" PRIx64, htobe64((uint64_t)meta.file.type)) << "," //
<< string_printf("%016" PRIx64, (uint64_t)meta.file.id) << "," //
<< string_printf("%016" PRIx64, (uint64_t)meta.file.type) << "," //
<< file_name.generic_string() << "," //
<< output.first //
<< std::endl;
Expand Down

0 comments on commit 56fb59f

Please sign in to comment.