Skip to content

Commit 54aabe3

Browse files
Anthony DiamondAnthony Diamond
authored andcommitted
Merge pull request #1 from Regal-Internet-Brothers/Experimental
Experimental
2 parents 4be10ed + 93c8fb9 commit 54aabe3

File tree

15 files changed

+479
-87
lines changed

15 files changed

+479
-87
lines changed

IOSync/Info.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ImportGroup Label="PropertySheets" />
44
<PropertyGroup Label="UserMacros">
5-
<IOSync_Version>1.0.0</IOSync_Version>
5+
<IOSync_Version>1.0.1</IOSync_Version>
66
</PropertyGroup>
77
<PropertyGroup />
88
<ItemDefinitionGroup />

IOSync/src/application/application.h

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,52 @@ namespace iosync
137137
}
138138

139139
#ifdef PLATFORM_WINDOWS
140+
static inline bool __winnt__startProcess(LPCTSTR applicationName, const string& commandLine=string(), DWORD flags=CREATE_NO_WINDOW)
141+
{
142+
// Local variable(s):
143+
STARTUPINFO si;
144+
PROCESS_INFORMATION pi;
145+
146+
// Set the size of the structures:
147+
ZeroMemory(&si, sizeof(si));
148+
ZeroMemory(&pi, sizeof(pi));
149+
150+
si.cb = sizeof(si);
151+
152+
CHAR cmd[MAX_PATH];
153+
154+
memcpy(cmd, commandLine.c_str(), min(commandLine.size(), MAX_PATH));
155+
cmd[commandLine.length()] = '\0';
156+
157+
// Start the specified program:
158+
if
159+
(
160+
CreateProcess
161+
(
162+
applicationName,
163+
(LPSTR)cmd,
164+
NULL,
165+
NULL,
166+
FALSE,
167+
flags,
168+
NULL,
169+
NULL,
170+
&si,
171+
&pi
172+
) == FALSE
173+
)
174+
{
175+
return false;
176+
}
177+
178+
// Close the process and thread handles:
179+
CloseHandle(pi.hProcess);
180+
CloseHandle(pi.hThread);
181+
182+
// Return the default response.
183+
return true;
184+
}
185+
140186
// This command will inject the library specified into the process with the PID specified by 'processID'.
141187
// The return-value of this command indicates if injection was successful.
142188
static inline bool __winnt__injectLibrary(string library, DWORD processID)
@@ -158,6 +204,7 @@ namespace iosync
158204
//cout << "Directory: " << buffer << endl;
159205

160206
SIZE_T strLength = (SIZE_T)strlen(buffer);
207+
//buffer[strLength] = '\0';
161208

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

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

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

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

180-
// Close the handle to the remote process.
181-
CloseHandle(remoteProc);
182-
183227
// Close our local handle to the remote thread.
184228
CloseHandle(h);
185229

230+
// Close the handle to the remote process.
231+
CloseHandle(remoteProc);
232+
186233
// Free the memory we allocated.
187234
VirtualFreeEx(remoteProc, remoteLibraryName, 0, MEM_RELEASE | MEM_DECOMMIT);
188235

189-
delete buffer;
236+
delete[] buffer;
190237

191238
// Return the default response.
192239
return true;

IOSync/src/devices/gamepad.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,33 @@ namespace iosync
120120
#ifdef PLATFORM_WINDOWS
121121
bool gamepad::__winnt__injectLibrary(DWORD processID, CPUArchitecture process_Architecture)
122122
{
123+
// Nested functions/lambdas:
124+
auto injectionStr = [&]() -> string
125+
{
126+
stringstream injectionStream;
127+
injectionStream << "IGNORE " << XINPUT_INJECTION_ARGUMENT << " " << processID;
128+
129+
return injectionStream.str();
130+
};
131+
123132
if (processID == 0)
124133
return false;
125134

126135
switch (process_Architecture)
127136
{
128137
#if defined(PLATFORM_X86) || defined(PLATFORM_X64)
129138
case x86:
130-
return application::__winnt__injectLibrary(INJECTION_DLL_NAME_X86, processID);
139+
#if defined(PLATFORM_X86)
140+
return application::__winnt__injectLibrary(INJECTION_DLL_NAME_X86, processID);
141+
#else
142+
return application::__winnt__startProcess(TEXT("IOSync_x86.exe"), injectionStr());
143+
#endif
131144
case x64:
132-
return application::__winnt__injectLibrary(INJECTION_DLL_NAME_X64, processID);
145+
#if defined(PLATFORM_X64)
146+
return application::__winnt__injectLibrary(INJECTION_DLL_NAME_X64, processID);
147+
#else
148+
return application::__winnt__startProcess(TEXT("IOSync_x64.exe"), injectionStr());
149+
#endif
133150
#elif defined(PLATFORM_ARM) || defined(PLATFORM_ARM64)
134151
case ARM:
135152
return application::__winnt__injectLibrary(INJECTION_DLL_NAME_ARM, processID);

IOSync/src/devices/gamepad.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ namespace iosync
112112
static const size_t serializedNativeGamepadSize = sizeof(nativeGamepad); // sizeof(nativeGamepad);
113113

114114
#ifdef PLATFORM_WINDOWS
115+
const string XINPUT_INJECTION_ARGUMENT = "XI_INJECT";
116+
const wstring XINPUT_INJECTION_ARGUMENTW = L"XI_INJECT";
117+
115118
static LPCTSTR SHARED_GAMEPAD_MEMORY_NAME = "IOSYNC_GAMEPAD_BUFFER";
116119

117120
static const size_t SHARED_SIZEOF_PLUGGED_IN_SEGMENT = (sizeof(bool)*MAX_GAMEPADS);

0 commit comments

Comments
 (0)