[ale] Binary Matching

James Sumners james.sumners at gmail.com
Mon Jun 6 10:37:26 EDT 2005


Here is one way to do it (off the top of my head):

<?php
$initial_offset = 10; // 10 bytes
$bytes_to_read = 500; // 500 bytes
$first_file = '/some/file.bin';
$files_to_read = array('/file/one.bin', '/file/two.bin', '/file/three.bin');

$f = fopen($first_file, 'r');
fseek($f, $initial_offset);
$data = fread($f, $bytes_to_read);
fclose($f);

foreach ($files_to_read as $x) {
     $f = fopen($x, 'r');
     $cmp_data = fread($f, $bytes_to_read);
     if ( $data == $cmp_data ) {
          printf("{$first_file} matches some data in {$x}.\n");
     }
     fclose($f);
}
?>

On 6/6/05, Mister Anonymous <atlantalinuxenthusiast at gmail.com> wrote:
> I need to do some binary matching across many files and was wanting to
> get some recommendations on how to do it.  I would like to be able to
> grab a section of binary data from one file (approximately 500
> continuous bytes) and check and see if that is included in other
> binary files.  Any recommendations on an easy way to extract the
> initial 500 bytes (assume I would like to do it from some particular
> offset in the file) and then search for that data in the other file?
> 
> I am afraid that perl might be the best way to do this, but I am not
> that much of a perl hacker.  If there is an easy way to do it using
> python or a shell script, that would be preferable.
> 
> Thanks.
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
> 


-- 
James Sumners
http://james.roomfullofmirrors.com/

"All governments suffer a recurring problem: Power attracts
pathological personalities. It is not that power corrupts but that it
is magnetic to the corruptible. Such people have a tendency to become
drunk on violence, a condition to which they are quickly addicted."

Missionaria Protectiva, Text QIV (decto)
CH:D 59



More information about the Ale mailing list