diff --git a/libr/cons/dietline.c b/libr/cons/dietline.c index e2a7c3f2fe..b03e2fef4d 100644 --- a/libr/cons/dietline.c +++ b/libr/cons/dietline.c @@ -79,11 +79,15 @@ static int r_line_readchar_utf8(unsigned char *s) { static int r_line_readchar() { ut8 buf[2]; *buf = '\0'; -do_it_again: #if __WINDOWS__ BOOL ret; LPDWORD mode, out; - HANDLE h = GetStdHandle (STD_INPUT_HANDLE); + HANDLE h; +#endif + +do_it_again: +#if __WINDOWS__ + h = GetStdHandle (STD_INPUT_HANDLE); GetConsoleMode (h, &mode); SetConsoleMode (h, 0); // RAW diff --git a/libr/include/r_util.h b/libr/include/r_util.h index 1593926412..b3722ef313 100644 --- a/libr/include/r_util.h +++ b/libr/include/r_util.h @@ -17,6 +17,8 @@ #include #endif +#include + // TODO: use lowercase here? #define R_REFCTR_CLASS int refctr;void (*ref_free)(x) #define R_REFCTR_INIT(x,y) x->refctr=0;x->ref_free=y diff --git a/libr/socket/socket.c b/libr/socket/socket.c index b05b8c15c6..5704e44c62 100644 --- a/libr/socket/socket.c +++ b/libr/socket/socket.c @@ -26,6 +26,10 @@ R_API RSocket *r_socket_new (int is_ssl) { return NULL; } //#include #endif +#ifdef __WINDOWS__ +#include +#endif + #define BUFFER_SIZE 4096 #if __UNIX__ diff --git a/libr/util/file.c b/libr/util/file.c index 064587e75b..1e594eba51 100644 --- a/libr/util/file.c +++ b/libr/util/file.c @@ -265,23 +265,24 @@ R_API int r_file_mmap_write(const char *file, ut64 addr, const ut8 *buf, int len #if __WINDOWS__ HANDLE fm, fh; if (r_sandbox_enable (0)) return -1; - fh = CreateFile (file, rw?GENERIC_WRITE:GENERIC_READ, + fh = CreateFile (file, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); if (fh == INVALID_HANDLE_VALUE) { r_sys_perror ("CreateFile"); - free (m); return -1; } - fm = CreateFileMapping (m->fh, NULL, - rw? PAGE_READWRITE:PAGE_READONLY, 0, 0, NULL); + + fm = CreateFileMapping (fh, NULL, + PAGE_READWRITE, 0, 0, NULL); if (fm == NULL) { CloseHandle (fh); return -1; } + if (fm != INVALID_HANDLE_VALUE) { - ut8 *obuf = MapViewOfFile (m->fm, rw? - (FILE_MAP_READ|FILE_MAP_WRITE):FILE_MAP_READ, - UT32_HI (base), UT32_LO (base), 0); + ut8 *obuf = MapViewOfFile (fm, + FILE_MAP_READ|FILE_MAP_WRITE, + 0, 0, len); memcpy (obuf, buf, len); UnmapViewOfFile (obuf); } @@ -310,29 +311,33 @@ R_API int r_file_mmap_write(const char *file, ut64 addr, const ut8 *buf, int len R_API int r_file_mmap_read (const char *file, ut64 addr, ut8 *buf, int len) { #if __WINDOWS__ HANDLE fm, fh; + if (r_sandbox_enable (0)) return -1; - fh = CreateFile (file, rw?GENERIC_WRITE:GENERIC_READ, + fh = CreateFile (file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); + if (fh == INVALID_HANDLE_VALUE) { r_sys_perror ("CreateFile"); - free (m); return -1; } - fm = CreateFileMapping (m->fh, NULL, - rw? PAGE_READWRITE:PAGE_READONLY, 0, 0, NULL); + + fm = CreateFileMapping (fh, NULL, + PAGE_READONLY, 0, 0, NULL); if (fm == NULL) { CloseHandle (fh); return -1; } + if (fm != INVALID_HANDLE_VALUE) { - ut8 *obuf = MapViewOfFile (m->fm, rw? - (FILE_MAP_READ|FILE_MAP_WRITE):FILE_MAP_READ, - UT32_HI (base), UT32_LO (base), 0); + ut8 *obuf = MapViewOfFile (fm, + FILE_MAP_READ, + 0, 0, len); memcpy (obuf, buf, len); UnmapViewOfFile (obuf); } CloseHandle (fh); CloseHandle (fm); + #elif __UNIX__ int fd = r_sandbox_open (file, O_RDONLY, 0644); const int pagesize = 4096; diff --git a/shlr/sdb/src/sdb.c b/shlr/sdb/src/sdb.c index b77f73e766..f7fea6ec46 100644 --- a/shlr/sdb/src/sdb.c +++ b/shlr/sdb/src/sdb.c @@ -13,6 +13,10 @@ #define O_BINARY 0 #endif +#if __WINDOWS__ +#include +#endif + // must be deprecated static ut32 eod, pos; // what about lseek?