97 lines
2.9 KiB
C++
Raw Normal View History

2024-01-08 23:37:00 +08:00
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
2024-04-02 15:36:52 +08:00
#include <Windows.h>
2024-01-08 23:37:00 +08:00
#include <io.h>
2024-04-02 15:36:52 +08:00
#include <fcntl.h>
#include <Shlwapi.h>
2024-01-08 23:37:00 +08:00
2024-04-02 15:36:52 +08:00
#define CODEPAGE_JA 932
#define CODEPAGE_GB 936
2024-01-08 23:37:00 +08:00
#define CODEPAGE_BIG5 950
2024-04-02 15:36:52 +08:00
UINT unpackuint32(unsigned char *s)
{
2024-01-08 23:37:00 +08:00
int i = 0;
return ((s[i]) << 24) | ((s[i + 1]) << 16) | ((s[i + 2]) << 8) | (s[i + 3]);
}
2024-04-02 15:36:52 +08:00
void packuint32(UINT i, unsigned char *b)
{
2024-01-08 23:37:00 +08:00
b[0] = (i >> 24) & 0xff;
b[1] = (i >> 16) & 0xff;
b[2] = (i >> 8) & 0xff;
b[3] = (i) & 0xff;
}
2024-04-02 15:36:52 +08:00
int jbjwmain(int argc, wchar_t *argv[])
2024-01-08 23:37:00 +08:00
{
2024-04-02 15:36:52 +08:00
HANDLE hPipe = CreateNamedPipe(argv[2], 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
/*_setmode(_fileno(stdout), _O_U16TEXT);
_setmode(_fileno(stdin), _O_U16TEXT);*/
fclose(stdout);
2024-04-02 15:36:52 +08:00
// system("chcp 932");
2024-01-08 23:37:00 +08:00
HMODULE module = LoadLibraryW(argv[1]);
2024-04-02 15:36:52 +08:00
typedef int (*_JC_Transfer_Unicode)(int, UINT, UINT, int, int, LPCWSTR, LPWSTR, int &, LPWSTR, int &);
typedef int(__cdecl * _DJC_OpenAllUserDic_Unicode)(LPWSTR, int unknown);
2024-01-08 23:37:00 +08:00
auto JC_Transfer_Unicode = (_JC_Transfer_Unicode)GetProcAddress(module, "JC_Transfer_Unicode");
auto DJC_OpenAllUserDic_Unicode = (_DJC_OpenAllUserDic_Unicode)GetProcAddress(module, "DJC_OpenAllUserDic_Unicode");
int USERDIC_PATH_SIZE = 0x204;
int MAX_USERDIC_COUNT = 3;
2024-04-02 15:36:52 +08:00
int USERDIC_BUFFER_SIZE = USERDIC_PATH_SIZE * MAX_USERDIC_COUNT; // 1548, sizeof(wchar_t)
wchar_t cache[1548] = {0};
int __i = 0;
for (int i = 4; i < argc; i++)
{
2024-02-18 11:56:40 +08:00
wchar_t _[MAX_PATH];
2024-04-02 15:36:52 +08:00
wcscpy(_, argv[i]);
wcscat(_, L".DIC");
if (PathFileExistsW(_))
2024-02-18 11:56:40 +08:00
{
wcscpy(cache + __i * USERDIC_PATH_SIZE, argv[i]);
__i++;
}
2024-01-08 23:37:00 +08:00
}
DJC_OpenAllUserDic_Unicode(cache, 0);
2024-04-02 15:36:52 +08:00
wchar_t *fr = new wchar_t[3000];
wchar_t *to = new wchar_t[3000];
wchar_t *buf = new wchar_t[3000];
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[3]));
2024-04-02 15:36:52 +08:00
if (ConnectNamedPipe(hPipe, NULL) != NULL)
{
2024-01-08 23:37:00 +08:00
DWORD len = 0;
}
unsigned char intcache[4];
2024-04-02 15:36:52 +08:00
while (true)
{
2024-01-08 23:37:00 +08:00
memset(fr, 0, 3000 * sizeof(wchar_t));
memset(to, 0, 3000 * sizeof(wchar_t));
memset(buf, 0, 3000 * sizeof(wchar_t));
int a = 3000;
int b = 3000;
2024-04-02 15:36:52 +08:00
char codec[4] = {0};
2024-01-08 23:37:00 +08:00
UINT code;
DWORD _;
ReadFile(hPipe, intcache, 4, &_, NULL);
code = unpackuint32(intcache);
2024-04-02 15:36:52 +08:00
if (!ReadFile(hPipe, (unsigned char *)fr, 6000, &_, NULL))
break;
2024-01-08 23:37:00 +08:00
JC_Transfer_Unicode(0, CODEPAGE_JA, code, 1, 1, fr, to, a, buf, b);
2024-04-02 15:36:52 +08:00
WriteFile(hPipe, (unsigned char *)to, 2 * wcslen(to), &_, NULL);
2024-01-08 23:37:00 +08:00
}
2024-04-02 15:36:52 +08:00
2024-01-08 23:37:00 +08:00
return 0;
2024-04-02 15:36:52 +08:00
}