|
Last change
on this file since 5 was
2,
checked in by phkim, 11 years ago
|
|
1.phkim
- revision copy newcon3sk r27
|
-
Property svn:executable set to
*
|
|
File size:
880 bytes
|
| Line | |
|---|
| 1 | #! /bin/awk |
|---|
| 2 | # Convert byte hex dump without addresses to 0x9abcdef type |
|---|
| 3 | # format suitable for initalization of C array. |
|---|
| 4 | # Works well with small amount of data like signatures. Large amounts |
|---|
| 5 | # probably extremely slow. |
|---|
| 6 | # hex dump can be obtaned with od -A n -t x1 -v filename. |
|---|
| 7 | |
|---|
| 8 | { |
|---|
| 9 | data = data $0 |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | END { |
|---|
| 13 | gsub(/[ \n\t]+/, "", data); |
|---|
| 14 | output_uints(data); |
|---|
| 15 | printf("\n"); |
|---|
| 16 | output_uchar(data); |
|---|
| 17 | printf("\n"); |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | function output_uints(hex_string) |
|---|
| 21 | { |
|---|
| 22 | str_length = length(hex_string); |
|---|
| 23 | for( i=1; i < str_length; i=i+8){ |
|---|
| 24 | printf("0x%s,", substr(hex_string, i, 8)); |
|---|
| 25 | if(0 == ((i+7)%32)) |
|---|
| 26 | printf("\n"); |
|---|
| 27 | } |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | function output_uchar(hex_string) |
|---|
| 31 | { |
|---|
| 32 | str_length = length(hex_string); |
|---|
| 33 | for( i=1; i < str_length; i=i+2){ |
|---|
| 34 | printf("0x%s,", substr(hex_string, i, 2)); |
|---|
| 35 | if(0 == ((i+1)%16)) |
|---|
| 36 | printf("\n"); |
|---|
| 37 | } |
|---|
| 38 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.