simonlindholm / decomp-permuter

Randomly permute C files to better match a target binary
MIT License
124 stars 44 forks source link

"path\to\compile.sh must be marked executable." (Windows) #173

Open H-A-M-G-E-R opened 1 week ago

H-A-M-G-E-R commented 1 week ago

i'm using windows 11 with devkitPro

ethteck commented 1 week ago

It sounds like you're not using import.py correctly. For people to help with your issue, you need to provide as much information as possible. Reproduction steps would be useful

H-A-M-G-E-R commented 1 week ago

when i try to use import.py on this fork: https://github.com/WhenGryphonsFly/decomp-permuter-agbcc it gives "OSError: [WinError 193] %1 is not a valid Win32 application"

H-A-M-G-E-R commented 1 week ago

i already followed the steps: create object files, config file but didn't create objdiff.json

ethteck commented 1 week ago

I don't know what that fork is, but you should be posting your issue there with the exact command(s) you are running

H-A-M-G-E-R commented 1 week ago

The fork doesn't allow issues

WhenGryphonsFly commented 1 week ago

That's odd, I certainly don't remember disabling issues. I've opened them up. I'm not sure how much I'll be able to help (I don't have a Windows computer and I don't use devkitPro), but we can take this over to my fork now.

WhenGryphonsFly commented 1 week ago

After some troubleshooting in https://github.com/WhenGryphonsFly/decomp-permuter-agbcc/issues/2, we've identified two issues. One of which is the issue specified in the title: permute.py fails with ./nonmatchings/BoxFallingDebrisFalling\compile.sh must be marked executable. This is despite compile.sh being marked executable, both in Windows and in MSYS2. I suspect the mismatched path separators may be part of the issue. Regardless, my fork only modifies import.py and the readme; this is an upstream issue.

As for the other one, I want to check before I make a separate issue for it: does permuter_settings.toml accept absolute paths for compiler_command? Similarly, does it support relative paths that go above the project root directory? Metroid Fusion's repo apparently has agbcc as a sibling directory to the project repository as opposed to a child directory.

H-A-M-G-E-R commented 4 days ago

Even without the forward slash it still throws an error! .\nonmatchings\CoreXShell\compile.sh must be marked executable. I'm now trying to permute CoreXShell https://decomp.me/scratch/4p2V6

H-A-M-G-E-R commented 4 days ago

i now fakematched it with asm

simonlindholm commented 3 days ago

I've never tested the permuter on native Windows, so not surprising to hear of errors. If you comment out this check in src/main.py:

        if not os.stat(compile_cmd).st_mode & 0o100:
            print(f"{compile_cmd} must be marked executable.", file=sys.stderr)
            sys.exit(1)

do things start working, or do you get additional errors? It's not an essential check, it's just for nicer error messages. I expect there are probably other things breaking, like the execution of the shell scripts, those not really being a thing in the first place on Windows.

I would recommend using WSL for the permuter; even if you got it to work on native Windows I would suspect it to be significantly slower at trying permutations just because of how slow process start times are on that platform.

As for the other one, I want to check before I make a separate issue for it: does permuter_settings.toml accept absolute paths for compiler_command? Similarly, does it support relative paths that go above the project root directory? Metroid Fusion's repo apparently has agbcc as a sibling directory to the project repository as opposed to a child directory.

Yes, it's supposed to accept absolute paths and relative paths that go above the project root directory.

H-A-M-G-E-R commented 3 days ago

Again, using WhenGryphonsFly's fork, gives an error

PS C:\GitHub\mf> ..\decomp-permuter-agbcc\permuter.py .vscode\nonmatchings\CoreXShell
Loading...
.vscode\nonmatchings\CoreXShell\base.c (CoreXShell)
No perm macros found. Defaulting to randomization.
Will try 1 different base sources.
Traceback (most recent call last):
  File "C:\GitHub\decomp-permuter-agbcc\permuter.py", line 5, in <module>
    main()
  File "C:\GitHub\decomp-permuter-agbcc\src\main.py", line 771, in main
    run(options)
  File "C:\GitHub\decomp-permuter-agbcc\src\main.py", line 283, in run
    return run_inner(options, heartbeat)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\GitHub\decomp-permuter-agbcc\src\main.py", line 360, in run_inner
    permuter = Permuter(
               ^^^^^^^^^
  File "C:\GitHub\decomp-permuter-agbcc\src\permuter.py", line 134, in __init__
    ) = self._create_and_score_base()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\GitHub\decomp-permuter-agbcc\src\permuter.py", line 154, in _create_and_score_base
    o_file = base_cand.compile(self.compiler, show_errors=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\GitHub\decomp-permuter-agbcc\src\candidate.py", line 91, in compile
    return compiler.compile(source, show_errors=show_errors)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\GitHub\decomp-permuter-agbcc\src\compiler.py", line 43, in compile
    subprocess.check_call(
  File "C:\Users\H A M\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 408, in check_call
    retcode = call(*popenargs, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\H A M\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 389, in call
    with Popen(*popenargs, **kwargs) as p:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\H A M\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\H A M\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1538, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 193] %1 is not a valid Win32 application
simonlindholm commented 3 days ago

Ah, I failed to read somehow. What happens if you change

             subprocess.check_call(
-                [self.compile_cmd, c_name, "-o", o_name],
+                ["bash", self.compile_cmd, c_name, "-o", o_name],
                 stdout=stderr,
                 stderr=stderr,
             )

in src/compiler.py?

simonlindholm commented 3 days ago

I would also be curious about whether

-        if not os.stat(compile_cmd).st_mode & 0o100:
+        if not os.access(compile_cmd, os.X_OK, effective_ids=True):

or

+import stat
 ...
-        if not os.stat(compile_cmd).st_mode & 0o100:
+        if not os.stat(compile_cmd).st_mode & stat.S_IXUSR:

help get around the "must be executable" error (I don't have any test environment for this)

H-A-M-G-E-R commented 2 days ago

I now switched to WSL to get around the error, but gives a different error instead: https://github.com/WhenGryphonsFly/decomp-permuter-agbcc/issues/2#issuecomment-2434279258