Re: Application Reading Itself
- From: "Malcolm" <regniztar@xxxxxxxxxxxxxx>
- Date: Fri, 30 Jun 2006 20:36:06 +0100
"ReaperUnreal" <reaperunreal@xxxxxxxxx> wrote in message
news:1151688932.914912.104440@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm writing an application that will store some hidden and encryptedargv[0] normally contains the name of the executable, often a path to it.
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?
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
.
- References:
- Application Reading Itself
- From: ReaperUnreal
- Application Reading Itself
- Prev by Date: Re: Need to implement strdup, strnicmp and stricmp
- Next by Date: Re: doubts
- Previous by thread: Re: Application Reading Itself
- Next by thread: Choosing function parameter types - pointers or objects?
- Index(es):
Relevant Pages
|