#include <windows.h>
#include <winternl.h>
#include <cstdio>
// https://www.dllhook.com
std::wstring ConvertAnsiToUnicode(const std::string& ansiStr)
{
ANSI_STRING ansiString;
RtlInitAnsiString(&ansiString, ansiStr.c_str());
UNICODE_STRING unicodeString;
RtlAnsiStringToUnicodeString(&unicodeString, &ansiString, TRUE);
const size_t bufferLength = unicodeString.MaximumLength;
std::unique_ptr<wchar_t[]> buffer(new wchar_t[bufferLength]);
unicodeString.Buffer = buffer.get();
unicodeString.Length = 0;
unicodeString.MaximumLength = static_cast<USHORT>(bufferLength);
RtlAnsiStringToUnicodeString(&unicodeString, &ansiString, FALSE);
const std::wstring result(unicodeString.Buffer, unicodeString.Length / sizeof(wchar_t));
return result;
}
std::string ConvertUnicodeToAnsi(const std::wstring& unicodeStr)
{
ANSI_STRING ansiString;
RtlInitAnsiString(&ansiString, NULL);
UNICODE_STRING unicodeString;
RtlInitUnicodeString(&unicodeString, unicodeStr.c_str());
RtlUnicodeStringToAnsiString(&ansiString, &unicodeString, TRUE);
std::string str(ansiString.Buffer, ansiString.Length);
RtlFreeAnsiString(&ansiString);
return str;
}
已有1220位网友发表了看法:
发表评论