Skip to content

Windows symlink error #838

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

Open
okaerin opened this issue Mar 13, 2025 · 0 comments · May be fixed by #839
Open

Windows symlink error #838

okaerin opened this issue Mar 13, 2025 · 0 comments · May be fixed by #839

Comments

@okaerin
Copy link

okaerin commented Mar 13, 2025

I noticed that the tool does not work under Windows without administrative privileges. This is a limitation due to Windows. I would suggest that binwalk would switch to hardlinks (does not need the admin privileges) for the original file when used with windows. Additionally it would probably make sense that a flag could be set to not create the symlink file at all. Anyway, the bug is quite easily fixed by:

diff --git a/src/binwalk.rs b/src/binwalk.rs
index 678df95..91c70fc 100644
--- a/src/binwalk.rs
+++ b/src/binwalk.rs
@@ -723,23 +723,23 @@ fn init_extraction_directory(
     );
 
     // Create a path for the symlink target path
-    let symlink_path = path::Path::new(&symlink_target_path_str);
+    let link_path = path::Path::new(&symlink_target_path_str);
 
     debug!(
         "Creating symlink from {} -> {}",
-        symlink_path.display(),
+        link_path.display(),
         target_path.display()
     );
 
     // Create a symlink from inside the extraction directory to the specified target file
     #[cfg(unix)]
     {
-        match unix::fs::symlink(target_path, symlink_path) {
+        match unix::fs::symlink(target_path, link_path) {
             Ok(_) => Ok(symlink_target_path_str),
             Err(e) => {
                 error!(
                     "Failed to create symlink {} -> {}: {}",
-                    symlink_path.display(),
+                    link_path.display(),
                     target_path.display(),
                     e
                 );
@@ -749,14 +749,14 @@ fn init_extraction_directory(
     }
     #[cfg(windows)]
     {
-        match windows::fs::symlink_file(target_path, symlink_path) {
+        match std::fs::hard_link(target_path, link_path){
             Ok(_) => {
                 return Ok(symlink_target_path_str);
             }
             Err(e) => {
                 error!(
-                    "Failed to create symlink {} -> {}: {}",
-                    symlink_path.display(),
+                    "Failed to create hardlink {} -> {}: {}",
+                    link_path.display(),
                     target_path.display(),
                     e
                 );

I could submit a PR regarding this issue.
BTW, big fan of the tool.

@okaerin okaerin linked a pull request Mar 13, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant