Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether two executable binary files are generated from same source code?

For example, I have two C binary executable files. How can I determine whether the two were generated using same source code or not?

like image 563
Toddler Avatar asked Oct 24 '25 03:10

Toddler


1 Answers

In general, this is completely impossible to do.

  • You can generate different binaries from the same source
  • Two identical binaries can be generated from different sources

It is possible to add version information in different ways. However, you can fool all of those methods quite easily if you want.

Here is a short script that might help you. Note that it might have flaws. It's just to show the idea. Don't just copy this and use in production code.

#!/bin/bash 

STR="asm(\".ascii \\\"$(md5sum $1)\\\"\");"
NEWNAME=$1.aux.c
cp $1 $NEWNAME
echo $STR >> $NEWNAME
gcc $NEWNAME

What it does is basically to make sure that the md5sum of the source gets included as a string in the binary. It's gcc specific, and you can read more about the idea here: embed string via header that cannot be optimized away

like image 148
klutt Avatar answered Oct 26 '25 17:10

klutt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!