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

bash decompile.sh fails with errors when run on Windows 10 with Windows Subsystem for Linux #18

Closed
0x0ACB opened this issue Dec 13, 2017 · 12 comments

Comments

@0x0ACB
Copy link

0x0ACB commented Dec 13, 2017

Running: bash decompile.sh test.exe results in multiple errors.
Running: decompile.sh test.exe from the command line works just fine.

@s3rvac
Copy link
Member

s3rvac commented Dec 16, 2017

Thank you for the report. What Windows version do you use? From which environment/console did you run bash decompile.sh test.exe? What errors did you get?

I tried to run bash decompile.sh test.exe from the following environments and in every case, the command worked as expected:

  • MSYS2 shell via C:\msys64\msys2_shell.cmd
  • ConEmu console via C:\msys64\usr\bin\bash.exe -i
  • cmd.exe

On the contrary, decompile.sh test.exe failed in all the above environments. I got either the expected error bash: decompile.sh: command not found or Windows can't open this type of file (.sh) in cmd.exe.

@0x0ACB
Copy link
Author

0x0ACB commented Dec 16, 2017

Im on windows 10 newest update and I ran the commands from cmd.exe.

This is the output if I prefix the command with 'bash'

E:\retdec\bin>bash decompile.sh update-server.exe
##### Checking if file is a Mach-O Universal static library...
RUN: /mnt/e/retdec/bin/macho-extractor --list /mnt/e/retdec/bin/update-server.exe

##### Checking if file is an archive...
RUN: /mnt/e/retdec/bin/ar-extractor --arch-magic /mnt/e/retdec/bin/update-server.exe
/mnt/e/retdec/bin/utils.sh: line 55: /mnt/e/retdec/bin/ar-extractor: No such file or directory
Not an archive, going to the next step.

##### Gathering file information...
RUN: /mnt/e/retdec/bin/fileinfo -c /mnt/e/retdec/bin/update-server.c.json --similarity /mnt/e/retdec/bin/update-server.exe --no-hashes=all --crypto /mnt/e/retdec/bin/../share/generic/yara_patterns/signsrch/signsrch.yara
decompile.sh: line 667: /mnt/e/retdec/bin/fileinfo: No such file or directory

Without bash everything works as expected.

@0x0ACB 0x0ACB closed this as completed Dec 16, 2017
@0x0ACB 0x0ACB reopened this Dec 16, 2017
@s3rvac
Copy link
Member

s3rvac commented Dec 16, 2017

Do you use Bash from the Windows Subsystem for Linux, MSYS2, Cygwin, or even from something else?

@0x0ACB
Copy link
Author

0x0ACB commented Dec 16, 2017

Nope just regular plain old command prompt. Though I do have WSL installed dont know if that might interfere. Calling bash in cmd.exe does open MSYS2 though if you meant that.

@s3rvac
Copy link
Member

s3rvac commented Dec 16, 2017

Well, to run decompile.sh, you need to have Bash on your system. I believe that the problem might be caused by Bash from WSL as we have AFAIK never tried to run RetDec via WSL :-).

I will have to ask someone with Windows 10 + WSL to verify and debug this as I currently do not have access to any Windows 10 machine.

@s3rvac
Copy link
Member

s3rvac commented Dec 17, 2017

We have found out that the problem is indeed caused by the use of Bash from WSL instead of Bash from MSYS2.

@ACB1337, could you please try running C:\msys64\usr\bin\bash.exe decompile.sh test.exe (or wherever you have installed MSYS2) instead of bash.exe decompile.sh test.exe? If this works, then it means that Bash from WSL is in your PATH before Bash from MSYS2, and thus when you run bash.exe decompile.sh test.exe, the system picks up the "wrong" Bash (from WSL).

@0x0ACB
Copy link
Author

0x0ACB commented Dec 17, 2017

Calling the correct bash.exe directly also does not work.

E:\retdec\bin>C:\msys64\usr\bin\bash.exe decompile.sh update-server.exe
decompile.sh: line 6: dirname: command not found
/e/retdec/bin/utils.sh: line 6: dirname: command not found
/e/retdec/bin/config.sh: line 6: dirname: command not found
/e/retdec/bin/config.sh: line 17: uname: command not found
/e/retdec/bin/config.sh: line 19: uname: command not found
/e/retdec/bin/config.sh: line 19: uname: command not found
Error: Unknown OS

However calling C:\msys64\msys2_shell.cmd -msys and then running the command with either bash or without does work

@jakubkroustek
Copy link

@ACB1337 Could you send us the value of your PATH variable? Is c:\msys64\usr\bin\ accessible from there as mentioned in the guide? And it should be listed before any WSL paths...

@0x0ACB
Copy link
Author

0x0ACB commented Dec 17, 2017

Ok moving the msys64 path to the very beginning has fixed the problem. Thanks. Also I had it removed some time during testing so that is where the other errors when calling the bash.exe directly have come from.

@s3rvac s3rvac changed the title Error in Windows instructions bash decompile.sh fails with errors when run on Windows 10 with Windows Subsystem for Linux Dec 17, 2017
@s3rvac
Copy link
Member

s3rvac commented Dec 17, 2017

Great! Thanks for your assistance during debugging. We have added a note into the wiki concerning the importance of a correct PATH when running on Windows 10 with WSL.

@AntonKukoba1
Copy link

AntonKukoba1 commented Jan 8, 2018

Well, I was able to run it under WSL. It only takes to

  1. add /mnt/ < yourpath > /retdec/bin to the PATH
  2. create symbolic links to all exe files in bin directory. Ex: ar-extractor.exe -> ar-extractor
  3. fix file path in SH files to use just file name i.e. IN=$(basename "$IN"), OUT=$(basename "$OUT"), CONFIG=$(basename "$CONFIG") etc.
  4. hard code FILECLASS="32" instead of "$CONFIG" --read --file-class (it never worked for me)

Then I was able to run it for x86 windows executables

@s3rvac
Copy link
Member

s3rvac commented Jan 11, 2018

@AntonKukoba1 Thank you for the tip. For running RetDec under WSL on Windows 10, I have created a separate ticket (#85), and added a link to your tip in there.

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

5 participants