Skip to content

Commit

Permalink
Merge pull request #1 from Regal-Internet-Brothers/Experimental
Browse files Browse the repository at this point in the history
Experimental
  • Loading branch information
Anthony Diamond authored and Anthony Diamond committed Apr 26, 2015
2 parents 4be10ed + 93c8fb9 commit 54aabe3
Show file tree
Hide file tree
Showing 15 changed files with 479 additions and 87 deletions.
2 changes: 1 addition & 1 deletion IOSync/Info.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros">
<IOSync_Version>1.0.0</IOSync_Version>
<IOSync_Version>1.0.1</IOSync_Version>
</PropertyGroup>
<PropertyGroup />
<ItemDefinitionGroup />
Expand Down
59 changes: 53 additions & 6 deletions IOSync/src/application/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,52 @@ namespace iosync
}

#ifdef PLATFORM_WINDOWS
static inline bool __winnt__startProcess(LPCTSTR applicationName, const string& commandLine=string(), DWORD flags=CREATE_NO_WINDOW)
{
// Local variable(s):
STARTUPINFO si;
PROCESS_INFORMATION pi;

// Set the size of the structures:
ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));

si.cb = sizeof(si);

CHAR cmd[MAX_PATH];

memcpy(cmd, commandLine.c_str(), min(commandLine.size(), MAX_PATH));
cmd[commandLine.length()] = '\0';

// Start the specified program:
if
(
CreateProcess
(
applicationName,
(LPSTR)cmd,
NULL,
NULL,
FALSE,
flags,
NULL,
NULL,
&si,
&pi
) == FALSE
)
{
return false;
}

// Close the process and thread handles:
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);

// Return the default response.
return true;
}

// This command will inject the library specified into the process with the PID specified by 'processID'.
// The return-value of this command indicates if injection was successful.
static inline bool __winnt__injectLibrary(string library, DWORD processID)
Expand All @@ -158,6 +204,7 @@ namespace iosync
//cout << "Directory: " << buffer << endl;

SIZE_T strLength = (SIZE_T)strlen(buffer);
//buffer[strLength] = '\0';

// Open the remote process with specific rights.
remoteProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID);
Expand All @@ -169,24 +216,24 @@ namespace iosync
LoadLibraryAddr = (LPVOID)GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA");

// Allocate a buffer using the remote process.
remoteLibraryName = (LPVOID)VirtualAllocEx(remoteProc, NULL, strLength, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
remoteLibraryName = (LPVOID)VirtualAllocEx(remoteProc, NULL, strLength, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); // strLength+1

// Write the 'library' string to the newly allocated portion of memory.
BOOL test = WriteProcessMemory(remoteProc, remoteLibraryName, buffer, strLength, NULL); // library.c_str()
BOOL test = WriteProcessMemory(remoteProc, remoteLibraryName, buffer, strLength, NULL); // strLength+1

// Create a remote thread that will immediately load the library specified into the remote process.
HANDLE h = CreateRemoteThread(remoteProc, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibraryAddr, remoteLibraryName, NULL, NULL);

// Close the handle to the remote process.
CloseHandle(remoteProc);

// Close our local handle to the remote thread.
CloseHandle(h);

// Close the handle to the remote process.
CloseHandle(remoteProc);

// Free the memory we allocated.
VirtualFreeEx(remoteProc, remoteLibraryName, 0, MEM_RELEASE | MEM_DECOMMIT);

delete buffer;
delete[] buffer;

// Return the default response.
return true;
Expand Down
21 changes: 19 additions & 2 deletions IOSync/src/devices/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,33 @@ namespace iosync
#ifdef PLATFORM_WINDOWS
bool gamepad::__winnt__injectLibrary(DWORD processID, CPUArchitecture process_Architecture)
{
// Nested functions/lambdas:
auto injectionStr = [&]() -> string
{
stringstream injectionStream;
injectionStream << "IGNORE " << XINPUT_INJECTION_ARGUMENT << " " << processID;

return injectionStream.str();
};

if (processID == 0)
return false;

switch (process_Architecture)
{
#if defined(PLATFORM_X86) || defined(PLATFORM_X64)
case x86:
return application::__winnt__injectLibrary(INJECTION_DLL_NAME_X86, processID);
#if defined(PLATFORM_X86)
return application::__winnt__injectLibrary(INJECTION_DLL_NAME_X86, processID);
#else
return application::__winnt__startProcess(TEXT("IOSync_x86.exe"), injectionStr());
#endif
case x64:
return application::__winnt__injectLibrary(INJECTION_DLL_NAME_X64, processID);
#if defined(PLATFORM_X64)
return application::__winnt__injectLibrary(INJECTION_DLL_NAME_X64, processID);
#else
return application::__winnt__startProcess(TEXT("IOSync_x64.exe"), injectionStr());
#endif
#elif defined(PLATFORM_ARM) || defined(PLATFORM_ARM64)
case ARM:
return application::__winnt__injectLibrary(INJECTION_DLL_NAME_ARM, processID);
Expand Down
3 changes: 3 additions & 0 deletions IOSync/src/devices/gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ namespace iosync
static const size_t serializedNativeGamepadSize = sizeof(nativeGamepad); // sizeof(nativeGamepad);

#ifdef PLATFORM_WINDOWS
const string XINPUT_INJECTION_ARGUMENT = "XI_INJECT";
const wstring XINPUT_INJECTION_ARGUMENTW = L"XI_INJECT";

static LPCTSTR SHARED_GAMEPAD_MEMORY_NAME = "IOSYNC_GAMEPAD_BUFFER";

static const size_t SHARED_SIZEOF_PLUGGED_IN_SEGMENT = (sizeof(bool)*MAX_GAMEPADS);
Expand Down
Loading

0 comments on commit 54aabe3

Please sign in to comment.