summaryrefslogtreecommitdiff
path: root/inject
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2015-07-06 16:16:13 +0100
committerJose Fonseca <jfonseca@vmware.com>2015-07-06 19:02:20 +0100
commit0eb4fe7a47b3f0f6b528ef0863a8348123b0d9c0 (patch)
tree03e9d92010d74dd180e39a3d849ab6d6de6ceaf6 /inject
parent127cc41e89790a7916fc7343f4260f0670b4f5b1 (diff)
inject: Eliminate SetSharedMem/GetSharedMem.
They stand in the way of adding more things to SharedMem struct.
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;