Thread: Load values from end of file (exe)

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    1

    Load values from end of file (exe)

    Hello.

    I'm writing an application which saving some values to EXE file.
    I wrote 'SaveToEXE' function.

    Now I've got a problem.
    How to read saved values in EXE file? Values are stored at the end of the file. How to read this string:

    Load values from end of file (exe)-generator-jpg

    I found the function LoadFromEXE, but in Delphi:

    Code:
    FUNCTION LoadFromFile(FName: string): string;
    var
    F: File of Byte;
    I: Integer;
    begin
    Result := '';
    AssignFile(F, FName);
    FileMode := fmOpenRead;
    Reset(F);
    try
    Seek(F, FileSize(F) - SizeOf(I));
    BlockRead(F, I, SizeOf(I));
    if (I < SizeOf(I)) or (I > FileSize(F)) then
    Exit;
    Seek(F, FileSize(F) - I);
    SetLength(Result, I - SizeOf(I));
    BlockRead(F, Result[1], Length(Result));
    XXX := Result;
    finally
    CloseFile(F);
    end;
    end;
    How to do it in C++?

    // Sorry for my english.

    Greetings,
    Kirgeron
    Last edited by Kirgeron; 01-01-2012 at 06:53 AM.

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    If you're just learning C++ perhaps you should start on something a little easier. However, since the exe file is just a file, you could open it (in binary mode) and either seek to a fixed number of bytes from the end (easiest) or seek to the end and search backwards for a delimiter to find your data. But why would you want to do this anyway?

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    What does SaveToEXE look like? Knowing will make it a lot easier to getLoadFromEXE correct.
    Also, do you know about program resources? They are the correct way to deal with this kind of thing.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by oogabooga View Post
    But why would you want to do this anyway?
    You'd want to do it if you're writing a virus that appends its own code and resources to the end of an executable.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. load file to structure
    By nynicue in forum C Programming
    Replies: 18
    Last Post: 08-06-2009, 04:41 PM
  2. how can I load a file into a stuct
    By timgao in forum C Programming
    Replies: 20
    Last Post: 01-21-2007, 12:46 PM
  3. How do I load a file name from string
    By kingpinzs in forum C++ Programming
    Replies: 7
    Last Post: 07-14-2005, 06:49 PM
  4. Load font from *.ttf file
    By Born_2B_Alone in forum Windows Programming
    Replies: 1
    Last Post: 12-04-2004, 04:45 PM
  5. how to load file in C#
    By SuperNewbie in forum C# Programming
    Replies: 1
    Last Post: 07-04-2002, 04:41 AM