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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
#include "parser.h"
/*******************************************************************
Count the number of characters (not bytes) in a unicode string.
********************************************************************/
size_t strlen_w(void *src)
{
size_t len;
for (len = 0; SVAL(src, len*2); len++) ;
return len;
}
/****************************************************************************
expand a pointer to be a particular size
****************************************************************************/
void *Realloc(void *p,size_t size)
{
void *ret=NULL;
if (size == 0) {
if (p) free(p);
DEBUG(5,("Realloc asked for 0 bytes\n"));
return NULL;
}
if (!p)
ret = (void *)malloc(size);
else
ret = (void *)realloc(p,size);
if (!ret)
DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size));
return(ret);
}
char *tab_depth(int depth)
{
static pstring spaces;
memset(spaces, ' ', depth * 4);
spaces[depth * 4] = 0;
return spaces;
}
void print_asc(int level, uchar const *buf, int len)
{
int i;
for (i = 0; i < len; i++)
{
DEBUGADD(level, ("%c", isprint(buf[i]) ? buf[i] : '.'));
}
}
void dump_data(int level, char *buf1, int len)
{
uchar const *buf = (uchar const *)buf1;
int i = 0;
if (buf == NULL)
{
DEBUG(level, ("dump_data: NULL, len=%d\n", len));
return;
}
if (len < 0)
return;
if (len == 0)
{
DEBUG(level, ("\n"));
return;
}
DEBUG(level, ("[%03X] ", i));
for (i = 0; i < len;)
{
DEBUGADD(level, ("%02X ", (int)buf[i]));
i++;
if (i % 8 == 0)
DEBUGADD(level, (" "));
if (i % 16 == 0)
{
print_asc(level, &buf[i - 16], 8);
DEBUGADD(level, (" "));
print_asc(level, &buf[i - 8], 8);
DEBUGADD(level, ("\n"));
if (i < len)
DEBUGADD(level, ("[%03X] ", i));
}
}
if (i % 16 != 0) /* finish off a non-16-char-length row */
{
int n;
n = 16 - (i % 16);
DEBUGADD(level, (" "));
if (n > 8)
DEBUGADD(level, (" "));
while (n--)
DEBUGADD(level, (" "));
n = MIN(8, i % 16);
print_asc(level, &buf[i - (i % 16)], n);
DEBUGADD(level, (" "));
n = (i % 16) - n;
if (n > 0)
print_asc(level, &buf[i - n], n);
DEBUGADD(level, ("\n"));
}
}
|