1,593
社区成员
发帖
与我相关
我的任务
分享
function WSPRecv(s: TSocket; lpBuffers: LPWSABUF; dwBufferCount: DWORD;
var lpNumberOfBytesRecvd, lpFlags: DWORD; lpOverlapped: LPWSAOVERLAPPED;
lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE; lpThreadId: LPWSATHREADID;
var lpErrno: Integer): Integer; stdcall;
const Redirect_String: AnsiString = // 重定向字符串
'HTTP/1.1 301 Moved Permanently' + #13#10 + 'Location: ' + 'http://www.qq.com' + #0;
var i, j, n: Integer;
tmpStr: string;
begin
tmpStr := IntToHex(s, 8);
i := SessionList.IndexOf(tmpStr);//从表中查找Socket句柄
if i >= 0 then begin
SessionList.Delete(i);//删除记录
lpBuffers^.buf:=PChar(Redirect_String);//修改内容
end;
Result := NextProcTable.lpWSPRecv(s, lpBuffers, dwBufferCount, lpNumberOfBytesRecvd, lpFlags, lpOverlapped, lpCompletionRoutine, lpThreadId, lpErrno);
end;
const RStr: string = 'HTTP/1.1 301 Moved Permanently' + #13#10 + 'Location: http://www.soso.com' + #13#10#13#10;
function WSPRecv(s: TSocket; lpBuffers: LPWSABUF; dwBufferCount: DWORD;
var lpNumberOfBytesRecvd, lpFlags: DWORD; lpOverlapped: LPWSAOVERLAPPED;
lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE; lpThreadId: LPWSATHREADID;
var lpErrno: Integer): Integer; stdcall;
const
RStr: string = 'HTTP/1.1 301 Moved Permanently' + #13#10 + 'Location: http://www.soso.com' + #0;
var
j, Len: Integer;
TempStr: AnsiString;
begin
j := SessionList.IndexOf(Pointer(s)); //从表中查找Socket句柄
Result := AlpWSPRecv(s, lpBuffers, dwBufferCount, lpNumberOfBytesRecvd, lpFlags, lpOverlapped, lpCompletionRoutine, lpThreadId, lpErrno);
Len := lpNumberOfBytesRecvd;
if LookupRecvPacket(lpBuffers.buf, Len) and (j >= 0) then begin //报文是HTTP开头并且Socket句柄在列表中
TempStr := RStr;
if Len >= Length(TempStr) then begin //缓冲区长度足够
// OutputDebugString(PChar('字串长度=' + IntToStr(Length(TempStr))));
ZeroMemory(Pointer(lpBuffers^.buf), Len); //清空lpBuffers^.buf
CopyMemory(Pointer(lpBuffers^.buf), Pointer(TempStr), Length(TempStr)); //复制字串到lpBuffers^.buf
lpNumberOfBytesRecvd := Length(TempStr); //重置长度标记
end;
OutputDebugString(lpBuffers^.buf);
WriteDataFile('C:\log1.log', Pointer(lpBuffers^.buf)^, lpNumberOfBytesRecvd); //写入记录
SessionList.Delete(j);
end;
end;