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

Dynamic linking seems to be broken for x86_windows #1530

Open
vdudouyt opened this issue Jan 26, 2025 · 3 comments
Open

Dynamic linking seems to be broken for x86_windows #1530

vdudouyt opened this issue Jan 26, 2025 · 3 comments
Assignees

Comments

@vdudouyt
Copy link

vdudouyt commented Jan 26, 2025

*Describe the bug
I'm trying to compile a simple dynamic linking example implemented in C language with MinGW and run it with qiling.

In my main.c I have:

#include <stdio.h>
void print_hello();

int main() {
   print_hello();
   return 0;
}

In my library.c I have:

#include <stdio.h>
void print_hello() {
   printf("Hello World!\n");
}

When I compile both and dynamically link they with each other, the resulting executable seems to be working under Wine without any problems:

$ i686-w64-mingw32-gcc library.c -shared -o hello.dll -static-libgcc -static-libstdc++
$ i686-w64-mingw32-gcc main.c hello.dll -o hello.exe  -static-libgcc -static-libstdc++
$ wine hello.exe
Hello World!

But, when I give it a run with Qiling it complains about unimplemented APIs in hello.dll:

# /root/qiling/qltool run --filename rootfs/x86_windows/bin/hello.exe --rootfs rootfs/x86_windows
<...>
[!]     api print_hello (hello) is not implemented
[!]     api _lock (msvcrt) is not implemented

I'm pretty sure there's no problems with hello.dll location, as when I remove it it starts printing an error message of a quite different kind.
Hooking print_hello() with ql.os.set_api() won't be a solution as it gives no chances to perform some instrumentation inside hello.dll real code.
I've also tried performing the same test with x8664_linux target, and unlike for x86_windows, it worked without any problems.
Is there anything I'm missing?

Expected behavior
I expect "Hello World!" to be printed just as under Wine, with print_hello() function from hello.dll being in use

P. S. I've attached my prebuild binaries just in case if you need it. Of course, I'm using the dev branch of Qiling just as suggested in your tutorial.

hello.zip

@elicn
Copy link
Member

elicn commented Jan 28, 2025

Thanks for reporting that. I don't think there is anything you are missing; please allow me a few days and I'll check what this is about.

@elicn elicn self-assigned this Jan 28, 2025
@vdudouyt
Copy link
Author

vdudouyt commented Feb 6, 2025

Any news about that?

Thank you

@elicn
Copy link
Member

elicn commented Feb 12, 2025

Hi again, sorry for the delayed reply.
I tested it locally and it works just fine for me. Here is what I did:

  • Copied the folder under ./rootfs/x86_windows/bin
  • Created a symbolic link to hello.dll in ./rootfs/x86_windows/Windows/System32
  • Used qltool to run:
    python3 ./qltool run -f "./examples/rootfs/x86_windows/bin/mingw32-hello/hello.exe" --rootfs "./examples/rootfs/x86_windows" --verbose disabled

(since logging is disabled, it looks like it is stuck, but it takes about 10 secs to complete and show the output)

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

No branches or pull requests

2 participants