I follow https://msdn.microsoft.com/en-us/librar ... S.85).aspx to execute a command line in C. I success if I build it without wxWidgets
Code: Select all
#define DRIVER32 "REG QUERY \"HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32\" /s"
int enumReg() {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
DRIVER32, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return 1;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return 0;
}
Full build log:E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|160|error: cannot convert 'const char*' to 'LPWSTR {aka wchar_t*}' for argument '2' to 'WINBOOL CreateProcessW(LPCWSTR, LPWSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, WINBOOL, DWORD, LPVOID, LPCWSTR, LPSTARTUPINFOW, LPPROCESS_INFORMATION)'|
My ForHelperGUIMain.cpp||=== Build: Debug in ForHelperGUI (compiler: GNU GCC Compiler) ===|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|16|warning: ignoring #pragma comment [-Wunknown-pragmas]|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp||In function 'int enumReg()':|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|160|error: cannot convert 'const char*' to 'LPWSTR {aka wchar_t*}' for argument '2' to 'WINBOOL CreateProcessW(LPCWSTR, LPWSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, WINBOOL, DWORD, LPVOID, LPCWSTR, LPSTARTUPINFOW, LPPROCESS_INFORMATION)'|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|163|warning: format '%d' expects argument of type 'int', but argument 2 has type 'DWORD {aka long unsigned int}' [-Wformat=]|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp||In function 'DWORD ListProcessModules()':|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|208|warning: deprecated conversion from string constant to 'TCHAR* {aka wchar_t*}' [-Wwrite-strings]|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|219|warning: deprecated conversion from string constant to 'TCHAR* {aka wchar_t*}' [-Wwrite-strings]|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp||In member function 'void ForHelperGUIFrame::OnbtnDumpClick(wxCommandEvent&)':|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|253|warning: unused variable 'lpThreadID' [-Wunused-variable]|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|254|warning: unused variable 'hThreadArray' [-Wunused-variable]|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|262|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated: use SetInitialSize() instead. [-Wdeprecated-declarations]|
C:\wxWidgets-3.1.0\include\wx\window.h|1917|note: declared here|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|262|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated: use SetInitialSize() instead. [-Wdeprecated-declarations]|
C:\wxWidgets-3.1.0\include\wx\window.h|1917|note: declared here|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|262|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated: use SetInitialSize() instead. [-Wdeprecated-declarations]|
C:\wxWidgets-3.1.0\include\wx\window.h|1917|note: declared here|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|262|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated: use SetInitialSize() instead. [-Wdeprecated-declarations]|
C:\wxWidgets-3.1.0\include\wx\window.h|1917|note: declared here|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|262|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated: use SetInitialSize() instead. [-Wdeprecated-declarations]|
C:\wxWidgets-3.1.0\include\wx\window.h|1917|note: declared here|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|262|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated: use SetInitialSize() instead. [-Wdeprecated-declarations]|
C:\wxWidgets-3.1.0\include\wx\window.h|1917|note: declared here|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|262|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated: use SetInitialSize() instead. [-Wdeprecated-declarations]|
C:\wxWidgets-3.1.0\include\wx\window.h|1917|note: declared here|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|262|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated: use SetInitialSize() instead. [-Wdeprecated-declarations]|
C:\wxWidgets-3.1.0\include\wx\window.h|1917|note: declared here|
E:\WorkSpace\Code\ForHelperGUI\ForHelperGUIMain.cpp|262|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated: use SetInitialSize() instead. [-Wdeprecated-declarations]|
C:\wxWidgets-3.1.0\include\wx\window.h|1917|note: declared here|
||=== Build failed: 1 error(s), 15 warning(s) (0 minute(s), 5 second(s)) ===|
Code: Select all
/***************************************************************
* Name: ForHelperGUIMain.cpp
* Purpose: Code for Application Frame
* Author: ()
* Created: 2018-01-21
* Copyright: ()
* License:
**************************************************************/
#include "ForHelperGUIMain.h"
#include <wx/msgdlg.h>
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
#include <shellapi.h>
#pragma comment(lib, "shell32")
//#include "built-inLibrary.h" //Lib
//(*InternalHeaders(ForHelperGUIFrame)
#include <wx/intl.h>
#include <wx/settings.h>
#include <wx/string.h>
//*)
//helper functions
enum wxbuildinfoformat {
short_f, long_f };
wxString wxbuildinfo(wxbuildinfoformat format)
{
wxString wxbuild(wxVERSION_STRING);
if (format == long_f )
{
#if defined(__WXMSW__)
wxbuild << _T("-Windows");
#elif defined(__UNIX__)
wxbuild << _T("-Linux");
#endif
#if wxUSE_UNICODE
wxbuild << _T("-Unicode build");
#else
wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
}
return wxbuild;
}
//(*IdInit(ForHelperGUIFrame)
const long ForHelperGUIFrame::ID_STATICBOX1 = wxNewId();
const long ForHelperGUIFrame::ID_STATICBOX2 = wxNewId();
const long ForHelperGUIFrame::ID_STATICBOX3 = wxNewId();
const long ForHelperGUIFrame::ID_STATICBOX4 = wxNewId();
const long ForHelperGUIFrame::ID_CHECKBOX1 = wxNewId();
const long ForHelperGUIFrame::ID_CHECKBOX2 = wxNewId();
const long ForHelperGUIFrame::ID_CHECKBOX3 = wxNewId();
const long ForHelperGUIFrame::ID_CHECKBOX4 = wxNewId();
const long ForHelperGUIFrame::ID_CHECKBOX5 = wxNewId();
const long ForHelperGUIFrame::ID_CHECKBOX6 = wxNewId();
const long ForHelperGUIFrame::ID_CHECKBOX7 = wxNewId();
const long ForHelperGUIFrame::ID_CHECKBOX8 = wxNewId();
const long ForHelperGUIFrame::ID_CHECKBOX9 = wxNewId();
const long ForHelperGUIFrame::ID_TEXTCTRL1 = wxNewId();
const long ForHelperGUIFrame::ID_BUTTON1 = wxNewId();
const long ForHelperGUIFrame::ID_BUTTON2 = wxNewId();
const long ForHelperGUIFrame::ID_PANEL1 = wxNewId();
//*)
BEGIN_EVENT_TABLE(ForHelperGUIFrame,wxFrame)
//(*EventTable(ForHelperGUIFrame)
//*)
END_EVENT_TABLE()
ForHelperGUIFrame::ForHelperGUIFrame(wxWindow* parent,wxWindowID id)
{
//(*Initialize(ForHelperGUIFrame)
Create(parent, id, _("ForHelperGUI"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
SetClientSize(wxSize(393,226));
pnBackGround = new wxPanel(this, ID_PANEL1, wxPoint(216,168), wxSize(393,224), wxTAB_TRAVERSAL, _T("ID_PANEL1"));
StaticBox1 = new wxStaticBox(pnBackGround, ID_STATICBOX1, _("Processes"), wxPoint(8,8), wxSize(104,96), 0, _T("ID_STATICBOX1"));
StaticBox2 = new wxStaticBox(pnBackGround, ID_STATICBOX2, _("Services"), wxPoint(128,8), wxSize(128,96), 0, _T("ID_STATICBOX2"));
StaticBox3 = new wxStaticBox(pnBackGround, ID_STATICBOX3, _("Registry"), wxPoint(272,8), wxSize(112,96), 0, _T("ID_STATICBOX3"));
StaticBox4 = new wxStaticBox(pnBackGround, ID_STATICBOX4, _("QuickCommand:"), wxPoint(8,160), wxSize(376,56), 0, _T("ID_STATICBOX4"));
chkConnections = new wxCheckBox(pnBackGround, ID_CHECKBOX1, _("Connections"), wxPoint(16,32), wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
chkConnections->SetValue(false);
chkProcessTree = new wxCheckBox(pnBackGround, ID_CHECKBOX2, _("Process Tree"), wxPoint(16,48), wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX2"));
chkProcessTree->SetValue(true);
chkModules = new wxCheckBox(pnBackGround, ID_CHECKBOX3, _("Modules"), wxPoint(16,64), wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX3"));
chkModules->SetValue(true);
chkThreads = new wxCheckBox(pnBackGround, ID_CHECKBOX4, _("Threads"), wxPoint(16,80), wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX4"));
chkThreads->SetValue(false);
chkEnumServices = new wxCheckBox(pnBackGround, ID_CHECKBOX5, _("Enumerate services"), wxPoint(136,32), wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX5"));
chkEnumServices->SetValue(true);
chkDumpBinary = new wxCheckBox(pnBackGround, ID_CHECKBOX6, _("Dump binary"), wxPoint(136,64), wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX6"));
chkDumpBinary->SetValue(false);
chkBasicRegistry = new wxCheckBox(pnBackGround, ID_CHECKBOX7, _("Basic registry"), wxPoint(280,32), wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX7"));
chkBasicRegistry->SetValue(true);
chkDrivers = new wxCheckBox(pnBackGround, ID_CHECKBOX8, _("Drivers"), wxPoint(280,48), wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX8"));
chkDrivers->SetValue(false);
chkDumpDriversBinary = new wxCheckBox(pnBackGround, ID_CHECKBOX9, _("Dump binary"), wxPoint(280,64), wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX9"));
chkDumpDriversBinary->SetValue(false);
txtCommand = new wxTextCtrl(pnBackGround, ID_TEXTCTRL1, wxEmptyString, wxPoint(16,184), wxSize(360,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
txtCommand->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENU));
btnDump = new wxButton(pnBackGround, ID_BUTTON1, _("Dump"), wxPoint(88,120), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
btnDump->SetDefault();
btnOpenDir = new wxButton(pnBackGround, ID_BUTTON2, _("OpenDir"), wxPoint(216,120), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
Center();
Connect(ID_TEXTCTRL1,wxEVT_COMMAND_TEXT_ENTER,(wxObjectEventFunction)&ForHelperGUIFrame::OntxtCommandTextEnter);
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&ForHelperGUIFrame::OnbtnDumpClick);
Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&ForHelperGUIFrame::OnbtnOpenDirClick);
//*)
}
ForHelperGUIFrame::~ForHelperGUIFrame()
{
//(*Destroy(ForHelperGUIFrame)
//*)
}
void ForHelperGUIFrame::OnQuit(wxCommandEvent& event)
{
Close();
}
void ForHelperGUIFrame::OnAbout(wxCommandEvent& event)
{
wxString msg = wxbuildinfo(long_f);
wxMessageBox(msg, _("Welcome to..."));
}
void ForHelperGUIFrame::OntxtCommandTextEnter(wxCommandEvent& event)
{
//Do command
}
// =====================================
#define DRIVER32 "REG QUERY \"HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32\" /s"
int enumReg() {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
DRIVER32, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return 1;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return 0;
}
void printError( TCHAR* msg )
{
DWORD eNum;
TCHAR sysMsg[256];
TCHAR* p;
eNum = GetLastError( );
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, eNum,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
sysMsg, 256, NULL );
// Trim the end of the line and terminate it with a null
p = sysMsg;
while( ( *p > 31 ) || ( *p == 9 ) )
++p;
do { *p-- = 0; } while( ( p >= sysMsg ) &&
( ( *p == '.' ) || ( *p < 33 ) ) );
// Display the message
_tprintf( TEXT("\n WARNING: %s failed with error %d (%s)"), msg, eNum, sysMsg );
}
DWORD WINAPI ListProcessModules()
{
HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
MODULEENTRY32 me32;
// Take a snapshot of all modules in the specified process.
hModuleSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, GetCurrentProcessId() );
if( hModuleSnap == INVALID_HANDLE_VALUE )
{
printError( TEXT("CreateToolhelp32Snapshot (of modules)") );
return( FALSE );
}
// Set the size of the structure before using it.
me32.dwSize = sizeof( MODULEENTRY32 );
// Retrieve information about the first module,
// and exit if unsuccessful
if( !Module32First( hModuleSnap, &me32 ) )
{
printError( TEXT("Module32First") ); // Show cause of failure
CloseHandle( hModuleSnap ); // Must clean up the snapshot object!
return 0;
}
// Now walk the module list of the process,
// and display information about each module
do
{
_tprintf( TEXT("\n\n MODULE NAME: %s"), me32.szModule );
_tprintf( TEXT("\n executable = %s"), me32.szExePath );
_tprintf( TEXT("\n process ID = 0x%08X"), me32.th32ProcessID );
_tprintf( TEXT("\n ref count (g) = 0x%04X"), me32.GlblcntUsage );
_tprintf( TEXT("\n ref count (p) = 0x%04X"), me32.ProccntUsage );
_tprintf( TEXT("\n base address = 0x%08X"), me32.modBaseAddr );
_tprintf( TEXT("\n base size = %d"), me32.modBaseSize );
} while( Module32Next( hModuleSnap, &me32 ) );
_tprintf( TEXT("\n"));
// Do not forget to clean up the snapshot object.
CloseHandle( hModuleSnap );
return 1;
}
// =====================================
void ForHelperGUIFrame::OnbtnDumpClick(wxCommandEvent& event)
{
CreateDirectory(TEXT("Data"), NULL);
CreateDirectory(TEXT("Data\\Services"), NULL);
CreateDirectory(TEXT("Data\\Registry"), NULL);
CreateDirectory(TEXT("Data\\Processes"), NULL);
DWORD lpThreadID[10];
HANDLE hThreadArray[10];
ListProcessModules();
}
void ForHelperGUIFrame::OnbtnOpenDirClick(wxCommandEvent& event)
{
Close();
}