aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.c
blob: 6fddd5766eb62e4d509fb9629adb39d2faaa4028 (plain)
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
#include "project.h"

void
hexdump (FILE * f, uint8_t * data, int s, int l)
{
  int e = s + l - 1;
  int b = s & ~15;
  int a = (e | 15) + 1;
  int i, j;

  for (i = b; i < a; i += 16)
    {
      fprintf (f, "      %04x: ", i);
      for (j = i; j < (i + 16); ++j)
        {
          if (j == (i + 8))
            fprintf (f, " ");

          if ((j >= s) && (j <= e))
            {
              fprintf (f, "%02x ", data[j]);
            }
          else
            {
              fprintf (f, "   ");
            }
        }

      for (j = i; j < (i + 16); ++j)
        {

          if (j == (i + 8))
            fprintf (f, " ");


          if ((j >= s) && (j <= e))
            {
              uint8_t c = data[j];
              if ((c < ' ') || (c > 126))
                c = '.';
              fprintf (f, "%c", c);
            }
          else
            {
              fprintf (f, " ");
            }
        }


      fprintf (f, "\n");
    }

}

void utf16_to_ascii(uint16_t  *u16,int u16_len,uint8_t *u8, int u8_len)
{
u16_len >>=1;

if (u8_len==1) {
	*u8=0;
	return;
}
while (*u16 && u16_len) {
*(u8++)=*(u16++);
u16_len--;
u8_len--;

if (u8_len==1) {
	*u8=0;
	return;
}
}

	*u8=0;
	return;
}