0
b'7668647866696c654d006900630072006f0073006f00660074002000570069006e0064006f0077007300200036002e0033002e0039003600300030002e003100370033003900360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'

I want to convert this hex string to ascii or readable text. I am getting this block from a system image file.

  • 4
    This looks readable to me. All the letters and numbers are quite legible. – Kevin Apr 09 '15 at 19:25
  • @AliAhmedSahi encoded how? What does it represent? What *should* it look like? – jonrsharpe Apr 09 '15 at 19:28
  • Possible duplicate of http://stackoverflow.com/questions/9641440/convert-from-ascii-string-encoded-in-hex-to-plain-ascii – thodic Apr 09 '15 at 19:28
  • it represents in ascii "vhdxfileM.i.c.r.o.s.o.f.t. .W.i.n.d.o.w.s. .6...3...9.6.0.0...1.7.3.9.6........................................................." – Ali Ahmed Sahi Apr 09 '15 at 19:31

2 Answers2

1
'7668647866696c654d006900630072006f0073006f00660074002000570069006e0064006f0077007300200036002e0033002e0039003600300030002e003100370033003900360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'.decode("hex")

at least in py2x

in 3x

bytes.fromhex(b'7668647866696c654d006900630072006f0073006f00660074002000570069006e0064006f0077007300200036002e0033002e0039003600300030002e003100370033003900360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'.decode("ascii"))
Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • I am using python 3.4 – Ali Ahmed Sahi Apr 09 '15 at 19:30
  • This reveals that the data starts with "vhdxfileM", which may be a useful hint for further processing. – Kevin Apr 09 '15 at 19:32
  • @kevin its an disk image file that i am reading with format VHDX and ascii string says vhdx file Microsoft Windows,But i am getting this converted data using an external tool which is not very helpful for me. – Ali Ahmed Sahi Apr 09 '15 at 19:38
  • @joran Beasley Now its data in this format " b'vhdxfileM\x00i\x00c\x00r\x00o\x00s\x00o\x00f\x00t\x00 \x00W\x00i\x00n\x00d\x00o\x00w\x00s\x00 \x006\x00.\x003\x00.\x009\x006\x000\x000\x00.\x001\x007\x003\x009\x006\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00....and so on" " – Ali Ahmed Sahi Apr 09 '15 at 19:44
  • yes because that is the ASCII representation of the data – Joran Beasley Apr 09 '15 at 19:59
0

Expanding on Joran's answer,

import string
data = bytes.fromhex(b'7668647866696c654d006900630072006f0073006f00660074002000570069006e0064006f0077007300200036002e0033002e0039003600300030002e003100370033003900360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'.decode("ascii"))
print("".join(chr(c) if chr(c) in string.printable else '.' for c in data))

Result:

vhdxfileM.i.c.r.o.s.o.f.t. .W.i.n.d.o.w.s. .6...3...9.6.0.0...1.7.3.9.6.........................................................................................................................................................................................

Note that this won't give you a perfect lossless representation of the data - unreadable characters get replaced with periods. So it's only really suitable if you're searching for textual data.

Kevin
  • 74,910
  • 12
  • 133
  • 166