Dynamic memory

This commit is contained in:
世元 李
2020-03-19 23:31:22 +08:00
parent ebb203fa84
commit 6ba09c63be
46 changed files with 315 additions and 184 deletions

View File

@@ -1,17 +1,31 @@
#include "pch.h"
#include "Replace.h"
int npID = 0;
#include<algorithm>
#include<iostream>
#include<set>
extern HMODULE hModL;
extern "C" extern DLLAPI wchar_t ms_str[3096];
extern "C" extern DLLAPI int nID;
void BuildCV(TESTDATA* pcv, TESTDATA flt, DWORD posinCross, DWORD posInLine, DWORD m_count, WCHAR nchar)
extern "C" extern DLLAPI wchar_t cn_str[1024];
extern "C" extern DLLAPI bool IsSuccess;
extern TESTDATA* pNewDf;
extern char IpfData[16];
#define PutInt(a) _itoa_s(a,IpfData,16);MessageBoxA(0,IpfData,"num",0);
multiset<DWORD> AddrList;
extern "C" DLLAPI void BuildCV(TESTDATA* pcv, TESTDATA flt, DWORD posinCross, DWORD posInLine, DWORD m_count, WCHAR nchar)
{
pcv->ForCast = flt.ForCast;
pcv->nLine = posinCross;
pcv->nChar = nchar;
pcv->nCross = posInLine;
pcv->Flag1 = flt.Flag1;
pcv->Flag2 = flt.Flag2;
pcv->Flag2 = 0xFFC8C8C8;
pcv->Flag3 = flt.Flag3;
pcv->Flag4 = flt.Flag4;
pcv->Flagn4 = flt.Flagn4;
@@ -30,59 +44,92 @@ void BuildCV(TESTDATA* pcv, TESTDATA flt, DWORD posinCross, DWORD posInLine, DWO
pcv->Over2 = flt.Over2;
return;
}
void ApplyStringToCV(LPCWSTR ws, DWORD pDf, int id)
void ApplyStringToCV(LPCWSTR ws, DWORD pDf)
{
// return;
// SetWindowTextW(GetForegroundWindow(),ws);
TESTDATA loadFirst = *((TESTDATA*)(*(DWORD*)pDf));
//if (pNewDf)
// free(pNewDf);
pNewDf =(TESTDATA*) malloc(1024*96);
for (int i = 0; i < 1024; i++)
BuildCV(&pNewDf[i], loadFirst, 0XD, 0, 0, 0);
wstring localString = ws;
if (!pDf)return;
if (!ws)return;
DWORD Df = *(DWORD*)pDf;//Df <20><><EFBFBD>ݵ<EFBFBD>ָ<EFBFBD><D6B8>
if (!Df)return;//Ϊ<><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
TESTDATA* nCView = (TESTDATA*)Df;//ʹһ<CAB9><D2BB>TESTDATA*ָ<><D6B8>Df
DWORD pOld;
VirtualProtect(nCView, 10 + (localString.length() * 2), PAGE_READWRITE, &pOld);
TESTDATA loadFirst = *nCView;//<2F><><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*(DWORD*)pDf = (DWORD)pNewDf;
int posInLine = 0;//<2F><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
int posinCross = 0xD;//<2F><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
// SetWindowTextW(m_hWnd, L"<22><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>");
int PJ = 0;
for (int i = 0; i < localString.length(); i++)
{
if (localString[i] == L'\n')
{
BuildCV(nCView, loadFirst, posinCross, posInLine, i * 2, 0);
nCView++;
BuildCV(nCView, loadFirst, posinCross, posInLine, i * 2, 0XFFFF);
nCView++;
BuildCV(&pNewDf[PJ], loadFirst, posinCross, posInLine, i * 2, 0);
PJ++;
BuildCV(&pNewDf[PJ], loadFirst, posinCross, posInLine, i * 2, 0XFFFF);
PJ++;
posinCross += 0x28;
posInLine = 0;
}
else
{
BuildCV(nCView, loadFirst, posinCross, posInLine, i * 2, localString[i]);
nCView++;
BuildCV(&pNewDf[PJ], loadFirst, posinCross, posInLine, i * 2, localString[i]);
PJ++;
posInLine += 0X1A;
}
}
PJ++;
// SetWindowTextW(m_hWnd, L"<22><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>");
*(DWORD*)(pDf + 4) = (DWORD)nCView;
VirtualProtect(nCView, 10 + (localString.length() * 2), pOld, NULL);
*(DWORD*)(pDf + 4) = (DWORD)&pNewDf[PJ];
int sized = *(DWORD*)(pDf + 4) - *(DWORD*)pDf;
// PutInt(sized);
lstrcpyW(cn_str, ws);
}
static bool InitOnce = true;
int TranSplete(DWORD lp)
{
// MessageBox(0,L"Transplete start",L"",0);
if (!lp)return -1;
// MessageBoxA(0,"","",0);
//定义缓冲区
WCHAR sjp[1024];
WCHAR scn[1024];
wstring nStr;
/*第一部分 排除无效的调用*/
if (!lp)return 1;
DWORD ppDf = *(DWORD*)(lp + 0x2B0);
if (!ppDf)return -1;
if (!ppDf)return 1;
DWORD pDf = *(DWORD*)(ppDf + 8);
if (!pDf)return -1;
if (!pDf)return 1;
DWORD Df = *(DWORD*)pDf;
if (!Df)return -1;
if (!Df)return 1;
DWORD pEnd = *(DWORD*)(pDf + 4);
if (!pEnd)return -1;
WCHAR sjp[1024];
WCHAR scn[1024];
DWORD Num = (pEnd - Df) / 96;
wstring nStr;
TESTDATA* nCView = (TESTDATA*)Df;
if (!pEnd)return 1;
/*************************/
TESTDATA* nCView = (TESTDATA*)Df;//定义指向当前数据的指针
DWORD Num = (pEnd - Df) / 96;//定义长度
if (Num == 0) {
return 1;
}
/*先扫描一次数据内存把字符逐一加入nStr*/
for (DWORD i = 0; i < Num; i++) {
if (nCView->nChar == 0xFFFF) {
}
@@ -94,55 +141,80 @@ void ApplyStringToCV(LPCWSTR ws, DWORD pDf, int id)
}
nCView++;
}
npID++;
// MessageBoxW(0,L"0",L"",0);
WCHAR csjp[1024];
WCHAR cscn[1024];
int ppId = 0;
if (!GetDataByID(nID - 1, csjp, cscn)) {
if (nID != 0)
if (!GetDataByJP(&ppId, nStr.c_str(), cscn))
return -1;
}
// MessageBoxW(0, L"1", L"", 0);
if (lstrcmpW(nStr.c_str(), cscn) == 0) {
// MessageBoxW(0, nStr.c_str(), L"", 0);
/***************************************/
if (lstrcmpW(nStr.c_str(), cn_str) == 0) {//如果和上一句的中文相同,则直接返回。
return -1;
}
// MessageBoxW(0, L"2", L"", 0);
if (wcsstr(nStr.c_str(), L"………")) {
// PutInt(*(DWORD*)pDf);
// PutInt(Num);
// MessageBoxW(0, nStr.c_str(), L"", 0);
/******排除较短的语气词******/
if (wcsstr(nStr.c_str(), L"………") && lstrlenW(nStr.c_str()) < 8)
return -1;
}
if (wcsstr(nStr.c_str(), L"…ああ"))
if (wcsstr(nStr.c_str(), L"…ああ")&&lstrlenW(nStr.c_str())<8)
return -1;
if (wcsstr(nStr.c_str(), L"ふふふっ"))
if (wcsstr(nStr.c_str(), L"ふふふっ") && lstrlenW(nStr.c_str()) < 8)
return -1;
/****************************/
//应用当前句到msstr
lstrcpyW(ms_str, nStr.c_str());
if (!GetDataByID(nID, sjp, scn)) {
// MessageBoxA(0,"","",0);
int ppdid = nID + 1;
if (!GetDataByID(ppdid, sjp, scn)) {//尝试获取当前ID的数据
//如果失败
int pID = 0;
if (GetDataByJP(&pID, nStr.c_str(), scn)) {
nID = pID + 1;
ApplyStringToCV(scn, pDf, pID);
return 0;
if (GetDataByJP(&pID, nStr.c_str(), scn)) {//尝试从原文获取翻译
//成功
nID = pID;
// MessageBoxW(0,scn,L"",0);
ApplyStringToCV(scn, pDf);
// MessageBoxA(0,"0","",0);
return 0;//直接返回
}
else {
//失败
if (GetDataByID(nID, sjp, scn))
nID = GEtLargestID() + 1;
// MessageBoxA(0, "1", "", 0);
return -1;
}
}
else
{
if (lstrcmpW(sjp, nStr.c_str()) == 0) {
ApplyStringToCV(scn, pDf, nID);
//如果成功
if (lstrcmpW(sjp, nStr.c_str()) == 0) {//检查是否是正确的翻译
//如果是则直接应用
// MessageBoxW(0, scn, L"", 0);
ApplyStringToCV(scn, pDf);
nID = ppdid;
// MessageBoxA(0, "2", "", 0);
return 0;
}
else
{
//如果不是则
int pID = 0;
if (GetDataByJP(&pID, nStr.c_str(), scn)) {
nID = pID + 1;
ApplyStringToCV(scn, pDf, pID);
return 0;
}
else
if (GetDataByJP(&pID, nStr.c_str(), scn)) {//再次尝试用原文获取数据
//如果成功
// MessageBoxW(0, scn, L"", 0);
ApplyStringToCV(scn, pDf);
nID = pID;
// MessageBoxA(0, "3", "", 0);
return 0;//直接返回
}
else {
//如果不是
nID = GEtLargestID()+1;
// MessageBoxA(0, "4", "", 0);
return -1;
}
}
}
nID++;
return 0;
return -1;
}