Rizin
unix-like reverse engineering framework and cli tools
mdump.c File Reference
#include <rz_userconf.h>
#include "file.h"
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <time.h>

Go to the source code of this file.

Macros

#define SZOF(a)   (sizeof(a) / sizeof(a[0]))
 

Functions

void file_mdump (struct rz_magic *m)
 
void file_magwarn (struct rz_magic_set *ms, const char *f,...)
 
const char * file_fmttime (ut32 v, int local, char *pp)
 

Macro Definition Documentation

◆ SZOF

#define SZOF (   a)    (sizeof(a) / sizeof(a[0]))

Definition at line 44 of file mdump.c.

Function Documentation

◆ file_fmttime()

const char* file_fmttime ( ut32  v,
int  local,
char *  pp 
)

Definition at line 188 of file mdump.c.

188  {
189  time_t t = (time_t)v;
190  struct tm *tm;
191  struct tm timestruct;
192 
193  if (local) {
194  rz_ctime_r(&t, pp);
195  } else {
196 #ifndef HAVE_DAYLIGHT
197  static int daylight = 0;
198 #ifdef HAVE_TM_ISDST
199  static time_t now = (time_t)0;
200 
201  if (now == (time_t)0) {
202  struct tm *tm1;
203  (void)time(&now);
204  tm1 = rz_localtime_r(&now, &timestruct);
205  if (!tm1)
206  return "*Invalid time*";
207  daylight = tm1->tm_isdst;
208  }
209 #endif /* HAVE_TM_ISDST */
210 #endif /* HAVE_DAYLIGHT */
211  if (daylight)
212  t += 3600;
213  tm = rz_gmtime_r(&t, &timestruct);
214  if (!tm)
215  return "*Invalid time*";
216  rz_asctime_r(tm, pp);
217  }
218 
219  pp[strcspn(pp, "\n")] = '\0';
220  return pp;
221 }
#define local
Definition: blast.c:36
const char * v
Definition: dsignal.c:12
static static fork const void static count static fd const char const char static newpath char char char static envp time
Definition: sflib.h:42
RZ_API struct tm * rz_localtime_r(RZ_NONNULL const time_t *time, RZ_NONNULL struct tm *res)
Definition: time.c:284
RZ_API struct tm * rz_gmtime_r(RZ_NONNULL const time_t *time, RZ_NONNULL struct tm *res)
Definition: time.c:294
RZ_API char * rz_asctime_r(RZ_NONNULL const struct tm *tm, RZ_NONNULL char *buf)
Definition: time.c:304
RZ_API char * rz_ctime_r(RZ_NONNULL const time_t *timer, RZ_NONNULL char *buf)
Definition: time.c:314
int time_t
Definition: sftypes.h:66

References local, rz_asctime_r(), rz_ctime_r(), rz_gmtime_r(), rz_localtime_r(), time, and v.

Referenced by file_mdump(), and mprint().

◆ file_magwarn()

void file_magwarn ( struct rz_magic_set *  ms,
const char *  f,
  ... 
)

Definition at line 172 of file mdump.c.

172  {
173  va_list va;
174 
175  /* cuz we use stdout for most, stderr here */
176  (void)fflush(stdout);
177 
178  if (ms->file)
179  (void)eprintf("%s, %lu: ", ms->file,
180  (unsigned long)ms->line);
181  (void)eprintf("Warning: ");
182  va_start(va, f);
183  (void)vfprintf(stderr, f, va);
184  va_end(va);
185  (void)fputc('\n', stderr);
186 }
#define eprintf(x, y...)
Definition: rlcc.c:7
#define f(i)
Definition: sha256.c:46

References eprintf, and f.

Referenced by apprentice_load(), check_cond(), check_format(), file_signextend(), getstr(), getvalue(), parse(), parse_mime(), and string_modifier_check().

◆ file_mdump()

void file_mdump ( struct rz_magic *  m)

Definition at line 47 of file mdump.c.

47  {
48  static const char optyp[] = { FILE_OPS };
49  char pp[ASCTIME_BUF_MINLEN];
50 
51  (void)eprintf("[%u", m->lineno);
52  (void)eprintf("%.*s %u", m->cont_level & 7, ">>>>>>>>", m->offset);
53 
54  if (m->flag & INDIR) {
55  (void)eprintf("(%s,",
56  /* Note: type is unsigned */
57  (m->in_type < file_nnames) ? magic_file_names[m->in_type] : "*bad*");
58  if (m->in_op & FILE_OPINVERSE)
59  (void)fputc('~', stderr);
60  (void)eprintf("%c%u),",
61  ((m->in_op & FILE_OPS_MASK) < SZOF(optyp)) ? optyp[m->in_op & FILE_OPS_MASK] : '?',
62  m->in_offset);
63  }
64  (void)eprintf(" %s%s", (m->flag & UNSIGNED) ? "u" : "",
65  /* Note: type is unsigned */
66  (m->type < file_nnames) ? magic_file_names[m->type] : "*bad*");
67  if (m->mask_op & FILE_OPINVERSE)
68  (void)fputc('~', stderr);
69 
70  if (MAGIC_IS_STRING(m->type)) {
71  if (m->str_flags) {
72  (void)fputc('/', stderr);
73  if (m->str_flags & STRING_COMPACT_BLANK)
74  (void)fputc(CHAR_COMPACT_BLANK, stderr);
75  if (m->str_flags & STRING_COMPACT_OPTIONAL_BLANK)
76  (void)fputc(CHAR_COMPACT_OPTIONAL_BLANK,
77  stderr);
78  if (m->str_flags & STRING_IGNORE_LOWERCASE)
79  (void)fputc(CHAR_IGNORE_LOWERCASE, stderr);
80  if (m->str_flags & STRING_IGNORE_UPPERCASE)
81  (void)fputc(CHAR_IGNORE_UPPERCASE, stderr);
82  if (m->str_flags & REGEX_OFFSET_START)
83  (void)fputc(CHAR_REGEX_OFFSET_START, stderr);
84  }
85  if (m->str_range)
86  (void)eprintf("/%u", m->str_range);
87  } else {
88  if ((m->mask_op & FILE_OPS_MASK) < SZOF(optyp))
89  (void)fputc(optyp[m->mask_op & FILE_OPS_MASK], stderr);
90  else
91  (void)fputc('?', stderr);
92 
93  if (m->num_mask)
94  (void)eprintf("%08" PFMT64x, (ut64)m->num_mask);
95  }
96  (void)eprintf(",%c", m->reln);
97 
98  if (m->reln != 'x') {
99  switch (m->type) {
100  case FILE_BYTE:
101  case FILE_SHORT:
102  case FILE_LONG:
103  case FILE_LESHORT:
104  case FILE_LELONG:
105  case FILE_MELONG:
106  case FILE_BESHORT:
107  case FILE_BELONG:
108  (void)eprintf("%d", m->value.l);
109  break;
110  case FILE_BEQUAD:
111  case FILE_LEQUAD:
112  case FILE_QUAD:
113  (void)eprintf("%" PFMT64d, (ut64)m->value.q);
114  break;
115  case FILE_PSTRING:
116  case FILE_STRING:
117  case FILE_REGEX:
118  case FILE_BESTRING16:
119  case FILE_LESTRING16:
120  case FILE_SEARCH:
121  file_showstr(stderr, m->value.s, (size_t)m->vallen);
122  break;
123  case FILE_DATE:
124  case FILE_LEDATE:
125  case FILE_BEDATE:
126  case FILE_MEDATE:
127  (void)eprintf("%s,",
128  file_fmttime(m->value.l, 1, pp));
129  break;
130  case FILE_LDATE:
131  case FILE_LELDATE:
132  case FILE_BELDATE:
133  case FILE_MELDATE:
134  (void)eprintf("%s,",
135  file_fmttime(m->value.l, 0, pp));
136  break;
137  case FILE_QDATE:
138  case FILE_LEQDATE:
139  case FILE_BEQDATE:
140  (void)eprintf("%s,",
141  file_fmttime((ut32)m->value.q, 1, pp));
142  break;
143  case FILE_QLDATE:
144  case FILE_LEQLDATE:
145  case FILE_BEQLDATE:
146  (void)eprintf("%s,",
147  file_fmttime((ut32)m->value.q, 0, pp));
148  break;
149  case FILE_FLOAT:
150  case FILE_BEFLOAT:
151  case FILE_LEFLOAT:
152  (void)eprintf("%G", m->value.f);
153  break;
154  case FILE_DOUBLE:
155  case FILE_BEDOUBLE:
156  case FILE_LEDOUBLE:
157  (void)eprintf("%G", m->value.d);
158  break;
159  case FILE_DEFAULT:
160  /* XXX - do anything here? */
161  break;
162  default:
163  (void)fputs("*bad*", stderr);
164  break;
165  }
166  }
167  (void)eprintf(",\"%s\"]\n", m->desc);
168 }
static const size_t file_nnames
Definition: apprentice.c:78
void file_showstr(FILE *fp, const char *s, size_t len)
Definition: apprentice.c:1778
static const char * magic_file_names[FILE_NAMES_SIZE]
Definition: apprentice.c:77
uint32_t ut32
#define SZOF(a)
Definition: mdump.c:44
const char * file_fmttime(ut32 v, int local, char *pp)
Definition: mdump.c:188
#define UNSIGNED(n, x)
#define ASCTIME_BUF_MINLEN
Definition: rz_time.h:13
#define PFMT64d
Definition: rz_types.h:394
#define PFMT64x
Definition: rz_types.h:393
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References ASCTIME_BUF_MINLEN, eprintf, file_fmttime(), file_nnames, file_showstr(), regress::m, magic_file_names, PFMT64d, PFMT64x, SZOF, UNSIGNED, and ut64().

Referenced by mget(), and parse().