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向WORD写入text字段值时出现乱码
- UDP传输问题
- 为什么这样动态多次调用DLL时候会报错?(另外静态调用对系统产生多大影响?)代码如下:
- 急~!!如果屏蔽EDIT、DBGRID中的粘贴功能????右键菜单粘贴也不要,CTRL+V也不要
- 注册系统热键后自动失效的问题
- 有关StoredProc的Handle的问题?请大家帮忙!在线等待!
- 我对Delphi包的目录不清楚,也可以说是对安装第三方组件不清楚~
- ****诚招Dephi程序设计人员,见具体内容
- 高手们指点:怎样成为delphi高手,是否必须先成为VC高手!
- 数字转换问题
- 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;