]>
cvs.zerfleddert.de Git - usb-driver/blob - usb-driver.c
1 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
6 #define REAL_LIBC RTLD_NEXT
8 #define REAL_LIBC ((void *) -1L)
17 #include <sys/types.h>
24 static int (*ioctl_func
) (int, int, void *) = NULL
;
25 static int windrvrfd
= 0;
26 static struct usb_bus
*busses
= NULL
;
27 static struct usb_device
*usb_cable
;
28 static unsigned long card_type
;
30 //#define USE_LIBUSB 1
32 void hexdump(unsigned char *buf
, int len
);
33 void diff(unsigned char *buf1
, unsigned char *buf2
, int len
);
35 int do_wdioctl(int fd
, unsigned int request
, unsigned char *wdioctl
) {
36 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
37 struct version_struct
*version
;
40 if (wdheader
->magic
!= MAGIC
) {
41 fprintf(stderr
,"!!!ERROR: magic header does not match!!!\n");
42 return (*ioctl_func
) (fd
, request
, wdioctl
);
47 version
= (struct version_struct
*)(wdheader
->data
);
48 strcpy(version
->version
, "WinDriver no more");
49 version
->versionul
= 999;
50 fprintf(stderr
,"faking VERSION\n");
54 fprintf(stderr
,"faking LICENSE\n");
59 //struct card_register* cr = (struct card_register*)(wdheader->data);
60 /* Todo: LPT-Port already in use */
62 fprintf(stderr
,"faking CARD_REGISTER\n");
66 fprintf(stderr
,"in USB_TRANSFER");
68 struct usb_transfer
*ut
= (struct usb_transfer
*)(wdheader
->data
);
70 fprintf(stderr
," unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n", ut
->dwUniqueID
, ut
->dwPipeNum
, ut
->fRead
, ut
->dwOptions
, ut
->dwBufferSize
, ut
->dwTimeout
);
71 fprintf(stderr
,"setup packet: ");
72 hexdump(ut
->SetupPacket
, 8);
74 if (!ut
->fRead
&& ut
->dwBufferSize
)
76 hexdump(ut
->pBuffer
, ut
->dwBufferSize
);
81 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
84 fprintf(stderr
,"Transferred: %lu (%s)\n",ut
->dwBytesTransferred
, (ut
->fRead
?"read":"write"));
85 if (ut
->fRead
&& ut
->dwBytesTransferred
)
87 fprintf(stderr
,"Read: ");
88 hexdump(ut
->pBuffer
, ut
->dwBytesTransferred
);
95 fprintf(stderr
,"faking INT_ENABLE");
97 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
99 fprintf(stderr
,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
, it
->dwLost
, it
->fStopped
);
102 //ret = (*ioctl_func) (fd, request, wdioctl);
108 fprintf(stderr
,"INT_DISABLE\n");
110 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
112 fprintf(stderr
,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
, it
->dwLost
, it
->fStopped
);
114 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
119 fprintf(stderr
,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
, it
->dwLost
, it
->fStopped
);
123 case USB_SET_INTERFACE
:
124 fprintf(stderr
,"USB_SET_INTERFACE\n");
126 struct usb_set_interface
*usi
= (struct usb_set_interface
*)(wdheader
->data
);
128 fprintf(stderr
,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi
->dwUniqueID
, usi
->dwInterfaceNum
, usi
->dwAlternateSetting
, usi
->dwOptions
);
130 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
135 case USB_GET_DEVICE_DATA
:
136 fprintf(stderr
,"USB_GET_DEVICE_DATA\n");
138 struct usb_get_device_data
*ugdd
= (struct usb_get_device_data
*)(wdheader
->data
);
141 fprintf(stderr
, "unique: %lu, bytes: %lu, options: %lx\n", ugdd
->dwUniqueID
, ugdd
->dwBytes
, ugdd
->dwOptions
);
142 pSize
= ugdd
->dwBytes
;
144 hexdump(ugdd
->pBuf
, pSize
);
147 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
149 if (!ugdd
->dwBytes
) {
151 ugdd
->dwBytes
= sizeof(struct usb_device_info
) - 8 + (sizeof(WDU_CONFIGURATION
)*2) + sizeof(WDU_INTERFACE
) * 6;
156 struct usb_device_info
*udi
= (struct usb_device_info
*)ugdd
->pBuf
;
157 unsigned char dings
[] = {0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0xfd, 0x03, 0x08, 0x00, 0x00, 0x00, 0x01, 0x02,
158 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
159 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x45, 0x21, 0x08, 0x38, 0x45, 0x21, 0x08,
160 0x4c, 0x45, 0x21, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
162 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
163 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
164 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
165 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
166 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x02, 0x20, 0x00, 0x01, 0x02, 0x00, 0x80,
168 0x8c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x4c, 0x45, 0x21, 0x08, 0x58, 0x45, 0x21, 0x08,
169 0x01, 0x00, 0x00, 0x00, 0x58, 0x45, 0x21, 0x08, 0x09, 0x04, 0x00, 0x00, 0x02, 0xff, 0x00, 0x00,
170 0x00, 0x00, 0x00, 0x00, 0x6c, 0x45, 0x21, 0x08, 0x7c, 0x45, 0x21, 0x08, 0x07, 0x05, 0x02, 0x02,
171 0x00, 0x02, 0x00, 0x00, 0x07, 0x05, 0x86, 0x02, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
172 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
173 0x86, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
174 0x00, 0x00, 0x00, 0x00};
176 //unique: 94, bytes: 276, options: 0
178 //12 01 00 02 00 00 00 40 fd 03 08 00 00 00 01 02 12 01 00 02 00 00 00 40 fd 03 08 00 00 00 01 02
179 //00 01 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
180 //03 00 00 00 00 00 00 00 38 45 21 08 38 45 21 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
181 //4c 45 21 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
182 //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
183 //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
184 //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
185 //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
186 //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
187 //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
188 //00 00 00 00 00 00 00 00 09 02 20 00 01 02 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
189 //8c 00 00 00 01 00 00 00 4c 45 21 08 58 45 21 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
190 //01 00 00 00 58 45 21 08 09 04 00 00 02 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
191 //00 00 00 00 6c 45 21 08 7c 45 21 08 07 05 02 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
192 //00 02 00 00 07 05 86 02 00 02 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
193 //00 02 00 00 02 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
194 //86 00 00 00 00 02 00 00 02 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
195 //00 00 00 00 00 00 00 00
197 bzero(udi
, ugdd
->dwBytes
);
198 //memcpy(udi, dings, 276);
199 udi
->Descriptor
.bLength
= sizeof(WDU_DEVICE_DESCRIPTOR
);
200 udi
->Descriptor
.bDescriptorType
= usb_cable
->descriptor
.bDescriptorType
;
201 udi
->Descriptor
.bcdUSB
= usb_cable
->descriptor
.bcdUSB
;
202 udi
->Descriptor
.bDeviceClass
= usb_cable
->descriptor
.bDeviceClass
;
203 udi
->Descriptor
.bDeviceSubClass
= usb_cable
->descriptor
.bDeviceSubClass
;
204 udi
->Descriptor
.bDeviceProtocol
= usb_cable
->descriptor
.bDeviceProtocol
;
205 udi
->Descriptor
.bMaxPacketSize0
= usb_cable
->descriptor
.bMaxPacketSize0
;
206 udi
->Descriptor
.idVendor
= usb_cable
->descriptor
.idVendor
;
207 udi
->Descriptor
.idProduct
= usb_cable
->descriptor
.idProduct
;
208 udi
->Descriptor
.bcdDevice
= usb_cable
->descriptor
.bcdDevice
;
209 udi
->Descriptor
.iManufacturer
= usb_cable
->descriptor
.iManufacturer
;
210 udi
->Descriptor
.iProduct
= usb_cable
->descriptor
.iProduct
;
211 udi
->Descriptor
.iSerialNumber
= usb_cable
->descriptor
.iSerialNumber
;
212 udi
->Descriptor
.bNumConfigurations
= usb_cable
->descriptor
.bNumConfigurations
;
216 struct usb_device_info
*udi
= (struct usb_device_info
*)ugdd
->pBuf
;
218 fprintf(stderr
, "Vendor: %x\n", udi
->Descriptor
.idVendor
);
220 hexdump(ugdd
->pBuf
, pSize
);
221 fprintf(stderr
, "\n");
227 fprintf(stderr
,"EVENT_REGISTER\n");
229 struct event
*e
= (struct event
*)(wdheader
->data
);
233 fprintf(stderr
,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e
->handle
, e
->dwAction
, e
->dwStatus
, e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
, e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
, e
->u
.Usb
.deviceId
.dwProductId
, e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
, e
->dwNumMatchTables
);
234 for (i
= 0; i
< e
->dwNumMatchTables
; i
++) {
235 fprintf(stderr
,"match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e
->matchTables
[i
].VendorId
, e
->matchTables
[i
].ProductId
, e
->matchTables
[i
].bDeviceClass
, e
->matchTables
[i
].bDeviceSubClass
, e
->matchTables
[i
].bInterfaceClass
, e
->matchTables
[i
].bInterfaceSubClass
, e
->matchTables
[i
].bInterfaceProtocol
);
237 for (bus
= busses
; bus
; bus
= bus
->next
) {
238 struct usb_device
*dev
;
240 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
241 struct usb_device_descriptor
*desc
= &(dev
->descriptor
);
243 if((desc
->idVendor
== e
->matchTables
[i
].VendorId
) &&
244 (desc
->idProduct
== e
->matchTables
[i
].ProductId
) &&
245 (desc
->bDeviceClass
== e
->matchTables
[i
].bDeviceClass
) &&
246 (desc
->bDeviceSubClass
== e
->matchTables
[i
].bDeviceSubClass
)) {
247 struct usb_interface
*interface
= dev
->config
->interface
;
250 for (ai
= 0; ai
< interface
->num_altsetting
; ai
++) {
251 fprintf(stderr
, "intclass: %x, intsubclass: %x, intproto: %x\n", interface
->altsetting
[i
].bInterfaceClass
, interface
->altsetting
[i
].bInterfaceSubClass
, interface
->altsetting
[i
].bInterfaceProtocol
);
252 if ((interface
->altsetting
[i
].bInterfaceSubClass
== e
->matchTables
[i
].bInterfaceSubClass
) &&
253 (interface
->altsetting
[i
].bInterfaceProtocol
== e
->matchTables
[i
].bInterfaceProtocol
)){
254 /* TODO: check interfaceClass! */
255 fprintf(stderr
,"!!!FOUND DEVICE WITH LIBUSB!!!\n");
257 card_type
= e
->dwCardType
;
266 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
269 fprintf(stderr
,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e
->handle
, e
->dwAction
, e
->dwStatus
, e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
, e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
, e
->u
.Usb
.deviceId
.dwProductId
, e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
, e
->dwNumMatchTables
);
270 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
271 fprintf(stderr
,"match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e
->matchTables
[i
].VendorId
, e
->matchTables
[i
].ProductId
, e
->matchTables
[i
].bDeviceClass
, e
->matchTables
[i
].bDeviceSubClass
, e
->matchTables
[i
].bInterfaceClass
, e
->matchTables
[i
].bInterfaceSubClass
, e
->matchTables
[i
].bInterfaceProtocol
);
276 fprintf(stderr
,"TRANSFER\n");
278 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
282 case EVENT_UNREGISTER
:
283 fprintf(stderr
,"EVENT_UNREGISTER\n");
285 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
290 fprintf(stderr
,"INT_WAIT\n");
292 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
294 fprintf(stderr
,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
, it
->dwLost
, it
->fStopped
);
297 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
303 fprintf(stderr
,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
, it
->dwLost
, it
->fStopped
);
307 case CARD_UNREGISTER
:
308 fprintf(stderr
,"CARD_UNREGISTER\n");
310 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
315 fprintf(stderr
,"EVENT_PULL\n");
317 struct event
*e
= (struct event
*)(wdheader
->data
);
320 fprintf(stderr
,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e
->handle
, e
->dwAction
, e
->dwStatus
, e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
, e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
, e
->u
.Usb
.deviceId
.dwProductId
, e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
, e
->dwNumMatchTables
);
321 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
322 fprintf(stderr
,"match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e
->matchTables
[i
].VendorId
, e
->matchTables
[i
].ProductId
, e
->matchTables
[i
].bDeviceClass
, e
->matchTables
[i
].bDeviceSubClass
, e
->matchTables
[i
].bInterfaceClass
, e
->matchTables
[i
].bInterfaceSubClass
, e
->matchTables
[i
].bInterfaceProtocol
);
325 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
328 //handle: 1, action: 0, status: 0, eventid: 0, cardtype: 0, kplug: 0, options: 0, dev: 0:0, unique: 0, ver: 1, nummatch: 1
329 //match: dev: 0:0, class: 0, subclass: 0, intclass: 0, intsubclass: 0, intproto: 0
330 //handle: 1, action: 1, status: 0, eventid: 109, cardtype: 4294967294, kplug: 0, options: 0, dev: 0:0, unique: 90, ver: 1, nummatch: 1
331 //match: dev: 3fd:8, class: 0, subclass: 0, intclass: ff, intsubclass: 0, intproto: 0
333 struct usb_interface
*interface
= usb_cable
->config
->interface
;
335 e
->dwCardType
= card_type
;
338 e
->u
.Usb
.dwUniqueID
= 4711;
339 e
->matchTables
[0].VendorId
= usb_cable
->descriptor
.idVendor
;
340 e
->matchTables
[0].ProductId
= usb_cable
->descriptor
.idProduct
;
341 e
->matchTables
[0].bDeviceClass
= usb_cable
->descriptor
.bDeviceClass
;
342 e
->matchTables
[0].bDeviceSubClass
= usb_cable
->descriptor
.bDeviceSubClass
;
343 e
->matchTables
[0].bInterfaceClass
= interface
->altsetting
[0].bInterfaceClass
;
344 e
->matchTables
[0].bInterfaceSubClass
= interface
->altsetting
[0].bInterfaceSubClass
;
345 e
->matchTables
[0].bInterfaceProtocol
= interface
->altsetting
[0].bInterfaceProtocol
;
349 fprintf(stderr
,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e
->handle
, e
->dwAction
, e
->dwStatus
, e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
, e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
, e
->u
.Usb
.deviceId
.dwProductId
, e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
, e
->dwNumMatchTables
);
350 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
351 fprintf(stderr
,"match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e
->matchTables
[i
].VendorId
, e
->matchTables
[i
].ProductId
, e
->matchTables
[i
].bDeviceClass
, e
->matchTables
[i
].bDeviceSubClass
, e
->matchTables
[i
].bInterfaceClass
, e
->matchTables
[i
].bInterfaceSubClass
, e
->matchTables
[i
].bInterfaceProtocol
);
356 fprintf(stderr
,"!!!Unsupported IOCTL: %x!!!\n", request
);
358 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
367 typedef int (*open_funcptr_t
) (const char *, int, mode_t
);
369 int open (const char *pathname
, int flags
, ...)
371 static open_funcptr_t func
= NULL
;
377 func
= (open_funcptr_t
) dlsym (REAL_LIBC
, "open");
379 if (flags
& O_CREAT
) {
380 va_start(args
, flags
);
381 mode
= va_arg(args
, mode_t
);
385 fd
= (*func
) (pathname
, flags
, mode
);
387 if (!strcmp (pathname
, "/dev/windrvr6")) {
388 fprintf(stderr
,"opening windrvr6\n");
395 busses
= usb_get_busses();
402 void diff(unsigned char *buf1
, unsigned char *buf2
, int len
) {
405 for(i
=0; i
<len
; i
++) {
406 if (buf1
[i
] != buf2
[i
]) {
407 fprintf(stderr
,"Diff at %d: %02x(%c)->%02x(%c)\n", i
, buf1
[i
], ((buf1
[i
] >= 31 && buf1
[i
] <= 126)?buf1
[i
]:'.'), buf2
[i
], ((buf2
[i
] >= 31 && buf2
[i
] <= 126)?buf2
[i
]:'.'));
412 void hexdump(unsigned char *buf
, int len
) {
415 for(i
=0; i
<len
; i
++) {
416 fprintf(stderr
,"%02x ", buf
[i
]);
418 fprintf(stderr
,"\n");
422 int ioctl(int fd
, int request
, ...)
429 ioctl_func
= (int (*) (int, int, void *)) dlsym (REAL_LIBC
, "ioctl");
431 va_start (args
, request
);
432 argp
= va_arg (args
, void *);
436 ret
= do_wdioctl(fd
, request
, argp
);
438 ret
= (*ioctl_func
) (fd
, request
, argp
);
444 void *mmap(void *start
, size_t length
, int prot
, int flags
, int fd
, off_t offset
)
446 static void* (*func
) (void *, size_t, int, int, int, off_t
) = NULL
;
450 func
= (void* (*) (void *, size_t, int, int, int, off_t
)) dlsym (REAL_LIBC
, "mmap");
452 ret
= (*func
) (start
, length
, prot
, flags
, fd
, offset
);
453 fprintf(stderr
,"MMAP: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start
, length
, prot
, flags
, fd
, offset
, (unsigned int)ret
);
460 void *mmap64(void *start
, size_t length
, int prot
, int flags
, int fd
, off64_t offset
)
462 static void* (*func
) (void *, size_t, int, int, int, off64_t
) = NULL
;
466 func
= (void* (*) (void *, size_t, int, int, int, off64_t
)) dlsym (REAL_LIBC
, "mmap64");
468 ret
= (*func
) (start
, length
, prot
, flags
, fd
, offset
);
469 fprintf(stderr
,"MMAP64: %x, %d, %d, %d, %d, %lld -> %x\n", (unsigned int)start
, length
, prot
, flags
, fd
, offset
, (unsigned int)ret
);
476 void *mmap2(void *start
, size_t length
, int prot
, int flags
, int fd
, off_t pgoffset
)
478 static void* (*func
) (void *, size_t, int, int, int, off_t
) = NULL
;
482 func
= (void* (*) (void *, size_t, int, int, int, off_t
)) dlsym (REAL_LIBC
, "mmap2");
484 ret
= (*func
) (start
, length
, prot
, flags
, fd
, pgoffset
);
485 fprintf(stderr
,"MMAP2: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start
, length
, prot
, flags
, fd
, pgoffset
, (unsigned int)ret
);
492 void *malloc(size_t size
)
494 static void* (*func
) (size_t) = NULL
;
498 func
= (void* (*) (size_t)) dlsym(REAL_LIBC
, "malloc");
500 ret
= (*func
) (size
);
502 //fprintf(stderr,"MALLOC: %d -> %x\n", size, (unsigned int) ret);