summaryrefslogtreecommitdiff
path: root/wrappers
diff options
context:
space:
mode:
Diffstat (limited to 'wrappers')
-rw-r--r--wrappers/dlltrace.hpp69
-rw-r--r--wrappers/dlltrace.py24
2 files changed, 73 insertions, 20 deletions
diff --git a/wrappers/dlltrace.hpp b/wrappers/dlltrace.hpp
new file mode 100644
index 00000000..fd8aca60
--- /dev/null
+++ b/wrappers/dlltrace.hpp
@@ -0,0 +1,69 @@
+/**************************************************************************
+ *
+ * Copyright 2016 VMware, Inc
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#pragma once
+
+
+#include <windows.h>
+#include <string>
+
+
+class Module
+{
+ const char *m_szName;
+ HMODULE m_hModule = nullptr;
+public:
+ Module(const char *szName) :
+ m_szName(szName)
+ {
+ }
+
+ ~Module()
+ {
+ if (m_hModule) {
+ FreeLibrary(m_hModule);
+ }
+ }
+
+ PROC
+ getProcAddress(LPCSTR lpProcName)
+ {
+ if (!m_hModule) {
+ char szSystemDir[MAX_PATH] = {0};
+ if (!GetSystemDirectoryA(szSystemDir, MAX_PATH)) {
+ return nullptr;
+ }
+ std::string sDllPath = szSystemDir;
+ sDllPath += "\\";
+ sDllPath += m_szName;
+ sDllPath += ".dll";
+ m_hModule = LoadLibraryA(sDllPath.c_str());
+ if (!m_hModule) {
+ return nullptr;
+ }
+ }
+ return GetProcAddress(m_hModule, lpProcName);
+ }
+};
diff --git a/wrappers/dlltrace.py b/wrappers/dlltrace.py
index 26962216..442ea0e4 100644
--- a/wrappers/dlltrace.py
+++ b/wrappers/dlltrace.py
@@ -36,35 +36,19 @@ from specs.stdapi import API
class DllDispatcher(Dispatcher):
def dispatchModule(self, module):
- tag = module.name.upper()
- print r'HMODULE g_h%sModule = NULL;' % (tag,)
- print r''
- print r'static PROC'
- print r'_get%sProcAddress(LPCSTR lpProcName) {' % tag
- print r' if (!g_h%sModule) {' % tag
- print r' char szDll[MAX_PATH] = {0};'
- print r' if (!GetSystemDirectoryA(szDll, MAX_PATH)) {'
- print r' return NULL;'
- print r' }'
- print r' strcat(szDll, "\\%s.dll");' % module.name
- print r' g_h%sModule = LoadLibraryA(szDll);' % tag
- print r' if (!g_h%sModule) {' % tag
- print r' return NULL;'
- print r' }'
- print r' }'
- print r' return GetProcAddress(g_h%sModule, lpProcName);' % tag
- print r'}'
- print r''
+ print r'Module g_mod%s("%s");' % (module.name.upper(), module.name)
Dispatcher.dispatchModule(self, module)
def getProcAddressName(self, module, function):
- return '_get%sProcAddress' % (module.name.upper())
+ return r'g_mod%s.getProcAddress' % (module.name.upper(),)
class DllTracer(Tracer):
def header(self, api):
+ print r'#include "dlltrace.hpp"'
+ print
for module in api.modules:
dispatcher = DllDispatcher()