Rizin
unix-like reverse engineering framework and cli tools
pyc_magic.c File Reference
#include "pyc_magic.h"
#include <rz_util.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

struct pyc_version get_pyc_version (ut32 magic)
 
bool magic_int_within (ut32 target_magic, ut32 lower, ut32 upper, bool *error)
 
double version2double (const char *version)
 

Variables

static struct pyc_version versions []
 

Function Documentation

◆ get_pyc_version()

struct pyc_version get_pyc_version ( ut32  magic)

Definition at line 1 of file pyc_magic.c.

273  {
274  struct pyc_version fail = { -1, 0, 0 };
275  ut32 i;
276  for (i = 0; i < sizeof(versions) / sizeof(*versions); i++)
277  if (versions[i].magic == magic) {
278  return versions[i];
279  }
280  return fail;
281 }
lzma_index ** i
Definition: index.h:629
uint32_t ut32
static struct pyc_version versions[]
Definition: pyc_magic.c:13
ut32 magic
Definition: pyc_magic.h:11
#define fail(test)
Definition: tests.h:29

Referenced by check_buffer(), and load_buffer().

◆ magic_int_within()

bool magic_int_within ( ut32  target_magic,
ut32  lower,
ut32  upper,
bool error 
)

Definition at line 283 of file pyc_magic.c.

283  {
284  if (*error) {
285  return false;
286  }
287  ut64 ti = 0, li = 0, ui = 0;
288  ut64 size = sizeof(versions) / sizeof(struct pyc_version);
289  for (; ti < size && versions[ti].magic != target_magic; ti++) {
290  }
291  if (ti == size) {
292  *error = true;
293  RZ_LOG_ERROR("Cannot find pyc target_magic.\n");
294  return false;
295  }
296 
297  for (; li < size && (versions[li].magic & 0xffff) != lower; li++) {
298  }
299  if (li == size) {
300  *error = true;
301  RZ_LOG_ERROR("Cannot find pyc lower magic_int.\n");
302  return false;
303  }
304 
305  for (; ui < size && (versions[ui].magic & 0xffff) != upper; ui++) {
306  }
307  if (ui == size) {
308  *error = true;
309  RZ_LOG_ERROR("Cannot find pyc upper magic_int.\n");
310  return false;
311  }
312 
313  return (li <= ti) && (ti <= ui);
314 }
voidpf void uLong size
Definition: ioapi.h:138
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
void error(const char *msg)
Definition: untgz.c:593
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References error(), pyc_version::magic, RZ_LOG_ERROR, ut64(), and versions.

Referenced by get_code_object().

◆ version2double()

double version2double ( const char *  version)

Definition at line 316 of file pyc_magic.c.

316  {
317  unsigned idx = 0, buf_idx = 0;
318  char buf[20];
319  double result;
320 
321  while (!('0' <= version[idx] && version[idx] <= '9'))
322  idx++;
323  for (; version[idx] != '.'; idx++)
324  buf[buf_idx++] = version[idx];
325  buf[buf_idx++] = version[idx++];
326  for (; '0' <= version[idx] && version[idx] <= '9'; idx++)
327  buf[buf_idx++] = version[idx];
328  buf[buf_idx] = '\x00';
329  sscanf(buf, "%lf", &result);
330  return result;
331 }
voidpf void * buf
Definition: ioapi.h:138
int idx
Definition: setup.py:197

References setup::idx.

Referenced by info().

Variable Documentation

◆ versions

struct pyc_version versions[]
static

Definition at line 1 of file pyc_magic.c.

Referenced by magic_int_within().