-
-
Notifications
You must be signed in to change notification settings - Fork 437
-
-
Notifications
You must be signed in to change notification settings - Fork 437
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
Errors while using Zydis.lib in windows driver #16
Comments
Thanks, I'll take a look! |
I'm using Visual Studio Community 2015, v14. |
The lack of |
Regarding
|
My WDK managed to corrupt itself during installation, I can't even build freshly created driver solutions. Thanks MS. I'll remove all Windows SDKs and WDKs I have installed, apply fresh ones and try again. May take a while. Pretty sure I'll end up trashing my entire VM, setting up a new one. |
I followed "Build" instructions from here and it worked. |
Alright, reinstalling SDKs and WDKs fixed my issue. I have now implemented various I suppose you just C&Ped the source and include files into your project for now? I'm not quite sure what's the best way of supporting linkage against Windows drivers right now. CMake doesn't seem to support generating VS projects with the WDK toolset and manually maintaining VS projects isn't my favorite either. This whole |
I'll close this for now. If you encounter any other problems, feel free to create a new issue or to reopen this one! |
Some other things I came across that may be of use (I am working on a Windows driver using Zydis at the moment, which is how I found this):
Re: |
Thanks for the very informative post! Our general design approach in regard of supporting more exotic build targets is not to implement shims for specific platforms, but to just make Zydis less dependant on the build environment in general. We already removed most dependencies on libc (e.g. sprint functions for formatting), to a level where only However, we're also not opposed to adding Windows driver specific switches as well after we achieved the generic no-libc support and your info will definitely come in handy for that! |
Yes, very true. So long as you minimise dependencies you can get C code to run on pretty much any platform. I don't have any Linux kernel mode experience, but I have written UEFI drivers in the past and even there (by "there" I mean in EDK2, which is what I used) you have some basic essentials such as As for |
Oh yeah, I'd be happy to contribute user/kernel mode Visual Studio project files if there is interest in it (meaning proper ones, not the garbage CMake generates). I know that the feelings w.r.t. doing this are mixed among CMake users, after all CMake can technically make Visual Studio project files so it is duplicating part of the build system. But non-VS users will never know the pain of having to hand-edit 15 XML files to 'un-CMake' them. |
UEFI is a little special in that it actually does provide a near-complete libc when you link against The We wrote the majority of this lib using VS, with those generated VS files. Quite honestly, we even prefer those. I've been using VS for C/C++ development for the past 8 years or so and it has always been a huge pain in the ass to configure even trivial things like "hey, link me against that target". Manually configuring include/lib pathes for all combinations of Release/Debug/Win32/Win64 like it's 1999 is just ridiculous. Generally, VS' C/C++ project settings feel like they have been stuck in time compared to what you get for the .NET languages. If you have issues with the lack of source file filtering in the solution explorer, just add Creating "real" VS files isn't much of an issue, maintaining them .. meh. Also, you always have that issue with what VS version to choose. No matter what you pick, people are going to be pissed. Too old? "You dinosaurs, use VS2017!" Too new? "How am I supposed to use that in my VS2008 enterprise code?!" |
Oh yes, it's hard to deny the VS project file system is part (or the main cause) of the problem. I actually think CMake is the closest thing to a "good" C/C++ cross-platform solution to the "how do I build this" problem we've ever had. But that doesn't mean I think its VS project output is acceptable, and I definitely don't agree that it is preferable to doing it the 1999 way. That's not CMake's fault per se, as it is tasked with doing something that is essentially impossible. But it does mean that every time I see an open source project use (only) CMake, I curse loudly and waste half an hour or so, depending on the size of the project, to unfuck it. I'm also not saying adding a second build system is nirvana. In the best case scenario it adds a burden to the project developers because now they have to maintain another build system, and in the worst case scenario one of the two goes stale and unmaintained over time, which causes issues for users if they are trying method X to compile as described in the README and getting nowhere. Still, maintaining a second build system is exactly what I do for many projects! (even ones I contribute to like x64dbg and ScyllaHide, because they use VS2013 and I use VS2017.) In those cases I create a local branch and have to pick from one of two evils, depending on what build system the project uses:
The second approach is clearly insane. Yet I still prefer doing that to working with CMake directly. (To be clear, I'm still talking about VS - I have no issues at all with CMake on e.g. Linux with either GCC or Clang.) The list of issues I've had with the combination of Visual Studio and CMake is endless. From the pointless build targets it adds, the missing (before) or terrible (now) support of custom build toolsets such as Clang/LLVM or the Intel compiler toolset, the fact that it generates hundreds of temporary files and directories seemingly at random when you hit build after making no changes at all, to completely regenerating and overwriting every single .vcxproj file in the solution (destroying my local changes) because of a syntax error in CMakeLists.txt. I could go on and on. But I think my opinion on this is clear, so I'll stop ranting now :P Anyway, should you decide to add VS files at some point in the future regardless, I'd be happy to maintain them (just ping me whenever CMakeLists.txt gets updated or something - I'm sure this should be possible to automate). That's what I'd essentially be doing regardless, and it makes no difference to me whether my project files are on a local private branch or a public one. |
Well, if you're willing to maintain that stuff, that's fine with us. If you'd ever decide to stop updating them however, we'd probably discard it again. I assume you'd have to create two distinct VS solutions for user and kernel-mode? Also, VS2017 ones? Feel free to drop a PR, we'll just bump it every time we change something in |
Also, on |
Alright, cool. I suppose As for multiple VS solutions: I think it would be best to keep it to one solution, with multiple configurations:
The user mode configurations would be VS2017 with the v141 toolset. I don't think requiring VS2017 is an issue really, the Community edition is free after all. And it's still possible to open newer solution files with older VS versions and downgrade the toolset version if there is a need to use a specific VS version. I'm not 100% sure what to do with the kernel mode configuration: looking at e.g. Capstone I see that they have a separate I will have to do some testing w.r.t. this, but I'm fairly certain it's possible to create a hybrid user/kernel mode project that does not require the WDK unless kernel mode is selected. If not, then there will have to be separate |
An update on this: it is indeed possible to create a combined user (static/dynamic) and kernel mode project without causing issues for those who don't have the WDK installed. I currently have this set up and working on the
The first two build Zydis using the user mode CRT and use either static or dynamic linking. The kernel mode option builds Zydis with the WDK toolset, the Does this sound OK? If so, I'll create a PR for it. (probably without the sample driver project to start, as I don't know how to go about writing the CMake equivalent of this.) Oh yeah: I did have to remove the |
Very nice! Basing off `develop` is good. The include is a bug and will be removed in my next commit — I must have missed this one when searching for libc includes. You can PR the driver sample without having it in the CMake project, if you want. I’ll check out if there is a low-effort method of supporting this using CMake and in case there is none, well, then that example is exclusive to the VS projects for now. Is the `/kernel` switch really all that is required to make that work in kernel? I’d assume there are also some additional include pathes for the WDK required?
… On 28. Nov 2017, at 22:03, Matthijs Lavrijsen ***@***.***> wrote:
An update on this: it is indeed possible to create a combined user (static/dynamic) and kernel mode project without causing issues for those who don't have the WDK installed. I currently have this set up and working on the develop branch, with the following solution configurations:
Debug / Release
Debug DLL / Release DLL
Debug Kernel / Release Kernel
The first two build Zydis using the user mode CRT and use either static or dynamic linking. The kernel mode option builds Zydis with the WDK toolset, the /kernel flag set and ZYDIS_NO_LIBC defined. I also have a ZydisWinKernel sample driver project that is compiled in this configuration for testing. The tools and examples are not built in the kernel mode configuration (technically they could be, but I can easily see that being confusing rather than helpful).
Does this sound OK? If so, I'll create a PR for it. (probably without the sample driver project to start, as I don't know how to go about writing the CMake equivalent of this.)
Oh yeah: I did have to remove the <stdint.h> #include from LibC.h in order to get ZYDIS_NO_LIBC to work in kernel mode, because the KM CRT does not have this header. But as far as I can tell this header doesn't need stdint.h anymore, because it now uses ZydisU8 and other such typedefs.
|
OK, PR added! To make Zydis itself kernel mode compatible - yes, vsnprintf(buf, size, format, args); for example would normally cause some reference to Using the full WDK toolchain is the most fool-proof way to ensure compability, because it does indeed change all of the include paths, standard linker inputs and so on. There are still some ways to check for zero dependencies though by building a minimal user mode program that does not link against anything other than Zydis. This is quite cumbersome to set up however. I think at that point you might be better off just installing the WDK. |
Quick fixes for:
stdint.h
not found -> just add a copy from visual studiounresolved external symbol __imp_wassert
: redefineZYDIS_ASSERT
andZYDIS_UNREACHABLE
to;
unresolved external symbol __imp___stdio_common_vsprintf
: usewinkernel_mm.*
from capstoneDriverEntry
/ALIGN
errors -> see this issueunresolved external symbol __imp___stdio_common_vsprintf
: add/D _NO_CRT_STDIO_INLINE
tocl
options in Zydis projectThe text was updated successfully, but these errors were encountered: