EXTERN_C LPVOID WINAPI Kmp(
LPVOID lpAddress,
LPVOID lpSignBuff,
INT nBufferSize,
INT nSignSize,
INT nStart
)
{
INT i = 0;
INT k = nStart;
LPBYTE lpSign = (LPBYTE)lpSignBuff;
LPBYTE lpBuffer = (LPBYTE)lpAddress;
LPDWORD lpNextArray = NULL;
LPVOID lpRel = NULL;
if ( NULL == lpBuffer || NULL == lpSign )
{
return lpRel;
} lpNextArray = (LPDWORD)LocalAlloc(LPTR,nSignSize*sizeof(DWORD));
if (NULL == lpNextArray)
{
return lpRel;
} GetNextArray(lpSign,lpNextArray,nSignSize); while( i < nSignSize && k < nBufferSize)
{
if(lpBuffer[k] == lpSign[i] || -1 == i)
{
k++;
i++;
}
else
{
i = lpNextArray[i];
}
} if( i >= nSignSize)
{
k -= nSignSize;
lpRel = (LPVOID)((LPBYTE)lpAddress + k);
if (lpRel == lpSign)
{
lpRel = NULL;
//过滤特征串....
} } if (NULL != lpNextArray)
{
LocalFree((HLOCAL)lpNextArray);
} return lpRel;
}
LPVOID lpAddress,
LPVOID lpSignBuff,
INT nBufferSize,
INT nSignSize,
INT nStart
)
{
INT i = 0;
INT k = nStart;
LPBYTE lpSign = (LPBYTE)lpSignBuff;
LPBYTE lpBuffer = (LPBYTE)lpAddress;
LPDWORD lpNextArray = NULL;
LPVOID lpRel = NULL;
if ( NULL == lpBuffer || NULL == lpSign )
{
return lpRel;
} lpNextArray = (LPDWORD)LocalAlloc(LPTR,nSignSize*sizeof(DWORD));
if (NULL == lpNextArray)
{
return lpRel;
} GetNextArray(lpSign,lpNextArray,nSignSize); while( i < nSignSize && k < nBufferSize)
{
if(lpBuffer[k] == lpSign[i] || -1 == i)
{
k++;
i++;
}
else
{
i = lpNextArray[i];
}
} if( i >= nSignSize)
{
k -= nSignSize;
lpRel = (LPVOID)((LPBYTE)lpAddress + k);
if (lpRel == lpSign)
{
lpRel = NULL;
//过滤特征串....
} } if (NULL != lpNextArray)
{
LocalFree((HLOCAL)lpNextArray);
} return lpRel;
}
解决方案 »
- Delphi WebBrowser如何模拟网页内嵌的一个子页面按钮点击
- 小外甥出生了,求一名字 大家帮忙想一个哦,呵。。
- 有谁写过开发文档,设计文档,程序说明书?
- 帮我看看什么错。
- 请问aiirii(ari-爱的眼睛),在使用你的这段代码时是否可以将dos窗口隐藏运行我的程序呢?
- 如何让 PageControl锁定某个ActivePage?
- 请问WIN2000下打印走纸的问题
- 急,一个关于stringlist的问题
- 关于内存分配的问题
- 线程问题123
- cds 用clientdataset 三层 执行 存储过程 open 后 如下错误
- 有一段string变量,内容结构与ini文件的结构一样,有没有方便的方法读出string的内容
function Kmp(lpAddress, lpSignBuff: Pointer;
nBufferSize, nSignSize, nStart: Integer): Pointer;
type
TDWORDArray = array[0..(MaxLongInt div 4) - 1] of LongWord;
PDWORDArray = ^TDWORDArray;
var
i, k: Integer;
lpSign: PByteArray;
lpBuffer: PByteArray;
lpNextArray: PDWORDArray;
begin
Result := nil;
if (lpAddress = nil) or (lpSignBuff = nil) then
Exit;
i := 0;
k := nStart;
lpSign := lpSignBuff;
lpBuffer := lpAddress;
lpNextArray := PDWORDArray(LocalAlloc(LPTR, nSignSize * sizeof(LongWord)));
if lpNextArray = nil then Exit;
try
GetNextArray(lpSign, lpNextArray, nSignSize);
while (i < nSignSize) and (k < nBufferSize) do
begin
if (lpBuffer[k] = lpSign[i]) or (i = -1) then
begin
Inc(i);
Inc(k);
end
else
i := lpNextArray[i];
end;
if i >= nSignSize then
begin
Dec(k, nSignSize);
Result := Pointer(LongWord(lpAddress) + k);
if Result = lpSign then
begin
Result := nil;
//过滤特征串....
end;
end;
finally
LocalFree(HLOCAL(lpNextArray));
end;
end;
GetNextArray(lpSign, lpNextArray, nSignSize);
为:
GetNextArray(lpSign, PLongWord(lpNextArray), nSignSize);
type
TDWORDArray = array[0..(MaxLongInt div 4) - 1] of LongWord;
PDWORDArray = ^TDWORDArray;procedure GetNextArray(lpSign: Pointer; lpNextBuffer: PDWORDArray; nSize: Integer);
var
i, k: Integer;
lpSubBuffer: PByteArray;
begin
if (lpSign = nil) or (lpNextBuffer = nil) then Exit;
i := 0;
k := -1;
lpSubBuffer := lpSign;
lpNextBuffer[0] := LongWord(-1);
while i < nSize - 1 do
begin
if (k = -1) or (lpSubBuffer[i] = lpSubBuffer[k]) then
begin
Inc(i);
Inc(k);
lpNextBuffer[i] := k;
end
else
k := lpNextBuffer[k];
end;
end;function Kmp(lpAddress, lpSignBuff: Pointer;
nBufferSize, nSignSize, nStart: Integer): Pointer;
var
i, k: Integer;
lpSign: PByteArray;
lpBuffer: PByteArray;
lpNextArray: PDWORDArray;
begin
Result := nil;
if (lpAddress = nil) or (lpSignBuff = nil) then
Exit;
i := 0;
k := nStart;
lpSign := lpSignBuff;
lpBuffer := lpAddress;
lpNextArray := PDWORDArray(LocalAlloc(LPTR, nSignSize * sizeof(LongWord)));
if lpNextArray = nil then Exit;
try
GetNextArray(lpSign, lpNextArray, nSignSize);
while (i < nSignSize) and (k < nBufferSize) do
begin
if (lpBuffer[k] = lpSign[i]) or (i = -1) then
begin
Inc(i);
Inc(k);
end
else
i := lpNextArray[i];
end;
if i >= nSignSize then
begin
Dec(k, nSignSize);
Result := Pointer(LongWord(lpAddress) + k);
if Result = lpSign then
begin
Result := nil;
//过滤特征串....
end;
end;
finally
LocalFree(HLOCAL(lpNextArray));
end;
end;