Convert binary to text Perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert binary to text Perl script
# 8  
Old 07-07-2012
@Ophiuchus
This script is designed in a way that it converts all the characters to either binary or to text. By looking into the code, it uses functions such as
Code:
 pack & unpack

You can look into PACK & UNPACK.

Thanks
# 9  
Old 07-07-2012
Quote:
Originally Posted by Ophiuchus
If I convert some text file to binary with this script the output is 0s and 1s and If I convert the generated binary to text, the conversion is correct.

The issue is the file I want to convert, with this script doesn't show correctly converted to text.

Do you know another script or command to get this?

Thanks again
I suspect you're confused about what those scripts do. What those scripts refer to as "binary" is actually an ascii text string of ones and zeroes. They're simply converting ascii text input into different ascii text output. Initially, each byte is an ascii character (perhaps a letter, a digit, some punctuation). The output converts each of those ascii bytes into 8 ascii bytes, where in the output the only possible value for a byte is 48 (ascii code in decimal for the digit 0) and 49 (ascii code in decimal value for the digit 1).

If you have a binary file (a file which may contain any byte value in any sequence it sees fit), and you don't know the format, what are you trying to achieve with a conversion? What is your goal? You can't expect some random set of bytes in a binary file to be convertible to meaningful text. Are you simply trying to extract embedded strings from an executable? If so, try the strings command.

Regards,
Alister
# 10  
Old 07-08-2012
od is another good command for examining the contents of binary files. try -x for hex representation -c for character and -d for decimal.

Code:
$ od -x /usr/bin/ls | head
0000000 5a4d 0090 0003 0000 0004 0000 ffff 0000
0000020 00b8 0000 0000 0000 0040 0000 0000 0000
0000040 0000 0000 0000 0000 0000 0000 0000 0000
0000060 0000 0000 0000 0000 0000 0000 0080 0000
0000100 1f0e 0eba b400 cd09 b821 4c01 21cd 6854
0000120 7369 7020 6f72 7267 6d61 6320 6e61 6f6e
0000140 2074 6562 7220 6e75 6920 206e 4f44 2053
0000160 6f6d 6564 0d2e 0a0d 0024 0000 0000 0000
0000200 4550 0000 014c 0005 dcb8 4f2f 8e00 0001
0000220 0000 0000 00e0 032f 010b 1602 3000 0001

Code:
$ od -c /usr/bin/ls | head
0000000   M   Z 220  \0 003  \0  \0  \0 004  \0  \0  \0 377 377  \0  \0
0000020 270  \0  \0  \0  \0  \0  \0  \0   @  \0  \0  \0  \0  \0  \0  \0
0000040  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000060  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0 200  \0  \0  \0
0000100 016 037 272 016  \0 264  \t 315   ! 270 001   L 315   !   T   h
0000120   i   s       p   r   o   g   r   a   m       c   a   n   n   o
0000140   t       b   e       r   u   n       i   n       D   O   S    
0000160   m   o   d   e   .  \r  \r  \n   $  \0  \0  \0  \0  \0  \0  \0
0000200   P   E  \0  \0   L 001 005  \0 270 334   /   O  \0 216 001  \0
0000220  \0  \0  \0  \0 340  \0   / 003  \v 001 002 026  \0   0 001  \0

# 11  
Old 07-13-2012
Hello to all,

Thank you fo your comments I'll try to check my data with your suggestions and try to understand the decoded part.

Thanks for help so far really.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Want to convert an expect script to binary in Linux

Does anyone know how to convert an expect script to binary in linux?. (3 Replies)
Discussion started by: John Wilson
3 Replies

2. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

3. Shell Programming and Scripting

convert shell script into a binary executable

Hello every one, i want to convert my shell script into a binary executable a .exe file , is it possible to do that if so are there any tools . Would the script take off when the arguments are parsed. Thanks Venu (13 Replies)
Discussion started by: venu
13 Replies

4. Shell Programming and Scripting

Perl program to convert PDF to text/CSV

Please suggest ways to easily convert pdf to text in perl only on windows (no other tools can be downloaded) Here is what I have been doing : using a module CAM::PDF to extract data. But it shows everything in messy format :wall: But this module is the only one working with the pdf... (0 Replies)
Discussion started by: chakrapani
0 Replies

5. AIX

Convert clear text into binary

Hi I need to display the binary text of an clearn text which is sent as input to the shell script (c shell); ex: I will pass "HELLO" as input, and i should get the binary format of the text Thanks in advance Mohan (1 Reply)
Discussion started by: mKarri
1 Replies

6. Shell Programming and Scripting

Is it possible to convert text file to html table using perl

Hi, I have a text file say file1 having data like ABC c:/hm/new1 Dir DEF d:/ner/d sd ...... So i want to make a table from this text file, is it possible to do it using perl. Thanks in advance Sarbjit (1 Reply)
Discussion started by: sarbjit
1 Replies

7. Shell Programming and Scripting

Is there any script which convert binary file to CSV format

Dear guys; I have a binary file and I need to convert its data to csv format ...appreciating your help. Best Regards (14 Replies)
Discussion started by: ahmad.diab
14 Replies

8. Shell Programming and Scripting

convert binary file into text file

im looking for anothr way to convert binary file into text file im using old solaris version (exatcly like xxd -r) thanks (2 Replies)
Discussion started by: modcan
2 Replies

9. Programming

trying to convert binary data to text using C++

i hav tried to convert binary 2D data into text using binreader and writing into text file using streamwriter. i use ReadSingle() function to convert from binary to ascii, although it works good in 1D data but not in more dimensions. the kind of values i get are -1.265369923E+038 and like ... (2 Replies)
Discussion started by: geet
2 Replies

10. UNIX for Dummies Questions & Answers

How to convert binary Unix file to text

Hi all, I have a print control file (dflt) for Oracle which is in binary. As I am going to develope an application in Window environment, I would like to reference the dflt file. But it is in binary format and I cannot access it. Anyone can suggest me how to convert the file into text or... (5 Replies)
Discussion started by: user12345
5 Replies
Login or Register to Ask a Question