Extracting “plaintext” header from HEX file using

2019-06-10 10:12发布

Have a file that appears to have plaintext headers in them that I would like to extract and convert to plaintext.

Using HEXedit, this is what I'm seeing, which is in a file:

3a40 - 31 65 33 38 00 00 00 00 00 00 00 00 00 00 00 00 - 1e38............
3a50 - 00 00 00 00 00 00 00 00 00 00 0a 00 74 00 65 00 - ............t.e.
3a60 - 78 00 74 00 2f 00 61 00 73 00 63 00 69 00 69 00 - x.t./.a.s.c.i.i.
3a70 - 00 00 18 00 61 00 66 00 66 00 79 00 6d 00 65 00 - ....a.f.f.y.m.e
3a80 - 74 00 72 00 69 00 78 00 2d 00 61 00 72 00 72 00 - t.r.i.x.-.a.r.r
3a90 - 61 00 79 00 2d 00 62 00 61 00 72 00 63 00 6f 00 - a.y.-.b.a.r.c.o.
3aa0 - 64 00 65 00 00 00 64 00 40 00 35 00 32 00 30 00 - d.e...d.@.5.2.0.
3ab0 - 38 00 32 00 36 00 30 00 30 00 39 00 31 00 30 00 - 8.2.6.0.0.9.1.0.
3ac0 - 37 00 30 00 36 00 31 00 31 00 31 00 38 00 31 00 - 7.0.6.1.1.1.8.1.
3ad0 - 31 00 34 00 31 00 32 00 31 00 33 00 34 00 35 00 - 1.4.1.2.1.3.4.5.
3ae0 - 35 00 30 00 39 00 38 00 39 00 00 00 00 00 00 00 - 5.0.9.8.9.......
3af0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 - ................
3b00 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 - ................

and this is the output I'd like to get:

text/ascii  affymetrix-array-barcode d@52082600910706111811412134550989

3条回答
Evening l夕情丶
2楼-- · 2019-06-10 10:54

A perl solution might be interesting, but wouldn't the unix strings command give you the plaintext portion of the file?

查看更多
ゆ 、 Hurt°
3楼-- · 2019-06-10 11:05

Granted, I'm no wiz, but this does the job if all your files look very similar to the one you just posted:

use strict;
open FILE, 'file.dat';
binmode FILE;
my ($chunk, $buf, $n);
seek FILE, 28, 0;
while (($n=read FILE, $chunk, 16)) { $buf .= $chunk; }
my @s=split(/\0\0/, $buf, 4);
print "$s[0] $s[1] $s[2]\n";
close (FILE);
查看更多
放我归山
4楼-- · 2019-06-10 11:09

Try with the iconv command. Something like this should work:

tail -c +6 input.txt | iconv -f UTF16 -t ASCII >output.txt

Then split on the null bytes.

查看更多
登录 后发表回答