how to read the executable that is running?

Everything else that doesn't fall into one of the other PB categories.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Hi,

Suppouse that i append some file to my executable and want it to run and read itself to found the start of the data and then read it and create a separate file.
Using OpenFile it was impossible to read it, is there someway?

Thanks in advance

Best Regards

Ricardo

Dont cry for me Argentina...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ebs.

Ricardo,

I'm not sure if it's the most elegant way, but I have done this by copying the executable file to a new file (use CopyFile()) and then reading the new copy of the file. You should delete the copy when your program ends.

Regards,
Eric
Originally posted by ricardo

Hi,

Suppouse that i append some file to my executable and want it to run and read itself to found the start of the data and then read it and create a separate file.
Using OpenFile it was impossible to read it, is there someway?

Thanks in advance

Best Regards

Ricardo

Dont cry for me Argentina...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

Try ReadFile(). The reason OpenFile() is not working is because it tries to open the file with both reading and writing abilities, this is not allowed on a file that is currently running i think.

I haven't tried myself but i think it's worth a try with the ReadFile() command...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Pupil you are right!!

With ReadFile it works : )


Best Regards

Ricardo

Dont cry for me Argentina...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Suppouse that i append some file to my executable and want it to
> run and read itself to found the start of the data and then read it
> and create a separate file.

Do you mean something like this?

viewtopic.php?t=3558
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by geoff.

I have used access to the executable file for quite the opposite reason, to stop anyone appending anything (eg a virus) to the executable.

The first time the executable runs it replaces a dummy string with checksums and other data. When the executable is subsequently run it will abort if any changes have been made that effect these checks.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TheBeck.

sorry, but most viri will have already done the nasty by then.
I have used access to the executable file for quite the opposite reason, to stop anyone appending anything (eg a virus) to the executable.

The first time the executable runs it replaces a dummy string with checksums and other data. When the executable is subsequently run it will abort if any changes have been made that effect these checks.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by geoff.

Sorry, I didn't make myself clear. The idea is not to make a file that can't contain a virus, that's impossible.

The idea is to create a working program that can't contain extra Trojan code. So if the executable does everything it is supposed to do then you know that it doesn't also contain extra code doing something nasty.

But you're right, it doesn't make the executable safe to run.

My idea was to run the program once to add the checks, then distribute the code with the checks. I was worried that someone might add something to the executable that would be undetectable and I would get the credit.

I suppose it's possible that someone could replace the less important parts of my code with virus code and rewrite my checks so that everything seemed to work OK. But to do that you would have to understand the checks in the executable because they are integrated with the true function of the program.

So if the program does what it is supposed to, then you don't have to worry that it also has Trojan code doing something extra.

Ok it's not perfect, but if you don't do something, its as easy as hell for someone to add to your code just by changing a machine code jump instruction, and the program still has your name on it!

Geoff (Paranoid)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TronDoc.
Originally posted by geoff

I don't think there's anything wrong with an executable containing a DATA section which can be read by itself. I've done that in the past when I programmed for DOS. I am curious why the topic:
viewtopic.php?t=3558">http://forums.pur ... om/theWRAP
It's limited to including 200 files for the registered version and only 17 for the trial version but it "only costs a buck" (DollarWareâ„¢). {I'm not pushing a product here just providing info about a programmer's tool as I've seen elsewhere on this forum so I hope it's O.K.}

elecTRONics DOCtor
{registeredPB}P150 32Mb w98/DOS/Linux NO DirX NO IE :wink:
Post Reply