Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] binary search of binary data
- Date: Mon, 27 Dec 2004 23:56:52 +0900
- From: Edward Wright <edw@example.com>
- Subject: Re: [tlug] binary search of binary data
- References: <20041225205936.GA2199@example.com> <87llbjj4xw.fsf@example.com>
- User-agent: Mutt/1.4i
Stephen, HUGE Thank You!! While I couldn't use your "guess", it pointed me in the right direction. If details interest, see below. Thanks, Ed On Mon, Dec 27, 2004 at 09:34:03PM +0900, Stephen J. Turnbull wrote: > >>>>> "Edward" == Edward Wright <edw@example.com> writes: > > Edward> Feels like there should be a simple answer to this, but it > Edward> eludes me. > > It depends on what you want to do with the bytes, and how big the file > is. Here's my guess Truth be known, I had an "accident". A ~40M file was truncated to 0 length. I promptly unmounted the partition and saved it off as a file. That is the file I want to seek in - it's about 750M. I have manually located a few blocks that contain consecutive data. If I can find an "indirect block" in the file system, I can recover a big chunk of data at once. That's what I want to seek. > > $ python > >>> infile = open (FILE, "r") > >>> s = infile.readlines() > >>> r = compile ("\xec\xa5\xc1\x01") > >>> m = r.search (s, 0) > >>> while m: > >>> print "match at %d\n" % m.start() > >>> m = r.search (s, m.end()) > >>> > >>> ^D > $ > The file is too big to slurp and I don't know enough (any?) python to modify the code. I did something similar in perl. This works. It returns the block(s) in which the match was found which is what I need. #!/usr/bin/perl my $tmp; my $rawbytes = "f1250000f2250000"; $tmp = length $rawbytes; my $seek = pack "H$tmp", $rawbytes; $INFILE = "/mnt/hda3/recover_src/sda2"; open INFILE, "<$INFILE"; my $i = 0; my $buf; while (read INFILE, $buf, 4096){ if ( $buf =~ $seek ){ print "Block: $i matched\n"; } $i++; } close INFILE; Comment: there oughta be a "binary" grep.
- Follow-Ups:
- Re: [tlug] binary search of binary data
- From: Stephen J. Turnbull
- References:
- [tlug] binary search of binary data
- From: Edward Wright
- Re: [tlug] binary search of binary data
- From: Stephen J. Turnbull
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] binary search of binary data
- Next by Date: [tlug] software patents in japan
- Previous by thread: Re: [tlug] binary search of binary data
- Next by thread: Re: [tlug] binary search of binary data
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links