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

[help] Please provide instructions to install on Windows #7

Closed
CypherpunkSamurai opened this issue Jun 25, 2022 · 22 comments
Closed

[help] Please provide instructions to install on Windows #7

CypherpunkSamurai opened this issue Jun 25, 2022 · 22 comments

Comments

@CypherpunkSamurai
Copy link

Hello,

I've been trying to install this server following the instructions.

But while installing I'm getting:

--- stderr
  thread 'main' panicked at 'Could not find system unicorn2: Could not run `"pkg-config" "--libs" "--cflags" "unicorn" "unicorn >= 2"`
  The pkg-config command could not be found.
  Most likely, you need to install a pkg-config package for your OS.
  If you've already installed it, ensure the pkg-config command is one of the
  directories in the PATH environment variable.
  If you did not expect this build to link to a pre-installed system library,
  then check documentation of the unicorn-engine crate for an option to
  build the library from source, or disable features or dependencies
  that require pkg-config.', C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\unicorn-engine-2.0.0-rc7\bindings/rust/build.rs:115:14
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
Error: CliError { error: Some(1 job failed), exit_code: 101 }

How do I install unicorn engine for pkg-config?

@bet4it
Copy link
Owner

bet4it commented Jun 25, 2022

You may use mingw64 to compile it on Windows ( Which is mentioned in #5, but I not try it, suggest you to use it on Linux )

@CypherpunkSamurai
Copy link
Author

suggest you to use it on Linux

cross compile for windows with mingw on linux?

@bet4it
Copy link
Owner

bet4it commented Jun 25, 2022

I guess you can compile it directly on Windows with MSYS2 or something?

@CypherpunkSamurai
Copy link
Author

Ok I'll try MSYS2.

I've also made a fork for using CI to compile for Windows using MSVC, can you check out why pkg-config is not finding unicorn2 even after compiling it :)

Workflow File
Run

@bet4it
Copy link
Owner

bet4it commented Jun 25, 2022

Because the command pkg-config only exists on Linux.
I suggest you to take a look at #4, which use the dev branch of unicorn that can deal with the situation that pkg-config doesn't exist.

@CypherpunkSamurai
Copy link
Author

Ah right. he also faces the same error. Should we try using mingw then?

@bet4it
Copy link
Owner

bet4it commented Jun 26, 2022

You can build udbserver in your CI after applying this patch:

diff --git a/Cargo.toml b/Cargo.toml
index fa78420..3870acd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,7 +18,7 @@ capi = []
 
 [dependencies]
 gdbstub = "0.6"
-unicorn-engine = { version = "2.0.0-rc7", features = ["use_system_unicorn"] }
+unicorn-engine = { git = "https://github.com/unicorn-engine/unicorn", branch="dev", features = ["dynamic_linkage"] }
 singlyton = "*"
 
 [package.metadata.capi.header]

It seems that unicorn is statically embedded in udbserver.dll rather than dynamic linkage, but it also may work?

@CypherpunkSamurai
Copy link
Author

Ohh. Thanks a lot, I'll try this :)

@CypherpunkSamurai
Copy link
Author

@bet4it Thanks a lot. It worked :D 👍🏼

@CypherpunkSamurai
Copy link
Author

CypherpunkSamurai commented Jun 27, 2022

Btw, the python bindings cant find the header during compilation.

Edit:
Added the following lines to fix the missing header, but now i'm getting linker errors:

https://github.com/CypherpunkSamurai/udbserver/runs/7081587661?check_suite_focus=true#step:14:158

library_dirs=['../../build/win/lib','../../unicorn', '../../unicorn/'],
include_dirs=['../../build/win/include', '../../unicorn/include', '../../unicorn/include/unicorn', '../../unicorn/build/Release/include'],

Error:

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:../../build/win/lib /LIBPATH:../../unicorn /LIBPATH:../../unicorn/ "/LIBPATH:C:\Program Files\Python37\libs" "/LIBPATH:C:\Program Files\Python37\PCbuild\amd64" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.19041.0\\um\x64" udbserver.lib /EXPORT:PyInit_udbserver build\temp.win-amd64-3.7\Release\udbserver.obj /OUT:build\lib.win-amd64-3.7\udbserver.cp37-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.7\Release\udbserver.cp37-win_amd64.lib
   Creating library build\temp.win-amd64-3.7\Release\udbserver.cp37-win_amd64.lib and object build\temp.win-amd64-3.7\Release\udbserver.cp37-win_amd64.exp
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.12.rcgu.o) : error LNK2001: unresolved external symbol uc_close
udbserver.lib(unicorn_engine-f200a5afdac62d7f.unicorn_engine.fefc9264-cgu.11.rcgu.o) : error LNK2001: unresolved external symbol uc_close
udbserver.lib(unicorn_engine-f200a5afdac62d7f.unicorn_engine.fefc9264-cgu.15.rcgu.o) : error LNK2001: unresolved external symbol uc_close
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.4.rcgu.o) : error LNK2001: unresolved external symbol uc_close
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_WSAStartup
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_WSACleanup
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_freeaddrinfo
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.9.rcgu.o) : error LNK2001: unresolved external symbol __imp_closesocket
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_closesocket
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.10.rcgu.o) : error LNK2001: unresolved external symbol __imp_closesocket
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.13.rcgu.o) : error LNK2001: unresolved external symbol __imp_closesocket
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.15.rcgu.o) : error LNK2001: unresolved external symbol __imp_closesocket
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_BCryptGenRandom
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_OpenProcessToken
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_GetUserProfileDirectoryW
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_shutdown
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_setsockopt
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_getsockopt
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_recv
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_WSARecv
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_WSASend
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_send
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_accept
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_ioctlsocket
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_getpeername
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_WSADuplicateSocketW
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_WSASocketW
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_connect
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_select
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_recvfrom
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_getaddrinfo
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_getsockname
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_bind
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_listen
udbserver.lib(std-c2061a8c4363ad39.std.902cd472-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp_sendto
udbserver.lib(unicorn_engine-f200a5afdac62d7f.unicorn_engine.fefc9264-cgu.11.rcgu.o) : error LNK2001: unresolved external symbol uc_context_free
udbserver.lib(unicorn_engine-f200a5afdac62d7f.unicorn_engine.fefc9264-cgu.11.rcgu.o) : error LNK2001: unresolved external symbol uc_open
udbserver.lib(unicorn_engine-f200a5afdac62d7f.unicorn_engine.fefc9264-cgu.11.rcgu.o) : error LNK2001: unresolved external symbol uc_query
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.2.rcgu.o) : error LNK2001: unresolved external symbol uc_query
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.4.rcgu.o) : error LNK2001: unresolved external symbol uc_query
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.2.rcgu.o) : error LNK2001: unresolved external symbol uc_hook_del
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.4.rcgu.o) : error LNK2001: unresolved external symbol uc_hook_del
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.2.rcgu.o) : error LNK2001: unresolved external symbol uc_reg_read
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.4.rcgu.o) : error LNK2001: unresolved external symbol uc_reg_read
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.2.rcgu.o) : error LNK2001: unresolved external symbol uc_reg_write
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.4.rcgu.o) : error LNK2001: unresolved external symbol uc_reg_write
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.2.rcgu.o) : error LNK2001: unresolved external symbol uc_mem_read
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.4.rcgu.o) : error LNK2001: unresolved external symbol uc_mem_read
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.2.rcgu.o) : error LNK2001: unresolved external symbol uc_mem_write
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.4.rcgu.o) : error LNK2001: unresolved external symbol uc_mem_write
udbserver.lib(udbserver.udbserver.c2c00f5b-cgu.4.rcgu.o) : error LNK2001: unresolved external symbol uc_hook_add
build\lib.win-amd64-3.7\udbserver.cp37-win_amd64.pyd : fatal error LNK1120: 38 unresolved externals
error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.30.30705\\bin\\HostX86\\x64\\link.exe' failed with exit status 1120

@bet4it
Copy link
Owner

bet4it commented Jun 27, 2022

#4 is the promising way to build python bindings on Windows, let's wait until it lands, or you can change base on it.

By the way, can the C bindings work on your computer?

@CypherpunkSamurai
Copy link
Author

By the way, can the C bindings work on your computer?

Nope, even the C bindings give symbol errors

n/ld.exe: lib/udbserver.lib(gdbstub-3323238ae3d9c88b.gdbstub.0ea11fd1-cgu.12.rcgu.o):gdbstub.0ea11fd1-c:(.xdata[$cppxdata$_ZN4core3ptr42drop_in_place$LT$std..io..error..Error$GT$17hb2c9ac909102a556E]+0xc): undefined reference to `__CxxFrameHandler3'
e:/mytools/c/winlibs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/udbserver.lib(gdbstub-3323238ae3d9c88b.gdbstub.0ea11fd1-cgu.12.rcgu.o):gdbstub.0ea11fd1-c:(.xdata[$cppxdata$_ZN7gdbstub4conn5impls9tcpstream83_$LT$impl$u20$gdbstub..conn..ConnectionExt$u20$for$u20$std..net..tcp..TcpStream$GT$4peek17hc41013a9c5bab834E]+0x10): undefined reference to `__CxxFrameHandler3'
e:/mytools/c/winlibs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/udbserver.lib(gdbstub-3323238ae3d9c88b.gdbstub.0ea11fd1-cgu.15.rcgu.o):gdbstub.0ea11fd1-c:(.xdata[$cppxdata$_ZN3std2io18default_read_exact17h24da8919fa0050e0E]+0x18): more undefined references to `__CxxFrameHandler3' follow
collect2.exe: error: ld returned 1 exit status

@CypherpunkSamurai
Copy link
Author

If you don't mind, are you on telegram / discord / matrix? That way it would be a bit more easy to debug the errors.

@bet4it
Copy link
Owner

bet4it commented Jun 28, 2022

I just built udbserver on mingw64 and everything works fine like on Linux.
As for the __CxxFrameHandler3 error, do you mix the use of mingw64 and MSVC? And could you try to set panic = "abort"? (rust-lang/rust#45492 (comment))

If you don't mind, are you on telegram / discord / matrix? That way it would be a bit more easy to debug the errors.

I'm sorry I don't have such accounts. Maybe we can use something like gitter? But it seems that it has little difference with chatting on Github😅

@CypherpunkSamurai
Copy link
Author

Yeah sure. I'm on gitter as well :)

@CypherpunkSamurai
Copy link
Author

Hello 👋🏼. I just managed to run the udbserver under msys2, but how can i use it under windows python?

Can i package the python module with the dependencies somehow?

@bet4it
Copy link
Owner

bet4it commented Jun 29, 2022

Oh, I really don't know how to do it, but as I said before, if you want to do it, remember to base on the work #4 had done.

@CypherpunkSamurai
Copy link
Author

CypherpunkSamurai commented Jun 29, 2022

I just extracted the unicorn package from MSYS2 and the build folder from msys2 udbserver and pasted it into my windows Mingw64, and added compiler=mingw32 to distutils.conf file. Then compiled the python and c bindings, and it works :)

@bet4it
Copy link
Owner

bet4it commented Jun 29, 2022

Great! So this can only be used in MSYS2/Mingw64? Or you can use it directly on Windows?

@CypherpunkSamurai
Copy link
Author

Great! So this can only be used in MSYS2/Mingw64? Or you can use it directly on Windows?

It can be used in Windows Python installation! however, I had to copy the include folder to my python install path, and libs to python libs folder.

This can also be done by packaging these files inside the .egg file. You need to edit setup.py to include folders and add them to path. Like unicorn does for its windows pip package. On extracting the unicorn Windows pip package i found "include" "lib" and dll files. I tried to edit the setup.py to do it myself, but it doesn't work for some reason.

@bet4it
Copy link
Owner

bet4it commented Jun 29, 2022

Hope you can send a PR on build python package for Windows by Github Action!

@CypherpunkSamurai
Copy link
Author

Hope you can send a PR on build python package for Windows by Github Action!

Sure I will try :D

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