1

Temat: Skrypt zmieniający układ danych ASCII lub HEX

Mam dane binarne - plik 210 bajtów ale w edytorze hex są one nieczytelne tzn. ciężko je interpretować. Aby były zrozumiałe trzeba je skopiować do pliku tekstowego i ułożyć w takiej formie, najlepiej oddzielone spacjami:

 85 83 F2 F6 82
 85 80 F6 80 88 F3 F6 82
 
 F0 F6 88 86 F6 82
 F2 F6 83 88 F6 82
 F0 F6 83 F3 F6 82
 F0 F6 83 F5 F6 82
 F0 F6 83 F3 F6 82
 F0 F6 83 F5 F6 82
 F5 F6 83 88 F6 82
 F0 F6 83 F3 F6 82
 
 F0 F6 83 F5 F6 82
 F0 F6 88 84 F6 82
 F0 F6 88 86 F6 82
 F2 F6 88 82 F6 82
 F0 F6 88 84 F6 82
 F0 F6 88 86 F6 82
 F0 F6 88 84 F6 82
 F0 F6 88 86 F6 82
 
 F2 F6 83 88 F6 82
 F0 F6 88 84 F6 82
 F0 F6 83 F5 F6 82
 F0 F6 88 84 F6 82
 F0 F6 83 F5 F6 82
 F5 F6 83 88 F6 82
 F0 F6 83 F3 F6 82
 F0 F6 83 F5 F6 82
 
 F0 F6 88 84 F6 82
 F0 F6 83 F5 F6 82
 F5 F6 88 82 F6 82
 F0 F6 83 F2 F6 82
 F0 F6 88 86 F6 82
 F0 F6 88 84 F6 82
 F0 F6 88 86 F6 82
 F0 F6 88 84 F6 82
 
 F0 F6 F4 87 82

Trochę jest z tym zabawy aby robić to ręcznie dlatego potrzebuję jakiś skrypt, który to zautomatyzuje.

2

Odp: Skrypt zmieniający układ danych ASCII lub HEX

Zwykły hexdump?

hexdump -C /tmp/plik 
00000000  3d 7e 7e 20 78 89 22 ad  a9 f8 78 f4 19 91 5a 79  |=~~ x."...x...Zy|
00000010  37 0a 54 65 ad 7e 4e 1b  e1 a6 38 2f 65 44 0f 31  |7.Te.~N...8/eD.1|
00000020  15 7c 38 23 b7 25 8c 90  3b a3 d2 50 57 ee e7 5e  |.|8#.%..;..PW..^|
00000030  d9 7d fd d7 e0 d9 22 eb  2b 76 15 af dd a7 bd 70  |.}....".+v.....p|
00000040  a9 b4 7c 70 cd 61 26 58  95 4d ad 7b 31 4a 94 22  |..|p.a&X.M.{1J."|
00000050  7e 1e 25 23 a2 80 3e 11  04 6d 8a 46 d0 8c 39 11  |~.%#..>..m.F..9.|
00000060  c4 8a 7f 3a 9d 3f 07 2a  85 9e e7 9c 3e 8b 77 8f  |...:.?.*....>.w.|
00000070  b8 75 e9 c1 de 63 82 d1  3b 44 f6 02 09 63 49 55  |.u...c..;D...cIU|
00000080  35 8e 36 93 82 dd f3 f7  7f 26 dc 2b d7 30 0c 7d  |5.6......&.+.0.}|
00000090  9c 46 e2 fc f8 ce f2 66  d9 ca 87 6f 04 6c fb e5  |.F.....f...o.l..|
000000a0  ab 4c 6a 85 6d 2f 3f ef  80 0c eb a5 f1 bf ba a0  |.Lj.m/?.........|
000000b0  5d 2e e6 87 e8 fe 15 8a  30 cf c0 7c d7 74 ac 1f  |].......0..|.t..|
000000c0  9a e9 17 48 dc b4 4a e9  7b ab 0d 2b 41 d9 66 27  |...H..J.{..+A.f'|
000000d0  0e 41                                             |.A|
000000d2
Masz niepotrzebny router, uszkodzony czy nie - chętnie przygarnę go.

3

Odp: Skrypt zmieniający układ danych ASCII lub HEX

Cezary napisał/a:

Zwykły hexdump?

Źle mnie zrozumiałeś. Dane muszą być ułożone tak jak pokazałem w poprzednim poście w sekcji code - bo tylko wtedy da się wywnioskować co one przedstawiają. Mam kilka plików po 210 bajtów i potrzebuję je porównać wzrokowo czym się różnią i np. widać iż wartość F6 w czterech sekcjach jest taka sama w tym samym miejscu (druga i piąta kolumna)

4

Odp: Skrypt zmieniający układ danych ASCII lub HEX

To ty wiesz jak je grupować, nie napisałeś jak i po czym ma być grupowane. Hexdump pokazał Ci je hexach, więc teraz pogrupuj sobie skryptem tak jak wiesz jak to powinno być,np. przez awk

Masz niepotrzebny router, uszkodzony czy nie - chętnie przygarnę go.

5

Odp: Skrypt zmieniający układ danych ASCII lub HEX

Masz:

hexdump -C /tmp/plik | awk '{
if(NR ==1) {printf "%s %s %s %s %s\n%s %s %s %s %s %s %s %s\n\n%s %s %s ", $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17}
if(NR ==2) {printf "%s %s %s\n%s %s %s %s %s %s\n%s %s %s %s %s %s\n%s ", $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17}
if(NR ==3) {printf "%s %s %s %s %s\n%s %s %s %s %s %s\n%s %s %s %s %s ", $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17}
if(NR ==4) {printf "%s\n%s %s %s %s %s %s\n%s %s %s %s %s %s\n\n%s %s %s ", $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17}
if(NR ==5) {printf "%s %s %s\n%s %s %s %s %s %s\n%s %s %s %s %s %s\n%s ", $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17}
if(NR ==6) {printf "%s %s %s %s %s\n%s %s %s %s %s %s\n%s %s %s %s %s ", $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17}
if(NR ==7) {printf "%s\n%s %s %s %s %s %s\n%s %s %s %s %s %s\n\n%s %s %s ", $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17}
if(NR ==8) {printf "%s %s %s\n%s %s %s %s %s %s\n%s %s %s %s %s %s\n%s ", $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17}
if(NR ==9) {printf "%s %s %s %s %s\n%s %s %s %s %s %s\n%s %s %s %s %s ", $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17}
if(NR ==10) {printf "%s\n%s %s %s %s %s %s\n%s %s %s %s %s %s\n\n%s %s %s ", $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17}
if(NR ==11) {printf "%s %s %s\n%s %s %s %s %s %s\n%s %s %s %s %s %s\n%s ", $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17}
if(NR ==12) {printf "%s %s %s %s %s\n%s %s %s %s %s %s\n%s %s %s %s %s ", $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17}
if(NR ==13) {printf "%s\n%s %s %s %s %s %s\n%s %s %s %s %s %s\n\n%s %s %s ", $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17}
if(NR ==14) {printf "%s %s\n", $2, $3}

}' 
Masz niepotrzebny router, uszkodzony czy nie - chętnie przygarnę go.

6

Odp: Skrypt zmieniający układ danych ASCII lub HEX

Dzięki, działa smile