Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Extracting single file - access denied #101

Open
Clearmist opened this issue Jun 3, 2023 · 5 comments
Open

[Bug] Extracting single file - access denied #101

Clearmist opened this issue Jun 3, 2023 · 5 comments

Comments

@Clearmist
Copy link

Clearmist commented Jun 3, 2023

Version: 1.7.0
Built: 15:09:37 Jan 21 2023
OS: Windows 11

I thoroughly read the documentation about extracting files. I am unable to extract single files from any archive without editing your source code. Even when the program absolutely has write access to the given directory an access is denied error is thrown. This line in FsProcess.cpp is the culprit. I commented out this line and the first try/catch and the file was extracted successfully.

local_fs->getDirectoryListing(parent_dir_path, dir_listing);

nstool/src/FsProcess.cpp

Lines 121 to 135 in 7abcedb

try {
tc::io::sDirectoryListing dir_listing;
local_fs->getDirectoryListing(itr->extract_path, dir_listing);
tc::io::Path file_extract_path = itr->extract_path + itr->virtual_path.back();
fmt::print("Saving {:s}...\n", file_extract_path.to_string());
writeStreamToFile(file_stream, itr->extract_path + itr->virtual_path.back(), mDataCache);
continue;
} catch (tc::io::DirectoryNotFoundException&) {
// acceptable exception, just means directory didn't exist
}

This means we need to clarify and separate some parameters so we can rely on separate functions instead of one big function.

Perhaps:

-x --extract: Extract all files or extract a single file if an optional value is supplied.
-o --output: Specify the output path.
-n --name: Overwrite the original file name with one you supply.

Extract all files:
.\nstool --output "./files" --extract

Extract one file:
.\nstool --output "./files" --extract "f79d12018da9db962f796fad2256fdfb.cnmt.nca"

Extract one file and give it a new name:
.\nstool --output "./files" --extract "f79d12018da9db962f796fad2256fdfb.cnmt.nca" --name "meta.nca"

Confirming this is a valid file

.\nstool.exe --fstree "test.nsp"

[PartitionFs]
  Type:        PFS0
  FileNum:     6
[PartitionFs/Tree]
 Root:/
  0100100016fb0000000000000000000e.tik
  0100100016fb0000000000000000000e.cert
  f79d12018da9db962f796fad2256fdfb.cnmt.nca
  b129954666b4baa187ad57e15cd87e49.nca
  5fb8eb95a47d349cfd0d7bfab12c2674.nca
  65a1ed53bb896c71ec9e6af3568f6a59.nca

Extracting all files is successful

.\nstool.exe --extract "./" "test.nsp"

[PartitionFs]
  Type:        PFS0
  FileNum:     6
[PartitionFs/Extract]
Saving .\0100100016fb0000000000000000000e.tik...
Saving .\0100100016fb0000000000000000000e.cert...
Saving .\f79d12018da9db962f796fad2256fdfb.cnmt.nca...
Saving .\b129954666b4baa187ad57e15cd87e49.nca...
Saving .\5fb8eb95a47d349cfd0d7bfab12c2674.nca...
Saving .\65a1ed53bb896c71ec9e6af3568f6a59.nca...

Extracting a single file fails

.\nstool.exe --extract "f79d12018da9db962f796fad2256fdfb.cnmt.nca" "./" "test.nsp"

[PartitionFs/Extract]
[tc::io::FileStream::open() ERROR] Access is denied.
@jakcron
Copy link
Owner

jakcron commented Jun 4, 2023

Hi,

Thank you for this well written bug report. (And debugging the issue for me)

I think I was too ambitious with the the extract command making it too versatile. Resulting in weird bugs.

This means we need to clarify and separate some parameters so we can rely on separate functions instead of one big function.

You are make a good point. I'll consider making more explicit commands instead of just fixing the uncaught exception.

@Clearmist
Copy link
Author

I built from commit 17b4091 on the bugfix-101-fs-extraction-issues branch and these are the new results.

Providing an output directory

.\nstool.exe --extract "f79d12018da9db962f796fad2256fdfb.cnmt.nca" "D:\Switch\images" "test.nsp"

[WARNING] Extract path was invalid, and was skipped: D:\Switch\images

Providing an output directory and output filename

.\nstool.exe --extract "f79d12018da9db962f796fad2256fdfb.cnmt.nca" "D:\Switch\images\extract.nca" "test.nsp"

[tc::io::LocalFileSystem::getDirectoryListing() ERROR] Failed to open directory (The directory name is invalid.)

@TsilaAllaoui
Copy link

Hi, i have the same problem when extracting a single file from a nsp. Which branch or PR have the modified code that i can test please? I only want to get cmnt.nca and the nca that contain the game icon by the way

@VolkerSchlegel
Copy link

Also encountering this one, I'll try that branch.

@VolkerSchlegel
Copy link

Building with Visual Studio is broken as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants