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

vsnprintf the only API preventing XP use, and CMake build failing #726

Closed
Wahpedlar opened this issue Jul 2, 2016 · 14 comments
Closed

vsnprintf the only API preventing XP use, and CMake build failing #726

Wahpedlar opened this issue Jul 2, 2016 · 14 comments

Comments

@Wahpedlar
Copy link

Wahpedlar commented Jul 2, 2016

I can successfully cleanly build the x86/x64 static libs using \Msvc\ but cannot use link the lib into my exe in XP as vsnprintf/_vsnprintf isn't exported from msvcrt. It's the only thing stopping it from working on XP.

Capstone.DLL itself doesn't actually import vsnprintf ... but the LIB does!?

Capstone Support suggested I try the CMake compile instead of Msvc, so I did, exactly as per the instructions, but that failed and I was instructed to make a Github New Issue. Any ideas?? I have VS2010 and VS2013, tried from the cmdprompt shortcut of each. CMake and Nasm are also both installed.

Here's the output from the cmake command, as per COMPILE_CMAKE.TXT

C:\CapstoneDisassembler\srcCmake\build>cmake -D CMAKE_BUILD_TYPE=RELEASE -G "NMake Makefiles" ..
-- The C compiler identification is MSVC 16.0.30319.1
-- The CXX compiler identification is MSVC 16.0.30319.1
-- Check for working C compiler: E:/VS2010/VC/bin/cl.exe
-- Check for working C compiler: E:/VS2010/VC/bin/cl.exe -- broken
CMake Error at F:/CMake/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "E:/VS2010/VC/bin/cl.exe" is not able to compile a simple  test program.

  It fails with the following output:

   Change Dir: C:/CapstoneDisassembler/srcCmake/build/CMakeFiles/CMakeTmp


  Run Build Command:"nmake" "/NOLOGO" "cmTC_8a525\fast"

        E:\VS2010\VC\BIN\nmake.exe -f CMakeFiles\cmTC_8a525.dir\build.make /nologo  -L CMakeFiles\cmTC_8a525.dir\build

  Building C object CMakeFiles/cmTC_8a525.dir/testCCompiler.c.obj

        E:\VS2010\VC\bin\cl.exe @E:\temp\nm81BF.tmp

  testCCompiler.c

  Linking C executable cmTC_8a525.exe

        F:\CMake\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_8a525.dir

  --manifests -- E:\VS2010\VC\bin\link.exe /nologo
  @CMakeFiles\cmTC_8a525.dir\objects1.rsp @E:\temp\nm81DF.tmp

  LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

  LINK Pass 1 failed.  with 1123

  NMAKE : fatal error U1077: 'F:\CMake\bin\cmake.exe' : return code
  '0xffffffff'

  Stop.

  NMAKE : fatal error U1077: 'E:\VS2010\VC\BIN\nmake.exe' : return code
  '0x2'

  Stop.



  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "C:/CapstoneDisassembler/srcCmake/build/CMakeFiles/CMakeOutput.log".
See also "C:/CapstoneDisassembler/srcCmake/build/CMakeFiles/CMakeError.log".

C:\CapstoneDisassembler\srcCmake\build>

@aquynh
Copy link
Collaborator

aquynh commented Jul 12, 2016

@Wahpedlar
Copy link
Author

Ive tried with VS2010 and VS2013, but successfully build the .lib but am unable to link to the lib due to vsnprintf

The link you described says to include a legacy .lib, but that only exists in VS2015! so I'm downloading VS2015 now (several gigs and its slow) so hopefully i'll be able to try that soon, but I would've thought itd be possible to use VS2010 or VS2013 to create a lib that worked on XP (it doesnt really make sense having to use 2015 for that!)

----- Original Message -----
From: Nguyen Anh Quynh
To: aquynh/capstone
Cc: Wahpedlar ; Author
Sent: Tuesday, July 12, 2016 9:59 AM
Subject: Re: [aquynh/capstone] vsnprintf the only API preventing XP use, and CMake build failing (#726)

Perhaps this can solve your issue: http://stackoverflow.com/questions/32418766/c-unresolved-external-symbol-sprintf-and-sscanf-in-visual-studio-2015


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

@Wahpedlar
Copy link
Author

Wahpedlar commented Jul 12, 2016

Still no luck. I installed VS2015 (to add to 2008, 2010 and 2013) which had the legacy .lib files to link to, but then it just gives me even more errors for missing functions:
___stdio_common_vfwprintf
___stdio_common_vfwprintf_s
___stdio_common_vfwprintf_p
___acrt_iob_func
___stdio_common_vsscanf
___stdio_common_vfwscanf

I also tried with various different "Platform Toolset" in Project Properties including XP-specific ones, but no luck

I would've thought somebody would've used Capstone as a static library with XP before!?

----- Original Message -----
From: Nguyen Anh Quynh
To: aquynh/capstone
Cc: Wahpedlar ; Author
Sent: Tuesday, July 12, 2016 9:59 AM
Subject: Re: [aquynh/capstone] vsnprintf the only API preventing XP use, and CMake build failing (#726)

Perhaps this can solve your issue: http://stackoverflow.com/questions/32418766/c-unresolved-external-symbol-sprintf-and-sscanf-in-visual-studio-2015


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

@Wahpedlar
Copy link
Author

Wahpedlar commented Jul 12, 2016

I found this but im not sure how to apply it to Capstone (it says the fix is to "delete any declarations to vsnprintif in user code", but that doesnt sound too safe as im guessing the code is there for a reason!?)
from https://msdn.microsoft.com/en-us/library/bb531344.aspx

snprintf and vsnprintf:
The snprintf and vsnprintf functions are now implemented. Older code often provided definitions macro versions of these functions because they were not implemented by the CRT library, but these are no longer needed in newer versions. If snprintf or vsnprintf is defined as a macro before including <stdio.h>, compilation now fails with an error that indicates where the macro was defined.
Normally, the fix to this problem is to delete any declarations of snprintf or vsnprintf in user code.

@mrexodia
Copy link
Contributor

mrexodia commented Sep 13, 2016

Just CMake to a visual studio solution and change the platform toolset to v120_xp (or v140_xp for VS2015) has been working great for x64dbg ever since the release of capstone. As for static libraries, make sure you link MSVC statically as well (the /MT option).

s

@aquynh
Copy link
Collaborator

aquynh commented Sep 13, 2016

Great, would you mind sending a pull req to update the docs with this trick?

@Wahpedlar
Copy link
Author

Fantastic!!!:) Could you please elaborate on what you mean by "Just CMake to a visual studio solution"? I'm new to CMake
Thankyou again and great work!!!

@mrexodia
Copy link
Contributor

Just output a visual studio solution. Just select visual studio 2013 in the
cmake gui (not nmake project) it will generate a sln
On Wed, 14 Sep 2016 at 02:46, Wahpedlar notifications@github.com wrote:

Fantastic!!!:) Could you please elaborate on what you mean by "Just CMake
to a visual studio solution"? I'm new to CMake
Thankyou again and great work!!!


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#726 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACWCmesn3L_OmfD9csbVxoSh72vBlT0qks5qp0PugaJpZM4JDppc
.

@aquynh
Copy link
Collaborator

aquynh commented Sep 14, 2016

can you generate .SLN file like this on Windows (this is for Win64, you can also do that for Win32), then open .SLN file to compile, and report the result?

mkdir build
cd build
cmake -G "Visual Studio 12 2013 Win64" ..

@mrexodia
Copy link
Contributor

Me?
On Wed, 14 Sep 2016 at 15:43, Nguyen Anh Quynh notifications@github.com
wrote:

can you generate .SLN file like this on Windows (this is for Win64, you
can also do that for Win32), then open .SLN file to compile, and report the
result?

mkdir build
cd build
cmake -G "Visual Studio 12 2013 Win64" ..


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#726 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACWCmQPjp9WfRIlxaFNnBdiZ6pUi_qMkks5qp_oHgaJpZM4JDppc
.

@aquynh
Copy link
Collaborator

aquynh commented Sep 14, 2016

yes, thanks.

@mrexodia
Copy link
Contributor

mrexodia commented Sep 15, 2016

It appears to be just the tests that fail to compile.

My CMake configuration (notice how I unchecked the TESTS):

cmake

capstone-static project properties 1:

prop1

capstone-static project properties 2 (not required):

prop2

The solution + binaries so you can test if it runs on XP for yourself: https://mega.nz/#!S4IxCYTL!W1tSm8oFjfrXoWeM5jblKRtA6MoEVa3s7duEqMgOTT0

@mrexodia
Copy link
Contributor

I pushed a fix that compiles the regression test successfully, see MSDN for more information. On Visual Studio 2015 someone uncommented the snprintf define I re-added this for Visual Studio versions < 2015.

Beginning with the UCRT in Visual Studio 2015 and Windows 10, snprintf is no longer identical to _snprintf. The snprintf function behavior is now C99 standard compliant.

aquynh added a commit that referenced this issue Sep 15, 2016
fixed issue #726 (snprintf undefined in test_arm_regression)
@kabeor
Copy link
Member

kabeor commented Dec 7, 2021

Close this issue for now because of legacy, we are preparing to release Capstone 5.0, plz feel free to open a new issue if that still has this issue.
thx :)

@kabeor kabeor closed this as completed Dec 7, 2021
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

4 participants