Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract text portion of a binary file in linux/bash?

Tags:

linux

grep

bash

sed

I have a binary file. If I open it with vi, it shows sequences of human-readable text and binary characters. What is the best way to extract the human-readable portion only using bash?

I was thinking, maybe we can do this over a grep or sed pattern?

$ cat file1.bin | grep '????'  > newfile.txt
like image 431
RonPringadi Avatar asked Aug 08 '16 15:08

RonPringadi


2 Answers

If you're on a Debian distro, you can probably get radare2 (r2) with just sudo apt install radare2.

After you've installed r2, either with apt, some other installer on some other distro, or by following an online guide, you can use rabin2 to extract just the text part of a binary:

$ rabin2 -z your_binary

This is often "better" than just strings because it outputs just the useful .data section of the binary. Stuff outside that section isn't always very useful.

like image 188
ChocolateOverflow Avatar answered Oct 20 '22 19:10

ChocolateOverflow


Use the strings utility - that's exactly what it's designed for.

like image 45
Marc B Avatar answered Oct 20 '22 17:10

Marc B