Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
redneck-f25 committed Mar 18, 2016
0 parents commit 53b4bae
Show file tree
Hide file tree
Showing 16 changed files with 891 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.vs
/x64
**~
/*.sdf
/*.VC.opendb
**/Debug/
**/Release/
50 changes: 50 additions & 0 deletions cSuRun.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cSuRun", "cSuRun\cSuRun.vcxproj", "{7953E24A-1E10-47B1-8F2B-175E21D19F7D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cSuRunH", "cSuRunH\cSuRunH.vcxproj", "{9AD85A6A-B86E-4138-8FC9-1B7964007A48}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fakeSuRun", "fakeSuRun\fakeSuRun.vcxproj", "{E296E6CB-E32C-44B7-BCD5-449BA6A975CE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "install", "install\install.vcxitems", "{45D41ACC-2C3C-43D2-BC10-02AA73FFC7C7}"
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
{7953E24A-1E10-47B1-8F2B-175E21D19F7D}.Debug|x64.ActiveCfg = Debug|x64
{7953E24A-1E10-47B1-8F2B-175E21D19F7D}.Debug|x64.Build.0 = Debug|x64
{7953E24A-1E10-47B1-8F2B-175E21D19F7D}.Debug|x86.ActiveCfg = Debug|Win32
{7953E24A-1E10-47B1-8F2B-175E21D19F7D}.Debug|x86.Build.0 = Debug|Win32
{7953E24A-1E10-47B1-8F2B-175E21D19F7D}.Release|x64.ActiveCfg = Release|x64
{7953E24A-1E10-47B1-8F2B-175E21D19F7D}.Release|x64.Build.0 = Release|x64
{7953E24A-1E10-47B1-8F2B-175E21D19F7D}.Release|x86.ActiveCfg = Release|Win32
{7953E24A-1E10-47B1-8F2B-175E21D19F7D}.Release|x86.Build.0 = Release|Win32
{9AD85A6A-B86E-4138-8FC9-1B7964007A48}.Debug|x64.ActiveCfg = Debug|x64
{9AD85A6A-B86E-4138-8FC9-1B7964007A48}.Debug|x64.Build.0 = Debug|x64
{9AD85A6A-B86E-4138-8FC9-1B7964007A48}.Debug|x86.ActiveCfg = Debug|Win32
{9AD85A6A-B86E-4138-8FC9-1B7964007A48}.Debug|x86.Build.0 = Debug|Win32
{9AD85A6A-B86E-4138-8FC9-1B7964007A48}.Release|x64.ActiveCfg = Release|x64
{9AD85A6A-B86E-4138-8FC9-1B7964007A48}.Release|x64.Build.0 = Release|x64
{9AD85A6A-B86E-4138-8FC9-1B7964007A48}.Release|x86.ActiveCfg = Release|Win32
{9AD85A6A-B86E-4138-8FC9-1B7964007A48}.Release|x86.Build.0 = Release|Win32
{E296E6CB-E32C-44B7-BCD5-449BA6A975CE}.Debug|x64.ActiveCfg = Debug|x64
{E296E6CB-E32C-44B7-BCD5-449BA6A975CE}.Debug|x64.Build.0 = Debug|x64
{E296E6CB-E32C-44B7-BCD5-449BA6A975CE}.Debug|x86.ActiveCfg = Debug|Win32
{E296E6CB-E32C-44B7-BCD5-449BA6A975CE}.Debug|x86.Build.0 = Debug|Win32
{E296E6CB-E32C-44B7-BCD5-449BA6A975CE}.Release|x64.ActiveCfg = Release|x64
{E296E6CB-E32C-44B7-BCD5-449BA6A975CE}.Release|x64.Build.0 = Release|x64
{E296E6CB-E32C-44B7-BCD5-449BA6A975CE}.Release|x86.ActiveCfg = Release|Win32
{E296E6CB-E32C-44B7-BCD5-449BA6A975CE}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
140 changes: 140 additions & 0 deletions cSuRun/cSuRun.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// cmd /e:on /v:on /c "for /l %n in (0,0,1) do @(echo !time! & >nul timeout /t 1)"
// cmd /e:on /v:on /c "for /l %n in (0,0,1) do @(echo !time! & >nul ping -n 2 localhost)"

#define _CRT_SECURE_NO_WARNINGS

#include <Windows.h>
#include <Psapi.h>
#include <strsafe.h>

#include "../cSuRun/strdefs.h"

#define NUM_INSTANCES (4)
HANDLE pipes[NUM_INSTANCES][2] = {
{ GetStdHandle(STD_INPUT_HANDLE), NULL },
{ NULL, GetStdHandle(STD_OUTPUT_HANDLE) },
{ NULL, GetStdHandle(STD_ERROR_HANDLE) }
};

DWORD WINAPI RedirStdBytesThread(int i)
{
char ch;
DWORD cch;

while (1)
{
if (!ReadFile(pipes[i][0], &ch, sizeof(ch), &cch, NULL))
break;
if (!cch)
break;
if (!WriteFile(pipes[i][1], &ch, sizeof(ch), &cch, NULL))
break;
if (!cch)
break;
}
return 0;
}

wchar_t* strip_part(wchar_t **pcmdline)
{
wchar_t *start = *pcmdline;
wchar_t *end;

if (*start == '"')
{
if (!(end = wcschr(start + 1, '"')))
return 0;
end++;
}
else
{
if (!(end = wcschr(start, ' ')))
end = wcschr(start, 0);
}
if (*end != 0)
{
if (*end != ' ')
return 0;
*end = 0;
do end++; while (*end != 0 && *end == ' ');
}
*pcmdline = end;
return start;
}

int main()
{
STARTUPINFO si = { sizeof(STARTUPINFO) };
PROCESS_INFORMATION pi = { 0 };
wchar_t *pch;
wchar_t *commandLine = GetCommandLine();
wchar_t *application;
wchar_t *helper_bin = (LPWSTR)malloc(4096);
wchar_t *surun_cmdline = (LPWSTR)malloc(4096);
wchar_t *application_full = (LPWSTR)malloc(4096);
wchar_t pipename[PIPENAME_LEN];
DWORD exitCode;
int nh = 0;

GetModuleFileName(NULL, helper_bin, 2047);
pch = wcsrchr(helper_bin, L'.');
wcscpy(pch, L"H.bin");

if (!(strip_part(&commandLine) && (application = strip_part(&commandLine))))
{
return 1;
}
if (*application == 0 || !wcscmp(application, L"\"\""))
{
return 1;
}
if (!CreateProcess(NULL, application, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi))
{
return 1;
}
GetModuleFileNameEx(pi.hProcess, NULL, application_full, 2047);
TerminateProcess(pi.hProcess, 0);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);

StringCchPrintf(surun_cmdline, 2048, CMDLINE_INVOKE_FMT,
helper_bin, GetCurrentProcessId(), application_full, commandLine);
free(helper_bin);
free(application_full);
//wprintf(L"%s\n", surun_cmdline);
if (!CreateProcess(NULL, surun_cmdline, NULL, NULL,
FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi))
{
return 1;
}

free(surun_cmdline);

StringCchPrintf(pipename, PIPENAME_LEN, PIPENAME_FMT, GetCurrentProcessId());
//wprintf(L"%s\n", pipe_name);
pipes[0][1] = CreateNamedPipe(pipename, PIPE_ACCESS_DUPLEX, 0, NUM_INSTANCES, 1, 1, 0, NULL);
pipes[1][0] = CreateNamedPipe(pipename, PIPE_ACCESS_DUPLEX, 0, NUM_INSTANCES, 1, 1, 0, NULL);
pipes[2][0] = CreateNamedPipe(pipename, PIPE_ACCESS_DUPLEX, 0, NUM_INSTANCES, 1, 1, 0, NULL);
pipes[3][0] = CreateNamedPipe(pipename, PIPE_ACCESS_DUPLEX, 0, NUM_INSTANCES, 1, 1, 0, NULL);
//DWORD pid;
//HANDLE hprocess;

ResumeThread(pi.hThread);
WaitForSingleObject(pi.hProcess, INFINITE);

GetExitCodeProcess(pi.hProcess, &exitCode);
if (exitCode)
return exitCode;

ConnectNamedPipe(pipes[0][1], NULL);
ConnectNamedPipe(pipes[1][0], NULL);
ConnectNamedPipe(pipes[2][0], NULL);
ConnectNamedPipe(pipes[3][0], NULL);

CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)RedirStdBytesThread, (LPVOID)0, 0, NULL);
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)RedirStdBytesThread, (LPVOID)1, 0, NULL);
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)RedirStdBytesThread, (LPVOID)2, 0, NULL);

ReadFile(pipes[3][0], &exitCode, sizeof(exitCode), NULL, NULL);
return exitCode;
}
157 changes: 157 additions & 0 deletions cSuRun/cSuRun.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{7953E24A-1E10-47B1-8F2B-175E21D19F7D}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>cSuRun</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="strdefs.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="cSuRun.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
27 changes: 27 additions & 0 deletions cSuRun/cSuRun.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="strdefs.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="cSuRun.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
Loading

0 comments on commit 53b4bae

Please sign in to comment.