Link to home
Start Free TrialLog in
Avatar of naga1979
naga1979

asked on

Comparing VB executables

Experts,

I have a problem. We have huge program library(executables) running in our production box. There is no proper code library maintained for those executables. But we do have a code library which we are not very sure whether it is the source for production executables.

I want to compare the executable with the source code. Is there a way to check this? Or shoud I create executables out of the available source code and compare the 2 executables? If later is the only option, how do I compare the executables?

Please help me with this.

Cheers!!!
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

You could compile the source code and then compare the executables using the "fc.exe" utility with the /b option:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/fc.mspx?mfr=true

I'm not sure what operating systems/configurations have this utility on them already.  It was in "c:\windows\system32" on my WinXP Pro SP2 machine.

that could work, but visual basic is compiling files different every time!,

not only the time is included in the file,
but it looks like some random data from memory is in it too

so you cannot find a 1 on 1 match.
Avatar of naga1979
naga1979

ASKER

Hi..

FC is not working. I am not getting any message after the comparison. Just hexadecimal values and nothing.

So anyway we can compare the exe files???

Cheers!!!
The hexadecimal values are the locations of the differences in the files.

Mark_FreeSoftware is right though.  I compiled the same source code into two different named EXEs and they came up different.

When I just copied the EXE and used FC.exe they came up the as same.

Sorry that didn't work.

ok here is somthing that you could try (can be much work):

create a new project in vb and save it

then compile it (Project1.exe)
now close it
do some stuff (open word or somthing like that)
now open the project again, and compile to Project2.exe

find yourself a texteditor that is capable of comparing files (BINARY ! )
i prefer UltraEdit 32 (not freeware)


now compare those two files (project1 and project2)
(in ultraedit File->Compare and then select the files)

now some window should pop up.
do not close it, but go back to ultraedit, and then click on "File->Compare" again

now select the original exe where it is all about, and the later compiled exe
again compare binary.

i call the now opened window "Compare2" , and the windows with the Project1 and Project2 "Compare1"

select the Compare2 window, and find the first block of differences.
now remember the address, and switch to Compare1
check if there is almost the same block ( you shouldnt look at one byte more or less) that differs

repeat this a few times.


!Note that this will work for the first part of the exe only!



it's then up to you to decide if they differ too much or that they have some minor pieces that equal.




if that's too much work for you, you can also try things like version, author and company.
also check for hard code dates that you could find in the code and in the app.



Good luck,

mark
Can you find a difference in the 2 versions of the source code.
Then test executable so thast it runs the line of code to see if the executable is from source-code1  or source-code2.
Compile the source code, then follow these steps to compare the .EXE with another. If you would like me to create a program that would compare a file with every file in a folder, I'll do so, though it may take awhile and i'm not sure whether your asking for this or the one that compares every file. Anyways, heres the steps:

1. Open Command Promp (Start->Run->Cmd)
2. Type in: Comp "[Name Of First File]" "[Name Of Second File]" /L
3. If the line: "Files Compare OK" appear under what you just typed, they are identical, if anything else appears, then they are not.

Hopefully this helped you.
Brownhead,

I have tested "comp" with known source code as below:

1. I have an exe compiled May 8,2006 named as 1.exe
2. I have recompiled source again today and named as 2.exe. No change in the source that of above one.
3. comp 1.exe 2.exe /L
4. Got the following error though we expect none.

I should not get any mismatch in this case. That's my requirement. Could you help please?

file1 = A
file2 = EB
Compare error at OFFSET D1
file1 = DD
file2 = D0
Compare error at OFFSET D2
file1 = 71
file2 = 5F
Compare error at OFFSET 120
file1 = 23
file2 = F6
Compare error at OFFSET 121
file1 = 5F
file2 = 75
Compare error at OFFSET 16F4
file1 = 80
file2 = 66
Compare error at OFFSET 16F5
file1 = 9
file2 = B9
Compare error at OFFSET 16F6
file1 = FB
file2 = 99
Compare error at OFFSET 16F7
file1 = 6D
file2 = 59
Compare error at OFFSET 16F8
file1 = 17
file2 = F3
10 mismatches - ending compare
I'm pretty sure that when Visual Basic compiles it places some info about the location of the file on you computer, into the actual data... I tested the Comp command extensivley yesterday (before I posted my comment) and in all cases there was never a false positive. I tested by Copying a .EXE (Made in visual basic) and then comparing the two, perfect match. Then I entered the program using a Hex Editor and changed a value.  Perfect Mis-Match, I also tested using a .TXT and both had the word "Taco" in it, perfect match, then I changed one to "Taso", mismatch. So its probably a compiling problem Perhaps you could try testing it again and see if the same mismatches are encountered. Then you could check to see if any mismatches BUT those are present, and that way you could check. BTW, a different program has a VERY little chance of being the same size, at which point the Comp command will return: "Files not the same size" or something like that... Actually, come to think of it. You could go into the properties of each of the .EXE's and check the size to the size of your compiled one. Then run a compare with one thats the same to see how many mismatches there are, if theres over 50 then there most likely different. Hope this helped :D
Well of course copying an Exe will give a perfect match when you use the Comp or the FC utilities.

Both Mark_FreeSoftware and myself have already posted that compiling the EXACT same source code gives two different executables...read thru the whole post please.  =)
Oops, hehe, that was my bad. I guess i'll just make a program that will compare them for you... I should have it done in an hour or so.
K, i'm done. Just pick the two files, wait a little while, and then when its done, look at the last line of the textbox. It'll say either: "Result: Files ARE Identical VB Programs" meaning that there identical, or "Result: Files ARE NOT Identical VB Programs" meaning they arn't (Duh ;), lol) The link to the upload site is below, hope this works for you, if it doesn't... I guess I'll try again, but I put it through quite a bit of testing and it never seemed to fail.

http://www.geocities.com/sullycorporation/VBBasicCompare.zip
Brownhead,

I tested with one exe, it seems working. Good job. Can you please pass me on the code so that I can also learn.

I will do more testing tomorrow. Thanks a lot.

Cheers!!!
ASKER CERTIFIED SOLUTION
Avatar of Brownhead
Brownhead

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Brownhead.

Is there a way to find out what is the difference between the exes???

Cheers!!!
What do you mean? Are you talking about trying to find out the code of the EXE's, because that is very close to impossible at present-day, the best compiler can only decompile a few very basic functions, and not very well...
Brownhead,

I am having another problem now. Your program is showing differences when the same code is compiled in two different machines. How to handle this? I want to compare exes created in two different machines.

Cheers!!!
Does the vbp have a version number in the project properties?
If so if you right click on the exe and go to properies you can see the version information.
If someone has incremented the version number when they released it you should be able to see if it is the same version.
could you give me two pairs of exe's from different machines? I don't have VB on 2 computers :(
I can send you by email......ur ID????

Cheers!!!
ID? You mean address? brownhead622@hotmail.com
Sent the exe files.....

Cheers!!!
WOrking on it now... and btw, what are these things? I ran one of them and it closes itself, and makes a clone or something in the My Documents folder :?
Crud... I'm sorry, this is near impossible. The only way I could see this working is if I made a decompiler... and fat chance of me figuring that out, lol. Sorry :\. The differences are too great to be calculated without false positives. And false negatives for that matter. Comparing the 2 brought up 30000 differences, comparing with an image thats near the same size brought up 10000. Compared with a different, greatly differenciated size (big word :D:D, though not sure if I'm using it right, lol), .EXE, brought up 50,000 differences. I then compared it using a hex editor and ran a compare with it and then looked at the differences searching for a possible offset that might correct the problem, no luck. Alot of the data was completly different. I guess you'll just have to settle with manual compare with decompiler, or only .EXE on your own machine.

here is somthing more you can try:

find Numega Smartcheck (floating around the internet)

run your program trough that, and you can examin what it is doing.

(it is running somewhat slower, but most of the time you don't notice the difference)