Jump to content











Photo
- - - - -

[Batch] Binary File Comparison


  • Please log in to reply
7 replies to this topic

#1 AceInfinity

AceInfinity

    Frequent Member

  • Team Reboot
  • 222 posts
  • Location:Canada
  • Interests:Windows Security, Programming, Customizing & Crash Dump Analysis.
  •  
    Canada

Posted 07 January 2012 - 08:01 AM

Here's a recent script I created to compare binary data between a group of selected files inputted as (command line) args to the batch file itself. The handy thing about this, is if you have lots of files that you want to compare, you can just simply drag and drop them over the base batch file itself in explorer.

Note: All files get compared with the file identified as %1 (the first parameter). So a key thing to note if you're dragging and dropping as your method, is to note that the file you grab to drag the group of selected files over the batch file is the file that gets inputted as %1. This will now be the file that all the other dragged files get compared to by binary streams.

@echo off

title Binary File Compare - Created by AceInfinity

set /a args=0 && for %%a in (%*) do ( set /a args+=1 )

if %args% lss 2 call :noArgs



if not exist "bin_output" md "bin_output"

(

echo.----------------------------------------------------------------

echo.    Binary File Comparison Script - Created by AceInfinity

echo.              Copyright Tech.Reboot.Pro 2012

echo.----------------------------------------------------------------

echo.

) > "bin_outputresults.txt"



echo Processing Binary Data...



for %%a in (%*) do (

	if not %%a==%1 ( 

		fc /b %1 %%a >> "bin_outputresults.txt"

	)

)

exit



:noArgs

echo No other input files as arguments could be found... 

echo Please specify at least 2 input files to be used for comparison 

echo. && pause

exit

Should support the following:
MS-DOS 3.3x and above
Windows 95
Windows 98
Windows ME
Windows NT
Windows 2000
Windows XP
Windows Vista
Windows 7
Enjoy friends :)

#2 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 10,862 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 07 January 2012 - 09:54 AM

Should support the following:

MS-DOS 3.3x and above
Windows 95
Windows 98
Windows ME

Windows NT
Windows 2000
Windows XP
Windows Vista
Windows 7

Enjoy friends :)

Are you sure? (I mean have you tesed the batch on the bolded OSes? :unsure:)
The lss operator has been introduced in the NT family, if I recall correctly. :dubbio:
http://www.robvanderwoude.com/ntif.php
(and is only available if Command Extensions is enabled):

Command Extensions
Command extensions enable extra features in NT shells.

By default command extensions are enabled. However, to be absolutely sure that they are, either use SETLOCAL ENABLEEXTENSIONS within your NT shell scripts (batch files) or execute those scripts using CMD /X.

Likewise, you may disable command extensions using SETLOCAL DISABLEEXTENSIONS or CMD /Y.

Read my SETLOCAL page if you intend to use SETLOCAL extension switches.




:cheers:
Wonko

#3 Holmes.Sherlock

Holmes.Sherlock

    Gold Member

  • Team Reboot
  • 1,427 posts
  • Location:Chennai, India
  •  
    India

Posted 07 January 2012 - 12:09 PM


Should support the following:

Wonko, that's why it is a "should", not a "must". ;)

#4 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 10,862 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 07 January 2012 - 12:26 PM

Wonko, that's why it is a "should", not a "must". ;)

A "must" would be even more senseless, I was asking IF the "should" was a "will" or "does", that's why I asked whether the "should" was intended as:
  • a wild guess
  • an educated guess
  • a senseless statement
  • result of (possibly accurate and exhaustive) testing

Please choose one.

Compare with these four carpenter's statements:

Two planks connected together by nailing cannot be separated easily, nailing should work with concrete slabs too.(never tried it, though)

Two planks connected together by nailing cannot be separated easily, nailing should work with concrete slabs too.(I tried it in some cases and it worked)

Two planks connected together by nailing cannot be separated easily, nailing must work with concrete slabs too.(I tried it on wooden planks only, though - no logical connection)

Two planks connected together by nailing cannot be separated easily, nailing will work with concrete slabs too.[ (I tested this extensively and the method never failed me)


:cheers:
Wonko

#5 Holmes.Sherlock

Holmes.Sherlock

    Gold Member

  • Team Reboot
  • 1,427 posts
  • Location:Chennai, India
  •  
    India

Posted 07 January 2012 - 12:28 PM

Makes me remember of my class V grammar class!!!

#6 AceInfinity

AceInfinity

    Frequent Member

  • Team Reboot
  • 222 posts
  • Location:Canada
  • Interests:Windows Security, Programming, Customizing & Crash Dump Analysis.
  •  
    Canada

Posted 07 January 2012 - 10:14 PM

Ahh, I do know that fc is supported on the listed Windows family though. But it is working on Windows NT 6.1 (Windows 7) for me. I developed and tested on Windows 7. I haven't heard of where the origin of lss came into play though, so you are probably right

#7 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 10,862 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 08 January 2012 - 10:43 AM

Ahh, I do know that fc is supported on the listed Windows family though. But it is working on Windows NT 6.1 (Windows 7) for me. I developed and tested on Windows 7. I haven't heard of where the origin of lss came into play though, so you are probably right

Yep :), and also SET /A was added to the NT family.
FC in itself should be OK. :)
Since both the "suspects" are in the command line parameters check:
set /a args=0 && for %%a in (%*) do ( set /a args+=1 )

if %args% lss 2 call :noArgs

by removing it, it may work on erlier systems as well. :thumbsup:

:cheers:
Wonko

#8 AceInfinity

AceInfinity

    Frequent Member

  • Team Reboot
  • 222 posts
  • Location:Canada
  • Interests:Windows Security, Programming, Customizing & Crash Dump Analysis.
  •  
    Canada

Posted 08 January 2012 - 11:10 AM

That's just my check for input params, so as long as it's not there, it just shows the errors, that's just my simplistic way of dealing with the errors for users that don't understand batch lol, but true it could be reduced down to just the script with the functional loop.

Edit: Basically just this lol...
for %%a in (%*) do (

	if not %%a==%1 (

		fc /b %1 %%a >> "results.txt"

	)

)

careless about @echo off or exit, becuase there's nothing that can interfere once the script has looped through. It'll end regardless.

• Removed "bin_output" dir though so it doesn't have to be created in the case that it doesn't exist.