I'm trying to resolve a matryoshka_doll problem. I already solved it by creating a script
using unzip, but know I would like to use binwalk to achieve the same effect. Searching through the binwalk --help I didn't find anything useful, but I could have missed something.
This is the command I'm using: binwalk -Me dolls.jpg
Which gives me a structure like:
./dolls_extracted/doll_2
./dolls_extracted/doll_2_extracted
./dolls_extracted/doll_2_extracted/doll_3
However I want a structure like this:
./doll_2
./doll_3
Can this be done using only binwalk ?
Binwalk does not have an option to extract files recursively to a specific folder, but you can achieve the desired output using a combination of binwalk and other command-line tools.
Here is one way to extract all files recursively to a folder using binwalk:
Run binwalk with the -e option to extract the files:
binwalk -e dolls.jpg
This will create a directory called "_dolls.jpg.extracted" in the current directory, which contains all the extracted files.
Use the find command to recursively move all files to a new folder:
find _dolls.jpg.extracted/ -type f -exec mv {} ./ ;
This will find all files in the "_dolls.jpg.extracted" directory and move them to the current directory. The directory structure will be flattened, so you will have all the files in the same directory.
Remove the empty directories:
find _dolls.jpg.extracted/ -type d -empty -delete
This will find all empty directories in the "_dolls.jpg.extracted" directory and delete them.
Rename the extracted files:
rename 's/./_dolls.jpg.extracted//' ''
This will remove the "_dolls.jpg.extracted/" prefix from the filenames.