Re: Application Reading Itself






"ReaperUnreal" <reaperunreal@xxxxxxxxx> wrote in message
news:1151688932.914912.104440@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm writing an application that will store some hidden and encrypted
data at the end of the file, however, I'm having trouble getting the
application to read itself. Here's the code I have:

FILE *myself = NULL;
if(!(myself = fopen("AppReader.exe", "rb")))
{
fprintf(stderr, "Cannot open file to read.");
}
fseek(myself, -8, SEEK_END);
char buffer[10];
fread(buffer, 1, 8, myself);
buffer[8] = '\0';
printf("String: %s\n", buffer);
fclose(myself);

I realize that this isn't exactly the safest application, and that I
have no real error measures in place, however this is just a test to
see if it will work.

So the question is, does anyone know how to get it to work?

argv[0] normally contains the name of the executable, often a path to it.

The OS may allow you to open this as a regular binary file. However a lot
won't because of the obvious security hazards.
The portable way to include data in your executable is to include it as a C
array. However you cannot guarantee being able to edit this data after
compilation - some systems will let you do so, others won't.

There are also many platform specific ways of including data objects in C
programs.
--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $7.20 paper, available www.lulu.com/bgy1mm


.



Relevant Pages

  • Re: emailing file that has links
    ... That is too much trouble. ... and then re-email out of office. ... >> always tell people I email files to to do not update ... >> This should open file without errors. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: How to count lines in a file that meet criteria?
    ... > 3) open file; ... I think I'm having trouble with #4 ... is this the best way to parse the array line by line? ...
    (comp.lang.php)
  • Re: Loop within Loop
    ... open FILE, '<', $File or die "Could not open ... If, however, you want everything in an Array of Arrays then: ...
    (perl.beginners)
  • Re: Pulling out lines of text from a text file
    ... chomp; ... open FILE, "$file"; ... # @lines would be a better name for the array though, ... file is going to be large), it may be better to loop over the file until ...
    (comp.lang.perl.misc)
  • Re: reading data files with headers and columns
    ... Well only initializes the array as empty, if you want to initialize it ... I don't know what your header looks like so it is difficult to say how to ... # open file in read mode ...
    (comp.lang.ruby)