Hello,
i'm going crazy for a problem i can't solve...
as in the image I have to extract the hexadecimal values represented as '00:08' in Little Endian and then turn them over: the final result must be '0x0800' that is 2048 decimal.
Well, for read multiple location I writed a function like this
function TMainFormHex.readLoc(startLocation: String;
byteToRead: Integer;
Endianness: Integer;
var oResList: TByteList;
var oStrErr: string): Boolean;
{-------------------------------------------------------------------}
function addToBL(var bl: TByteList; byteToAdd: byte): Boolean;
begin
Result := false;
try
SetLength(bl, Length(bl) +1);
bl[Length(bl)-1] := byteToAdd;
Result := true;
except
end;
end;
{-------------------------------------------------------------------}
var
F : THexEditorFrame;
cnt,
n : Integer;
tres: Integer;
strErr: string;
begin
Result := False;
try
F := GetActiveHexEditorFrame;
if Assigned(F) then
begin
if (F.HexEditor = nil) or (not F.HexEditor.HasFile) then
exit;
try
strErr:= '';
n := StrToInt(startLocation);
F.JumpToPosition(n, strErr);
if Length(strErr) > 0 then
begin
oStrErr:= strErr;
exit;
end;
for cnt := 0 to byteToRead -1 do
begin
tres := F.HexEditor.CurrentValue;
addToBL(oResList, tres);
inc(n,1);
F.JumpToPosition(n, strErr);
if Length(strErr) > 0 then
begin
oStrErr:= strErr;
exit;
end;
end;
if Endianness=0 then
THexBitUtility.reverseByteList(oResList);
Result := True;
except
on e: Exception do
begin
oStrErr:=e.Message;
end;
end;
end;
finally
end;
end;
class function THexBitUtility.reverseByteList(var byteLst: TByteList;
lenghtCouple: Integer): Boolean;
var
tempList : TByteList;
bl,
cntStart,
cnt : Integer;
begin
Result := false;
try
tempList := TByteList.Create;
SetLength(tempList, Length(byteLst) );
bl := Length(byteLst);
cntStart:= 0;
for cnt := bl-1 downto 0 do
begin
tempList[cntStart] := byteLst[cnt];
Inc(cntStart);
end;
byteLst := tempList;
Result := true;
finally
end;
Result := true;
end;
With 'F.HexEditor.CurrentValue' I obtain a decimal value from 0 to 254: in the end I basically get 8 as a value and not 800.
I can't find another way to fix this,
thank you in advance.