diff --git a/.gitignore b/.gitignore index 8c37dcc..c9b032e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ # Ignore build folders -Debug/ -Release/ -x64/ +build +lib # Ignore user-specific Visual Studio files *.vcxproj.filters diff --git a/ArgX.sln b/ArgX.sln deleted file mode 100755 index bca4f38..0000000 --- a/ArgX.sln +++ /dev/null @@ -1,51 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29025.244 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ArgX", "ArgX\ArgX.vcxproj", "{0CB574FB-350E-49D0-8268-073C0240F4E0}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "argxrun", "argxrun\argxrun.vcxproj", "{2AC75A65-4601-4C7E-B185-DE1FB4B1A8F8}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "argxtest", "argxtest\argxtest.vcxproj", "{12B405CD-810C-44EF-9B2D-9931A3AEFCD6}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0CB574FB-350E-49D0-8268-073C0240F4E0}.Debug|x64.ActiveCfg = Debug|x64 - {0CB574FB-350E-49D0-8268-073C0240F4E0}.Debug|x64.Build.0 = Debug|x64 - {0CB574FB-350E-49D0-8268-073C0240F4E0}.Debug|x86.ActiveCfg = Debug|Win32 - {0CB574FB-350E-49D0-8268-073C0240F4E0}.Debug|x86.Build.0 = Debug|Win32 - {0CB574FB-350E-49D0-8268-073C0240F4E0}.Release|x64.ActiveCfg = Release|x64 - {0CB574FB-350E-49D0-8268-073C0240F4E0}.Release|x64.Build.0 = Release|x64 - {0CB574FB-350E-49D0-8268-073C0240F4E0}.Release|x86.ActiveCfg = Release|Win32 - {0CB574FB-350E-49D0-8268-073C0240F4E0}.Release|x86.Build.0 = Release|Win32 - {2AC75A65-4601-4C7E-B185-DE1FB4B1A8F8}.Debug|x64.ActiveCfg = Debug|x64 - {2AC75A65-4601-4C7E-B185-DE1FB4B1A8F8}.Debug|x64.Build.0 = Debug|x64 - {2AC75A65-4601-4C7E-B185-DE1FB4B1A8F8}.Debug|x86.ActiveCfg = Debug|Win32 - {2AC75A65-4601-4C7E-B185-DE1FB4B1A8F8}.Debug|x86.Build.0 = Debug|Win32 - {2AC75A65-4601-4C7E-B185-DE1FB4B1A8F8}.Release|x64.ActiveCfg = Release|x64 - {2AC75A65-4601-4C7E-B185-DE1FB4B1A8F8}.Release|x64.Build.0 = Release|x64 - {2AC75A65-4601-4C7E-B185-DE1FB4B1A8F8}.Release|x86.ActiveCfg = Release|Win32 - {2AC75A65-4601-4C7E-B185-DE1FB4B1A8F8}.Release|x86.Build.0 = Release|Win32 - {12B405CD-810C-44EF-9B2D-9931A3AEFCD6}.Debug|x64.ActiveCfg = Debug|x64 - {12B405CD-810C-44EF-9B2D-9931A3AEFCD6}.Debug|x64.Build.0 = Debug|x64 - {12B405CD-810C-44EF-9B2D-9931A3AEFCD6}.Debug|x86.ActiveCfg = Debug|Win32 - {12B405CD-810C-44EF-9B2D-9931A3AEFCD6}.Debug|x86.Build.0 = Debug|Win32 - {12B405CD-810C-44EF-9B2D-9931A3AEFCD6}.Release|x64.ActiveCfg = Release|x64 - {12B405CD-810C-44EF-9B2D-9931A3AEFCD6}.Release|x64.Build.0 = Release|x64 - {12B405CD-810C-44EF-9B2D-9931A3AEFCD6}.Release|x86.ActiveCfg = Release|Win32 - {12B405CD-810C-44EF-9B2D-9931A3AEFCD6}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {18FC670C-5E74-4AC0-A7AD-BA638837800C} - EndGlobalSection -EndGlobal diff --git a/ArgX.vcxproj b/ArgX.vcxproj new file mode 100644 index 0000000..3c13f63 --- /dev/null +++ b/ArgX.vcxproj @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + build\$(Platform) + $(VCToolsInstallDir)bin\HostX64\$(Platform)\CL.exe + + + + + + + + + + + + + + + + + + + + + + + + + + + lib\ArgX32.lib + lib\ArgX64.lib + MachineX86 + MachineX64 + a + w + build\$(Platform) + + $(VCToolsInstallDir)bin\HostX64\$(Platform)\CL.exe + $(VCToolsInstallDir)bin\HostX64\$(Platform)\Link.exe + $(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@InstallationFolder) + $(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0@InstallationFolder) + $([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSdkTargetPlatformVersion('Windows', '10.0')) + $(WindowsSdkDir)\Lib\$(LatestSdk)\um\$(Platform) + $(WindowsSdkDir)\Lib\$(LatestSdk)\ucrt\$(Platform) + + $(VCToolsInstallDir)lib\$(Platform);$(WindowsSdkLibDir);$(WindowsUcrtLibDir) + + + + + + + + + + + + + + + + + + diff --git a/ArgX/ArgX.vcxproj b/ArgX/ArgX.vcxproj deleted file mode 100644 index 41c5ddb..0000000 --- a/ArgX/ArgX.vcxproj +++ /dev/null @@ -1,175 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - {0CB574FB-350E-49D0-8268-073C0240F4E0} - Win32Proj - ArgX - 10.0 - - - - StaticLibrary - true - v142 - Unicode - - - StaticLibrary - false - v142 - true - Unicode - - - StaticLibrary - true - v142 - Unicode - - - StaticLibrary - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - true - - - true - - - false - - - false - - - - Use - Level3 - Disabled - true - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - true - pch.h - - - Windows - true - - - - - Use - Level3 - Disabled - true - _DEBUG;_LIB;%(PreprocessorDefinitions) - true - pch.h - - - Windows - true - - - - - Use - Level3 - MaxSpeed - true - true - true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - true - pch.h - - - Windows - true - true - true - - - - - Use - Level3 - MaxSpeed - true - true - true - NDEBUG;_LIB;%(PreprocessorDefinitions) - true - pch.h - - - Windows - true - true - true - - - - - - - - - - - - - - Create - Create - Create - Create - - - - - - - \ No newline at end of file diff --git a/ArgX/pch.cpp b/ArgX/pch.cpp deleted file mode 100644 index d2c2055..0000000 --- a/ArgX/pch.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// pch.cpp: source file corresponding to the pre-compiled header - -#include "pch.h" - -// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. -#define WIN32_LEAN_AND_MEAN 1 -#include \ No newline at end of file diff --git a/ArgX/pch.h b/ArgX/pch.h deleted file mode 100644 index 72dc7f7..0000000 --- a/ArgX/pch.h +++ /dev/null @@ -1,14 +0,0 @@ -// pch.h: This is a precompiled header file. -// Files listed below are compiled only once, improving build performance for future builds. -// This also affects IntelliSense performance, including code completion and many code browsing features. -// However, files listed here are ALL re-compiled if any one of them is updated between builds. -// Do not add files here that you will be updating frequently as this negates the performance advantage. - -#ifndef PCH_H -#define PCH_H - -// add headers that you want to pre-compile here -#define WIN32_LEAN_AND_MEAN 1 -#include - -#endif //PCH_H diff --git a/argxrun/argxrun.cpp b/argxrun/argxrun.cpp deleted file mode 100755 index d587d1e..0000000 --- a/argxrun/argxrun.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#define WIN32_LEAN_AND_MEAN 1 -#include -#include -#include - -int wmain(int argc, wchar_t **argv) -{ - PROCESS_INFORMATION pi; - STARTUPINFOW si; - memset(&si, 0, sizeof(si)); - - if (argc < 2) { - wprintf(L"usage: argxrun \n"); - return 0; - } - - wprintf(L"Running %s\n", argv[1]); - - BOOL bRet = ArgxCreateProcessW(argv[1], - (LPCWSTR *)&argv[1], - argc - 1, - NULL, - NULL, - FALSE, - 0, - NULL, - NULL, - &si, - &pi); - - if (!bRet) { - wprintf(L"Failed\n"); - return 1; - } - - WaitForSingleObject(pi.hProcess, INFINITE); - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); - - wprintf(L"Finished\n"); - - return 0; -} diff --git a/argxrun/argxrun.vcxproj b/argxrun/argxrun.vcxproj deleted file mode 100755 index 6cfd106..0000000 --- a/argxrun/argxrun.vcxproj +++ /dev/null @@ -1,168 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - {2AC75A65-4601-4C7E-B185-DE1FB4B1A8F8} - Win32Proj - argxrun - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - $(ProjectDir)..\ArgX;$(IncludePath) - - - true - $(ProjectDir)..\ArgX;$(IncludePath) - - - false - $(ProjectDir)..\ArgX;$(IncludePath) - - - false - $(ProjectDir)..\ArgX;$(IncludePath) - - - - - - Level3 - Disabled - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - Disabled - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - MaxSpeed - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - Level3 - MaxSpeed - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - {0cb574fb-350e-49d0-8268-073c0240f4e0} - - - - - - \ No newline at end of file diff --git a/argxtest/argxtest.cpp b/argxtest/argxtest.cpp deleted file mode 100755 index 6fb9271..0000000 --- a/argxtest/argxtest.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#define WIN32_LEAN_AND_MEAN 1 -#include -#include -#include - -int wmain(void) -{ - DWORD dwArgc; - LPCWSTR *lpArgv; - - BOOL argx = ArgxGetArgumentsW(&dwArgc, &lpArgv); - - if (argx) { - wprintf(L"Using ArgX\n"); - } else { - wprintf(L"Not using ArgX\n"); - } - - for (DWORD n = 0; n < dwArgc; ++n) { - wprintf(L"%2lu: %p - %s\n", n, lpArgv[n], lpArgv[n]); - } - - return 0; -} diff --git a/argxtest/argxtest.vcxproj b/argxtest/argxtest.vcxproj deleted file mode 100755 index 676c5b3..0000000 --- a/argxtest/argxtest.vcxproj +++ /dev/null @@ -1,168 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - {12B405CD-810C-44EF-9B2D-9931A3AEFCD6} - Win32Proj - argxtest - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - $(ProjectDir)..\ArgX;$(IncludePath) - - - true - $(ProjectDir)..\ArgX;$(IncludePath) - - - false - $(ProjectDir)..\ArgX;$(IncludePath) - - - false - $(ProjectDir)..\ArgX;$(IncludePath) - - - - - - Level3 - Disabled - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - Disabled - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - MaxSpeed - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - Level3 - MaxSpeed - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - {0cb574fb-350e-49d0-8268-073c0240f4e0} - - - - - - \ No newline at end of file diff --git a/ArgX/ArgX.h b/include/ArgX.h similarity index 92% rename from ArgX/ArgX.h rename to include/ArgX.h index 325be91..d577acc 100644 --- a/ArgX/ArgX.h +++ b/include/ArgX.h @@ -59,9 +59,11 @@ BOOL ARGXAPI ArgxCreateProcessA(LPCSTR lpApplicationName, LPPROCESS_INFORMATION lpProcessInformation); BOOL ARGXAPI ArgxGetArgumentsW(PDWORD pdwArgc, - LPCWSTR** plpArgv); -BOOL ARGXAPI ArgxGetArgumentsA(PDWORD pdwArgc, - LPCSTR** plpArgv); + LPCWSTR** plpArgv, + BOOL* pbUsedArgX); +BOOL ARGXAPI ArgxGetArgumentsA(PDWORD pdwArgc, + LPCSTR** plpArgv, + BOOL* pbUsedArgX); #if _UNICODE #define ArgxCreateProcess ArgxCreateProcessW diff --git a/ArgX/ArgxCreateProcess.cpp b/src/ArgxCreateProcess.cpp similarity index 99% rename from ArgX/ArgxCreateProcess.cpp rename to src/ArgxCreateProcess.cpp index 3b9192b..95f8c20 100644 --- a/ArgX/ArgxCreateProcess.cpp +++ b/src/ArgxCreateProcess.cpp @@ -5,8 +5,6 @@ * */ -#include "pch.h" - #define WIN32_LEAN_AND_MEAN 1 #include #include @@ -218,8 +216,8 @@ ArgxCreateProcessW(LPCWSTR lpApplicationName, goto fail; // Look for the ArgX section - BOOL bSupportsArgX; - DWORD64 ulArgXSectionAddr; + BOOL bSupportsArgX = FALSE; + DWORD64 ulArgXSectionAddr = 0; switch (bitness) { case BITNESS_32_BIT: @@ -237,7 +235,7 @@ ArgxCreateProcessW(LPCWSTR lpApplicationName, if (bSupportsArgX) { // Write the argument vector and update the ArgX section - BOOL bRet; + BOOL bRet = FALSE; switch (bitness) { case BITNESS_32_BIT: @@ -280,8 +278,7 @@ ArgxCreateProcessW(LPCWSTR lpApplicationName, namespace { -BOOL CALLBACK InitArgxCreateFunction(PINIT_ONCE InitOnce, PVOID Parameter, - PVOID *lpContext) +BOOL CALLBACK InitArgxCreateFunction(PINIT_ONCE, PVOID, PVOID *) { hProcessHeap = GetProcessHeap(); if (!hProcessHeap) diff --git a/ArgX/ArgxCreateProcessA.cpp b/src/ArgxCreateProcessA.cpp similarity index 99% rename from ArgX/ArgxCreateProcessA.cpp rename to src/ArgxCreateProcessA.cpp index a0102e1..489aa91 100644 --- a/ArgX/ArgxCreateProcessA.cpp +++ b/src/ArgxCreateProcessA.cpp @@ -5,8 +5,6 @@ * */ -#include "pch.h" - #define WIN32_LEAN_AND_MEAN 1 #include #include diff --git a/ArgX/ArgxGetArguments.cpp b/src/ArgxGetArguments.cpp similarity index 82% rename from ArgX/ArgxGetArguments.cpp rename to src/ArgxGetArguments.cpp index d2c2d48..7ce5429 100644 --- a/ArgX/ArgxGetArguments.cpp +++ b/src/ArgxGetArguments.cpp @@ -5,8 +5,6 @@ * */ -#include "pch.h" - #define WIN32_LEAN_AND_MEAN 1 #include #include @@ -20,7 +18,8 @@ namespace { BOOL ARGXAPI ArgxGetArgumentsW(PDWORD pdwArgc, - LPCWSTR** plpArgv) + LPCWSTR** plpArgv, + BOOL* pbUsedArgX) { if (argxData.dwMagic != ARGX_MAGIC) { LPWSTR pszCmdline = GetCommandLineW(); @@ -29,11 +28,16 @@ ArgxGetArgumentsW(PDWORD pdwArgc, *pdwArgc = numArgs; *plpArgv = (LPCWSTR*)args; - return FALSE; + if (pbUsedArgX) + *pbUsedArgX = FALSE; + + return TRUE; } *pdwArgc = argxData.dwArgc; *plpArgv = const_cast(argxData.pszArgv); + if (pbUsedArgX) + *pbUsedArgX = TRUE; return TRUE; } diff --git a/ArgX/ArgxGetArgumentsA.cpp b/src/ArgxGetArgumentsA.cpp similarity index 91% rename from ArgX/ArgxGetArgumentsA.cpp rename to src/ArgxGetArgumentsA.cpp index eec540c..b7803e0 100644 --- a/ArgX/ArgxGetArgumentsA.cpp +++ b/src/ArgxGetArgumentsA.cpp @@ -5,8 +5,6 @@ * */ -#include "pch.h" - #define WIN32_LEAN_AND_MEAN 1 #include #include @@ -19,27 +17,29 @@ namespace { INIT_ONCE initOnce = INIT_ONCE_STATIC_INIT; + BOOL bUsedArgX; DWORD dwArgc; LPCSTR* lpArgv; } BOOL ARGXAPI ArgxGetArgumentsA(PDWORD pdwArgc, - LPCSTR** plpArgv) + LPCSTR** plpArgv, + BOOL* pbUsedArgX) { // The first time this is called, and *only* the first time, convert the // argv array. if (!InitOnceExecuteOnce(&initOnce, InitArgxGetArgumentsA, NULL, - NULL)) - return FALSE; - - if (!lpArgv) + NULL)) { return FALSE; + } *pdwArgc = dwArgc; *plpArgv = lpArgv; + if (pbUsedArgX) + *pbUsedArgX = bUsedArgX; return TRUE; } @@ -53,8 +53,8 @@ BOOL CALLBACK InitArgxGetArgumentsA(PINIT_ONCE, PVOID, PVOID *) dwArgc = 0; lpArgv = NULL; - - if (!ArgxGetArgumentsW(&dwArgc, &lpArgvW)) + + if (!ArgxGetArgumentsW(&dwArgc, &lpArgvW, &bUsedArgX)) return FALSE; // First, work out how much memory we need for the converted strings diff --git a/ArgX/PEB.hpp b/src/PEB.hpp similarity index 100% rename from ArgX/PEB.hpp rename to src/PEB.hpp diff --git a/test/argxrun.cpp b/test/argxrun.cpp new file mode 100755 index 0000000..d380b37 --- /dev/null +++ b/test/argxrun.cpp @@ -0,0 +1,44 @@ +#define WIN32_LEAN_AND_MEAN 1 +#include +#include +#include +#include + +int _tmain(int argc, TCHAR **argv) +{ + PROCESS_INFORMATION pi; + STARTUPINFO si; + memset(&si, 0, sizeof(si)); + + if (argc < 2) { + _tprintf(_T("usage: argxrun \n")); + return 0; + } + + _tprintf(_T("Running %s\n"), argv[1]); + + BOOL bRet = ArgxCreateProcess(argv[1], + (LPCTSTR *)&argv[1], + argc - 1, + NULL, + NULL, + FALSE, + 0, + NULL, + NULL, + &si, + &pi); + + if (!bRet) { + _tprintf(_T("Failed\n")); + return 1; + } + + WaitForSingleObject(pi.hProcess, INFINITE); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + + _tprintf(_T("Finished\n")); + + return 0; +} diff --git a/test/argxtest.cpp b/test/argxtest.cpp new file mode 100755 index 0000000..d2838f7 --- /dev/null +++ b/test/argxtest.cpp @@ -0,0 +1,31 @@ +#define WIN32_LEAN_AND_MEAN 1 +#include +#include +#include +#include + +int _tmain(void) +{ + DWORD dwArgc; + LPCTSTR *lpArgv; + BOOL bUsedArgX; + + BOOL ret = ArgxGetArguments(&dwArgc, &lpArgv, &bUsedArgX); + + if (!ret) { + _tprintf(_T("Failed to get arguments\n")); + return 1; + } + + if (bUsedArgX) { + _tprintf(_T("Using ArgX\n")); + } else { + _tprintf(_T("Not using ArgX\n")); + } + + for (DWORD n = 0; n < dwArgc; ++n) { + _tprintf(_T("%2lu: %p - %s\n"), n, lpArgv[n], lpArgv[n]); + } + + return 0; +}