Author Topic: C++ Compiler Errors  (Read 2041 times)

0 Members and 1 Guest are viewing this topic.

Offline soakingtub

  • NULL
  • Posts: 4
  • Cookies: 0
    • View Profile
C++ Compiler Errors
« on: September 24, 2015, 04:56:34 am »
I'm trying to compile https://www.exploit-db.com/exploits/37098/ to test on my WinXP VM but i'm getting the following compiler errors. Any ideas on how i can resolve these? Thanks!

root@kali:~/.wine/drive_c/MinGW/bin# wine g++ ex.cpp -o ex.exe
ex.h:9:20: error: typedef 'NTSTATUS' is initialized (use decltype instead)
typedef NTSTATUS ( WINAPI *_ZwAllocateVirtualMemory ) (
^
ex.h:9:20: error: expected primary-expression before '__attribute__'
typedef NTSTATUS ( WINAPI *_ZwAllocateVirtualMemory ) (
^
ex.h:18:20: error: typedef 'NTSTATUS' is initialized (use decltype instead)
typedef NTSTATUS ( WINAPI *_PsLookupProcessByProcessId ) (
^
ex.h:18:20: error: expected primary-expression before '__attribute__'
typedef NTSTATUS ( WINAPI *_PsLookupProcessByProcessId ) (
^
In file included from ex.cpp:14:0:
ex.h:24:5: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
_Inout_ PVOID Process
^
ex.h:24:5: error: typedef '_PsReferencePrimaryToken' is initialized (use decltype instead)
ex.h:24:5: error: '_Inout_' was not declared in this scope
ex.h:32:20: error: typedef 'NTSTATUS' is initialized (use decltype instead)
typedef NTSTATUS ( WINAPI *_ZwQuerySystemInformation ) (
^
ex.h:32:20: error: expected primary-expression before '__attribute__'
typedef NTSTATUS ( WINAPI *_ZwQuerySystemInformation ) (
^
ex.cpp:16:1: error: '_ZwAllocateVirtualMemory' does not name a type
_ZwAllocateVirtualMemory ZwAllocateVirtualMemory;
^
ex.cpp:17:1: error: '_PsLookupProcessByProcessId' does not name a type
_PsLookupProcessByProcessId PsLookupProcessByProcessId;
^
ex.cpp:18:1: error: '_PsReferencePrimaryToken' does not name a type
_PsReferencePrimaryToken PsReferencePrimaryToken;
^
ex.cpp: In function 'DWORD_PTR pti()':
ex.cpp:29:47: error: '__readfsdword' was not declared in this scope
LPBYTE p = ( LPBYTE ) __readfsdword( 0x18 );
^
ex.cpp: In function 'BOOL Init()':
ex.cpp:67:5: error: '__try' was not declared in this scope
__try {
^
ex.cpp:67:11: error: expected ';' before '{' token
__try {
^
ex.cpp:286:1: error: expected '}' at end of input
}
^

Offline Trevor

  • Serf
  • *
  • Posts: 39
  • Cookies: 18
  • Coder, Reverser
    • View Profile
Re: C++ Compiler Errors
« Reply #1 on: September 26, 2015, 06:50:37 pm »
Have you tried compiling with Visual Studio. GCC is not suitable for this. With MSVC it compiles fine, with a few warnings.

You can try compiling with MSVC here http://webcompiler.cloudapp.net/
Make sure to paste the contents of the .h file at the top of the source code.

Code: [Select]
Compiled with  /EHsc /nologo /W4 /c
main.cpp
main.cpp(82): warning C4245: '=': conversion from 'int' to 'DWORD_PTR', signed/unsigned mismatch
main.cpp(110): warning C4996: 'GetVersionExA': was declared deprecated
c:\tools_root\cl\inc\um\sysinfoapi.h(433): note: see declaration of 'GetVersionExA'
main.cpp(181): warning C4100: 'lParam': unreferenced formal parameter
main.cpp(181): warning C4100: 'wParam': unreferenced formal parameter
main.cpp(181): warning C4100: 'uMsg': unreferenced formal parameter
main.cpp(181): warning C4100: 'hWnd': unreferenced formal parameter
main.cpp(245): warning C4100: 'nCmdShow': unreferenced formal parameter
main.cpp(244): warning C4100: 'lpCmdLine': unreferenced formal parameter
main.cpp(243): warning C4100: 'hPrevInstance': unreferenced formal parameter

Compilation successful!

Total compilation time: 390ms
« Last Edit: September 26, 2015, 06:52:47 pm by Trevor »

Offline soakingtub

  • NULL
  • Posts: 4
  • Cookies: 0
    • View Profile
Re: C++ Compiler Errors
« Reply #2 on: September 27, 2015, 01:56:03 am »
Thanks! Is there a way to download the exe one it has been compiled at webcompiler? I tried compiling using the Visual Studio Developer Command Prompt and CL (cl ex.cpp) but received the following errors. Any ideas?

C:\temp>cl ex.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23026 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

ex.cpp
Microsoft (R) Incremental Linker Version 14.00.23026.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:ex.exe
ex.obj
ex.obj : error LNK2019: unresolved external symbol __imp__GetMessageA@16 referen
ced in function _WinMain@16
ex.obj : error LNK2019: unresolved external symbol __imp__TranslateMessage@4 ref
erenced in function _WinMain@16
ex.obj : error LNK2019: unresolved external symbol __imp__DispatchMessageA@4 ref
erenced in function _WinMain@16
ex.obj : error LNK2019: unresolved external symbol __imp__DefWindowProcA@16 refe
renced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned
 int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
ex.obj : error LNK2019: unresolved external symbol __imp__PostQuitMessage@4 refe
renced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned
 int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
ex.obj : error LNK2019: unresolved external symbol __imp__RegisterClassExA@4 ref
erenced in function _WinMain@16
ex.obj : error LNK2019: unresolved external symbol __imp__CreateWindowExA@48 ref
erenced in function _WinMain@16
ex.obj : error LNK2019: unresolved external symbol __imp__DestroyWindow@4 refere
nced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned i
nt,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
ex.obj : error LNK2019: unresolved external symbol __imp__ShowWindow@8 reference
d in function _WinMain@16
ex.obj : error LNK2019: unresolved external symbol __imp__FlashWindow@8 referenc
ed in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int
,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
ex.obj : error LNK2019: unresolved external symbol __imp__keybd_event@16 referen
ced in function "void __stdcall leave(void)" (?leave@@YGXXZ)
ex.obj : error LNK2019: unresolved external symbol __imp__SetTimer@16 referenced
 in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,l
ong)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
ex.obj : error LNK2019: unresolved external symbol __imp__KillTimer@8 referenced
 in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,l
ong)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
ex.obj : error LNK2019: unresolved external symbol __imp__UpdateWindow@4 referen
ced in function _WinMain@16
ex.obj : error LNK2019: unresolved external symbol __imp__ShellExecuteA@24 refer
enced in function _WinMain@16
ex.exe : fatal error LNK1120: 15 unresolved externals

Offline soakingtub

  • NULL
  • Posts: 4
  • Cookies: 0
    • View Profile
Re: C++ Compiler Errors
« Reply #3 on: September 27, 2015, 04:21:51 am »
Had a few more tries and it looks like the problem only happens when trying to compile to exe. If i compile with the switches "/EHsc /nologo /W4 /c" it compiles fine but no exe is generated, only the .obj file.
If i attempt to compile without any switches (to .exe) that's when the fatal errors occur. Any ideas?

Offline Trevor

  • Serf
  • *
  • Posts: 39
  • Cookies: 18
  • Coder, Reverser
    • View Profile
Re: C++ Compiler Errors
« Reply #4 on: September 27, 2015, 09:57:19 am »
Those are linker errors. You need to link with the kernel32, user32, and shell32
I have also attached the source.

Code: [Select]
cl ex.cpp /link kernel32.lib shell32.lib user32.lib

Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23026 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

ex.cpp
Microsoft (R) Incremental Linker Version 14.00.23026.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:ex.exe
kernel32.lib
shell32.lib
user32.lib
ex.obj
« Last Edit: September 27, 2015, 09:57:57 am by Trevor »

Offline soakingtub

  • NULL
  • Posts: 4
  • Cookies: 0
    • View Profile
Re: C++ Compiler Errors
« Reply #5 on: September 27, 2015, 12:15:10 pm »
It works! You're a legend! Thanks for your help!

Offline novaccainne

  • Serf
  • *
  • Posts: 29
  • Cookies: 2
    • View Profile
Re: C++ Compiler Errors
« Reply #6 on: September 29, 2015, 09:36:17 pm »
If you would like to create win32 executable files on linux then try mingw. Once you have installed it you should have a new folder on your filesystem called /usr/i686-w64-mingw32/ (for win32) or /usr/x86_64-w64-mingw32/. These folders contain various pieces belonging to the mingw-w64 toolchain, for example the headers belonging to the Windows API and the import libraries for the default Windows API libraries (like shell32.dll and winsock2.dll).

[mingw-w64.sourceforge.net]: provides 32 and 64-bit toolchains with secure crt, Vista+ API, DDK (ReactOS), and DirectX (WINE) support. For a full list of supported features and differences with the old MinGW.org.

http://sourceforge.net/p/mingw-w64/wiki2/FAQ/