mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-19 12:22:43 +00:00
Fix mmap and other minor issues on w32
This commit is contained in:
parent
d82c53224f
commit
9b1df62609
@ -123,3 +123,6 @@ You are probably using an old version of r2, go checkout the git!
|
||||
Run your own r2 scripts in awk using the r2awk program
|
||||
I love gradients
|
||||
Use -e bin.strings=false to disable search for strings when loading the binary
|
||||
wait a moment..
|
||||
Don't do this.
|
||||
No such file or directory.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2007-2012 pancake<nopcode.org> */
|
||||
/* radare - LGPL - Copyright 2007-2013 - pancake */
|
||||
|
||||
#include <r_cons.h>
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2012 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2013 - pancake */
|
||||
|
||||
#include <r_cons.h>
|
||||
#include <unistd.h>
|
||||
@ -13,12 +13,12 @@ static int backup_fd = -1;
|
||||
#endif
|
||||
|
||||
R_API int r_cons_pipe_open(const char *file, int append) {
|
||||
int fd = open (file, O_BINARY | O_RDWR | O_CREAT | (append?O_APPEND:O_TRUNC), 0644);
|
||||
int fd = r_sandbox_open (file,
|
||||
O_BINARY | O_RDWR | O_CREAT | (append?O_APPEND:O_TRUNC), 0644);
|
||||
if (fd==-1) {
|
||||
eprintf ("r_cons_pipe_open: Cannot open file '%s'\n", file);
|
||||
return -1;
|
||||
}// else eprintf ("%s created\n", file);
|
||||
|
||||
if (backup_fd != -1)
|
||||
close (backup_fd);
|
||||
#if __WINDOWS__
|
||||
|
@ -236,6 +236,7 @@ R_API ut64 r_num_chs (int cylinder, int head, int sector, int sectorsize);
|
||||
|
||||
#define R_BUF_CUR -1
|
||||
R_API RBuffer *r_buf_new();
|
||||
R_API RBuffer *r_buf_file (const char *file);
|
||||
R_API RBuffer *r_buf_mmap (const char *file, int rw);
|
||||
R_API int r_buf_set_bits(RBuffer *b, int bitoff, int bitsize, ut64 value);
|
||||
R_API int r_buf_set_bytes(RBuffer *b, const ut8 *buf, int length);
|
||||
|
@ -40,6 +40,17 @@ R_API RBuffer *r_buf_mmap (const char *file, int rw) {
|
||||
return b;
|
||||
}
|
||||
|
||||
R_API RBuffer *r_buf_file (const char *file) {
|
||||
RBuffer *b = r_buf_new ();
|
||||
if (!b) return NULL;
|
||||
b->buf = (ut8*)r_file_slurp (file, &b->length);
|
||||
if (!b->buf) {
|
||||
r_buf_free (b);
|
||||
return NULL; /* we just freed b, don't return it */
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
R_API int r_buf_set_bits(RBuffer *b, int bitoff, int bitsize, ut64 value) {
|
||||
// TODO: implement r_buf_set_bits
|
||||
// TODO: get the implementation from reg/value.c ?
|
||||
|
@ -48,7 +48,7 @@ R_API char *r_file_abspath(const char *file) {
|
||||
ret = r_str_dup_printf ("%s/%s", cwd, file);
|
||||
#elif __WINDOWS__
|
||||
if (cwd && !strchr (file, ':'))
|
||||
ret = r_str_dup_printf ("%s/%s", cwd, file);
|
||||
ret = r_str_dup_printf ("%s\\%s", cwd, file);
|
||||
#endif
|
||||
free (cwd);
|
||||
// TODO: remove // and ./
|
||||
@ -277,8 +277,10 @@ R_API RMmap *r_file_mmap (const char *file, boolt rw) {
|
||||
}
|
||||
#elif __WINDOWS__
|
||||
close (fd);
|
||||
m->fh = CreateFile (file, rw?GENERIC_WRITE:GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
|
||||
if (m->fh == NULL) {
|
||||
m->fh = CreateFile (file, rw?GENERIC_WRITE:GENERIC_READ,
|
||||
FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
|
||||
if (m->fh == INVALID_HANDLE_FILE) {
|
||||
r_sys_perror ("CreateFile");
|
||||
free (m);
|
||||
return NULL;
|
||||
}
|
||||
@ -290,7 +292,8 @@ R_API RMmap *r_file_mmap (const char *file, boolt rw) {
|
||||
return NULL;
|
||||
}
|
||||
if (m->fm != INVALID_HANDLE_VALUE) {
|
||||
m->buf = MapViewOfFile (m->fm, rw?FILE_MAP_READ|FILE_MAP_WRITE:FILE_MAP_READ, 0, 0, 0);
|
||||
m->buf = MapViewOfFile (m->fm, rw?
|
||||
FILE_MAP_READ|FILE_MAP_WRITE:FILE_MAP_READ, 0, 0, 0);
|
||||
} else {
|
||||
CloseHandle (m->fh);
|
||||
free (m);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2012 - pancake */
|
||||
/* radare - LGPL - Copyright 2012-2013 - pancake */
|
||||
|
||||
#include <r_util.h>
|
||||
#include <signal.h>
|
||||
@ -51,6 +51,9 @@ R_API int r_sandbox_open (const char *path, int mode, int perm) {
|
||||
if (!r_sandbox_check_path (path))
|
||||
return -1;
|
||||
}
|
||||
#if __WINDOWS__
|
||||
perm = 0;
|
||||
#endif
|
||||
return open (path, mode, perm);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ r2.get_flags = function (fn) {
|
||||
|
||||
r2.get_opcodes = function (off, n, cb) {
|
||||
r2.cmd ("pdj @"+off+"!"+n, function (json) {
|
||||
cb (JSON.parse (o));
|
||||
cb (JSON.parse (json));
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user