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

Go to the source code of this file.

Classes

struct  pyc_object
 
struct  pyc_code_object
 
struct  pyc_context
 

Typedefs

typedef struct pyc_context RzBinPycObj
 

Enumerations

enum  pyc_marshal_type {
  TYPE_ASCII = 'a' , TYPE_ASCII_INTERNED = 'A' , TYPE_BINARY_COMPLEX = 'y' , TYPE_BINARY_FLOAT = 'g' ,
  TYPE_CODE_v0 = 'C' , TYPE_CODE_v1 = 'c' , TYPE_COMPLEX = 'x' , TYPE_DICT = '{' ,
  TYPE_ELLIPSIS = '.' , TYPE_FALSE = 'F' , TYPE_FLOAT = 'f' , TYPE_FROZENSET = '>' ,
  TYPE_INT64 = 'I' , TYPE_INTERNED = 't' , TYPE_INT = 'i' , TYPE_LIST = '[' ,
  TYPE_LONG = 'l' , TYPE_NONE = 'N' , TYPE_NULL = '0' , TYPE_REF = 'r' ,
  TYPE_SET = '<' , TYPE_SHORT_ASCII_INTERNED = 'Z' , TYPE_SHORT_ASCII = 'z' , TYPE_SMALL_TUPLE = ')' ,
  TYPE_STOPITER = 'S' , TYPE_STRINGREF = 'R' , TYPE_STRING = 's' , TYPE_TRUE = 'T' ,
  TYPE_TUPLE = '(' , TYPE_UNICODE = 'u' , TYPE_UNKNOWN = '?'
}
 
enum  pyc_marshal_flag { FLAG_REF = '\x80' }
 

Functions

bool get_sections_symbols_from_code_objects (RzBinPycObj *pyc, RzBuffer *buffer, RzList *sections, RzList *symbols, RzList *objs, ut32 magic)
 
ut64 get_code_object_addr (RzBinPycObj *pyc, RzBuffer *buffer, ut32 magic)
 

Typedef Documentation

◆ RzBinPycObj

typedef struct pyc_context RzBinPycObj

Enumeration Type Documentation

◆ pyc_marshal_flag

Enumerator
FLAG_REF 

Definition at line 46 of file marshal.h.

46  {
47  FLAG_REF = '\x80',
pyc_marshal_flag
Definition: marshal.h:46
@ FLAG_REF
Definition: marshal.h:47

◆ pyc_marshal_type

Enumerator
TYPE_ASCII 
TYPE_ASCII_INTERNED 
TYPE_BINARY_COMPLEX 
TYPE_BINARY_FLOAT 
TYPE_CODE_v0 
TYPE_CODE_v1 
TYPE_COMPLEX 
TYPE_DICT 
TYPE_ELLIPSIS 
TYPE_FALSE 
TYPE_FLOAT 
TYPE_FROZENSET 
TYPE_INT64 
TYPE_INTERNED 
TYPE_INT 
TYPE_LIST 
TYPE_LONG 
TYPE_NONE 
TYPE_NULL 
TYPE_REF 
TYPE_SET 
TYPE_SHORT_ASCII_INTERNED 
TYPE_SHORT_ASCII 
TYPE_SMALL_TUPLE 
TYPE_STOPITER 
TYPE_STRINGREF 
TYPE_STRING 
TYPE_TRUE 
TYPE_TUPLE 
TYPE_UNICODE 
TYPE_UNKNOWN 

Definition at line 12 of file marshal.h.

12  {
13  TYPE_ASCII = 'a',
14  TYPE_ASCII_INTERNED = 'A',
15  TYPE_BINARY_COMPLEX = 'y',
16  TYPE_BINARY_FLOAT = 'g',
17  TYPE_CODE_v0 = 'C',
18  TYPE_CODE_v1 = 'c',
19  TYPE_COMPLEX = 'x',
20  TYPE_DICT = '{',
21  TYPE_ELLIPSIS = '.',
22  TYPE_FALSE = 'F',
23  TYPE_FLOAT = 'f',
24  TYPE_FROZENSET = '>',
25  TYPE_INT64 = 'I',
26  TYPE_INTERNED = 't',
27  TYPE_INT = 'i',
28  TYPE_LIST = '[',
29  TYPE_LONG = 'l',
30  TYPE_NONE = 'N',
31  TYPE_NULL = '0',
32  TYPE_REF = 'r',
33  TYPE_SET = '<',
35  TYPE_SHORT_ASCII = 'z',
36  TYPE_SMALL_TUPLE = ')',
37  TYPE_STOPITER = 'S',
38  TYPE_STRINGREF = 'R',
39  TYPE_STRING = 's',
40  TYPE_TRUE = 'T',
41  TYPE_TUPLE = '(',
42  TYPE_UNICODE = 'u',
43  TYPE_UNKNOWN = '?',
pyc_marshal_type
Definition: marshal.h:12
@ TYPE_NONE
Definition: marshal.h:30
@ TYPE_STRINGREF
Definition: marshal.h:38
@ TYPE_INT64
Definition: marshal.h:25
@ TYPE_SHORT_ASCII
Definition: marshal.h:35
@ TYPE_NULL
Definition: marshal.h:31
@ TYPE_BINARY_FLOAT
Definition: marshal.h:16
@ TYPE_FLOAT
Definition: marshal.h:23
@ TYPE_LIST
Definition: marshal.h:28
@ TYPE_BINARY_COMPLEX
Definition: marshal.h:15
@ TYPE_TUPLE
Definition: marshal.h:41
@ TYPE_TRUE
Definition: marshal.h:40
@ TYPE_LONG
Definition: marshal.h:29
@ TYPE_INT
Definition: marshal.h:27
@ TYPE_UNKNOWN
Definition: marshal.h:43
@ TYPE_DICT
Definition: marshal.h:20
@ TYPE_UNICODE
Definition: marshal.h:42
@ TYPE_SMALL_TUPLE
Definition: marshal.h:36
@ TYPE_INTERNED
Definition: marshal.h:26
@ TYPE_ELLIPSIS
Definition: marshal.h:21
@ TYPE_COMPLEX
Definition: marshal.h:19
@ TYPE_CODE_v1
Definition: marshal.h:18
@ TYPE_ASCII_INTERNED
Definition: marshal.h:14
@ TYPE_REF
Definition: marshal.h:32
@ TYPE_FALSE
Definition: marshal.h:22
@ TYPE_SET
Definition: marshal.h:33
@ TYPE_CODE_v0
Definition: marshal.h:17
@ TYPE_STRING
Definition: marshal.h:39
@ TYPE_FROZENSET
Definition: marshal.h:24
@ TYPE_ASCII
Definition: marshal.h:13
@ TYPE_STOPITER
Definition: marshal.h:37
@ TYPE_SHORT_ASCII_INTERNED
Definition: marshal.h:34

Function Documentation

◆ get_code_object_addr()

ut64 get_code_object_addr ( RzBinPycObj pyc,
RzBuffer buffer,
ut32  magic 
)

Definition at line 981 of file marshal.c.

981  {
982  pyc->magic_int = magic;
983  pyc_object *co = get_code_object(pyc, buffer);
984  ut64 result = 0;
985  if (!co) {
986  return 0;
987  }
988 
989  pyc_code_object *cobj = co->data;
990  result = cobj->start_offset;
991  free_object(co);
992 
993  return result;
994 }
static void free_object(pyc_object *object)
Definition: marshal.c:712
static pyc_object * get_code_object(RzBinPycObj *pyc, RzBuffer *buffer)
Definition: marshal.c:850
Definition: buffer.h:15
st64 start_offset
Definition: marshal.h:72
ut32 magic_int
Definition: marshal.h:84
void * data
Definition: marshal.h:52
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References pyc_object::data, free_object(), get_code_object(), pyc_context::magic_int, pyc_code_object::start_offset, and ut64().

Referenced by get_entrypoint().

◆ get_sections_symbols_from_code_objects()

bool get_sections_symbols_from_code_objects ( RzBinPycObj pyc,
RzBuffer buffer,
RzList sections,
RzList symbols,
RzList objs,
ut32  magic 
)

Definition at line 1190 of file marshal.c.

1190  {
1191  bool ret;
1192  pyc->magic_int = magic;
1194  if (!pyc->refs) {
1195  return false;
1196  }
1197  ret = extract_sections_symbols(pyc, get_object(pyc, buffer), sections, symbols, cobjs, NULL);
1198  rz_list_free(pyc->refs);
1199  return ret;
1200 }
RzList * symbols(RzBinFile *bf)
Definition: bin_ne.c:102
RzList * sections(RzBinFile *bf)
Definition: bin_ne.c:110
#define NULL
Definition: cris-opc.c:27
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
static bool extract_sections_symbols(RzBinPycObj *pyc, pyc_object *obj, RzList *sections, RzList *symbols, RzList *cobjs, char *prefix)
Definition: marshal.c:1125
static pyc_object * get_object(RzBinPycObj *pyc, RzBuffer *buffer)
Definition: marshal.c:996
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
RzList * refs
Definition: marshal.h:83

References extract_sections_symbols(), free_object(), get_object(), pyc_context::magic_int, NULL, pyc_context::refs, rz_list_free(), rz_list_newf(), sections(), and symbols().

Referenced by pyc_get_sections_symbols().