![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2005
Posts: 2
Rep Power: 0
![]() |
Hex Editing Module
Hello everyone! Yesterday I was very bored, and came up with the idea to make a module for hex-editing. I made two overloaded procedures for writing to the executable, with either a string or array of byte as input. I also made a procedure that converts a string into array of byte (StrToByte):
procedure StrToByte(input:string; Out output:array of byte); var i:byte; begin for i := 1 to Length(input) do begin output[i-1] := Ord(input[i]); end; end; var Stream:TFileStream; ..................... procedure WriteInfo(buffer:array of byte; offset:integer; exepath:string);overload; begin Stream := TFileStream.Create(exepath, fmOpenReadWrite); Stream.Seek(offset, soFromBeginning); Stream.WriteBuffer(buffer, SizeOf(buffer)); Stream.Free; end; procedure WriteInfo(buffer:string; offset:integer; exepath:string);overload; var bytes:array of byte; begin SetLength(bytes, Length(buffer)); StrToByte(buffer, bytes); Stream := TFileStream.Create(exepath, fmOpenReadWrite); Stream.Seek(offset, soFromBeginning); Stream.WriteBuffer(bytes, SizeOf(bytes)); Stream.Free; end; (1)
procedure TForm1.Button2Click(Sender: TObject);
begin
WriteInfo('Testing',$AFAFAF,'TestProg.exe');
end;
(2)
procedure TForm1.Button1Click(Sender: TObject);
var
bytes:array of byte;
begin
SetLength(bytes,7);
StrToByte('Testing', bytes);
WriteInfo(bytes,$AFAFAF,'TestProg.exe');
end;Karamellz~ |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Jun 2005
Posts: 1
Rep Power: 0
![]() |
I'm not sure, there is several things that seem odd to me. But I've only been working with Delphi 4 & 5, nothing newer.
procedure StrToByte(input:string; Out output:array of byte); I don't know that way of notation. Is this new? It used to be procedure StrToByte(input:string; var output:array of byte); And I think you can not pass "array of" in a "var" argument without defining its own type for it. (type A_O_B=array of byte; var output: A_O_B;). But if the compiler doesn't complain, they seem to have fixed this. Try passing "bytes[0]" instead of "bytes" to the Stream.WriteBuffer() method. IIRC Pascal handles arrays in memory a little different from C. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|