1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| procedure HexaStringToBinFile(const OutFileName: string; const HexaText: string);
function LowCharCase(C: Char): Char;
asm
CMP AL,'A'
JB @@exit
CMP AL,'Z'
JA @@exit
SUB AL,'A' - 'a'
@@exit:
end;
var
HexaCleanText: string;
HexaBuffer: array of Char;
OutFile: file;
I, Count: Integer;
begin
AssignFile(OutFile, OutFileName);
Rewrite(OutFile, 1);
try
Count := 0;
SetLength(HexaCleanText, Length(HexaText));
ZeroMemory(@HexaCleanText[1], Length(HexaCleanText));
for I := 1 to Length(HexaText) do
begin
if HexaText[I] in ['0'..'9', 'A'..'F', 'a'..'f'] then
begin
Inc(Count);
HexaCleanText[Count] := LowCharCase(HexaText[I]);
end;
end;
Count := Count div 2;
SetLength(HexaBuffer, Count);
HexToBin(@HexaCleanText[1], @HexaBuffer[0], Count);
BlockWrite(OutFile, HexaBuffer[0], Count);
finally
CloseFile(OutFile);
end;
end; |
Partager