diff options
| author | Tannin <devnull@localhost> | 2015-01-24 19:34:12 +0100 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2015-01-24 19:34:12 +0100 |
| commit | c3a95bdef1d989a54684b966e042b12bf682046d (patch) | |
| tree | 83a09ca9252b9d5a060acb415b8c3c0923cfe2c3 /src/shared | |
| parent | 9edc39633b82b5e02d33c4b0a395fe110af28eb4 (diff) | |
| parent | f756aede08edb315ebe5882098191ebfe971fd81 (diff) | |
Merge with branch1.2
Diffstat (limited to 'src/shared')
| -rw-r--r-- | src/shared/directoryentry.cpp | 11 | ||||
| -rw-r--r-- | src/shared/directoryentry.h | 5 | ||||
| -rw-r--r-- | src/shared/inject.cpp | 5 | ||||
| -rw-r--r-- | src/shared/stackdata.cpp | 8 | ||||
| -rw-r--r-- | src/shared/util.cpp | 68 | ||||
| -rw-r--r-- | src/shared/util.h | 7 |
6 files changed, 16 insertions, 88 deletions
diff --git a/src/shared/directoryentry.cpp b/src/shared/directoryentry.cpp index 7f7a01f5..5cf75752 100644 --- a/src/shared/directoryentry.cpp +++ b/src/shared/directoryentry.cpp @@ -24,23 +24,18 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <ctime>
#include <algorithm>
#include <bsatk.h>
-#include "error_report.h"
-#include "util.h"
#include "windows_error.h"
#include <boost/bind.hpp>
#include <boost/scoped_array.hpp>
#include <boost/foreach.hpp>
-#include "util.h"
#include "leaktrace.h"
-
#include <map>
+#include "error_report.h"
namespace MOShared {
-
-static int s_Count = 0;
-
+static const int MAXPATH_UNICODE = 32767;
class OriginConnection {
@@ -155,7 +150,7 @@ void FilesOrigin::removeFile(FileEntry::Index index) -std::wstring tail(const std::wstring &source, const size_t count)
+static std::wstring tail(const std::wstring &source, const size_t count)
{
if (count >= source.length()) {
return source;
diff --git a/src/shared/directoryentry.h b/src/shared/directoryentry.h index 4333c1eb..0075d5e5 100644 --- a/src/shared/directoryentry.h +++ b/src/shared/directoryentry.h @@ -36,11 +36,6 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "util.h"
-
-#include "error_report.h"
-
-
-
namespace MOShared {
diff --git a/src/shared/inject.cpp b/src/shared/inject.cpp index 143652c2..36db7840 100644 --- a/src/shared/inject.cpp +++ b/src/shared/inject.cpp @@ -93,7 +93,7 @@ void injectDLL(HANDLE processHandle, HANDLE threadHandle, const std::string &dll 0x68, 0xBA, 0xAD, 0xF0, 0x0D, // PUSH imm32 ("Init")
0x50, // PUSH EAX
0xB8, 0xBA, 0xAD, 0xF0, 0x0D, // MOVE EAX, imm32 (GetProcAddress)
- 0xFF, 0xD0, // CALL EAX (GetProcAddress)
+ 0xFF, 0xD0, // CALL EAX (=GetProcAddress, leaves address of init function in eax)
0x68, 0xBA, 0xAD, 0xF0, 0x0D, // PUSH imm32 (profile name)
0x68, 0xBA, 0xAD, 0xF0, 0x0D, // PUSH imm32 (log level)
0xFF, 0xD0, // CALL EAX (=InitFunction)
@@ -109,9 +109,6 @@ void injectDLL(HANDLE processHandle, HANDLE threadHandle, const std::string &dll throw windows_error("failed to allocate memory for stub");
}
TParameters *remoteParams = reinterpret_cast<TParameters*>(remoteMem);
- // determine the remote addresses of each of the parameters
-// ULONG remoteDLLName = reinterpret_cast<ULONG>(remoteMem);
-// ULONG remoteInitString = remoteDLLName + MAX_PATH * sizeof(char);
// dizzy yet? we still have to calculate the entry point as an address relative to our stub
ULONG entryPoint = 0;
diff --git a/src/shared/stackdata.cpp b/src/shared/stackdata.cpp index 39e69569..2f8bfc4e 100644 --- a/src/shared/stackdata.cpp +++ b/src/shared/stackdata.cpp @@ -5,12 +5,14 @@ #include <sstream>
#include <TlHelp32.h>
#include <set>
+#include "error_report.h"
+#include <boost/predef.h>
using namespace MOShared;
-void initDbgIfNecess()
+static void initDbgIfNecess()
{
HANDLE process = ::GetCurrentProcess();
static std::set<DWORD> initialized;
@@ -88,8 +90,7 @@ void StackData::load_modules(HANDLE process, DWORD processID) { CloseHandle(snap);
}
-#include "error_report.h"
-#include <boost/predef.h>
+#pragma warning( disable : 4748 )
void StackData::initTrace() {
load_modules(::GetCurrentProcess(), ::GetCurrentProcessId());
@@ -134,6 +135,7 @@ void StackData::initTrace() { }
}
+#pragma warning( enable : 4748 )
bool MOShared::operator==(const StackData &LHS, const StackData &RHS) {
if (LHS.m_Count != RHS.m_Count) {
diff --git a/src/shared/util.cpp b/src/shared/util.cpp index 8f64277f..ceed3a34 100644 --- a/src/shared/util.cpp +++ b/src/shared/util.cpp @@ -32,28 +32,16 @@ namespace MOShared { bool FileExists(const std::string &filename)
{
- WIN32_FIND_DATAA findData;
- ZeroMemory(&findData, sizeof(WIN32_FIND_DATAA));
- HANDLE search = ::FindFirstFileExA(filename.c_str(), FindExInfoStandard, &findData, FindExSearchNameMatch, nullptr, 0);
- if (search == INVALID_HANDLE_VALUE) {
- return false;
- } else {
- FindClose(search);
- return true;
- }
+ DWORD dwAttrib = ::GetFileAttributesA(filename.c_str());
+
+ return (dwAttrib != INVALID_FILE_ATTRIBUTES);
}
bool FileExists(const std::wstring &filename)
{
- WIN32_FIND_DATAW findData;
- ZeroMemory(&findData, sizeof(WIN32_FIND_DATAW));
- HANDLE search = ::FindFirstFileExW(filename.c_str(), FindExInfoStandard, &findData, FindExSearchNameMatch, nullptr, 0);
- if (search == INVALID_HANDLE_VALUE) {
- return false;
- } else {
- FindClose(search);
- return true;
- }
+ DWORD dwAttrib = ::GetFileAttributesW(filename.c_str());
+
+ return (dwAttrib != INVALID_FILE_ATTRIBUTES);
}
bool FileExists(const std::wstring &searchPath, const std::wstring &filename)
@@ -153,48 +141,4 @@ VS_FIXEDFILEINFO GetFileVersion(const std::wstring &fileName) }
-
-
-std::string GetStack()
-{
-#ifdef _DEBUG
- HANDLE process = ::GetCurrentProcess();
- static std::set<DWORD> initialized;
- if (initialized.find(::GetCurrentProcessId()) == initialized.end()) {
- static bool firstCall = true;
- if (firstCall) {
- ::SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);
- firstCall = false;
- }
- if (!::SymInitialize(process, nullptr, TRUE)) {
- log("failed to initialize symbols: %d", ::GetLastError());
- }
- initialized.insert(::GetCurrentProcessId());
- }
-
- LPVOID stack[32];
- WORD frames = ::CaptureStackBackTrace(0, 100, stack, nullptr);
-
- char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
- PSYMBOL_INFO symbol = (PSYMBOL_INFO)buffer;
- symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
- symbol->MaxNameLen = MAX_SYM_NAME;
-
- std::ostringstream stackStream;
- for(unsigned int i = 0; i < frames; ++i) {
- DWORD64 addr = (DWORD64)stack[i];
- DWORD64 displacement = 0;
- if (!::SymFromAddr(::GetCurrentProcess(), addr, &displacement, symbol)) {
- stackStream << frames - i - 1 << ": " << stack[i] << " - " << ::GetLastError() << " (error)\n";
- } else {
- stackStream << frames - i - 1 << ": " << symbol->Name << "\n";
- }
- }
- return stackStream.str();
-#else
- return "";
-#endif
-}
-
-
} // namespace MOShared
diff --git a/src/shared/util.h b/src/shared/util.h index 4af1fb1e..14017526 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -27,9 +27,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. namespace MOShared {
-
-static const int MAXPATH_UNICODE = 32767;
-
+/// Test if a file (or directory) by the specified name exists
bool FileExists(const std::string &filename);
bool FileExists(const std::wstring &filename);
@@ -46,9 +44,6 @@ std::wstring ToLower(const std::wstring &text); VS_FIXEDFILEINFO GetFileVersion(const std::wstring &fileName);
-/// Get a stack trace as a line-break separated list of function names. This only works in debug builds
-std::string GetStack();
-
} // namespace MOShared
#endif // UTIL_H
|
