Replace array of data.

Home Forums Discussions Support Replace array of data.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #5375
    mel
    Participant

      I want to change some bytes before they come to my browser.
      Do i have to recalculate TCPchecksum?

      also, i like to buy code for D5 for doing this if is availble.

      Thanks.


      program Pass;
      {$APPTYPE CONSOLE}

      uses
      forms,
      SysUtils,
      Windows,
      Winsock,
      winpkf,
      iphlp;

      var
      ExitProcessProc: procedure;
      iIndex, counter : DWORD;
      hFilt : THANDLE;
      Adapts : TCP_AdapterList;
      AdapterMode : ADAPTER_MODE;
      Buffer, ParsedBuffer : INTERMEDIATE_BUFFER;
      ReadRequest : ETH_REQUEST;
      hEvent : THANDLE;
      hAdapter : THANDLE;
      pEtherHeader : TEtherHeaderPtr;
      pIPHeader : TIPHeaderPtr;
      pTcpHeader : TTCPHeaderPtr;
      pUdpHeader : TUDPHeaderPtr;
      SourceIP, DestIP : TInAddr;
      thePacket : PChar;
      SourceIpString, DestinationIpString : string;
      SourceName, DestinationName : string;

      function IPAddrToName(IPAddr : string) : string;
      var
      SockAddrIn : TSockAddrIn;
      HostEnt : PHostEnt;
      WSAData : TWSAData;
      begin
      WSAStartup($101, WSAData);
      SockAddrIn.sin_addr.s_addr := inet_addr(PChar(IPAddr));
      HostEnt := gethostbyaddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET);
      if HostEnt <> nil then
      begin
      result := StrPas(Hostent^.h_name)
      end
      else
      begin
      result := '';
      end;
      end;








      procedure ReleaseInterface();
      begin
      AdapterMode.dwFlags := 0;
      AdapterMode.hAdapterHandle := hAdapter;
      SetAdapterMode(hFilt, @AdapterMode);
      SetPacketEvent(hFilt, hAdapter, 0);
      if hEvent <> 0 then
      CloseHandle(hEvent);
      CloseFilterDriver(hFilt);
      FreeNDISAPI();
      end;

      begin
      iIndex := 4;
      InitNDISAPI();
      hFilt := OpenFilterDriver('NDISRD');
      if not IsDriverLoaded(hFilt) then exit;
      ExitProcessProc:= ReleaseInterface;
      GetTcpipBoundAdaptersInfo(hFilt, @Adapts);
      hAdapter := Adapts.m_nAdapterHandle[iIndex];
      AdapterMode.dwFlags := MSTCP_FLAG_RECV_TUNNEL or MSTCP_flag_sent_TUNNEL ;
      AdapterMode.hAdapterHandle := hAdapter;
      hEvent := CreateEvent(nil, TRUE, FALSE, nil);

      if hEvent <> 0 then
      begin//1

      if SetPacketEvent(hFilt, hAdapter, hEvent) <> 0 then
      begin//2
      ReadRequest.EthPacket.Buffer := @Buffer;
      ReadRequest.hAdapterHandle := hAdapter;
      SetAdapterMode(hFilt, @AdapterMode);
      WaitForSingleObject(hEvent,INFINITE);

      while ReadPacket(hFilt, @ReadRequest) <> 0 do
      begin//3

      pEtherHeader := TEtherHeaderPtr(@Buffer.m_IBuffer);
      if ntohs(pEtherHeader.h_proto) = ETH_P_IP then
      begin
      pIPHeader := TIPHeaderPtr(Integer(pEtherHeader) +
      SizeOf(TEtherHeader));
      SourceIP.S_addr := pIPHeader.SourceIp;
      DestIP.S_addr := pIPHeader.DestIp;
      if pIPHeader.Protocol = IPPROTO_TCP then
      begin
      pTcpHeader := TTCPHeaderPtr(Integer(pIPHeader) + (pIPHeader.VerLen and $F) * 4);
      if (pTcpHeader.SourcePort = htons(80)) or (pTcpHeader.DestPort = htons(80)) then begin thePacket := pchar(pEtherHeader)+ (sizeof(TEtherHeaderPtr) + pIpHeader.VerLen * 4 + pTcpHeader.Offset * 4);writeln(thePacket);end;
      end;
      end;
      case Buffer.m_dwDeviceFlags of

      PACKET_FLAG_ON_SEND:
      /////////***************************************
      //lets say i want ReadRequest.EthPacket.Buffer.m_IBuffer[30]=100;
      /// do i have to recalculate TCPChecksum ????
      /////////***************************************
      begin SendPacketToAdapter(hFilt, @ReadRequest);
      end;
      PACKET_FLAG_ON_RECEIVE: SendPacketToMstcp(hFilt, @ReadRequest);
      end;
      end;//3

      ResetEvent(hEvent);
      end;//2
      end;//1

      end.
      #7083
      Vadim Smirnov
      Keymaster

        Yes, you have to recalculate checksums if modify the packet content. What code do you need? Checksum recalculation?

      Viewing 2 posts - 1 through 2 (of 2 total)
      • You must be logged in to reply to this topic.