forked from cezanne/usbip-win
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stub_dbg.c
73 lines (62 loc) · 1.34 KB
/
stub_dbg.c
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
#include "stub_driver.h"
#include "stub_dev.h"
#include "dbgcommon.h"
#include <ntstrsafe.h>
#include "dbgcode.h"
#include "usbip_stub_api.h"
#ifdef DBG
const char *
dbg_device(PDEVICE_OBJECT devobj)
{
static char buf[32];
ANSI_STRING name;
if (devobj == NULL)
return "null";
if (devobj->DriverObject)
return "driver null";
if (NT_SUCCESS(RtlUnicodeStringToAnsiString(&name, &devobj->DriverObject->DriverName, TRUE))) {
RtlStringCchCopyA(buf, 32, name.Buffer);
RtlFreeAnsiString(&name);
return buf;
}
else {
return "error";
}
}
const char *
dbg_devices(PDEVICE_OBJECT devobj, BOOLEAN is_attached)
{
static char buf[1024];
int n = 0;
int i;
for (i = 0; i < 16; i++) {
if (devobj == NULL)
break;
n += dbg_snprintf(buf + n, 1024 - n, "[%s]", dbg_device(devobj));
if (is_attached)
devobj = devobj->AttachedDevice;
else
devobj = devobj->NextDevice;
}
return buf;
}
const char *
dbg_devstub(usbip_stub_dev_t *devstub)
{
static char buf[512];
if (devstub == NULL)
return "<null>";
RtlStringCchPrintfA(buf, 512, "id:%d,hw:%s", devstub->id, devstub->id_hw);
return buf;
}
static namecode_t namecodes_stub_ioctl[] = {
K_V(IOCTL_USBIP_STUB_GET_DEVINFO)
K_V(IOCTL_USBIP_STUB_EXPORT)
{0,0}
};
const char *
dbg_stub_ioctl_code(ULONG ioctl_code)
{
return dbg_namecode(namecodes_stub_ioctl, "ioctl", ioctl_code);
}
#endif