11 #include <sys/types.h>
16 #include <sys/types.h>
34 #include <sys/types.h>
53 #include <sys/types.h>
64 #include <sys/resource.h>
66 #include <sys/ptrace.h>
93 #include <sys/types.h>
103 #define DEFAULT_SCRIPT "/usr/share/wcc/scripts/debug"
104 #define DEFAULT_SCRIPT_INDEX "/usr/share/wcc/scripts/INDEX"
105 #define PROC_ASLR_PATH "/proc/sys/kernel/randomize_va_space"
107 #define DEFAULT_LEARN_FILE "./learnwitch.log"
109 #define MAX_SIGNALS 2000000
111 #define MY_CPU 1 // Which CPU to set affinity to
113 #define BIND_FLAGS RTLD_NOW
122 #define DMGL_PARAMS (1 << 0)
123 #define DMGL_ANSI (1 << 1)
124 #define DMGL_ARM (1 << 11)
127 #define Elf_Dyn Elf64_Dyn
128 #define Elf_Ehdr Elf64_Ehdr
129 #define Elf_Phdr Elf64_Phdr
130 #define Elf_Shdr Elf64_Shdr
131 #define Elf_Sym Elf64_Sym
133 #define Elf_Dyn Elf32_Dyn
134 #define Elf_Ehdr Elf32_Ehdr
135 #define Elf_Phdr Elf32_Phdr
136 #define Elf_Shdr Elf32_Shdr
137 #define Elf_Sym Elf32_Sym
142 #define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4)
143 #define ELF32_ST_TYPE(val) ((val) & 0xf)
144 #define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
146 #define ELF64_ST_BIND(val) ELF32_ST_BIND (val)
147 #define ELF64_ST_TYPE(val) ELF32_ST_TYPE (val)
148 #define ELF64_ST_INFO(bind, type) ELF32_ST_INFO ((bind), (type))
153 #define STB_GNU_UNIQUE 10
154 #define STB_GNU_SECONDARY 11
159 #define STT_SECTION 3
171 #define read_arg1(arg1){ \
172 if (lua_isnil(L, 1)) { \
174 } else if (lua_isnumber(L, 1)) { \
175 arg1 = (unsigned long) lua_tonumber(L, 1); \
176 } else if (lua_isstring(L, 1)) { \
177 arg1 = luaL_checkstring(L, 1); \
178 } else if (lua_istable(L, 1)) { \
179 } else if (lua_isfunction(L, 1)) { \
180 arg1 = lua_tocfunction(L, 1); \
181 } else if (lua_iscfunction(L, 1)) { \
182 arg1 = lua_touserdata(L, 1); \
183 } else if (lua_isuserdata(L, 1)) { \
184 arg1 = lua_touserdata(L, 1); \
193 #define read_arg2(arg2){ \
194 if (lua_isnil(L, 2)) { \
196 } else if (lua_isnumber(L, 2)) { \
197 arg2 = (unsigned long) lua_tonumber(L, 2); \
198 } else if (lua_isstring(L, 2)) { \
199 arg2 = luaL_checkstring(L, 2); \
200 } else if (lua_istable(L, 2)) { \
201 } else if (lua_isfunction(L, 2)) { \
202 arg2 = lua_tocfunction(L, 2); \
203 } else if (lua_iscfunction(L, 2)) { \
204 arg2 = lua_touserdata(L, 2); \
205 } else if (lua_isuserdata(L, 2)) { \
206 arg2 = lua_touserdata(L, 2); \
215 #define read_arg3(arg3){ \
216 if (lua_isnil(L, 3)) { \
218 } else if (lua_isnumber(L, 3)) { \
219 arg3 = (unsigned long) lua_tonumber(L, 3); \
220 } else if (lua_isstring(L, 3)) { \
221 arg3 = luaL_checkstring(L, 3); \
222 } else if (lua_istable(L, 3)) { \
223 } else if (lua_isfunction(L, 3)) { \
224 arg3 = lua_tocfunction(L, 3); \
225 } else if (lua_iscfunction(L, 3)) { \
226 arg3 = lua_touserdata(L, 3); \
227 } else if (lua_isuserdata(L, 3)) { \
228 arg3 = lua_touserdata(L, 3); \
237 #define read_arg4(arg4){ \
238 if (lua_isnil(L, 4)) { \
240 } else if (lua_isnumber(L, 4)) { \
241 arg4 = (unsigned long) lua_tonumber(L, 4); \
242 } else if (lua_isstring(L, 4)) { \
243 arg4 = luaL_checkstring(L, 4); \
244 } else if (lua_istable(L, 4)) { \
245 } else if (lua_isfunction(L, 4)) { \
246 arg4 = lua_tocfunction(L, 4); \
247 } else if (lua_iscfunction(L, 4)) { \
248 arg4 = lua_touserdata(L, 4); \
249 } else if (lua_isuserdata(L, 4)) { \
250 arg4 = lua_touserdata(L, 4); \
259 #define read_arg(arg, j){ \
260 if (lua_isnil(L, j)) { \
262 } else if (lua_isnumber(L, j)) { \
263 arg = (unsigned long) lua_tonumber(L, j); \
264 } else if (lua_isstring(L, j)) { \
265 arg = luaL_checkstring(L, j); \
266 } else if (lua_istable(L, j)) { \
267 } else if (lua_isfunction(L, j)) { \
268 arg = lua_tocfunction(L, j); \
269 } else if (lua_iscfunction(L, j)) { \
270 arg = lua_touserdata(L, j); \
271 } else if (lua_isuserdata(L, j)) { \
272 arg = lua_touserdata(L, j); \
278 #define SHELL_HISTORY_NAME ".wsh_history"
279 #define luaL_reg luaL_Reg
281 #define MIN_BIN_SIZE 10
284 #define FAULT_WRITE 2
287 #define default_poison 0x61
293 #define SKIP_INIT 0 // for developpment
294 #define SKIP_BOTTOM 0
297 #define SKIP_BOTTOM 13
328 int usage(
char *name);
351 int add_symbol(
char *symbol,
char *libname,
char *htype,
char *hbind,
unsigned long value,
unsigned int size,
unsigned long int addr);
352 void segment_add(
unsigned long int addr,
unsigned long int size,
char *perms,
char *fname,
char *ptype,
int flags);
384 unsigned int ltrace(
void);
387 void hexdump(uint8_t * data,
size_t size,
size_t colorstart,
size_t color_len);
434 unsigned long long int min;
435 unsigned long long int max;
unsigned int trace_singlebranch
int print_libs(lua_State *L)
struct script_t * scripts
int rawmemstr(lua_State *L)
unsigned int trace_strace
void verbosetrace(lua_State *L)
int gencore(lua_State *L)
unsigned int globalsignals
int do_loadlib(char *libname)
unsigned long long int singlebranch_hash
void set_trace_flag(void)
void traceunaligned(lua_State *L)
struct symbols_t * symbols
int breakpoint(lua_State *L)
int headers(lua_State *L)
unsigned int longjmp_ptr_high_cnt
int rawmemaddr(lua_State *L)
int newarray(lua_State *L)
int add_symbol(char *symbol, char *libname, char *htype, char *hbind, unsigned long value, unsigned int size, unsigned long int addr)
struct sections_t * shdrs
unsigned int trace_rtrace
int libcall(lua_State *L)
void systrace(lua_State *L)
int print_functions(lua_State *L)
int getcharbuf(lua_State *L)
unsigned int ltrace(void)
struct symbols_t symbols_t
void unset_branch_flag(void)
void singlestep(lua_State *L)
void set_align_flag(void)
void segment_add(unsigned long int addr, unsigned long int size, char *perms, char *fname, char *ptype, int flags)
char * signaltoname(int signal)
void unsystrace(lua_State *L)
unsigned int trace_singlestep
int setcharbuf(lua_State *L)
void hexdump(uint8_t *data, size_t size, size_t colorstart, size_t color_len)
struct lua_State lua_State
int disable_core(lua_State *L)
int rawmemstrlen(lua_State *L)
void untraceunaligned(lua_State *L)
int hollywood(lua_State *L)
unsigned long long int min
int rawmemwrite(lua_State *L)
char * sicode_strerror(int signal, siginfo_t *s)
struct link_map * link_map
unsigned int singlestep_count
int grepptr(lua_State *L)
int bsspolute(lua_State *L)
int priv_strcat(lua_State *L)
unsigned int opt_hollywood
struct sections_t sections_t
int priv_memcpy(lua_State *L)
int print_symbols(lua_State *L)
void unrtrace(lua_State *L)
unsigned long long int sigbus_hash
unsigned int is_stdinscript
struct segments_t * phdrs
struct breakpoint_t breakpoint_t
void unset_align_flag(void)
void set_branch_flag(void)
unsigned long long int max
int wsh_getopt(wsh_t *wsh1, int argc, char **argv)
unsigned long int faultaddr
struct preload_t preload_t
void unverbosetrace(lua_State *L)
int getsize(lua_State *L)
char * cplus_demangle(const char *mangled, int options)
unsigned int trace_unaligned
int verbose(lua_State *L)
int loadbin(lua_State *L)
void unsinglebranch(lua_State *L)
int rawmemread(lua_State *L)
unsigned int opt_verbosetrace
int rawmemusage(lua_State *L)
unsigned long int btcaller
int prototypes(lua_State *L)
void unset_trace_flag(void)
void rtrace(lua_State *L)
int enable_core(lua_State *L)
void singlebranch(lua_State *L)
unsigned int singlebranch_count
int entrypoints(lua_State *L)
unsigned int script_argnum
void unsinglestep(lua_State *L)
unsigned long long int singlestep_hash
int alloccharbuf(lua_State *L)
struct preload_t * preload
int priv_strcpy(lua_State *L)
struct segments_t segments_t
unsigned int sigbus_count
int setarray(lua_State *L)
int execlib(lua_State *L)
int print_objects(lua_State *L)