⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 u_databuffer.pas

📁 linux program to read packet data
💻 PAS
字号:
(*
 * One Way Network Sniffer (OWNS)
 * Copyright (C) 2001-2002 OWNS
 *
 * http://owns.sourceforge.net/
 * http://www.owns.st
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *)

(*
 * $Id: u_DataBuffer.pas,v 1.5 2002/11/02 14:05:37 owns Exp $
 * This represents a dynamic buffer
 * You can write in it at at any position. If necessary memory is dynamically
 * allocated
 *)
unit u_DataBuffer;
interface

type
  TDataBuffer = class
  private
    FData          : PChar;             // donn閑s de la connection
    FAllocatedSize : Cardinal;             // taille allou閑
    FSize          : Cardinal;             // taille utilis閑
    FBytesWritten  : Cardinal;             // octets 閏rits
  public
    constructor create;
    destructor destroy; override;
    procedure Write(p_Position : Cardinal;p_Data : PChar;p_Size : Cardinal);
    property Size : Cardinal read FSize;
    property BytesWritten : Cardinal read FBytesWritten;
    property Data : PChar read FData;
  end;

implementation

constructor TDataBuffer.create;
begin
  FData := nil;
  FAllocatedSize := 0;
  FSize := 0;
  FBytesWritten := 0;
end;

destructor TDataBuffer.destroy;
begin
  FreeMem(FData);
  inherited;
end;

// write data in the buffer
procedure TDataBuffer.Write(p_Position : Cardinal;p_Data : PChar;p_Size : Cardinal);
begin
  if (p_Position < FSize) then
  begin
    FSize := Fsize;
  end;
  if (p_Position + p_Size > FSize) then
    FSize := p_Position + p_Size;

  if (FSize > FAllocatedSize) then
  begin
    FAllocatedSize := FSize*2;
    ReallocMem(FData,FAllocatedSize);
  end;

  FBytesWritten := FBytesWritten + p_Size;
  Move(p_Data^,FData[p_Position], p_Size);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -