开发者

How can i open binary files (exe) in "Delphi" , like Visual basic?

开发者 https://www.devze.com 2023-01-08 02:19 出处:网络
in visual basic i can open a binary(exe) file with below way : Strx$ = Space(FileLen(FileName)) Open FileName For Binary As #1

in visual basic i can open a binary(exe) file with below way :

Strx$ = Space(FileLen(FileName))
Open FileName For Binary As #1
  Get #1, , Strx开发者_如何学C$
Close

in this way i can read all of binary file characters and read file content like this format :

How can i open binary files (exe) in "Delphi" , like Visual basic?

(source: iranblog.com)

and the question is how can i open a binary(exe) file in delphi with a string format(Like image) and not 0,1(binary) format ?

Thank you!


EXE files contain embedded NULL (#0) Characters. You may have problems using Strings as typically NULL is found at the end of the string. Some routines will stop working with a string once the NULL is encountered.

Having said that the following would get the contents of a file into a string.

function GetFileIntoString(FileName : String) : String;
var
 SS : TStringStream;
begin
  SS := TStringStream.Create('');   
  try
    SS.LoadFromFile(FileName);
    result := SS.DataString;
  finally
    SS.Free;
  end;
end;


Here are some good resources with examples.

  • Create your own Database using Delphi's "File Of" Typed Files : Understanding Typed Files.

  • Acessing Files With Unknown Structure: Direct Access to Files Regardless of Type and Structuring.

0

精彩评论

暂无评论...
验证码 换一张
取 消