From 5daf7bf6c00221104fe6544b72832ee9c1583e62 Mon Sep 17 00:00:00 2001 From: koolkdev Date: Tue, 23 Apr 2024 23:25:18 +0300 Subject: [PATCH 01/12] use `std::println` instead of std::cout` and `std::format` --- wfs-extract/src/main.cpp | 44 +++++++++++++++---------------- wfs-file-injector/src/main.cpp | 33 ++++++++++++----------- wfs-fuse/src/main.cpp | 12 ++++----- wfs-info/src/main.cpp | 48 ++++++++++++++++------------------ wfs-reencryptor/src/main.cpp | 41 ++++++++++++++--------------- 5 files changed, 86 insertions(+), 92 deletions(-) diff --git a/wfs-extract/src/main.cpp b/wfs-extract/src/main.cpp index 3a5322e..e5e41a6 100644 --- a/wfs-extract/src/main.cpp +++ b/wfs-extract/src/main.cpp @@ -9,10 +9,10 @@ #include #include #include -#include #include #include #include +#include #include #include @@ -30,7 +30,7 @@ void dumpdir(const std::filesystem::path& target, target_dir /= path; if (!std::filesystem::exists(target_dir)) { if (!std::filesystem::create_directories(target_dir)) { - std::cerr << "Error: Failed to create directory " << target_dir.string() << std::endl; + std::println(std::cerr, "Error: Failed to create directory {}", target_dir.string()); return; } } @@ -39,7 +39,7 @@ void dumpdir(const std::filesystem::path& target, try { auto item = throw_if_error(item_or_error); if (verbose) - std::cout << "Dumping /" << npath.generic_string() << std::endl; + std::println("Dumping /{}", npath.generic_string()); if (item->is_directory()) { dumpdir(target, std::dynamic_pointer_cast(item), npath, verbose); } else if (item->is_file()) { @@ -52,7 +52,7 @@ void dumpdir(const std::filesystem::path& target, stream.read(data.data(), std::min(data.size(), to_read)); auto read = stream.gcount(); if (read <= 0) { - std::cerr << "Error: Failed to read /" << npath.generic_string() << std::endl; + std::println(std::cerr, "Error: Failed to read /{}", npath.generic_string()); break; } output_file.write(data.data(), read); @@ -61,7 +61,7 @@ void dumpdir(const std::filesystem::path& target, output_file.close(); } } catch (const WfsException& e) { - std::cout << std::format("Error: Failed to dump {} ({})\n", prettify_path(npath), e.what()); + std::println(std::cerr, "Error: Failed to dump {} ({})", prettify_path(npath), e.what()); } } } @@ -112,10 +112,10 @@ int main(int argc, char* argv[]) { boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); if (vm.count("help")) { - std::cout << "usage: wfs-extract --input [--type ]" << std::endl - << " [--otp [--seeprom ]]" << std::endl - << " [--dump-path ] [--verbose]" << std::endl - << std::endl; + std::println("usage: wfs-extract --input [--type ]"); + std::println(" [--otp [--seeprom ]]"); + std::println(" [--dump-path ] [--verbose]"); + std::println(""); std::cout << desc << std::endl; return 0; } @@ -139,8 +139,8 @@ int main(int argc, char* argv[]) { throw boost::program_options::error("Missing --seeprom"); } catch (const boost::program_options::error& e) { - std::cerr << "Error: " << e.what() << std::endl; - std::cerr << "Use --help to display program options" << std::endl; + std::println(std::cerr, "Error: {}", e.what()); + std::println(std::cerr, "Use --help to display program options"); return 1; } @@ -154,9 +154,9 @@ int main(int argc, char* argv[]) { auto wfs_with_usr_dir = Recovery::OpenUsrDirectoryWithoutWfsDeviceHeader(device, key); if (!wfs_with_usr_dir.has_value()) { if (wfs_with_usr_dir.error() == WfsError::kInvalidWfsVersion) { - std::cerr - << "Error: Didn't find directory at the expected location, either the /usr dir is also corrupted or " - "the keys are wrong"; + std::println(std::cerr, + "Error: Didn't find directory at the expected location, either the /usr dir is also corrupted " + "or the keys are wrong"); } else { throw WfsException(wfs_with_usr_dir.error()); } @@ -169,17 +169,17 @@ int main(int argc, char* argv[]) { } else if (dump_path.starts_with("usr/")) { dump_path = dump_path.substr(4); } else { - std::cerr << "Error: can only dump the /usr directory in this mode"; + std::println(std::cerr, "Error: can only dump the /usr directory in this mode"); return 1; } } auto dir = (*wfs_with_usr_dir)->GetDirectory(dump_path); if (!dir) { - std::cerr << "Error: Didn't find directory /usr/" << dump_path << " in wfs" << std::endl; + std::println(std::cerr, "Error: Didn't find directory /usr/{} in wfs", dump_path); return 1; } dumpdir(std::filesystem::path(output_path), dir, "usr/" + dump_path, verbose); - std::cout << "Done!" << std::endl; + std::println("Done!"); return 0; } @@ -187,21 +187,21 @@ int main(int argc, char* argv[]) { auto detection_result = Recovery::DetectDeviceParams(device, key); if (detection_result.has_value()) { if (*detection_result == WfsError::kInvalidWfsVersion) - std::cerr << "Error: Incorrect WFS version, possible wrong keys"; + std::println(std::cerr, "Error: Incorrect WFS version, possible wrong keys"); else throw WfsException(*detection_result); return 1; } auto dir = throw_if_error(WfsDevice::Open(device, key))->GetDirectory(dump_path); if (!dir) { - std::cerr << "Error: Didn't find directory " << dump_path << " in wfs" << std::endl; + std::println(std::cerr, "Error: Didn't find directory {} in wfs", dump_path); return 1; } - std::cout << "Dumping..." << std::endl; + std::println("Dumping..."); dumpdir(std::filesystem::path(output_path), dir, dump_path, verbose); - std::cout << "Done!" << std::endl; + std::println("Done!"); } catch (std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; + std::println(std::cerr, "Error: {}", e.what()); return 1; } return 0; diff --git a/wfs-file-injector/src/main.cpp b/wfs-file-injector/src/main.cpp index 930e13b..7ef8eae 100644 --- a/wfs-file-injector/src/main.cpp +++ b/wfs-file-injector/src/main.cpp @@ -6,10 +6,10 @@ */ #include -#include #include #include #include +#include #include #include @@ -60,11 +60,10 @@ int main(int argc, char* argv[]) { boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); if (vm.count("help")) { - std::cout << "usage: wfs-file-injector --image [--type ]" << std::endl - << " [--otp [--seeprom ]]" << std::endl - << " --inject-file --inject-path " - << std::endl - << std::endl; + std::println("usage: wfs-file-injector --image [--type ]"); + std::println(" [--otp [--seeprom ]]"); + std::println(" --inject-file --inject-path "); + std::println(""); std::cout << desc << std::endl; return 0; } @@ -85,8 +84,8 @@ int main(int argc, char* argv[]) { throw boost::program_options::error("Missing --seeprom"); } catch (const boost::program_options::error& e) { - std::cerr << "Error: " << e.what() << std::endl; - std::cerr << "Use --help to display program options" << std::endl; + std::println(std::cerr, "Error: {}", e.what()); + std::println(std::cerr, "Use --help to display program options"); return 1; } @@ -94,12 +93,12 @@ int main(int argc, char* argv[]) { std::ifstream input_file(inject_file, std::ios::binary | std::ios::in); if (input_file.fail()) { - std::cerr << "Failed to open file to inject" << std::endl; + std::println(std::cerr, "Failed to open file to inject"); return 1; } input_file.seekg(0, std::ios::end); if (static_cast(input_file.tellg()) > SIZE_MAX) { - std::cerr << "Error: File to inject too big" << std::endl; + std::println(std::cerr, "Error: File to inject too big"); return 1; } size_t file_size = static_cast(input_file.tellg()); @@ -109,19 +108,19 @@ int main(int argc, char* argv[]) { auto detection_result = Recovery::DetectDeviceParams(device, key); if (detection_result.has_value()) { if (*detection_result == WfsError::kInvalidWfsVersion) - std::cerr << "Error: Incorrect WFS version, possible wrong keys"; + std::println(std::cerr, "Error: Incorrect WFS version, possible wrong keys"); else throw WfsException(*detection_result); return 1; } auto file = throw_if_error(WfsDevice::Open(device, key))->GetFile(inject_path); if (!file) { - std::cerr << "Error: Didn't find file " << inject_path << " in wfs" << std::endl; + std::println(std::cerr, "Error: Didn't find file {} in wfs", inject_path); return 1; } if (file_size > file->SizeOnDisk()) { - std::cerr << "Error: File to inject too big (wanted size: " << file_size - << " bytes, available size: " << file->SizeOnDisk() << ")" << std::endl; + std::println(std::cerr, "Error: File to inject too big (wanted size: {} bytes, available size: {})", file_size, + file->SizeOnDisk()); return 1; } File::stream stream(file); @@ -131,7 +130,7 @@ int main(int argc, char* argv[]) { input_file.read(data.data(), std::min(data.size(), to_copy)); auto read = input_file.gcount(); if (read <= 0) { - std::cerr << "Error: Failed to read file to inject" << std::endl; + std::println(std::cerr, "Error: Failed to read file to inject"); return 1; } stream.write(data.data(), read); @@ -142,9 +141,9 @@ int main(int argc, char* argv[]) { if (file_size < file->Size()) { file->Resize(file_size); } - std::cout << "Done!" << std::endl; + std::println("Done!"); } catch (std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; + std::println(std::cerr, "Error: {}", e.what()); return 1; } return 0; diff --git a/wfs-fuse/src/main.cpp b/wfs-fuse/src/main.cpp index 1f46c5c..e6a5297 100644 --- a/wfs-fuse/src/main.cpp +++ b/wfs-fuse/src/main.cpp @@ -190,7 +190,7 @@ int main(int argc, char* argv[]) { return 1; } if (fuse_opt_parse(&args, ¶m, wfs_opts, wfs_process_arg)) { - printf("failed to parse option\n"); + printf(stderr, "failed to parse option\n"); return 1; } @@ -202,15 +202,15 @@ int main(int argc, char* argv[]) { is_mlc = param.type && !strcmp(param.type, "mlc"); is_plain = param.type && !strcmp(param.type, "plain"); if (!is_usb && !is_mlc && !is_plain) { - printf("Unsupported type (--type=usb/mlc/plain)\n"); + fprintf(stderr, "Unsupported type (--type=usb/mlc/plain)\n"); return 1; } if ((is_mlc || is_usb) && !param.otp) { - printf("Missing otp file (--otp)\n"); + fprintf(stderr, "Missing otp file (--otp)\n"); return 1; } if (is_usb && !param.seeprom) { - printf("Missing seeprom file (--seeprom)\n"); + fprintf(stderr, "Missing seeprom file (--seeprom)\n"); return 1; } if (param.otp) @@ -224,14 +224,14 @@ int main(int argc, char* argv[]) { auto detection_result = Recovery::DetectDeviceParams(device, key); if (detection_result.has_value()) { if (*detection_result == WfsError::kInvalidWfsVersion) - std::cerr << "Error: Incorrect WFS version, possible wrong keys"; + fprintf(stderr, "Error: Incorrect WFS version, possible wrong keys\n"); else throw WfsException(*detection_result); return 1; } wfs_device = throw_if_error(WfsDevice::Open(device, key)); } catch (std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; + fprintf(stderr, "Error: %s\n", e.what()); return 1; } diff --git a/wfs-info/src/main.cpp b/wfs-info/src/main.cpp index 89fc35c..23f07db 100644 --- a/wfs-info/src/main.cpp +++ b/wfs-info/src/main.cpp @@ -6,12 +6,11 @@ */ #include -#include #include -#include #include #include #include +#include #include #include @@ -25,19 +24,19 @@ std::string inline prettify_path(const std::filesystem::path& path) { void quotaInfo(int depth, const std::filesystem::path& path, const std::shared_ptr& quota) { std::string padding(depth, '\t'); - std::cout << std::format("{}Area {} [0x{:08x}-0x{:08x}]:\n", padding, prettify_path(path), - quota->device_block_number(), quota->to_area_block_number(quota->blocks_count())); + std::println("{}Area {} [0x{:08x}-0x{:08x}]:", padding, prettify_path(path), quota->device_block_number(), + quota->to_area_block_number(quota->blocks_count())); padding += '\t'; std::shared_ptr allocator = throw_if_error(quota->GetFreeBlocksAllocator()); FreeBlocksTree tree(allocator.get()); auto* allocator_header = EPTree(allocator.get()).extra_header(); - std::cout << std::format("{}Free blocks: 0x{:08x}\n", padding, allocator_header->free_blocks_count.value()); - std::cout << std::format("{}Free metadata blocks: 0x{:08x}\n", padding, - quota->to_device_block_number(allocator_header->free_blocks_cache_count.value())); - std::cout << std::format("{}Free metadata block: 0x{:08x}\n", padding, - quota->to_device_block_number(allocator_header->free_blocks_cache_count.value())); + std::println("{}Free blocks: 0x{:08x}", padding, allocator_header->free_blocks_count.value()); + std::println("{}Free metadata blocks: 0x{:08x}", padding, + quota->to_device_block_number(allocator_header->free_blocks_cache_count.value())); + std::println("{}Free metadata block: 0x{:08x}", padding, + quota->to_device_block_number(allocator_header->free_blocks_cache_count.value())); std::vector ranges; for (const auto& extent : tree) { @@ -47,11 +46,11 @@ void quotaInfo(int depth, const std::filesystem::path& path, const std::shared_p ranges.push_back({extent.block_number(), extent.blocks_count()}); } - std::cout << std::format("{}Free ranges:\n", padding); + std::println("{}Free ranges:", padding); padding += '\t'; for (const auto& range : ranges) { - std::cout << std::format("{}[0x{:08x}-0x{:08x}]\n", padding, quota->to_device_block_number(range.block_number), - quota->to_device_block_number(range.block_number + range.blocks_count)); + std::println("{}[0x{:08x}-0x{:08x}]", padding, quota->to_device_block_number(range.block_number), + quota->to_device_block_number(range.block_number + range.blocks_count)); } } @@ -67,7 +66,7 @@ void dirInfo(int depth, const std::shared_ptr& dir, const std::filesy if (item->is_directory()) dirInfo(depth, std::dynamic_pointer_cast(item), npath); } catch (const WfsException& e) { - std::cout << std::format("Error: Failed to dump {} ({})\n", prettify_path(npath), e.what()); + std::println(std::cerr, "Error: Failed to dump {} ({})", prettify_path(npath), e.what()); } } } @@ -112,10 +111,9 @@ int main(int argc, char* argv[]) { boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); if (vm.count("help")) { - std::cout << "usage: wfs-info --input [--type ]" << std::endl - << " [--otp [--seeprom ]]" << std::endl - << std::endl - << std::endl; + std::println("usage: wfs-info --input [--type ]"); + std::println(" [--otp [--seeprom ]]"); + std::println(""); std::cout << desc << std::endl; return 0; } @@ -136,8 +134,8 @@ int main(int argc, char* argv[]) { throw boost::program_options::error("Missing --seeprom"); } catch (const boost::program_options::error& e) { - std::cerr << "Error: " << e.what() << std::endl; - std::cerr << "Use --help to display program options" << std::endl; + std::println(std::cerr, "Error: {}", e.what()); + std::println(std::cerr, "Use --help to display program options"); return 1; } @@ -146,20 +144,20 @@ int main(int argc, char* argv[]) { auto detection_result = Recovery::DetectDeviceParams(device, key); if (detection_result.has_value()) { if (*detection_result == WfsError::kInvalidWfsVersion) - std::cerr << "Error: Incorrect WFS version, possible wrong keys"; + std::println(std::cerr, "Error: Incorrect WFS version, possible wrong keys"); else throw WfsException(*detection_result); return 1; } auto wfs_device = throw_if_error(WfsDevice::Open(device, key)); - std::cout << "Allocator state:" << std::endl; + std::println("Allocator state:"); auto transactions_area = throw_if_error(wfs_device->GetTransactionsArea()); - std::cout << std::format("Transactions area [0x{:08x}-0x{:08x}]\n", transactions_area->device_block_number(), - transactions_area->to_device_blocks_count(transactions_area->blocks_count())); + std::println("Transactions area [0x{:08x}-0x{:08x}]", transactions_area->device_block_number(), + transactions_area->to_device_blocks_count(transactions_area->blocks_count())); dirInfo(0, throw_if_error(wfs_device->GetRootDirectory()), {}); - std::cout << "Done!" << std::endl; + std::println("Done!"); } catch (std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; + std::println(std::cerr, "Error: {}", e.what()); return 1; } return 0; diff --git a/wfs-reencryptor/src/main.cpp b/wfs-reencryptor/src/main.cpp index 328c199..979327d 100644 --- a/wfs-reencryptor/src/main.cpp +++ b/wfs-reencryptor/src/main.cpp @@ -8,10 +8,10 @@ #include #include #include -#include #include #include #include +#include #include #include @@ -83,18 +83,17 @@ void exploreDir(const std::shared_ptr& dir, const std::filesystem::pa for ([[maybe_unused]] const auto& extent : tree) { } } catch (const WfsException& e) { - std::cout << std::format("Error: Failed to explore {} free blocks allocator ({})\n", prettify_path(path), - e.what()); + std::println(std::cerr, "Error: Failed to explore {} free blocks allocator ({})", prettify_path(path), e.what()); } try { exploreDir(throw_if_error(quota->GetShadowDirectory1()), path / ".shadow_dir_1", true); } catch (const WfsException& e) { - std::cout << std::format("Error: Failed to explore {} shadow dir 12 ({})\n", prettify_path(path), e.what()); + std::println(std::cerr, "Error: Failed to explore {} shadow dir 12 ({})", prettify_path(path), e.what()); } try { exploreDir(throw_if_error(quota->GetShadowDirectory2()), path / ".shadow_dir_2", true); } catch (const WfsException& e) { - std::cout << std::format("Error: Failed to explore {} shadow dir 2 ({})\n", prettify_path(path), e.what()); + std::println(std::cerr, "Error: Failed to explore {} shadow dir 2 ({})", prettify_path(path), e.what()); } } for (auto [name, item_or_error] : *dir) { @@ -112,14 +111,14 @@ void exploreDir(const std::shared_ptr& dir, const std::filesystem::pa stream.read(data.data(), std::min(data.size(), to_read)); auto read = stream.gcount(); if (read <= 0) { - std::cerr << "Error: Failed to read /" << npath.generic_string() << std::endl; + std::println(std::cerr, "Error: Failed to read /{}", npath.generic_string()); break; } to_read -= static_cast(read); } } } catch (const WfsException& e) { - std::cout << std::format("Error: Failed to explore {} ({})\n", prettify_path(npath), e.what()); + std::println(std::cerr, "Error: Failed to explore {} ({})", prettify_path(npath), e.what()); } } } @@ -128,12 +127,12 @@ void exploreTransactions(const std::shared_ptr& wfs_device) { try { throw_if_error(wfs_device->GetTransactionsArea(false)); } catch (const WfsException& e) { - std::cout << std::format("Error: Failed to explore transactions area 1 ({})\n", e.what()); + std::println(std::cerr, "Error: Failed to explore transactions area 1 ({})", e.what()); } try { throw_if_error(wfs_device->GetTransactionsArea(true)); } catch (const WfsException& e) { - std::cout << std::format("Error: Failed to explore transactions area 2 ({})\n", e.what()); + std::println(std::cerr, "Error: Failed to explore transactions area 2 ({})", e.what()); } } @@ -183,12 +182,10 @@ int main(int argc, char* argv[]) { boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); if (vm.count("help")) { - std::cout << "usage: wfs-reencryptor --input [--output ]" << std::endl - << " [--input-type ] [--input-otp [--input-seeprom ]]" - << std::endl - << " [--output-type ] [--output-otp [--output-seeprom ]]" - << std::endl - << std::endl; + std::println("usage: wfs-reencryptor --input [--output ]"); + std::println(" [--input-type ] [--input-otp [--input-seeprom ]]"); + std::println(" [--output-type ] [--output-otp [--output-seeprom ]]"); + std::println(""); std::cout << desc << std::endl; return 0; } @@ -225,8 +222,8 @@ int main(int argc, char* argv[]) { throw boost::program_options::error("Missing --output-seeprom"); } catch (const boost::program_options::error& e) { - std::cerr << "Error: " << e.what() << std::endl; - std::cerr << "Use --help to display program options" << std::endl; + std::println(std::cerr, "Error: {}", e.what()); + std::println(std::cerr, "Use --help to display program options"); return 1; } @@ -237,7 +234,7 @@ int main(int argc, char* argv[]) { auto detection_result = Recovery::DetectDeviceParams(input_device, input_key); if (detection_result.has_value()) { if (*detection_result == WfsError::kInvalidWfsVersion) - std::cerr << "Error: Incorrect WFS version, possible wrong keys"; + std::println(std::cerr, "Error: Incorrect WFS version, possible wrong keys"); else throw WfsException(*detection_result); return 1; @@ -248,17 +245,17 @@ int main(int argc, char* argv[]) { /*read_only=*/false, /*open_create=*/true) : input_device; - std::cout << "Exploring blocks..." << std::endl; + std::println("Exploring blocks..."); auto reencryptor = std::make_shared(input_device, input_key); auto wfs_device = throw_if_error(WfsDevice::Open(reencryptor)); exploreTransactions(wfs_device); exploreDir(throw_if_error(wfs_device->GetRootDirectory()), {}); - std::cout << std::format("Found {} blocks! Reencrypting...\n", reencryptor->blocks().size()); + std::println("Found {} blocks! Reencrypting...", reencryptor->blocks().size()); reencryptor->Reencrypt(std::make_shared(output_device, output_key)); - std::cout << "Done!" << std::endl; + std::println("Done!"); } catch (std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; + std::println(std::cerr, "Error: {}", e.what()); return 1; } return 0; From 29be1f698daa5d14e5117d3e767e1e35f2670070 Mon Sep 17 00:00:00 2001 From: koolkdev Date: Tue, 23 Apr 2024 23:31:05 +0300 Subject: [PATCH 02/12] fix --- wfs-fuse/src/main.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/wfs-fuse/src/main.cpp b/wfs-fuse/src/main.cpp index e6a5297..16f646e 100644 --- a/wfs-fuse/src/main.cpp +++ b/wfs-fuse/src/main.cpp @@ -11,7 +11,7 @@ #include #include -static std::shared_ptr wfs_device; +static std::shared_ptr g_wfs_device; struct locked_stream { std::unique_ptr stream; @@ -21,7 +21,7 @@ struct locked_stream { static int wfs_getattr(const char* path, struct stat* stbuf) { memset(stbuf, 0, sizeof(struct stat)); - auto item = wfs_device->GetObject(path); + auto item = g_wfs_device->GetObject(path); if (!item) return -ENOENT; if (item->is_directory()) { @@ -47,7 +47,7 @@ static int wfs_readdir(const char* path, void* buf, fuse_fill_dir_t filler, off_ (void)offset; (void)fi; - auto item = wfs_device->GetObject(path); + auto item = g_wfs_device->GetObject(path); if (!item || !item->is_directory()) return -ENOENT; @@ -62,7 +62,7 @@ static int wfs_readdir(const char* path, void* buf, fuse_fill_dir_t filler, off_ } static int wfs_open(const char* path, struct fuse_file_info* fi) { - auto item = wfs_device->GetObject(path); + auto item = g_wfs_device->GetObject(path); if (!item->is_file()) return -ENOENT; @@ -96,7 +96,7 @@ static int wfs_read(const char* path, char* buf, size_t size, off_t offset, stru int wfs_readlink(const char* path, [[maybe_unused]] char* buf, [[maybe_unused]] size_t size) { // TODO - auto item = wfs_device->GetObject(path); + auto item = g_wfs_device->GetObject(path); if (!item || !item->is_link()) return -ENOENT; @@ -190,7 +190,7 @@ int main(int argc, char* argv[]) { return 1; } if (fuse_opt_parse(&args, ¶m, wfs_opts, wfs_process_arg)) { - printf(stderr, "failed to parse option\n"); + fprintf(stderr, "failed to parse option\n"); return 1; } @@ -226,10 +226,15 @@ int main(int argc, char* argv[]) { if (*detection_result == WfsError::kInvalidWfsVersion) fprintf(stderr, "Error: Incorrect WFS version, possible wrong keys\n"); else - throw WfsException(*detection_result); + fprintf(stderr, "Error: %s\n", WfsException(*detection_result).what()); return 1; } - wfs_device = throw_if_error(WfsDevice::Open(device, key)); + auto wfs_device = WfsDevice::Open(device, key); + if (!wfs_device.has_value()) { + fprintf(stderr, "Error: %s\n", WfsException(wfs_device.error()).what()); + return 1; + } + g_wfs_device = std::move(*wfs_device); } catch (std::exception& e) { fprintf(stderr, "Error: %s\n", e.what()); return 1; From 8926b1b2bf85c4ddc875bb279f7256c8a1851d42 Mon Sep 17 00:00:00 2001 From: koolkdev Date: Wed, 24 Apr 2024 00:44:57 +0300 Subject: [PATCH 03/12] test --- .github/workflows/build.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d5e9337..14564d2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,6 +77,8 @@ jobs: rm /usr/local/bin/python3-config || true brew install llvm brew install macfuse + echo "LDFLAGS=-L/usr/local/opt/llvm/lib" >> $GITHUB_ENV + echo "CXXFLAGS=-isystem /usr/local/opt/llvm/include" >> $GITHUB_ENV shell: bash if: matrix.platform == 'macos-13' @@ -85,6 +87,8 @@ jobs: brew update brew install llvm brew install macfuse + echo "LDFLAGS=-L/opt/homebrew/opt/llvm/lib" >> $GITHUB_ENV + echo "CXXFLAGS=-isystem /opt/homebrew/opt/llvm/include" >> $GITHUB_ENV shell: bash if: matrix.platform == 'macos-14' From 9f9b0ded5dc34bc2c51258f3c73fa9fa2c838322 Mon Sep 17 00:00:00 2001 From: koolkdev Date: Wed, 24 Apr 2024 00:46:01 +0300 Subject: [PATCH 04/12] test2 --- .github/workflows/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 14564d2..9ebd1be 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,7 +77,6 @@ jobs: rm /usr/local/bin/python3-config || true brew install llvm brew install macfuse - echo "LDFLAGS=-L/usr/local/opt/llvm/lib" >> $GITHUB_ENV echo "CXXFLAGS=-isystem /usr/local/opt/llvm/include" >> $GITHUB_ENV shell: bash if: matrix.platform == 'macos-13' @@ -87,7 +86,6 @@ jobs: brew update brew install llvm brew install macfuse - echo "LDFLAGS=-L/opt/homebrew/opt/llvm/lib" >> $GITHUB_ENV echo "CXXFLAGS=-isystem /opt/homebrew/opt/llvm/include" >> $GITHUB_ENV shell: bash if: matrix.platform == 'macos-14' From 16cb5caa3b7936dcce42360c70747895451dbe06 Mon Sep 17 00:00:00 2001 From: koolkdev Date: Wed, 24 Apr 2024 00:48:55 +0300 Subject: [PATCH 05/12] test3 --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9ebd1be..4a5cd11 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,7 +77,7 @@ jobs: rm /usr/local/bin/python3-config || true brew install llvm brew install macfuse - echo "CXXFLAGS=-isystem /usr/local/opt/llvm/include" >> $GITHUB_ENV + echo "CXXFLAGS=-I/usr/local/opt/llvm/include" >> $GITHUB_ENV shell: bash if: matrix.platform == 'macos-13' @@ -86,7 +86,7 @@ jobs: brew update brew install llvm brew install macfuse - echo "CXXFLAGS=-isystem /opt/homebrew/opt/llvm/include" >> $GITHUB_ENV + echo "CXXFLAGS=-I/opt/homebrew/opt/llvm/include" >> $GITHUB_ENV shell: bash if: matrix.platform == 'macos-14' From 4afddc88fcd50764d0bbad2aec9e134f8725950e Mon Sep 17 00:00:00 2001 From: koolkdev Date: Sat, 27 Apr 2024 13:55:17 +0300 Subject: [PATCH 06/12] test --- .github/workflows/build.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4a5cd11..a73b83e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,7 +77,8 @@ jobs: rm /usr/local/bin/python3-config || true brew install llvm brew install macfuse - echo "CXXFLAGS=-I/usr/local/opt/llvm/include" >> $GITHUB_ENV + sed -i '' '/^#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS/d' /usr/local/opt/llvm/include/c++/v1/__config_site + # echo "CXXFLAGS=-I/usr/local/opt/llvm/include" >> $GITHUB_ENV shell: bash if: matrix.platform == 'macos-13' @@ -86,7 +87,8 @@ jobs: brew update brew install llvm brew install macfuse - echo "CXXFLAGS=-I/opt/homebrew/opt/llvm/include" >> $GITHUB_ENV + sed -i '' '/^#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS/d' /opt/homebrew/opt/llvm/include/c++/v1/__config_site + #echo "CXXFLAGS=-I/opt/homebrew/opt/llvm/include" >> $GITHUB_ENV shell: bash if: matrix.platform == 'macos-14' From f4690072abdaaf9a2e724ee78f2994be4d0b611f Mon Sep 17 00:00:00 2001 From: koolkdev Date: Sat, 27 Apr 2024 14:01:59 +0300 Subject: [PATCH 07/12] test --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a73b83e..8bf4c99 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -79,6 +79,7 @@ jobs: brew install macfuse sed -i '' '/^#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS/d' /usr/local/opt/llvm/include/c++/v1/__config_site # echo "CXXFLAGS=-I/usr/local/opt/llvm/include" >> $GITHUB_ENV + echo "CXXFLAGS=-mmacos-version-min=10.10" >> $GITHUB_ENV shell: bash if: matrix.platform == 'macos-13' @@ -89,6 +90,7 @@ jobs: brew install macfuse sed -i '' '/^#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS/d' /opt/homebrew/opt/llvm/include/c++/v1/__config_site #echo "CXXFLAGS=-I/opt/homebrew/opt/llvm/include" >> $GITHUB_ENV + echo "CXXFLAGS=-mmacos-version-min=10.10" >> $GITHUB_ENV shell: bash if: matrix.platform == 'macos-14' From fb6bb9fd7e809ffb7886dedf99fc5ab9d6eb7d6f Mon Sep 17 00:00:00 2001 From: koolkdev Date: Sat, 27 Apr 2024 14:08:08 +0300 Subject: [PATCH 08/12] test --- .github/workflows/build.yml | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8bf4c99..280840d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,34 +65,28 @@ jobs: sudo apt install gcc-14 g++-14 sudo apt install libfuse-dev if: matrix.platform == 'ubuntu-latest' - - - name: Install requirements (MacOS) + + - name: Brew python fix run: | - brew update # Temporary fix, see https://github.com/actions/setup-python/issues/577 rm /usr/local/bin/2to3 || true rm /usr/local/bin/idle3 || true rm /usr/local/bin/pydoc3 || true rm /usr/local/bin/python3 || true rm /usr/local/bin/python3-config || true - brew install llvm - brew install macfuse - sed -i '' '/^#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS/d' /usr/local/opt/llvm/include/c++/v1/__config_site - # echo "CXXFLAGS=-I/usr/local/opt/llvm/include" >> $GITHUB_ENV - echo "CXXFLAGS=-mmacos-version-min=10.10" >> $GITHUB_ENV shell: bash if: matrix.platform == 'macos-13' - - name: Install requirements (MacOS arm64) + - name: Install requirements (MacOS) run: | brew update brew install llvm brew install macfuse - sed -i '' '/^#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS/d' /opt/homebrew/opt/llvm/include/c++/v1/__config_site - #echo "CXXFLAGS=-I/opt/homebrew/opt/llvm/include" >> $GITHUB_ENV - echo "CXXFLAGS=-mmacos-version-min=10.10" >> $GITHUB_ENV + #sed -i '' '/^#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS/d' $(brew --prefix llvm)/include/c++/v1/__config_site + #echo "CXXFLAGS=-mmacos-version-min=13.3" >> $GITHUB_ENV + echo "LDFLAGS=-L$(brew --prefix llvm)/lib/c++" >> $GITHUB_ENV shell: bash - if: matrix.platform == 'macos-14' + if: (matrix.platform == 'macos-13' || matrix.platform == 'macos-14') - name: Set compiler run: | From b0862d18bddb145d677d1d4eb983d7e9e87951d7 Mon Sep 17 00:00:00 2001 From: koolkdev Date: Sat, 27 Apr 2024 14:10:24 +0300 Subject: [PATCH 09/12] quick test --- .github/workflows/build.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 280840d..a6f508d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -86,7 +86,7 @@ jobs: #echo "CXXFLAGS=-mmacos-version-min=13.3" >> $GITHUB_ENV echo "LDFLAGS=-L$(brew --prefix llvm)/lib/c++" >> $GITHUB_ENV shell: bash - if: (matrix.platform == 'macos-13' || matrix.platform == 'macos-14') + if: matrix.platform == 'macos-13' || matrix.platform == 'macos-14' - name: Set compiler run: | @@ -128,6 +128,9 @@ jobs: name: wfs-reencryptor-${{matrix.release_name}} path: build/${{matrix.configure_preset}}/wfs-reencryptor/Release + - name: Quick test + run: build/${{matrix.configure_preset}}/wfs-info/Release/wfs-info --help + - name: Prepare Release Windows run: powershell Compress-Archive -Path build\${{matrix.configure_preset}}\wfs-file-injector\Release\wfs-file-injector.exe, build\${{matrix.configure_preset}}\wfs-extract\Release\wfs-extract.exe, build\${{matrix.configure_preset}}\wfs-info\Release\wfs-info.exe, build\${{matrix.configure_preset}}\wfs-reencryptor\Release\wfs-reencryptor.exe -DestinationPath wfs-tools-${{github.ref_name}}-${{matrix.release_name}}.zip if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && matrix.platform == 'windows-latest' From 76fd0f571bb973ce1c86e38a5c48d14f342163f7 Mon Sep 17 00:00:00 2001 From: koolkdev Date: Sat, 27 Apr 2024 14:13:18 +0300 Subject: [PATCH 10/12] final? --- .github/workflows/build.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a6f508d..c3c3355 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -82,9 +82,8 @@ jobs: brew update brew install llvm brew install macfuse - #sed -i '' '/^#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS/d' $(brew --prefix llvm)/include/c++/v1/__config_site - #echo "CXXFLAGS=-mmacos-version-min=13.3" >> $GITHUB_ENV - echo "LDFLAGS=-L$(brew --prefix llvm)/lib/c++" >> $GITHUB_ENV + sed -i '' '/^#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS/d' "$(brew --prefix llvm)"/include/c++/v1/__config_site + echo "CXXFLAGS=-mmacos-version-min=13.3" >> $GITHUB_ENV shell: bash if: matrix.platform == 'macos-13' || matrix.platform == 'macos-14' @@ -128,9 +127,6 @@ jobs: name: wfs-reencryptor-${{matrix.release_name}} path: build/${{matrix.configure_preset}}/wfs-reencryptor/Release - - name: Quick test - run: build/${{matrix.configure_preset}}/wfs-info/Release/wfs-info --help - - name: Prepare Release Windows run: powershell Compress-Archive -Path build\${{matrix.configure_preset}}\wfs-file-injector\Release\wfs-file-injector.exe, build\${{matrix.configure_preset}}\wfs-extract\Release\wfs-extract.exe, build\${{matrix.configure_preset}}\wfs-info\Release\wfs-info.exe, build\${{matrix.configure_preset}}\wfs-reencryptor\Release\wfs-reencryptor.exe -DestinationPath wfs-tools-${{github.ref_name}}-${{matrix.release_name}}.zip if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && matrix.platform == 'windows-latest' From 6591f733544b69a5b4d659a86105fc3b0c4e18ef Mon Sep 17 00:00:00 2001 From: koolkdev Date: Sat, 27 Apr 2024 14:22:44 +0300 Subject: [PATCH 11/12] update readme --- README.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3373667..b68fa5e 100644 --- a/README.md +++ b/README.md @@ -152,10 +152,7 @@ brew install cmake ninja llvm macfus ``` Build using the installled llvm: ``` -# For x86-64 -export CC=/usr/local/opt/llvm/bin/clang -export CXX=/usr/local/opt/llvm/bin/clang++ -# For arm -export CC=/opt/homebrew/opt/llvm/bin/clang -export CXX=/opt/homebrew/opt/llvm/bin/clang++ +export CC="$(brew --prefix llvm)"/bin/clang +export CXX="$(brew --prefix llvm)"/bin/clang++ +export LDFLAGS=-L"$(brew --prefix llvm)"/lib/c++ ``` From 36723efc656f87a2949d67eb0af9f478f041fbbb Mon Sep 17 00:00:00 2001 From: koolkdev Date: Sat, 27 Apr 2024 20:53:18 +0300 Subject: [PATCH 12/12] doc --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c3c3355..b9be78e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -82,6 +82,7 @@ jobs: brew update brew install llvm brew install macfuse + # Hack to properly target the os libcxx dynlib sed -i '' '/^#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS/d' "$(brew --prefix llvm)"/include/c++/v1/__config_site echo "CXXFLAGS=-mmacos-version-min=13.3" >> $GITHUB_ENV shell: bash