mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-01 19:23:04 +00:00
Fix #242 - Implement HFS timestamp in pth
This commit is contained in:
parent
13b119eae1
commit
c1c4086e38
@ -41,6 +41,7 @@ static int bbExist(AbbState *abb, ut64 addr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int fcnExist(AbbState *abb, ut64 addr) {
|
||||
AbbAddr *a;
|
||||
RListIter *iter;
|
||||
@ -56,6 +57,7 @@ static int fcnExist(AbbState *abb, ut64 addr) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
static AbbState *abbstate_new(ut64 len) {
|
||||
ut8 *buf = malloc (len);
|
||||
|
@ -4370,7 +4370,7 @@ static int cmd_print(void *data, const char *input) {
|
||||
c = r_cons_canvas_new (w, rows * 11);
|
||||
for (i = 0; i < rows; i++) {
|
||||
for (j = 0; j < cols; j++) {
|
||||
r_cons_canvas_gotoxy (c, j*20, i*11);
|
||||
r_cons_canvas_gotoxy (c, j * 20, i * 11);
|
||||
core->offset += len;
|
||||
r_core_read_at (core, core->offset, core->block, len);
|
||||
s = r_print_randomart (core->block, len, core->offset);
|
||||
@ -4388,7 +4388,7 @@ static int cmd_print(void *data, const char *input) {
|
||||
case 'n': // easter
|
||||
eprintf ("easter egg license has expired\n");
|
||||
break;
|
||||
case 't':
|
||||
case 't': // "pt"
|
||||
switch (input[1]) {
|
||||
case ' ':
|
||||
case '\0':
|
||||
@ -4403,6 +4403,18 @@ static int cmd_print(void *data, const char *input) {
|
||||
r_print_date_unix (core->print, core->block + l, sizeof (ut32));
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
//len must be multiple of 4 since r_mem_copyendian move data in fours - sizeof(ut32)
|
||||
if (len < sizeof (ut32)) {
|
||||
eprintf ("You should change the block size: b %d\n", (int)sizeof (ut32));
|
||||
}
|
||||
if (len % sizeof (ut32)) {
|
||||
len = len - (len % sizeof (ut32));
|
||||
}
|
||||
for (l = 0; l < len; l += sizeof (ut32)) {
|
||||
r_print_date_hfs (core->print, core->block + l, sizeof (ut32));
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
//len must be multiple of 4 since r_print_date_dos read buf+3
|
||||
//if block size is 1 or 5 for example it reads beyond the buffer
|
||||
@ -4430,9 +4442,10 @@ static int cmd_print(void *data, const char *input) {
|
||||
case '?':{
|
||||
const char* help_msg[] = {
|
||||
"Usage: pt", "[dn]", "print timestamps",
|
||||
"pt", "", "print unix time (32 bit `cfg.bigendian`)",
|
||||
"ptd","", "print dos time (32 bit `cfg.bigendian`)",
|
||||
"ptn","", "print ntfs time (64 bit `cfg.bigendian`)",
|
||||
"pt", "", "print UNIX time (32 bit `cfg.bigendian`) Since January 1, 1970",
|
||||
"ptd","", "print DOS time (32 bit `cfg.bigendian`) Since January 1, 1980",
|
||||
"pth","", "print HFS time (32 bit `cfg.bigendian`) Since January 1, 1904",
|
||||
"ptn","", "print NTFS time (64 bit `cfg.bigendian`) Since January 1, 1601",
|
||||
NULL};
|
||||
r_core_cmd_help (core, help_msg);
|
||||
}
|
||||
|
@ -145,6 +145,7 @@ R_API void r_print_offset(RPrint *p, ut64 off, int invert, int opt, int dec, int
|
||||
#define R_PRINT_STRING_URLENCODE 4
|
||||
R_API int r_print_string(RPrint *p, ut64 seek, const ut8 *str, int len, int options);
|
||||
R_API int r_print_date_dos(RPrint *p, ut8 *buf, int len);
|
||||
R_API int r_print_date_hfs(RPrint *p, const ut8 *buf, int len);
|
||||
R_API int r_print_date_w32(RPrint *p, const ut8 *buf, int len);
|
||||
R_API int r_print_date_unix(RPrint *p, const ut8 *buf, int len);
|
||||
R_API int r_print_date_get_now(RPrint *p, char *str);
|
||||
|
@ -25,18 +25,44 @@ R_API int r_print_date_dos(RPrint *p, ut8 *buf, int len) {
|
||||
// TODO: support p->datezone
|
||||
// TODO: support p->datefmt
|
||||
/* la data de modificacio del fitxer, no de creacio del zip */
|
||||
p->cb_printf("%d-%02d-%02d %d:%d:%d\n",
|
||||
p->cb_printf ("%d-%02d-%02d %d:%d:%d\n",
|
||||
year, month, day, hour, minutes, seconds);
|
||||
return 4;
|
||||
}
|
||||
|
||||
R_API int r_print_date_hfs(RPrint *p, const ut8 *buf, int len) {
|
||||
const int hfs_unix_delta = 2082844800;
|
||||
time_t t = 0;
|
||||
char s[256];
|
||||
int ret = 0;
|
||||
const struct tm* time;
|
||||
|
||||
if (p && len >= sizeof (ut32)) {
|
||||
t = r_read_ble32 (buf, p->big_endian);
|
||||
// "%d:%m:%Y %H:%M:%S %z",
|
||||
if (p->datefmt[0]) {
|
||||
t += p->datezone * (60*60);
|
||||
t += hfs_unix_delta;
|
||||
time = (const struct tm*)gmtime((const time_t*)&t);
|
||||
if (time) {
|
||||
ret = strftime (s, sizeof (s), p->datefmt, time);
|
||||
if (ret) {
|
||||
p->cb_printf ("%s\n", s);
|
||||
ret = sizeof (time_t);
|
||||
}
|
||||
} else p->cb_printf ("Invalid time\n");
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_print_date_unix(RPrint *p, const ut8 *buf, int len) {
|
||||
time_t t = 0;
|
||||
char s[256];
|
||||
int ret = 0;
|
||||
const struct tm* time;
|
||||
|
||||
if (p != NULL && len >= sizeof(ut32)) {
|
||||
if (p && len >= sizeof (ut32)) {
|
||||
t = r_read_ble32 (buf, p->big_endian);
|
||||
// "%d:%m:%Y %H:%M:%S %z",
|
||||
if (p->datefmt[0]) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user