如何在发送之前修改数据包上的某些字节? 我正在执行以下代码:
function WSASendHookProc(s: TSocket; var lpBuffers; dwBufferCount: DWORD; var lpNumberOfBytesSent: DWORD; dwFlags: DWORD; lpOverlapped: LPWSAOVERLAPPED; lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE): Integer; stdcall;
var
DataBuffer : PChar;
DataS : TSocket;
begin
Result := 0; (here already tried call the TramplineWSASend, dwBufferCount, lpNumberOfBytesSent and still the same thing)
DataS := s;
GetMem(DataBuffer, Result);
try
CopyMemory(DataBuffer, @lpBuffers, Result);
//word(pointer(DataBuffer)^) := word(pointer(DataBuffer)^);
CopyMemory(@lpBuffers, DataBuffer, Result);
finally
FreeMem(DataBuffer);
end;
Result := TrampolineWSASend(s, lpBuffers, dwBufferCount, lpNumberOfBytesSent, dwFlags, lpOverlapped, lpCompletionRoutine);
end;
但在//word(pointer(DataBuffer)^) := word(pointer(DataBuffer)^);
行,如果删除//应用程序崩溃而没有显示任何错误。
但是现在,如果我不删除//应用程序就可以了,但是我无法修改字节。
答案 0 :(得分:0)
您需要使用GetMem(DataBuffer, dwBufferCount);
这将分配缓冲区所需的内存。
然后您复制缓冲区:
CopyMemory(DataBuffer, lpBuffers, dwBufferCount);
现在您可以从DataBuffer
编辑内存,例如:
PWord(DataBuffer)^ := Word(Your word value here);
然后在TrampolineWSASend
中,您需要将lpBuffers
替换为DataBuffer
。