• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

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!!!
0
naga1979
Asked:
naga1979
  • 10
  • 7
  • 3
  • +2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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.
0
 
Mark_FreeSoftwareCommented:

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.
0
 
naga1979Author Commented:
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!!!
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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.
0
 
Mark_FreeSoftwareCommented:

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
0
 
JR2003Commented:
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.
0
 
BrownheadCommented:
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.
0
 
naga1979Author Commented:
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
0
 
BrownheadCommented:
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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.  =)
0
 
BrownheadCommented:
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.
0
 
BrownheadCommented:
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
0
 
naga1979Author Commented:
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!!!
0
 
BrownheadCommented:
Course :D. I used a simple method of checking the number of differences between programs with different dates and times. (I just changed my computers date dramatically to test :D). And the numbe was usually like 530 or something... I can't remember, but it was always lower tahn 600, so I made it check to see if there are more than 600 differences, if there are, they ain't identical. Else they are. Anyways, Heres the code for the form that does all the action, I'm sure you can figure out the one that you select the files :D

'//Code\\
'This is the code to a form. There is a TextBox, a Progress Bar, and a Label.
Private Sub Form_Load()
Dim bHold1 As Byte, bHold2 As Byte
Dim iCount As Long
Dim Diff As Long
Me.Visible = True
txtStatus = "Diagnostic started at " & Format(DateTime.Time, "HH:MM:SS AMPM") & vbNewLine
DoEvents

Open frmMain.txtF1 For Random As #1 Len = 1
Open frmMain.txtF2 For Random As #2 Len = 1

If (Abs(LOF(1) - LOF(2)) > 150) Then
    AddStat "File Sizes Are Greatly Different"
    AddStat "Diagnostic Complete at " & Format(DateTime.Time, "HH:MM:SS AMPM")
    AddStat "Result: Files Are Not Identical VB Programs"
End If
Prog.Max = IIf(LOF(1) > LOF(2), LOF(2), LOF(1))
Prog = 0
For iCount = 1 To Prog.Max
    Get #1, iCount, bHold1
    Get #2, iCount, bHold2
    If (bHold1 <> bHold2) Then
        Diff = Diff + 1
        AddStat "Difference found at position " & iCount
    End If
    Prog = iCount
    lblPercent = "Diagnostic Is " & Round((Prog / Prog.Max) * 100) & "% Complete"
    If (Round(iCount / 100) = iCount / 100) Then DoEvents
    If (Diff > 600) Then AddStat ("Max Differences Reached"): Exit For
Next iCount
If (Diff > 600) Then
    AddStat "Diagnostic Complete at " & Format(DateTime.Time, "HH:MM:SS AMPM")
    AddStat "Result: Files ARE NOT Identical VB Programs"
    Prog = Prog.Max
    lblPercent = "Diagnostic Is 100% Complete"
Else
    AddStat "Diagnostic Complete at " & Format(DateTime.Time, "HH:MM:SS AMPM")
    AddStat "Result: Files ARE Identical VB Programs"
    Prog = Prog.Max
    lblPercent = "Diagnostic Is 100% Complete"
End If
Close
End Sub

Private Sub AddStat(ByVal Text As String)
txtStatus = txtStatus & Text & vbNewLine
txtStatus.SelStart = Len(txtStatus)
End Sub
'\\Code//

Happy Learning :D
0
 
naga1979Author Commented:
Thanks Brownhead.

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

Cheers!!!
0
 
BrownheadCommented:
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...
0
 
naga1979Author Commented:
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!!!
0
 
JR2003Commented:
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.
0
 
BrownheadCommented:
could you give me two pairs of exe's from different machines? I don't have VB on 2 computers :(
0
 
naga1979Author Commented:
I can send you by email......ur ID????

Cheers!!!
0
 
BrownheadCommented:
ID? You mean address? brownhead622@hotmail.com
0
 
naga1979Author Commented:
Sent the exe files.....

Cheers!!!
0
 
BrownheadCommented:
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 :?
0
 
BrownheadCommented:
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.
0
 
Mark_FreeSoftwareCommented:

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)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 10
  • 7
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now