代码拉取完成,页面将自动刷新
{$I LockBox.inc}
unit LbUtils;
{- odds-n-ends }
interface
uses
SysUtils;
function BufferToHex(const Buf; BufSize : Cardinal) : string;
function HexToBuffer(const Hex : string; var Buf; BufSize : Cardinal) : Boolean;
function Min(A, B : LongInt) : LongInt;
function Max(A, B : LongInt) : LongInt;
function CompareBuffers(const Buf1, Buf2; BufSize : Cardinal) : Boolean;
{$IFDEF Debugging}
procedure DebugStr(const AStr : string);
procedure DebugLogFile(const AFileName : string);
{$ENDIF}
implementation
{$IFDEF Debugging}
var
DebugLogFileName : string = 'LbDebug.txt';
procedure DebugStr(const AStr : string);
var
F : TextFile;
begin
try
AssignFile(F, DebugLogFileName);
Append(F);
except
on E : EInOutError do
if (E.ErrorCode = 2) or (E.ErrorCode = 32) then
Rewrite(F)
else
raise;
end;
WriteLn(F, AStr);
Close(F);
if IOResult <> 0 then ;
end;
procedure DebugLogFile(const AFileName : string);
begin
if FileExists(AFileName) then
DeleteFile(AFileName);
DebugLogFileName := AFileName;
end;
{$ENDIF}
{ -------------------------------------------------------------------------- }
function BufferToHex(const Buf; BufSize : Cardinal) : string;
var
I : LongInt;
begin
Result := '';
for I := 0 to BufSize - 1 do
Result := Result + IntToHex(TByteArray(Buf)[I], 2); {!!.01}
end;
{ -------------------------------------------------------------------------- }
function HexToBuffer(const Hex : string; var Buf; BufSize : Cardinal) : Boolean;
var
i, C : Integer;
Str : string;
Count : Integer;
begin
Result := False;
Str := '';
for i := 1 to Length(Hex) do
if Upcase(Hex[i]) in ['0'..'9', 'A'..'F'] then
Str := Str + Hex[i];
FillChar(Buf, BufSize, #0);
Count := Min(Length(Hex), BufSize);
for i := 0 to Count - 1 do begin
Val('$' + Copy(Str, (i shl 1) + 1, 2), TByteArray(Buf)[i], C); {!!.01}
if (C <> 0) then
Exit;
end;
Result := True;
end;
{ -------------------------------------------------------------------------- }
function Min(A, B : LongInt) : LongInt;
begin
if A < B then
Result := A
else
Result := B;
end;
{ -------------------------------------------------------------------------- }
function Max(A, B : LongInt) : LongInt;
begin
if A > B then
Result := A
else
Result := B;
end;
{ -------------------------------------------------------------------------- }
function CompareBuffers(const Buf1, Buf2; BufSize : Cardinal) : Boolean;
{ return true if buffers are the same }
var
i : Integer;
begin
Result := False;
for i := 0 to Pred(BufSize) do begin
Result := TByteArray(Buf1)[i] = TByteArray(Buf2)[i];
if not Result then
Break;
end;
end;
end.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。