本帖最后由 solly 于 2024-3-9 22:16 编辑
是这样的吧,VS2019编译的x86模式:
[C++] 纯文本查看 复制代码 // crackme_mulng.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include <fstream>
#include <string>
#include <codecvt>
#include <Windows.h>
using namespace std;
class GetFiles {
public:
string engFile = "G:\\MyProjects\\vs2019\\crackme_mulng\\Debug\\english.txt";
wstring chnFile = L"G:\\MyProjects\\vs2019\\crackme_mulng\\Debug\\中文.txt";
wstring arbFile = L"G:\\MyProjects\\vs2019\\crackme_mulng\\Debug\\عرب ..txt";
//string arbFile = "G:\\MyProjects\\vs2019\\crackme_mulng\\Debug\\arabic.txt";
void crackme1(const char * fileName);
void crackme2(const WCHAR * fileName);
void crackme3(const WCHAR * fileName);
};
#define MAX_SIZE 256
int main(int argc, char * argv[])
{
std::cout << "Hello World!\n";
GetFiles get1;
OutputDebugStringW(L"\n");
get1.crackme1(get1.engFile.c_str());
get1.crackme2(get1.chnFile.c_str());
get1.crackme3(get1.arbFile.c_str());
OutputDebugStringW(L"\n");
OutputDebugStringW(L"\n");
}
void GetFiles::crackme1(const char * fileName) {
char buff[MAX_SIZE];
locale english("English");
ifstream ifs1(fileName, ios::in);
if (ifs1.good()) {
ifs1.imbue(english);
streambuf* pbuf = ifs1.rdbuf();
streamsize size = pbuf->pubseekoff(0, ifs1.end);
pbuf->pubseekoff(0, ifs1.beg);
size = (size >= MAX_SIZE) ? (MAX_SIZE - 1) : size;
streamsize n = pbuf->sgetn(buff, size);
buff[n] = '\0';
ifs1.close();
//cout << buff << std::endl;
OutputDebugStringA("\n");
OutputDebugStringA("English = ");
OutputDebugStringA(buff);
OutputDebugStringA("\n");
} else {
OutputDebugString(L"\n文件不存在!!!!!\n\n");
}
}
void GetFiles::crackme2(const WCHAR * fileName) {
WCHAR buff[MAX_SIZE];
//wstring buff;
locale china("zh_CN.UTF-8");
wifstream ifs2(fileName, ios::in);
if (ifs2.good()) {
ifs2.imbue(china);
wstreambuf* pbuf = ifs2.rdbuf();
streamsize size = pbuf->pubseekoff(0, ifs2.end);
pbuf->pubseekoff(0, ifs2.beg);
size = (size >= MAX_SIZE) ? (MAX_SIZE - 1) : size;
streamsize n = pbuf->sgetn(buff, size);
buff[n] = '\0';
ifs2.close();
//wcout << buff << std::endl;
OutputDebugStringW(L"\n");
OutputDebugStringW(L"中文 = ");
OutputDebugStringW(buff);
OutputDebugStringW(L"\n");
}
else {
OutputDebugString(L"\n文件不存在!!!!!\n\n");
}
}
void GetFiles::crackme3(const WCHAR * fileName) {
WCHAR buff[MAX_SIZE];
std::codecvt_utf16<wchar_t, 0x10ffff, std::little_endian>* codecvtToUnicode = new std::codecvt_utf16 < wchar_t, 0x10ffff, std::little_endian >;
//locale arab("Arabic");
wifstream ifs3(fileName, ios::binary); //// العربية
//wifstream ifs3(fileName, ios::in); //// العربية
if (ifs3.good()) {
//ifs3.imbue(arab);
ifs3.imbue(locale(ifs3.getloc(), codecvtToUnicode));
wstreambuf* pbuf = ifs3.rdbuf();
streamsize size = pbuf->pubseekoff(0, ifs3.end);
pbuf->pubseekoff(0, ifs3.beg);
size = (size >= MAX_SIZE) ? (MAX_SIZE - 1) : size;
streamsize n = pbuf->sgetn(buff, size);
buff[n] = L'\0';
ifs3.close();
//wcout.imbue(arab);
//wcout << L"العربية = " << buff << std::endl;
OutputDebugStringW(L"\n");
OutputDebugStringW(L"العربية = ");
OutputDebugStringW(buff);
OutputDebugStringW(L"\n");
}
else {
OutputDebugString(L"\n文件不存在!!!!!\n\n");
}
}
上面代码中的阿拉伯文全部html转码了,看效果图吧:
文件名:
|