I'm trying to convert an integer value of 10 digits for byte, but the function only returns me 4 values, I need 6 points, how to solve?
function I'm using to convert integer in bytes
var
i, j: integer;
bbI : array[1.. sizeof(integer)] of byte;
begin
i := 2337669003;
Move(i, bbI[1], SizeOf(Integer));
for j := Low(bbI) to High(bbI) do
Memo1.Lines.Append(IntToHex(bbI[j],2))
end;
the function returns me
8B FF 55 8B
values that are returned
but i need more 2 values
EC 51
the function should return me
8B FF 55 8B EC 51
I'm trying to convert an integer value of 10 digits for byte, but the function only returns me 4 values, I need 6 points, how to solve?
You can't. An Integer
is only 4 bytes in size. The Integer
value 2337669003
is the byte sequence 8B FF 55 8B
. There is no way you can get the extra EC 51
bytes from that.
An Int64
is 8 bytes in size. The byte sequence 8B FF 55 8B EC 51
would be an Int64
value of 5903246413051658240
with its high 2 bytes (00 00
) truncated off.
From the screenshot, we can clearly see that the byte sequence 8B FF 55 8B EC 51
actually corresponds to the first 4 x86 assembly instructions of the Win32 BitBlt()
function. Why are you using integer values to represent assembly instructions? That is not a good way to approach this. Do you understand how the x86 instruction set actually works? Do you understand how Integers work?
In this situation, I would suggest using an actual byte array instead of an integer array:
var
Instructions: array[0..5] of byte;
i: Integer;
begin
// mov edi,edi
Instructions[0] := $8B;
Instructions[1] := $FF;
// push ebp
Instructions[2] := $55;
// mov ebp,esp
Instructions[3] := $8B;
Instructions[4] := $EC;
// push ecx
Instructions[5] := $51;
for i := Low(Instructions) to High(Instructions) do
Memo1.Lines.Append(IntToHex(Instructions[i], 2));
end;
Or even use a record instead:
type
BitBltInstructions = packed record
MovEdiEdi: array[0..1] of byte; // $8B $FF
PushEbp: byte; // $55
MovEbpEsp: array[0..1] of byte; // $8B $EC
PushEcx: byte; // $51
end;
var
Instructions: BitBltInstructions;
bytes: array[0..Sizeof(BitBltInstructions)-1] of byte absolute Instructions;
i: Integer;
begin
Instructions.MovEdiEdi[0] := $8B;
Instructions.MovEdiEdi[1] := $FF;
Instructions.PushEbp := $55;
Instructions.MovEbpEsp[0] := $8B;
Instructions.MovEbpEsp[1] := $EC;
Instructions.PushEcx := $51;
for i := Low(bytes) to High(bytes) do
Memo1.Lines.Append(IntToHex(bytes[i], 2));
end;