Rizin
unix-like reverse engineering framework and cli tools
luac_common.c File Reference
#include "luac_common.h"

Go to the source code of this file.

Functions

LuaDbgUpvalueEntrylua_new_dbg_upvalue_entry ()
 
LuaLocalVarEntrylua_new_local_var_entry ()
 
LuaAbsLineinfoEntrylua_new_abs_lineinfo_entry ()
 
LuaLineinfoEntrylua_new_lineinfo_entry ()
 
LuaUpvalueEntrylua_new_upvalue_entry ()
 
LuaConstEntrylua_new_const_entry ()
 
LuaProtolua_new_proto_entry ()
 
void lua_free_dbg_upvalue_entry (LuaDbgUpvalueEntry *entry)
 
void lua_free_local_var_entry (LuaLocalVarEntry *entry)
 
void lua_free_const_entry (LuaConstEntry *entry)
 
void lua_free_proto_entry (LuaProto *proto)
 

Function Documentation

◆ lua_free_const_entry()

void lua_free_const_entry ( LuaConstEntry entry)

Definition at line 111 of file luac_common.c.

111  {
112  if (!entry) {
113  return;
114  }
115  free(entry->data);
116  free(entry);
117 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
Definition: zipcmp.c:77

References free().

Referenced by lua_new_proto_entry().

◆ lua_free_dbg_upvalue_entry()

void lua_free_dbg_upvalue_entry ( LuaDbgUpvalueEntry entry)

Definition at line 94 of file luac_common.c.

94  {
95  if (!entry) {
96  return;
97  }
98  free(entry->upvalue_name);
99  // leave entry to rz_list_free
100  free(entry);
101 }

References free().

Referenced by lua_new_proto_entry().

◆ lua_free_local_var_entry()

void lua_free_local_var_entry ( LuaLocalVarEntry entry)

Definition at line 103 of file luac_common.c.

103  {
104  if (!entry) {
105  return;
106  }
107  free(entry->varname);
108  free(entry);
109 }

References free().

Referenced by lua_new_proto_entry().

◆ lua_free_proto_entry()

void lua_free_proto_entry ( LuaProto proto)

Definition at line 119 of file luac_common.c.

119  {
120  if (!proto) {
121  return;
122  }
123 
124  /* free constants entries */
125  rz_list_free(proto->const_entries);
126 
127  /* free upvalue entries */
129 
130  /* free debug */
135 
136  /* recursively free protos */
137  rz_list_free(proto->proto_entries);
138 
139  free(proto->proto_name);
140  free(proto);
141 }
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RzList * dbg_upvalue_entries
A list to store upvalue names.
Definition: luac_common.h:83
RzList * upvalue_entries
A list to store upvalue entries.
Definition: luac_common.h:68
RzList * abs_line_info_entries
A list to store absolutely line info entries.
Definition: luac_common.h:81
RzList * local_var_info_entries
A list to store local var entries.
Definition: luac_common.h:82
RzList * const_entries
A list to store constant entries.
Definition: luac_common.h:63
ut8 * proto_name
current proto name
Definition: luac_common.h:47
RzList * proto_entries
A list to store sub proto entries.
Definition: luac_common.h:73
RzList * line_info_entries
A list to store line info entries.
Definition: luac_common.h:80

References lua_proto_ex::abs_line_info_entries, lua_proto_ex::const_entries, lua_proto_ex::dbg_upvalue_entries, free(), lua_proto_ex::line_info_entries, lua_proto_ex::local_var_info_entries, lua_proto_ex::proto_entries, lua_proto_ex::proto_name, rz_list_free(), and lua_proto_ex::upvalue_entries.

Referenced by load_buffer(), lua_new_proto_entry(), lua_parse_body_53(), and lua_parse_body_54().

◆ lua_new_abs_lineinfo_entry()

LuaAbsLineinfoEntry* lua_new_abs_lineinfo_entry ( )

Definition at line 18 of file luac_common.c.

18  {
20  return entry;
21 }
#define RZ_NEW0(x)
Definition: rz_types.h:284
Store line info attributes.
Definition: luac_common.h:127

References RZ_NEW0.

Referenced by lua_parse_debug().

◆ lua_new_const_entry()

LuaConstEntry* lua_new_const_entry ( )

Definition at line 33 of file luac_common.c.

33  {
35  return entry;
36 }
Store constant type, data, and offset of this constant in luac file.
Definition: luac_common.h:93

References RZ_NEW0.

Referenced by lua_parse_const_entry().

◆ lua_new_dbg_upvalue_entry()

LuaDbgUpvalueEntry* lua_new_dbg_upvalue_entry ( )

Definition at line 8 of file luac_common.c.

8  {
10  return entry;
11 }
Store upvalue's debug info.
Definition: luac_common.h:149

References RZ_NEW0.

Referenced by lua_parse_debug().

◆ lua_new_lineinfo_entry()

LuaLineinfoEntry* lua_new_lineinfo_entry ( )

Definition at line 23 of file luac_common.c.

23  {
25  return entry;
26 }
Store line info attributes.
Definition: luac_common.h:118

References RZ_NEW0.

Referenced by lua_parse_debug().

◆ lua_new_local_var_entry()

LuaLocalVarEntry* lua_new_local_var_entry ( )

Definition at line 13 of file luac_common.c.

13  {
15  return entry;
16 }
Store local var names and other info.
Definition: luac_common.h:137

References RZ_NEW0.

Referenced by lua_parse_debug().

◆ lua_new_proto_entry()

LuaProto* lua_new_proto_entry ( )

Definition at line 38 of file luac_common.c.

38  {
39  LuaProto *proto = RZ_NEW0(LuaProto);
40  if (!proto) {
41  RZ_LOG_ERROR("Cannot allocate LuaProto\n");
42  return NULL;
43  }
44 
46  if (!proto->const_entries) {
47  RZ_LOG_ERROR("Cannot allocate Const Entry List\n");
48  goto fail;
49  }
50 
52  if (!proto->upvalue_entries) {
53  RZ_LOG_ERROR("Cannot allocate Upvalue Entry List\n");
54  goto fail;
55  }
56 
58  if (!proto->proto_entries) {
59  RZ_LOG_ERROR("Cannot allocate Proto Entry List\n");
60  goto fail;
61  }
62 
64  if (!proto->line_info_entries) {
65  RZ_LOG_ERROR("Cannot allocate Debug Line Info\n");
66  goto fail;
67  }
68 
70  if (!proto->abs_line_info_entries) {
71  RZ_LOG_ERROR("Cannot allocate Abs Line Info\n");
72  goto fail;
73  }
74 
76  if (!proto->local_var_info_entries) {
77  RZ_LOG_ERROR("Cannot allocate Local Var\n");
78  goto fail;
79  }
80 
82  if (!proto->dbg_upvalue_entries) {
83  RZ_LOG_ERROR("Cannot allocate Debug Upvalues\n");
84  goto fail;
85  }
86 
87  return proto;
88 
89 fail:
90  lua_free_proto_entry(proto);
91  return NULL;
92 }
#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
void lua_free_const_entry(LuaConstEntry *entry)
Definition: luac_common.c:111
void lua_free_local_var_entry(LuaLocalVarEntry *entry)
Definition: luac_common.c:103
void lua_free_dbg_upvalue_entry(LuaDbgUpvalueEntry *entry)
Definition: luac_common.c:94
void lua_free_proto_entry(LuaProto *proto)
Definition: luac_common.c:119
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
Store valuable info when parsing. Treat luac file body as a main function.
Definition: luac_common.h:43
#define fail(test)
Definition: tests.h:29

References lua_proto_ex::abs_line_info_entries, lua_proto_ex::const_entries, lua_proto_ex::dbg_upvalue_entries, fail, free(), lua_proto_ex::line_info_entries, lua_proto_ex::local_var_info_entries, lua_free_const_entry(), lua_free_dbg_upvalue_entry(), lua_free_local_var_entry(), lua_free_proto_entry(), NULL, lua_proto_ex::proto_entries, rz_list_newf(), RZ_LOG_ERROR, RZ_NEW0, and lua_proto_ex::upvalue_entries.

Referenced by lua_parse_body_53(), and lua_parse_body_54().

◆ lua_new_upvalue_entry()

LuaUpvalueEntry* lua_new_upvalue_entry ( )

Definition at line 28 of file luac_common.c.

28  {
30  return entry;
31 }
Store upvalue attributes.
Definition: luac_common.h:104

References RZ_NEW0.

Referenced by lua_parse_upvalue_entry().