Merge pull request #54 from x64dbg/emulator-improvements

Emulator improvements
This commit is contained in:
Matthijs Lavrijsen 2020-10-10 01:34:07 +02:00 committed by GitHub
commit 2d92c9f236
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 1 deletions

42
GleeBug/stringutils.cpp Normal file
View File

@ -0,0 +1,42 @@
#include "stringutils.h"
#include <Windows.h>
#include <iostream>
#include <sstream>
// Functions from x64dbg project: https://github.com/x64dbg/x64dbg
//Conversion functions taken from: http://www.nubaria.com/en/blog/?p=289
String Utf16ToUtf8(const WString & wstr)
{
String convertedString;
int requiredSize = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, 0, 0, 0, 0);
if(requiredSize > 0)
{
std::vector<char> buffer(requiredSize);
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &buffer[0], requiredSize, 0, 0);
convertedString.assign(buffer.begin(), buffer.end() - 1);
}
return convertedString;
}
String Utf16ToUtf8(const wchar_t* wstr)
{
return Utf16ToUtf8(wstr ? WString(wstr) : WString());
}
WString Utf8ToUtf16(const String & str)
{
WString convertedString;
int requiredSize = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, 0, 0);
if(requiredSize > 0)
{
std::vector<wchar_t> buffer(requiredSize);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &buffer[0], requiredSize);
convertedString.assign(buffer.begin(), buffer.end() - 1);
}
return convertedString;
}
WString Utf8ToUtf16(const char* str)
{
return Utf8ToUtf16(str ? String(str) : String());
}

16
GleeBug/stringutils.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef _STRINGUTILS_H
#define _STRINGUTILS_H
#include <string>
#include <vector>
typedef std::string String;
typedef std::wstring WString;
String Utf16ToUtf8(const WString & wstr);
String Utf16ToUtf8(const wchar_t* wstr);
WString Utf8ToUtf16(const String & str);
WString Utf8ToUtf16(const char* str);
#endif //_STRINGUTILS_H

View File

@ -520,7 +520,10 @@ public:
__debugbreak(); //return 0;
if (!found->second.pe->IsValidPe())
__debugbreak(); //return 0;
return found->second.pe->ConvertRvaToOffset(uint32(AddressToConvert));
auto offset = found->second.pe->ConvertRvaToOffset(uint32(AddressToConvert));
if (offset == INVALID_VALUE)
return 0;
return ReturnType ? FileMapVA + offset : offset;
}
template<typename T>