-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHEX.C
More file actions
78 lines (71 loc) · 2.9 KB
/
Copy pathHEX.C
File metadata and controls
78 lines (71 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/***************************************************************************
* HEX.C -- This file is part of diskdump. *
* *
* Copyright (C) 2021 Imanol-Mikel Barba Sabariego *
* *
* diskdump is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published *
* by the Free Software Foundation, either version 3 of the License, *
* or (at your option) any later version. *
* *
* diskdump is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty *
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see http://www.gnu.org/licenses/. *
* *
***************************************************************************/
#include "hex.h"
void print_offset(uint8_t hi, ulongint lo) {
printf("%02X%04X%04X ", hi, *((uint16_t*)((uint8_t*)(&lo)+2)), *((uint16_t*)(&lo)));
}
int is_printable(unsigned char c) {
if(c >= 0x20 && c < 127) {
return 1;
}
return 0;
}
ssize_t hex_medium_send(uint8_t far *buf, ulongint buf_len, medium_data md) {
ulongint i;
unsigned char ascii_str[17];
hex_medium_data* hmd = (hex_medium_data*)md;
print_offset(hmd->current_offset_hi, hmd->current_offset_lo);
for(i = 0; i < buf_len; ++i) {
printf("%02X ",buf[i]);
if(is_printable(buf[i])) {
ascii_str[i%16] = buf[i];
} else {
ascii_str[i%16] = '.';
}
if(i % 16 == 15) {
if(hmd->current_offset_lo + 16 < hmd->current_offset_lo) {
hmd->current_offset_hi++;
}
hmd->current_offset_lo += 16;
ascii_str[16] = '\0';
printf(" |%s|\n", ascii_str);
print_offset(hmd->current_offset_hi, hmd->current_offset_lo);
}
}
return buf_len;
}
int hex_medium_ready(medium_data md) {
md = md;
return MEDIUM_READY;
}
void hex_medium_done(medium_data md, char* hash) {
md = md;
hash = hash;
}
void create_hex_medium(Medium* m, hex_medium_data* hmd, Digest* digest) {
hmd->current_offset_hi = 0;
hmd->current_offset_lo = 0;
m->send = &hex_medium_send;
m->ready = &hex_medium_ready;
m->data = (void*)hmd;
m->done = &hex_medium_done;
m->digest = digest;
m->mtu = 0;
}