summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libirecovery.c74
-rw-r--r--tools/irecovery.c8
2 files changed, 40 insertions, 42 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c
index e8e2cab..009ad76 100644
--- a/src/libirecovery.c
+++ b/src/libirecovery.c
@@ -36,7 +36,7 @@
36#include <libimobiledevice-glue/thread.h> 36#include <libimobiledevice-glue/thread.h>
37 37
38#ifndef USE_DUMMY 38#ifndef USE_DUMMY
39#ifndef WIN32 39#ifndef _WIN32
40#ifndef HAVE_IOKIT 40#ifndef HAVE_IOKIT
41#include <libusb.h> 41#include <libusb.h>
42#if (defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01000102)) || (defined(LIBUSBX_API_VERSION) && (LIBUSBX_API_VERSION >= 0x01000102)) 42#if (defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01000102)) || (defined(LIBUSBX_API_VERSION) && (LIBUSBX_API_VERSION >= 0x01000102))
@@ -80,7 +80,7 @@ struct irecv_client_private {
80 int isKIS; 80 int isKIS;
81 struct irecv_device_info device_info; 81 struct irecv_device_info device_info;
82#ifndef USE_DUMMY 82#ifndef USE_DUMMY
83#ifndef WIN32 83#ifndef _WIN32
84#ifndef HAVE_IOKIT 84#ifndef HAVE_IOKIT
85 libusb_device_handle* handle; 85 libusb_device_handle* handle;
86#else 86#else
@@ -122,7 +122,7 @@ struct irecv_client_private {
122 122
123static int libirecovery_debug = 0; 123static int libirecovery_debug = 0;
124#ifndef USE_DUMMY 124#ifndef USE_DUMMY
125#ifndef WIN32 125#ifndef _WIN32
126#ifndef HAVE_IOKIT 126#ifndef HAVE_IOKIT
127static libusb_context* libirecovery_context = NULL; 127static libusb_context* libirecovery_context = NULL;
128#endif 128#endif
@@ -497,7 +497,7 @@ static unsigned int crc32_lookup_t1[256] = {
497#define crc32_step(a,b) \ 497#define crc32_step(a,b) \
498 a = (crc32_lookup_t1[(a & 0xFF) ^ ((unsigned char)b)] ^ (a >> 8)) 498 a = (crc32_lookup_t1[(a & 0xFF) ^ ((unsigned char)b)] ^ (a >> 8))
499 499
500#ifdef WIN32 500#ifdef _WIN32
501#pragma pack(1) 501#pragma pack(1)
502typedef struct { 502typedef struct {
503 uint16_t vid; 503 uint16_t vid;
@@ -595,7 +595,7 @@ struct collection listeners;
595static mutex_t listener_mutex; 595static mutex_t listener_mutex;
596struct collection devices; 596struct collection devices;
597static mutex_t device_mutex; 597static mutex_t device_mutex;
598#ifndef WIN32 598#ifndef _WIN32
599#ifdef HAVE_IOKIT 599#ifdef HAVE_IOKIT
600static CFRunLoopRef iokit_runloop = NULL; 600static CFRunLoopRef iokit_runloop = NULL;
601#else 601#else
@@ -611,7 +611,7 @@ static void _irecv_init(void)
611 irecv_set_debug_level(libirecovery_debug); 611 irecv_set_debug_level(libirecovery_debug);
612 } 612 }
613#ifndef USE_DUMMY 613#ifndef USE_DUMMY
614#ifndef WIN32 614#ifndef _WIN32
615#ifndef HAVE_IOKIT 615#ifndef HAVE_IOKIT
616 libusb_init(&libirecovery_context); 616 libusb_init(&libirecovery_context);
617#endif 617#endif
@@ -624,7 +624,7 @@ static void _irecv_init(void)
624static void _irecv_deinit(void) 624static void _irecv_deinit(void)
625{ 625{
626#ifndef USE_DUMMY 626#ifndef USE_DUMMY
627#ifndef WIN32 627#ifndef _WIN32
628#ifndef HAVE_IOKIT 628#ifndef HAVE_IOKIT
629 if (libirecovery_context != NULL) { 629 if (libirecovery_context != NULL) {
630 libusb_exit(libirecovery_context); 630 libusb_exit(libirecovery_context);
@@ -656,7 +656,7 @@ static void __attribute__((destructor)) libirecovery_deinitialize(void)
656{ 656{
657 thread_once(&deinit_once, _irecv_deinit); 657 thread_once(&deinit_once, _irecv_deinit);
658} 658}
659#elif defined(WIN32) 659#elif defined(_WIN32)
660BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved) 660BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved)
661{ 661{
662 switch (dwReason) { 662 switch (dwReason) {
@@ -726,7 +726,7 @@ static int iokit_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc
726 726
727static int irecv_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc_index, unsigned char * buffer, int size) 727static int irecv_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc_index, unsigned char * buffer, int size)
728{ 728{
729#ifndef WIN32 729#ifndef _WIN32
730#ifdef HAVE_IOKIT 730#ifdef HAVE_IOKIT
731 return iokit_get_string_descriptor_ascii(client, desc_index, buffer, size); 731 return iokit_get_string_descriptor_ascii(client, desc_index, buffer, size);
732#else 732#else
@@ -939,7 +939,7 @@ static void irecv_copy_nonce_with_tag(irecv_client_t client, const char* tag, un
939 irecv_copy_nonce_with_tag_from_buffer(tag,nonce,nonce_size,buf); 939 irecv_copy_nonce_with_tag_from_buffer(tag,nonce,nonce_size,buf);
940} 940}
941 941
942#ifndef WIN32 942#ifndef _WIN32
943static irecv_error_t irecv_kis_request_init(KIS_req_header *hdr, uint8_t portal, uint16_t index, size_t argCount, size_t payloadSize, size_t rplWords) 943static irecv_error_t irecv_kis_request_init(KIS_req_header *hdr, uint8_t portal, uint16_t index, size_t argCount, size_t payloadSize, size_t rplWords)
944{ 944{
945 if (argCount > UINT8_MAX) { 945 if (argCount > UINT8_MAX) {
@@ -1072,7 +1072,7 @@ static int irecv_kis_read_string(KIS_device_info *di, size_t off, char *buf, siz
1072 1072
1073static irecv_error_t irecv_kis_init(irecv_client_t client) 1073static irecv_error_t irecv_kis_init(irecv_client_t client)
1074{ 1074{
1075#ifndef WIN32 1075#ifndef _WIN32
1076 irecv_error_t err = irecv_kis_config_write32(client, KIS_PORTAL_CONFIG, KIS_INDEX_ENABLE_A, KIS_ENABLE_A_VAL); 1076 irecv_error_t err = irecv_kis_config_write32(client, KIS_PORTAL_CONFIG, KIS_INDEX_ENABLE_A, KIS_ENABLE_A_VAL);
1077 if (err != IRECV_E_SUCCESS) { 1077 if (err != IRECV_E_SUCCESS) {
1078 debug("Failed to write to KIS_INDEX_ENABLE_A, error %d\n", err); 1078 debug("Failed to write to KIS_INDEX_ENABLE_A, error %d\n", err);
@@ -1093,7 +1093,7 @@ static irecv_error_t irecv_kis_init(irecv_client_t client)
1093static irecv_error_t irecv_kis_load_device_info(irecv_client_t client) 1093static irecv_error_t irecv_kis_load_device_info(irecv_client_t client)
1094{ 1094{
1095 debug("Loading device info in KIS mode...\n"); 1095 debug("Loading device info in KIS mode...\n");
1096#ifdef WIN32 1096#ifdef _WIN32
1097 KIS_device_info kisInfo; 1097 KIS_device_info kisInfo;
1098 DWORD transferred = 0; 1098 DWORD transferred = 0;
1099 int ret = DeviceIoControl(client->handle, 0x220004, NULL, 0, &kisInfo, sizeof(kisInfo), (PDWORD)&transferred, NULL); 1099 int ret = DeviceIoControl(client->handle, 0x220004, NULL, 0, &kisInfo, sizeof(kisInfo), (PDWORD)&transferred, NULL);
@@ -1161,7 +1161,7 @@ static irecv_error_t irecv_kis_load_device_info(irecv_client_t client)
1161 return IRECV_E_SUCCESS; 1161 return IRECV_E_SUCCESS;
1162} 1162}
1163 1163
1164#ifdef WIN32 1164#ifdef _WIN32
1165static const GUID GUID_DEVINTERFACE_IBOOT = {0xED82A167L, 0xD61A, 0x4AF6, {0x9A, 0xB6, 0x11, 0xE5, 0x22, 0x36, 0xC5, 0x76}}; 1165static const GUID GUID_DEVINTERFACE_IBOOT = {0xED82A167L, 0xD61A, 0x4AF6, {0x9A, 0xB6, 0x11, 0xE5, 0x22, 0x36, 0xC5, 0x76}};
1166static const GUID GUID_DEVINTERFACE_DFU = {0xB8085869L, 0xFEB9, 0x404B, {0x8C, 0xB1, 0x1E, 0x5C, 0x14, 0xFA, 0x8C, 0x54}}; 1166static const GUID GUID_DEVINTERFACE_DFU = {0xB8085869L, 0xFEB9, 0x404B, {0x8C, 0xB1, 0x1E, 0x5C, 0x14, 0xFA, 0x8C, 0x54}};
1167static const GUID GUID_DEVINTERFACE_KIS = {0xB36F4137L, 0xF4EF, 0x4BFC, {0xA2, 0x5A, 0xC2, 0x41, 0x07, 0x68, 0xEE, 0x37}}; 1167static const GUID GUID_DEVINTERFACE_KIS = {0xB36F4137L, 0xF4EF, 0x4BFC, {0xA2, 0x5A, 0xC2, 0x41, 0x07, 0x68, 0xEE, 0x37}};
@@ -1388,7 +1388,7 @@ int irecv_usb_control_transfer(irecv_client_t client, uint8_t bm_request_type, u
1388#ifdef USE_DUMMY 1388#ifdef USE_DUMMY
1389 return IRECV_E_UNSUPPORTED; 1389 return IRECV_E_UNSUPPORTED;
1390#else 1390#else
1391#ifndef WIN32 1391#ifndef _WIN32
1392#ifdef HAVE_IOKIT 1392#ifdef HAVE_IOKIT
1393 return iokit_usb_control_transfer(client, bm_request_type, b_request, w_value, w_index, data, w_length, timeout); 1393 return iokit_usb_control_transfer(client, bm_request_type, b_request, w_value, w_index, data, w_length, timeout);
1394#else 1394#else
@@ -1523,7 +1523,7 @@ int irecv_usb_bulk_transfer(irecv_client_t client,
1523#else 1523#else
1524 int ret; 1524 int ret;
1525 1525
1526#ifndef WIN32 1526#ifndef _WIN32
1527#ifdef HAVE_IOKIT 1527#ifdef HAVE_IOKIT
1528 return iokit_usb_bulk_transfer(client, endpoint, data, length, transferred, timeout); 1528 return iokit_usb_bulk_transfer(client, endpoint, data, length, transferred, timeout);
1529#else 1529#else
@@ -1713,7 +1713,7 @@ static irecv_error_t iokit_open_with_ecid(irecv_client_t* pclient, uint64_t ecid
1713} 1713}
1714#endif 1714#endif
1715 1715
1716#ifndef WIN32 1716#ifndef _WIN32
1717#ifndef HAVE_IOKIT 1717#ifndef HAVE_IOKIT
1718static irecv_error_t libusb_usb_open_handle_with_descriptor_and_ecid(irecv_client_t *pclient, struct libusb_device_handle *usb_handle, struct libusb_device_descriptor *usb_descriptor, uint64_t ecid) 1718static irecv_error_t libusb_usb_open_handle_with_descriptor_and_ecid(irecv_client_t *pclient, struct libusb_device_handle *usb_handle, struct libusb_device_descriptor *usb_descriptor, uint64_t ecid)
1719{ 1719{
@@ -1824,7 +1824,7 @@ irecv_error_t irecv_open_with_ecid(irecv_client_t* pclient, uint64_t ecid)
1824 if (libirecovery_debug) { 1824 if (libirecovery_debug) {
1825 irecv_set_debug_level(libirecovery_debug); 1825 irecv_set_debug_level(libirecovery_debug);
1826 } 1826 }
1827#ifndef WIN32 1827#ifndef _WIN32
1828#ifdef HAVE_IOKIT 1828#ifdef HAVE_IOKIT
1829 error = iokit_open_with_ecid(pclient, ecid); 1829 error = iokit_open_with_ecid(pclient, ecid);
1830#else 1830#else
@@ -1907,7 +1907,7 @@ irecv_error_t irecv_usb_set_configuration(irecv_client_t client, int configurati
1907 if (check_context(client) != IRECV_E_SUCCESS) 1907 if (check_context(client) != IRECV_E_SUCCESS)
1908 return IRECV_E_NO_DEVICE; 1908 return IRECV_E_NO_DEVICE;
1909 1909
1910#ifndef WIN32 1910#ifndef _WIN32
1911 debug("Setting to configuration %d\n", configuration); 1911 debug("Setting to configuration %d\n", configuration);
1912 1912
1913#ifdef HAVE_IOKIT 1913#ifdef HAVE_IOKIT
@@ -2026,7 +2026,7 @@ irecv_error_t irecv_usb_set_interface(irecv_client_t client, int usb_interface,
2026 return IRECV_E_NO_DEVICE; 2026 return IRECV_E_NO_DEVICE;
2027 2027
2028 debug("Setting to interface %d:%d\n", usb_interface, usb_alt_interface); 2028 debug("Setting to interface %d:%d\n", usb_interface, usb_alt_interface);
2029#ifndef WIN32 2029#ifndef _WIN32
2030#ifdef HAVE_IOKIT 2030#ifdef HAVE_IOKIT
2031 if (iokit_usb_set_interface(client, usb_interface, usb_alt_interface) < 0) { 2031 if (iokit_usb_set_interface(client, usb_interface, usb_alt_interface) < 0) {
2032 return IRECV_E_USB_INTERFACE; 2032 return IRECV_E_USB_INTERFACE;
@@ -2064,7 +2064,7 @@ irecv_error_t irecv_reset(irecv_client_t client)
2064 if (check_context(client) != IRECV_E_SUCCESS) 2064 if (check_context(client) != IRECV_E_SUCCESS)
2065 return IRECV_E_NO_DEVICE; 2065 return IRECV_E_NO_DEVICE;
2066 2066
2067#ifndef WIN32 2067#ifndef _WIN32
2068#ifdef HAVE_IOKIT 2068#ifdef HAVE_IOKIT
2069 IOReturn result; 2069 IOReturn result;
2070 2070
@@ -2203,7 +2203,7 @@ struct irecv_usb_device_info {
2203 int alive; 2203 int alive;
2204}; 2204};
2205 2205
2206#ifdef WIN32 2206#ifdef _WIN32
2207struct irecv_win_dev_ctx { 2207struct irecv_win_dev_ctx {
2208 PSP_DEVICE_INTERFACE_DETAIL_DATA_A details; 2208 PSP_DEVICE_INTERFACE_DETAIL_DATA_A details;
2209 uint32_t location; 2209 uint32_t location;
@@ -2221,7 +2221,7 @@ static int _irecv_is_recovery_device(void *device)
2221{ 2221{
2222 uint16_t vendor_id = 0; 2222 uint16_t vendor_id = 0;
2223 uint16_t product_id = 0; 2223 uint16_t product_id = 0;
2224#ifdef WIN32 2224#ifdef _WIN32
2225 const char *path = (const char*)device; 2225 const char *path = (const char*)device;
2226 unsigned int vendor = 0; 2226 unsigned int vendor = 0;
2227 unsigned int product = 0; 2227 unsigned int product = 0;
@@ -2289,7 +2289,7 @@ static void* _irecv_handle_device_add(void *userdata)
2289 irecv_client_t client = NULL; 2289 irecv_client_t client = NULL;
2290 2290
2291 memset(serial_str, 0, 256); 2291 memset(serial_str, 0, 256);
2292#ifdef WIN32 2292#ifdef _WIN32
2293 struct irecv_win_dev_ctx *win_ctx = (struct irecv_win_dev_ctx*)userdata; 2293 struct irecv_win_dev_ctx *win_ctx = (struct irecv_win_dev_ctx*)userdata;
2294 PSP_DEVICE_INTERFACE_DETAIL_DATA_A details = win_ctx->details; 2294 PSP_DEVICE_INTERFACE_DETAIL_DATA_A details = win_ctx->details;
2295 LPSTR result = (LPSTR)details->DevicePath; 2295 LPSTR result = (LPSTR)details->DevicePath;
@@ -2349,7 +2349,7 @@ static void* _irecv_handle_device_add(void *userdata)
2349 } 2349 }
2350 } 2350 }
2351 2351
2352#else /* !WIN32 */ 2352#else /* !_WIN32 */
2353#ifdef HAVE_IOKIT 2353#ifdef HAVE_IOKIT
2354 struct irecv_iokit_dev_ctx* iokit_ctx = (struct irecv_iokit_dev_ctx*)userdata; 2354 struct irecv_iokit_dev_ctx* iokit_ctx = (struct irecv_iokit_dev_ctx*)userdata;
2355 io_service_t device = iokit_ctx->device; 2355 io_service_t device = iokit_ctx->device;
@@ -2443,7 +2443,7 @@ static void* _irecv_handle_device_add(void *userdata)
2443 libusb_close(usb_handle); 2443 libusb_close(usb_handle);
2444 } 2444 }
2445#endif /* !HAVE_IOKIT */ 2445#endif /* !HAVE_IOKIT */
2446#endif /* !WIN32 */ 2446#endif /* !_WIN32 */
2447 memset(&client_loc, '\0', sizeof(client_loc)); 2447 memset(&client_loc, '\0', sizeof(client_loc));
2448 if (product_id == KIS_PRODUCT_ID) { 2448 if (product_id == KIS_PRODUCT_ID) {
2449 int i = 0; 2449 int i = 0;
@@ -2546,7 +2546,7 @@ static void _irecv_handle_device_remove(struct irecv_usb_device_info *devinfo)
2546 free(devinfo); 2546 free(devinfo);
2547} 2547}
2548 2548
2549#ifndef WIN32 2549#ifndef _WIN32
2550#ifdef HAVE_IOKIT 2550#ifdef HAVE_IOKIT
2551static void iokit_device_added(void *refcon, io_iterator_t iterator) 2551static void iokit_device_added(void *refcon, io_iterator_t iterator)
2552{ 2552{
@@ -2643,7 +2643,7 @@ static int _irecv_usb_hotplug_cb(libusb_context *ctx, libusb_device *device, lib
2643} 2643}
2644#endif /* HAVE_LIBUSB_HOTPLUG_API */ 2644#endif /* HAVE_LIBUSB_HOTPLUG_API */
2645#endif /* !HAVE_IOKIT */ 2645#endif /* !HAVE_IOKIT */
2646#endif /* !WIN32 */ 2646#endif /* !_WIN32 */
2647 2647
2648struct _irecv_event_handler_info { 2648struct _irecv_event_handler_info {
2649 cond_t startup_cond; 2649 cond_t startup_cond;
@@ -2653,7 +2653,7 @@ struct _irecv_event_handler_info {
2653static void *_irecv_event_handler(void* data) 2653static void *_irecv_event_handler(void* data)
2654{ 2654{
2655 struct _irecv_event_handler_info* info = (struct _irecv_event_handler_info*)data; 2655 struct _irecv_event_handler_info* info = (struct _irecv_event_handler_info*)data;
2656#ifdef WIN32 2656#ifdef _WIN32
2657 struct collection newDevices; 2657 struct collection newDevices;
2658 const GUID *guids[] = { &GUID_DEVINTERFACE_KIS, &GUID_DEVINTERFACE_PORTDFU, &GUID_DEVINTERFACE_DFU, &GUID_DEVINTERFACE_IBOOT, NULL }; 2658 const GUID *guids[] = { &GUID_DEVINTERFACE_KIS, &GUID_DEVINTERFACE_PORTDFU, &GUID_DEVINTERFACE_DFU, &GUID_DEVINTERFACE_IBOOT, NULL };
2659 int running = 1; 2659 int running = 1;
@@ -2797,7 +2797,7 @@ static void *_irecv_event_handler(void* data)
2797 } while (running); 2797 } while (running);
2798 2798
2799 collection_free(&newDevices); 2799 collection_free(&newDevices);
2800#else /* !WIN32 */ 2800#else /* !_WIN32 */
2801#ifdef HAVE_IOKIT 2801#ifdef HAVE_IOKIT
2802 kern_return_t kr; 2802 kern_return_t kr;
2803 2803
@@ -2922,7 +2922,7 @@ static void *_irecv_event_handler(void* data)
2922 } while (running); 2922 } while (running);
2923#endif /* !HAVE_LIBUSB_HOTPLUG_API */ 2923#endif /* !HAVE_LIBUSB_HOTPLUG_API */
2924#endif /* !HAVE_IOKIT */ 2924#endif /* !HAVE_IOKIT */
2925#endif /* !WIN32 */ 2925#endif /* !_WIN32 */
2926 return NULL; 2926 return NULL;
2927} 2927}
2928#endif /* !USE_DUMMY */ 2928#endif /* !USE_DUMMY */
@@ -2951,7 +2951,7 @@ irecv_error_t irecv_device_event_subscribe(irecv_device_event_context_t *context
2951 struct _irecv_event_handler_info info; 2951 struct _irecv_event_handler_info info;
2952 cond_init(&info.startup_cond); 2952 cond_init(&info.startup_cond);
2953 mutex_init(&info.startup_mutex); 2953 mutex_init(&info.startup_mutex);
2954#ifndef WIN32 2954#ifndef _WIN32
2955#ifndef HAVE_IOKIT 2955#ifndef HAVE_IOKIT
2956 libusb_init(&irecv_hotplug_ctx); 2956 libusb_init(&irecv_hotplug_ctx);
2957#endif 2957#endif
@@ -3023,7 +3023,7 @@ irecv_error_t irecv_device_event_unsubscribe(irecv_device_event_context_t contex
3023 collection_free(&devices); 3023 collection_free(&devices);
3024 mutex_unlock(&device_mutex); 3024 mutex_unlock(&device_mutex);
3025 mutex_destroy(&device_mutex); 3025 mutex_destroy(&device_mutex);
3026#ifndef WIN32 3026#ifndef _WIN32
3027#ifndef HAVE_IOKIT 3027#ifndef HAVE_IOKIT
3028 libusb_exit(irecv_hotplug_ctx); 3028 libusb_exit(irecv_hotplug_ctx);
3029 irecv_hotplug_ctx = NULL; 3029 irecv_hotplug_ctx = NULL;
@@ -3051,7 +3051,7 @@ irecv_error_t irecv_close(irecv_client_t client)
3051 event.type = IRECV_DISCONNECTED; 3051 event.type = IRECV_DISCONNECTED;
3052 client->disconnected_callback(client, &event); 3052 client->disconnected_callback(client, &event);
3053 } 3053 }
3054#ifndef WIN32 3054#ifndef _WIN32
3055#ifdef HAVE_IOKIT 3055#ifdef HAVE_IOKIT
3056 if (client->usbInterface) { 3056 if (client->usbInterface) {
3057 (*client->usbInterface)->USBInterfaceClose(client->usbInterface); 3057 (*client->usbInterface)->USBInterfaceClose(client->usbInterface);
@@ -3094,7 +3094,7 @@ void irecv_set_debug_level(int level)
3094{ 3094{
3095 libirecovery_debug = level; 3095 libirecovery_debug = level;
3096#ifndef USE_DUMMY 3096#ifndef USE_DUMMY
3097#ifndef WIN32 3097#ifndef _WIN32
3098#ifndef HAVE_IOKIT 3098#ifndef HAVE_IOKIT
3099 if (libirecovery_context) { 3099 if (libirecovery_context) {
3100#if LIBUSB_API_VERSION >= 0x01000106 3100#if LIBUSB_API_VERSION >= 0x01000106
@@ -3258,7 +3258,7 @@ static irecv_error_t irecv_kis_send_buffer(irecv_client_t client, unsigned char*
3258 if (toUpload > 0x4000) 3258 if (toUpload > 0x4000)
3259 toUpload = 0x4000; 3259 toUpload = 0x4000;
3260 3260
3261#ifdef WIN32 3261#ifdef _WIN32
3262 memcpy(chunk->data, buffer, toUpload); 3262 memcpy(chunk->data, buffer, toUpload);
3263 chunk->size = toUpload; 3263 chunk->size = toUpload;
3264 chunk->address = address; 3264 chunk->address = address;
@@ -3275,7 +3275,7 @@ static irecv_error_t irecv_kis_send_buffer(irecv_client_t client, unsigned char*
3275 memcpy(chunk->data, buffer, toUpload); 3275 memcpy(chunk->data, buffer, toUpload);
3276#endif 3276#endif
3277 3277
3278#ifdef WIN32 3278#ifdef _WIN32
3279 DWORD transferred = 0; 3279 DWORD transferred = 0;
3280 int ret = DeviceIoControl(client->handle, 0x220008, chunk, sizeof(*chunk), NULL, 0, (PDWORD)&transferred, NULL); 3280 int ret = DeviceIoControl(client->handle, 0x220008, chunk, sizeof(*chunk), NULL, 0, (PDWORD)&transferred, NULL);
3281 irecv_error_t error = (ret) ? IRECV_E_SUCCESS : IRECV_E_USB_UPLOAD; 3281 irecv_error_t error = (ret) ? IRECV_E_SUCCESS : IRECV_E_USB_UPLOAD;
@@ -3308,7 +3308,7 @@ static irecv_error_t irecv_kis_send_buffer(irecv_client_t client, unsigned char*
3308 free(chunk); 3308 free(chunk);
3309 3309
3310 if (options & IRECV_SEND_OPT_DFU_NOTIFY_FINISH) { 3310 if (options & IRECV_SEND_OPT_DFU_NOTIFY_FINISH) {
3311#ifdef WIN32 3311#ifdef _WIN32
3312 DWORD amount = (DWORD)origLen; 3312 DWORD amount = (DWORD)origLen;
3313 DWORD transferred = 0; 3313 DWORD transferred = 0;
3314 int ret = DeviceIoControl(client->handle, 0x22000C, &amount, 4, NULL, 0, (PDWORD)&transferred, NULL); 3314 int ret = DeviceIoControl(client->handle, 0x22000C, &amount, 4, NULL, 0, (PDWORD)&transferred, NULL);
diff --git a/tools/irecovery.c b/tools/irecovery.c
index b41573c..b293324 100644
--- a/tools/irecovery.c
+++ b/tools/irecovery.c
@@ -37,18 +37,16 @@
37#include <readline/readline.h> 37#include <readline/readline.h>
38#include <readline/history.h> 38#include <readline/history.h>
39#else 39#else
40#ifndef WIN32 40#ifndef _WIN32
41#include <termios.h> 41#include <termios.h>
42#endif 42#endif
43#endif 43#endif
44 44
45#ifdef WIN32 45#ifdef _WIN32
46#include <windows.h> 46#include <windows.h>
47#include <conio.h> 47#include <conio.h>
48#ifndef sleep
49#define sleep(n) Sleep(1000 * n) 48#define sleep(n) Sleep(1000 * n)
50#endif 49#endif
51#endif
52 50
53#define FILE_HISTORY_PATH ".irecovery" 51#define FILE_HISTORY_PATH ".irecovery"
54#define debug(...) if (verbose) fprintf(stderr, __VA_ARGS__) 52#define debug(...) if (verbose) fprintf(stderr, __VA_ARGS__)
@@ -293,7 +291,7 @@ static void append_command_to_history(const char* cmd)
293} 291}
294 292
295#ifndef HAVE_READLINE 293#ifndef HAVE_READLINE
296#ifdef WIN32 294#ifdef _WIN32
297#define BS_CC '\b' 295#define BS_CC '\b'
298#else 296#else
299#define BS_CC 0x7f 297#define BS_CC 0x7f