2024-04-02 15:36:52 +08:00
|
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
typedef int(__stdcall *MTInitCJ)(int);
|
|
|
|
|
typedef int(__stdcall *TranTextFlowCJ)(char *src, char *dest, int, int);
|
2024-01-08 23:37:00 +08:00
|
|
|
|
}
|
2024-04-02 15:36:52 +08:00
|
|
|
|
std::string WStrToStr(wchar_t *xx, UINT uCodePage)
|
2024-01-08 23:37:00 +08:00
|
|
|
|
{
|
|
|
|
|
std::wstring wstrString = xx;
|
|
|
|
|
int lenStr = 0;
|
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
|
|
lenStr = WideCharToMultiByte(uCodePage, NULL, wstrString.c_str(), wstrString.size(), NULL, NULL, NULL, NULL);
|
2024-04-02 15:36:52 +08:00
|
|
|
|
char *buffer = new char[lenStr + 1];
|
2024-01-08 23:37:00 +08:00
|
|
|
|
WideCharToMultiByte(uCodePage, NULL, wstrString.c_str(), wstrString.size(), buffer, lenStr, NULL, NULL);
|
|
|
|
|
buffer[lenStr] = '\0';
|
|
|
|
|
|
|
|
|
|
result.append(buffer);
|
|
|
|
|
delete[] buffer;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2024-04-02 15:36:52 +08:00
|
|
|
|
#include <vector>
|
|
|
|
|
std::wstring StringToWideString(const std::string &text, UINT encoding)
|
2024-01-08 23:37:00 +08:00
|
|
|
|
{
|
|
|
|
|
std::vector<wchar_t> buffer(text.size() + 1);
|
|
|
|
|
int length = MultiByteToWideChar(encoding, 0, text.c_str(), text.size() + 1, buffer.data(), buffer.size());
|
|
|
|
|
return std::wstring(buffer.data(), length - 1);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-02 15:36:52 +08:00
|
|
|
|
int dreyewmain(int argc, wchar_t *argv[])
|
2024-01-08 23:37:00 +08:00
|
|
|
|
{
|
|
|
|
|
SetCurrentDirectory(argv[1]);
|
|
|
|
|
HMODULE h = LoadLibrary(argv[2]);
|
|
|
|
|
/*wchar_t* apiinit = argv[3];
|
|
|
|
|
wchar_t* apitrans = argv[4];*/
|
2024-04-02 15:36:52 +08:00
|
|
|
|
if (h)
|
|
|
|
|
{
|
2024-01-08 23:37:00 +08:00
|
|
|
|
|
|
|
|
|
MTInitCJ _MTInitCJ;
|
|
|
|
|
TranTextFlowCJ _TranTextFlowCJ;
|
2024-04-02 15:36:52 +08:00
|
|
|
|
if (_wtoi(argv[3]) == 3 || _wtoi(argv[3]) == 10)
|
|
|
|
|
{
|
|
|
|
|
_MTInitCJ = (MTInitCJ)GetProcAddress(h, "MTInitCJ"); // WStrToStr(apiinit, 936).c_str());
|
|
|
|
|
_TranTextFlowCJ = (TranTextFlowCJ)GetProcAddress(h, "TranTextFlowCJ"); // WStrToStr(apitrans, 936).c_str());
|
2024-01-08 23:37:00 +08:00
|
|
|
|
}
|
2024-04-02 15:36:52 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_MTInitCJ = (MTInitCJ)GetProcAddress(h, "MTInitEC"); // WStrToStr(apiinit, 936).c_str());
|
|
|
|
|
_TranTextFlowCJ = (TranTextFlowCJ)GetProcAddress(h, "TranTextFlowEC"); // WStrToStr(apitrans, 936).c_str());
|
2024-01-08 23:37:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_MTInitCJ(_wtoi(argv[3]));
|
|
|
|
|
|
2024-04-02 15:36:52 +08:00
|
|
|
|
HANDLE hPipe = CreateNamedPipe(argv[4], PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 65535, 65535, NMPWAIT_WAIT_FOREVER, 0);
|
2024-01-08 23:37:00 +08:00
|
|
|
|
SECURITY_DESCRIPTOR sd = {};
|
|
|
|
|
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
|
|
|
|
|
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
|
2024-04-02 15:36:52 +08:00
|
|
|
|
SECURITY_ATTRIBUTES allAccess = SECURITY_ATTRIBUTES{sizeof(SECURITY_ATTRIBUTES), &sd, FALSE};
|
2024-01-08 23:37:00 +08:00
|
|
|
|
SetEvent(CreateEvent(&allAccess, FALSE, FALSE, argv[5]));
|
2024-04-02 15:36:52 +08:00
|
|
|
|
if (ConnectNamedPipe(hPipe, NULL) != NULL)
|
|
|
|
|
{
|
2024-01-08 23:37:00 +08:00
|
|
|
|
DWORD len = 0;
|
|
|
|
|
}
|
2024-04-02 15:36:52 +08:00
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
char src[4096] = {0};
|
|
|
|
|
char buffer[3000] = {0};
|
2024-01-08 23:37:00 +08:00
|
|
|
|
DWORD _;
|
2024-04-02 15:36:52 +08:00
|
|
|
|
if (!ReadFile(hPipe, src, 4096, &_, NULL))
|
|
|
|
|
break;
|
|
|
|
|
|
2024-01-08 23:37:00 +08:00
|
|
|
|
_TranTextFlowCJ(src, buffer, 3000, _wtoi(argv[3]));
|
2024-04-02 15:36:52 +08:00
|
|
|
|
// MessageBoxW(0, StringToWideString(src,932).c_str(),L"", 0);
|
|
|
|
|
StringToWideString(src, 932); //?????<3F><>ȫ<EFBFBD>㲻<EFBFBD><E3B2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>仰ȥ<E4BBB0><C8A5><EFBFBD><EFBFBD>writefile<6C><65>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ȥ<EFBFBD>ˡ<EFBFBD><CBA1><EFBFBD><EFBFBD><EFBFBD>
|
2024-01-08 23:37:00 +08:00
|
|
|
|
WriteFile(hPipe, buffer, strlen(buffer), &_, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|