Program to check itself.

Just starting out? Need help? Post your questions and find answers here.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Program to check itself.

Post by matalog »

Is there a way to get a program to check itself, before successfully working to see if it has been changed fromi its original form in any way? The plan would be for it not to work in the case that it has been altered.

For example, if I wanted to do this to an image, I might just carry out a simple addition of all bytes mod 65536, and then there would be a checksum with assumably a 65536 to 1 chance of working correctly if the program had been altered.

I would have read the bytes of the image one by one, but i'm not sure about how I could get a program to do this to itself. Any ideas?
miso
Enthusiast
Enthusiast
Posts: 491
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Program to check itself.

Post by miso »

I never did such thing, so just guessing:
You can add an empty datasection (filled with $00-s) in the range of your checksum, and later fill it with a real one and recompile. That way the size of the executable won't change. I'm not sure though, where will that data will be placed, but I guess it will be at the end of the exe.

Must be important, or else it does not worth the hassle. (it still will take only one conditional jump to change in the machine code to jump to start when your condition NOT true, so not a real defense, but might be good checking against viruses.)

Another solution can be to add a launcher, that tests your exe, and if ok launches it with a proper program parameter or make a handshake or something.
User avatar
Caronte3D
Addict
Addict
Posts: 1371
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Program to check itself.

Post by Caronte3D »

I ever use a launcher and the procedure: FileFingerprint()
It works very well and detects even a simple bit modification.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: Program to check itself.

Post by BarryG »

matalog wrote: Sun Mar 09, 2025 9:51 pmIs there a way to get a program to check itself, before successfully working to see if it has been changed fromi its original form in any way?
For Windows exes, this works fantastic -> https://www.purebasic.fr/english/viewto ... 98#p559198

The best thing is you don't need to calculate anything, because Windows does it all.
Post Reply