Add file.lastpath to fix regression in projects using malloc://

This commit is contained in:
pancake 2017-05-29 14:02:50 +02:00
parent 22cde23367
commit 1b854be75e
9 changed files with 69 additions and 15 deletions

View File

@ -1305,7 +1305,9 @@ static int cb_io_oxff(void *user, void *data) {
}
static int cb_filepath(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
r_config_set (core->config, "file.lastpath", node->value);
char *pikaboo = strstr (node->value, "://");
if (pikaboo) {
if (pikaboo[3] == '/') {
@ -2462,6 +2464,7 @@ R_API int r_core_config_init(RCore *core) {
SETPREF ("file.info", "true", "RBin info loaded");
SETPREF ("file.offset", "", "Offset where the file will be mapped at");
SETCB ("file.path", "", &cb_filepath, "Path of current file");
SETPREF ("file.lastpath", "", "Path of current file");
SETPREF ("file.sha1", "", "SHA1 hash of current file");
SETPREF ("file.type", "", "Type of current file");
n = NODECB ("file.loadmethod", "fail", &cb_fileloadmethod);

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2010-2016 - pancake, maijin */
/* radare - LGPL - Copyright 2010-2017 - pancake, maijin */
#include <r_types.h>
#include <r_list.h>
@ -338,18 +338,18 @@ R_API RThread *r_core_project_load_bg(RCore *core, const char *prjName, const ch
R_API bool r_core_project_open(RCore *core, const char *prjfile, bool thready) {
int askuser = 1;
int ret, close_current_session = 1;
char *prj, *filepath, *oldbin;
char *oldbin;
const char *newbin;
ut64 mapaddr = 0;
if (!prjfile || !*prjfile) {
return false;
}
prj = projectScriptPath (core, prjfile);
char *prj = projectScriptPath (core, prjfile);
if (!prj) {
eprintf ("Invalid project name '%s'\n", prjfile);
return false;
}
filepath = r_core_project_info (core, prj);
char *filepath = r_core_project_info (core, prj);
// eprintf ("OPENING (%s) from %s\n", prj, r_config_get (core->config, "file.path"));
/* if it is not an URI */
if (!filepath) {
@ -366,7 +366,11 @@ R_API bool r_core_project_open(RCore *core, const char *prjfile, bool thready) {
return false;
}
}
oldbin = strdup (r_config_get (core->config, "file.path"));
const char *file_path = r_config_get (core->config, "file.path");
if (!file_path || !*file_path) {
file_path = r_config_get (core->config, "file.lastpath");
}
oldbin = strdup (file_path);
if (!strcmp (prjfile, r_config_get (core->config, "prj.name"))) {
// eprintf ("Reloading project\n");
askuser = 0;
@ -396,10 +400,8 @@ R_API bool r_core_project_open(RCore *core, const char *prjfile, bool thready) {
fh = r_core_file_open (core, filepath, 0, 0);
if (!fh) {
eprintf ("Cannot open file '%s'\n", filepath);
free (oldbin);
free (filepath);
free (prj);
return false;
ret = false;
goto beach;
}
}
@ -415,9 +417,13 @@ R_API bool r_core_project_open(RCore *core, const char *prjfile, bool thready) {
ret = r_core_project_load (core, prjfile, prj);
}
newbin = r_config_get (core->config, "file.path");
if (!newbin || !*newbin) {
newbin = r_config_get (core->config, "file.lastpath");
}
if (strcmp (oldbin, newbin)) {
eprintf ("WARNING: file.path changed: %s => %s\n", oldbin, newbin);
}
beach:
free (oldbin);
free (filepath);
free (prj);
@ -444,6 +450,11 @@ R_API char *r_core_project_info(RCore *core, const char *prjfile) {
file = r_str_new (buf + 15);
break;
}
if (!strncmp (buf, "\"e file.lastpath = ", 19)) {
buf[strlen (buf) - 2] = 0;
file = r_str_new (buf + 19);
break;
}
// TODO: deprecate before 1.0
if (!strncmp (buf, "e file.path = ", 14)) {
buf[strlen (buf) - 1] = 0;

View File

@ -1,7 +1,7 @@
#ifndef SDB_H
#define SDB_H
#if !defined(O_BINARY) && !defined(_MSC_VER)
#ifndef O_BINARY
#define O_BINARY 0
#endif
@ -39,6 +39,11 @@ extern "C" {
#ifndef _MSC_VER
extern __attribute__((dllimport)) void *__cdecl _aligned_malloc(size_t, size_t);
extern char *strdup (const char *);
#else
#include <process.h>
#include <windows.h>
#include <malloc.h> // for _aligned_malloc
#define ftruncate _chsize
#endif
#undef r_offsetof
#define r_offsetof(type, member) ((unsigned long) (ut64)&((type*)0)->member)

View File

@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#undef eprintf
#define eprintf(...) fprintf(stderr,__VA_ARGS__)

View File

@ -101,8 +101,8 @@ bool cdb_read(struct cdb *c, char *buf, ut32 len, ut32 pos) {
return false;
}
while (len > 0) {
ssize_t r = read (c->fd, buf, len);
if (r < 1 || (ut32) r != len) {
int r = (int)read (c->fd, buf, len);
if (r < 1 || (ut32)r != len) {
return false;
}
buf += r;

View File

@ -6,9 +6,9 @@
#include "rangstr.h"
#ifdef _MSC_VER
#pragma message ("TODO: json not implemented for this platform")
int js0n(const ut8 *js, RangstrType len, RangstrType *out) {
#pragma message("json/js0n.c: Unimplemented for this platform.")
return 0;
return 1;
}
#else
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))

View File

@ -1,7 +1,7 @@
#ifndef SDB_H
#define SDB_H
#if !defined(O_BINARY) && !defined(_MSC_VER)
#ifndef O_BINARY
#define O_BINARY 0
#endif
@ -39,6 +39,11 @@ extern "C" {
#ifndef _MSC_VER
extern __attribute__((dllimport)) void *__cdecl _aligned_malloc(size_t, size_t);
extern char *strdup (const char *);
#else
#include <process.h>
#include <windows.h>
#include <malloc.h> // for _aligned_malloc
#define ftruncate _chsize
#endif
#undef r_offsetof
#define r_offsetof(type, member) ((unsigned long) (ut64)&((type*)0)->member)

View File

@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#undef eprintf
#define eprintf(...) fprintf(stderr,__VA_ARGS__)

View File

@ -6,9 +6,37 @@
#if USE_MONOTONIC_CLOCK
#include <time.h>
#else
#ifdef _MSC_VER
#pragma message ("gettimeofday: Windows support is ugly here")
#include <windows.h>
int gettimeofday (struct timeval* p, void* tz) {
ULARGE_INTEGER ul; // As specified on MSDN.
FILETIME ft;
// Returns a 64-bit value representing the number of
// 100-nanosecond intervals since January 1, 1601 (UTC).
GetSystemTimeAsFileTime (&ft);
// Fill ULARGE_INTEGER low and high parts.
ul.LowPart = ft.dwLowDateTime;
ul.HighPart = ft.dwHighDateTime;
// Convert to microseconds.
ul.QuadPart /= 10ULL;
// Remove Windows to UNIX Epoch delta.
ul.QuadPart -= 11644473600000000ULL;
// Modulo to retrieve the microseconds.
p->tv_usec = (long)(ul.QuadPart % 1000000LL);
// Divide to retrieve the seconds.
p->tv_sec = (long)(ul.QuadPart / 1000000LL);
return 0;
}
#else
#include <sys/time.h>
#endif
#endif
SDB_API ut32 sdb_hash_len(const char *s, ut32 *len) {
ut32 h = CDB_HASHSTART;