Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Access a binary file.

Posted on 1999-07-23
Medium Priority
Last Modified: 2012-05-04
Suppose a binary file, say SAMPLE.EXE is 111,234 bytes long.
If I want to "extract" some contents from sample.exe and output it to another file(extract.dat), for instance, copy from 10,000th bytes to 12,499th bytes, a total of 2,500 bytes.
How can I do so?  Thanks in advance!
Question by:yingkit
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 10

Accepted Solution

Lischke earned 60 total points
ID: 1390721
1) Use a file stream and open the file (not necessarily an executable).
2) Set the streams position to the one you need.
3) Create a target sream for the part to extract.
4) Call TargetStream.CopyFrom(SourceStream, NumberOfBytesToCopy).
5) Close both streams.

Ciao, Mike

Author Comment

ID: 1390722
Can you pls provide me detail source codes?  I am only a beginner... :-(
LVL 10

Expert Comment

ID: 1390723
Right, here's the code:

procedure ExtractFile(const Source, Target: String; Start, Length: Cardinal);

// Extracts from a file which name is passed in Target from
// another file which name is passed in Source. Both strings
// must include valid pathes. Start determines the start
// position in Source and Length the the length of the file
// to be extracted.

var SourceStream, TargetStream: TFileStream;

  SourceStream := TFileStream.Create(Source, fmOpenRead);
  TargetStream := TFileStream.Create(Target, fmOpenWrite);
  SourceStream.Position := Start;
  TargetStream.CopyFrom(SourceStream, Length);

Ciao, Mike

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question