1211
This commit is contained in:
113
test/DNFTOOL.cpp
113
test/DNFTOOL.cpp
@@ -48,6 +48,11 @@ int DNFTOOL::GetHook(int Addr, std::string
|
||||
{
|
||||
for (int z = 0; z < i; z++)
|
||||
{
|
||||
if (num <= 0 && z != i - 1)//可能读取发生了错误
|
||||
{
|
||||
num = 0;
|
||||
return num;
|
||||
}
|
||||
if (z == i - 1)
|
||||
{
|
||||
if (Type == 0)return *(int*)(num + GetHookArr[z]);
|
||||
@@ -233,6 +238,37 @@ int DNFTOOL::GetEquAddr(int addr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
char* DNFTOOL::U8ToUnicode(const char* szU8)
|
||||
{
|
||||
//UTF8 to Unicode
|
||||
//预转换,得到所需空间的大小
|
||||
int wcsLen = ::MultiByteToWideChar(CP_UTF8, NULL, szU8, strlen(szU8), NULL, 0);
|
||||
//分配空间要给'\0'留个空间,MultiByteToWideChar不会给'\0'空间
|
||||
wchar_t* wszString = new wchar_t[wcsLen + 1];
|
||||
//转换
|
||||
::MultiByteToWideChar(CP_UTF8, NULL, szU8, strlen(szU8), wszString, wcsLen);
|
||||
//最后加上'\0'
|
||||
wszString[wcsLen] = '\0';
|
||||
|
||||
char* m_char;
|
||||
int len = WideCharToMultiByte(CP_ACP, 0, wszString, wcslen(wszString), NULL, 0, NULL, NULL);
|
||||
m_char = new char[len + 1];
|
||||
WideCharToMultiByte(CP_ACP, 0, wszString, wcslen(wszString), m_char, len, NULL, NULL);
|
||||
delete []wszString;
|
||||
m_char[len] = '\0';
|
||||
return m_char;
|
||||
}
|
||||
|
||||
char* DNFTOOL::UnicodeToUtf8(const wchar_t* unicode)
|
||||
{
|
||||
int len;
|
||||
len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, NULL, 0, NULL, NULL);
|
||||
char* szUtf8 = (char*)malloc(len + 1);
|
||||
memset(szUtf8, 0, len + 1);
|
||||
WideCharToMultiByte(CP_UTF8, 0, unicode, -1, szUtf8, len, NULL, NULL);
|
||||
return szUtf8;
|
||||
}
|
||||
|
||||
char* DNFTOOL::UnicodeToAnsi(const wchar_t* szStr, char* pResult, int maxLen)
|
||||
{
|
||||
if (NULL == pResult)
|
||||
@@ -305,10 +341,35 @@ wchar_t* DNFTOOL::SquirrelW2W(const wchar_t* Str)
|
||||
}
|
||||
cbuffer[len / 2] = '\0';
|
||||
wchar_t* str = DNFTOOL::char2wchar(cbuffer);
|
||||
delete cbuffer;
|
||||
delete []cbuffer;
|
||||
return str;
|
||||
}
|
||||
|
||||
char* DNFTOOL::SquirrelU2W(const wchar_t* Str)
|
||||
{
|
||||
size_t len = 0;
|
||||
char* wbuffer = (char*)(Str);
|
||||
while (true)
|
||||
{
|
||||
if (wbuffer[len] == 0 && wbuffer[len - 1] == 0)break;
|
||||
++len;
|
||||
}
|
||||
char* cbuffer = new char[len / 2 + 1];
|
||||
int k = 0;
|
||||
for (size_t i = 0; i < len; i++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
cbuffer[k] = wbuffer[i];
|
||||
++k;
|
||||
}
|
||||
}
|
||||
cbuffer[len / 2] = '\0';
|
||||
char* Text = U8ToUnicode(cbuffer);
|
||||
delete []cbuffer;
|
||||
return Text;
|
||||
}
|
||||
|
||||
wchar_t* DNFTOOL::AnsiToUnicode(const char* szStr, wchar_t* pResult, int maxLen)
|
||||
{
|
||||
if (NULL == pResult)
|
||||
@@ -349,12 +410,12 @@ void DNFTOOL::GMNotice(char* str, int type, int color)
|
||||
#if defined LOCALHOSTS_SWITCH
|
||||
|
||||
#else
|
||||
std::string DNFTOOL::GetIP()
|
||||
std::string BAKIP()
|
||||
{
|
||||
//std::cout << "获取Ip" << std::endl;
|
||||
httplib::SSLClient Tencword("yosin-team.coding.net");
|
||||
httplib::SSLClient Tencword("gitee.com");
|
||||
std::string body;
|
||||
auto res = Tencword.Get("/p/huoqushuju/d/GetIp/git/raw/master/ip.txt?download=false",
|
||||
auto res = Tencword.Get("/yosin_team/request-ip/raw/master/README.md",
|
||||
[&](const char* data, size_t data_length) {
|
||||
body.append(data, data_length);
|
||||
return true;
|
||||
@@ -364,10 +425,36 @@ std::string DNFTOOL::GetIP()
|
||||
return body;
|
||||
}
|
||||
else
|
||||
return GetIP();
|
||||
return DNFTOOL::GetIP();
|
||||
}
|
||||
std::string DNFTOOL::GetIP()
|
||||
{
|
||||
//std::cout << "获取Ip" << std::endl;
|
||||
httplib::SSLClient Tencword("raw.codehub.cn");
|
||||
std::string body;
|
||||
auto res = Tencword.Get("/p/huoqushuju/d/GetIp/git/raw/master/ip.txt?token=9iylYXiVKiGH3OK2szhpCK1hbvKI7e98Q1JuKpSu4r",
|
||||
[&](const char* data, size_t data_length) {
|
||||
body.append(data, data_length);
|
||||
return true;
|
||||
});
|
||||
if (!body.empty())
|
||||
{
|
||||
return body;
|
||||
}
|
||||
else
|
||||
return BAKIP();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
DWORD DNFTOOL::Motify_memory_attributes(int address, DWORD attributes)
|
||||
{
|
||||
DWORD Old_attributes;
|
||||
VirtualProtect(reinterpret_cast<void*>(address), Byte_Length, attributes, &Old_attributes);
|
||||
return Old_attributes;
|
||||
}
|
||||
|
||||
|
||||
void DNFTOOL::Wchar_tToString(std::string& szDst, wchar_t* wchar)
|
||||
{
|
||||
wchar_t* wText = wchar;
|
||||
@@ -389,6 +476,20 @@ const wchar_t* DNFTOOL::GetWC(const char* c)
|
||||
return wc;
|
||||
}
|
||||
|
||||
std::string DNFTOOL::UtfToGbk(const char* utf8)
|
||||
{
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
|
||||
wchar_t* wstr = new wchar_t[len + 1];
|
||||
memset(wstr, 0, len + 1);
|
||||
MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, len);
|
||||
len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
|
||||
char* str = new char[len + 1];
|
||||
memset(str, 0, len + 1);
|
||||
WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL);
|
||||
if (wstr) delete[] wstr;
|
||||
return str;
|
||||
}
|
||||
|
||||
void DNFTOOL::Split(const std::string& src, std::vector<std::string>& dest, const std::string& separator)
|
||||
{
|
||||
std::string str = src;
|
||||
@@ -415,7 +516,7 @@ void DNFTOOL::Split(const std::string& src, std::vector<std::string>& dest, cons
|
||||
|
||||
bool DNFTOOL::isNum(std::string str)
|
||||
{
|
||||
for (int i = 0; i < str.size(); i++)
|
||||
for (unsigned int i = 0; i < str.size(); i++)
|
||||
{
|
||||
int tmp = (int)str[i];
|
||||
if (tmp >= 48 && tmp <= 57)
|
||||
|
||||
Reference in New Issue
Block a user