It is currently Thu May 24, 2018 3:39 pm

Splitting a large file with a HEX key

All times are UTC - 6 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Thu Jul 18, 2013 10:38 am   

Joined: Thu Jul 18, 2013 10:13 am
Posts: 1
Hi all,

I googled a script, which extracts a piece of binary file and saving the chunk as a new file:
xxd -c1 -p file |
  awk -v b="ffd8ffd0" -v e="aaffd9" '
    found == 1 {
      print $0
      str = str $0
      if (str == e) {found = 0; exit}
      if (length(str) == length(e)) str = substr(str, 3)}
    found == 0 {
      str = str $0
      if (str == b) {found = 1; print str; str = ""}
      if (length(str) == length(b)) str = substr(str, 3)}
    END{ exit found }' |
  xxd -r -p > new_file
test ${PIPESTATUS[1]} -eq 0 || rm new_file

It actually works very well exept the last line (which appears in bash separately as next command waiting to be executed), extracting one file in between the given Hex codes including. It is also very fast, comparing other methods I tried.
What I need to do and struggle with, is to: Loop this to get all the chunks from the image file I want to split. In my case, I also need to use same hex code for start and end (so using a start of a second JPEG file as the indication, where the previous ends). I'm actually using those "strings":
awk -v b="ffd8ffe1fffe4578696600004d4d002a" -v e="ffd8ffe1fffe4578696600004d4d002a"
This is because I found out, that the JPEG files I'm extracting don't end with "aaffd9" codes, but only "ffd9" is constant, but not enough to identify end (you get false ends from within the file).
I have a good knowledge of VB, but bash scripting is way off my experience. Could you please point me to what to do? I'd probably get the loop, but I have no idea how to shift start back few bits in bash...

As you may guessed, I'm trying to recover JPEG files from a 1,9GB image file created from a broken SD card. I succeeded with the same method 11 years ago and I hope to be lucky again :-).


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: Google [Bot] and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group