summaryrefslogtreecommitdiff
path: root/inject
diff options
context:
space:
mode:
Diffstat (limited to 'inject')
-rw-r--r--inject/inject.h34
-rw-r--r--inject/injectee.cpp10
-rw-r--r--inject/injector.cpp9
3 files changed, 17 insertions, 36 deletions
diff --git a/inject/inject.h b/inject/inject.h
index 749f47c0..e72dfeca 100644
--- a/inject/inject.h
+++ b/inject/inject.h
@@ -210,40 +210,6 @@ CloseSharedMem(void) {
}
-static inline VOID
-SetSharedMem(LPCSTR lpszSrc) {
- SharedMem *pSharedMem = OpenSharedMemory();
- if (!pSharedMem) {
- return;
- }
-
- LPSTR lpszDst = pSharedMem->szDllName;
-
- size_t n = 1;
- while (*lpszSrc && n < sizeof pSharedMem->szDllName) {
- *lpszDst++ = *lpszSrc++;
- n++;
- }
- *lpszDst = '\0';
-}
-
-
-static inline VOID
-GetSharedMem(LPSTR lpszDst, size_t n) {
- SharedMem *pSharedMem = OpenSharedMemory();
- if (!pSharedMem) {
- return;
- }
-
- LPCSTR lpszSrc = pSharedMem->szDllName;
-
- while (*lpszSrc && --n) {
- *lpszDst++ = *lpszSrc++;
- }
- *lpszDst = '\0';
-}
-
-
static BOOL
injectDll(HANDLE hProcess, const char *szDllPath)
{
diff --git a/inject/injectee.cpp b/inject/injectee.cpp
index af60c8b0..42d152e2 100644
--- a/inject/injectee.cpp
+++ b/inject/injectee.cpp
@@ -1031,8 +1031,16 @@ DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
return FALSE;
}
} else {
+ SharedMem *pSharedMem = OpenSharedMemory();
+ if (!pSharedMem) {
+ debugPrintf("inject: error: failed to open shared memory\n");
+ return FALSE;
+ }
+
static char szSharedMemCopy[MAX_PATH];
- GetSharedMem(szSharedMemCopy, sizeof szSharedMemCopy);
+ strncpy(szSharedMemCopy, pSharedMem->szDllName, _countof(szSharedMemCopy) - 1);
+ szSharedMemCopy[_countof(szSharedMemCopy) - 1] = '\0';
+
szNewDllName = szSharedMemCopy;
}
diff --git a/inject/injector.cpp b/inject/injector.cpp
index 7bb3a7d6..76edda1d 100644
--- a/inject/injector.cpp
+++ b/inject/injector.cpp
@@ -547,7 +547,14 @@ main(int argc, char *argv[])
return 1;
}
- SetSharedMem(szDll);
+ SharedMem *pSharedMem = OpenSharedMemory();
+ if (!pSharedMem) {
+ debugPrintf("error: failed to open shared memory\n");
+ return 1;
+ }
+
+ strncpy(pSharedMem->szDllName, szDll, _countof(pSharedMem->szDllName) - 1);
+ pSharedMem->szDllName[_countof(pSharedMem->szDllName) - 1] = '\0';
}
BOOL bAttachDwm = FALSE;