Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Classes | Functions | Variables
miasm2.os_dep.linux_stdlib Namespace Reference

Classes

class  c_linobjs
 

Functions

def xxx_isprint
 
def xxx_memcpy
 
def xxx_memset
 
def xxx_puts
 
def get_fmt_args
 
def xxx_snprintf
 
def xxx_sprintf
 
def xxx_printf
 
def xxx_strcpy
 
def xxx_strlen
 
def xxx_malloc
 
def xxx_free
 
def xxx_strcmp
 
def xxx_strncmp
 

Variables

tuple linobjs = c_linobjs()
 

Function Documentation

def miasm2.os_dep.linux_stdlib.get_fmt_args (   jitter,
  fmt,
  cur_arg 
)

Definition at line 78 of file linux_stdlib.py.

78 
79 def get_fmt_args(jitter, fmt, cur_arg):
80  output = ""
81  while True:
82  char = jitter.vm.get_mem(fmt, 1)
83  fmt += 1
84  if char == '\x00':
85  break
86  if char == '%':
87  token = '%'
88  while True:
89  char = jitter.vm.get_mem(fmt, 1)
90  fmt += 1
91  token += char
92  if char.lower() in '%cdfsux':
93  break
94  if token.endswith('s'):
95  arg = jitter.get_str_ansi(jitter.get_arg_n_stdcall(cur_arg))
96  else:
97  arg = jitter.get_arg_n_stdcall(cur_arg)
98  char = token % arg
99  cur_arg += 1
100  output += char
101  return output
102 

+ Here is the caller graph for this function:

def miasm2.os_dep.linux_stdlib.xxx_free (   jitter)

Definition at line 151 of file linux_stdlib.py.

152 def xxx_free(jitter):
153  ret_ad, args = jitter.func_args_stdcall(["ptr"])
154  jitter.func_ret_stdcall(ret_ad, 0)
155 
def miasm2.os_dep.linux_stdlib.xxx_isprint (   jitter)
#include <ctype.h>
int isprint(int c);

checks for any printable character including space.

Definition at line 23 of file linux_stdlib.py.

23 
24 def xxx_isprint(jitter):
25  '''
26  #include <ctype.h>
27  int isprint(int c);
28 
29  checks for any printable character including space.
30  '''
31  ret_addr, args = jitter.func_args_stdcall(['c'])
32  ret = 1 if chr(args.c & 0xFF) in printable else 0
33  return jitter.func_ret_stdcall(ret_addr, ret)
34 
def miasm2.os_dep.linux_stdlib.xxx_malloc (   jitter)

Definition at line 145 of file linux_stdlib.py.

146 def xxx_malloc(jitter):
147  ret_ad, args = jitter.func_args_stdcall(["msize"])
148  addr = linobjs.heap.alloc(jitter, args.msize)
149  jitter.func_ret_stdcall(ret_ad, addr)
150 
def miasm2.os_dep.linux_stdlib.xxx_memcpy (   jitter)
#include <string.h>
void *memcpy(void *dest, const void *src, size_t n);

copies n bytes from memory area src to memory area dest.

Definition at line 35 of file linux_stdlib.py.

35 
36 def xxx_memcpy(jitter):
37  '''
38  #include <string.h>
39  void *memcpy(void *dest, const void *src, size_t n);
40 
41  copies n bytes from memory area src to memory area dest.
42  '''
43  ret_addr, args = jitter.func_args_stdcall(['dest', 'src', 'n'])
44  jitter.vm.set_mem(args.dest, jitter.vm.get_mem(args.src, args.n))
45  return jitter.func_ret_stdcall(ret_addr, args.dest)
46 
def miasm2.os_dep.linux_stdlib.xxx_memset (   jitter)
#include <string.h>
void *memset(void *s, int c, size_t n);

fills the first n bytes of the memory area pointed to by s with the constant
byte c.

Definition at line 47 of file linux_stdlib.py.

47 
48 def xxx_memset(jitter):
49  '''
50  #include <string.h>
51  void *memset(void *s, int c, size_t n);
52 
53  fills the first n bytes of the memory area pointed to by s with the constant
54  byte c.'''
55 
56  ret_addr, args = jitter.func_args_stdcall(['dest', 'c', 'n'])
57  jitter.vm.set_mem(args.dest, chr(args.c & 0xFF) * args.n)
58  return jitter.func_ret_stdcall(ret_addr, args.dest)
59 
def miasm2.os_dep.linux_stdlib.xxx_printf (   jitter)

Definition at line 123 of file linux_stdlib.py.

124 def xxx_printf(jitter):
125  ret_addr, args = jitter.func_args_stdcall(['fmt'])
126  cur_arg, fmt = 1, args.fmt
127  output = get_fmt_args(jitter, fmt, cur_arg)
128  ret = len(output)
129  print output,
130  return jitter.func_ret_stdcall(ret_addr, ret)
131 

+ Here is the call graph for this function:

def miasm2.os_dep.linux_stdlib.xxx_puts (   jitter)
#include <stdio.h>
int puts(const char *s);

writes the string s and a trailing newline to stdout.

Definition at line 60 of file linux_stdlib.py.

60 
61 def xxx_puts(jitter):
62  '''
63  #include <stdio.h>
64  int puts(const char *s);
65 
66  writes the string s and a trailing newline to stdout.
67  '''
68  ret_addr, args = jitter.func_args_stdcall(['s'])
69  index = args.s
70  char = jitter.vm.get_mem(index, 1)
71  while char != '\x00':
72  stdout.write(char)
73  index += 1
74  char = jitter.vm.get_mem(index, 1)
75  stdout.write('\n')
76  return jitter.func_ret_stdcall(ret_addr, 1)
77 
def miasm2.os_dep.linux_stdlib.xxx_snprintf (   jitter)

Definition at line 103 of file linux_stdlib.py.

104 def xxx_snprintf(jitter):
105  ret_addr, args = jitter.func_args_stdcall(['string', 'size', 'fmt'])
106  cur_arg, fmt = 3, args.fmt
107  size = args.size if args.size else 1
108  output = get_fmt_args(jitter, fmt, cur_arg)
109  output = output[:size - 1]
110  ret = len(output)
111  jitter.vm.set_mem(args.string, output + '\x00')
112  return jitter.func_ret_stdcall(ret_addr, ret)
113 

+ Here is the call graph for this function:

def miasm2.os_dep.linux_stdlib.xxx_sprintf (   jitter)

Definition at line 114 of file linux_stdlib.py.

115 def xxx_sprintf(jitter):
116  ret_addr, args = jitter.func_args_stdcall(['string', 'fmt'])
117  cur_arg, fmt = 2, args.fmt
118  output = get_fmt_args(jitter, fmt, cur_arg)
119  ret = len(output)
120  jitter.vm.set_mem(args.string, output + '\x00')
121  return jitter.func_ret_stdcall(ret_addr, ret)
122 

+ Here is the call graph for this function:

def miasm2.os_dep.linux_stdlib.xxx_strcmp (   jitter)

Definition at line 156 of file linux_stdlib.py.

157 def xxx_strcmp(jitter):
158  ret_ad, args = jitter.func_args_stdcall(["ptr_str1", "ptr_str2"])
159  s1 = get_str_ansi(jitter, args.ptr_str1)
160  s2 = get_str_ansi(jitter, args.ptr_str2)
161  jitter.func_ret_stdcall(ret_ad, cmp(s1, s2))
162 

+ Here is the call graph for this function:

def miasm2.os_dep.linux_stdlib.xxx_strcpy (   jitter)

Definition at line 132 of file linux_stdlib.py.

133 def xxx_strcpy(jitter):
134  ret_ad, args = jitter.func_args_stdcall(["dst", "src"])
135  str_src = jitter.get_str_ansi(args.src) + '\x00'
136  jitter.vm.set_mem(args.dst, str_src)
137  jitter.func_ret_stdcall(ret_ad, args.dst)
138 
def miasm2.os_dep.linux_stdlib.xxx_strlen (   jitter)

Definition at line 139 of file linux_stdlib.py.

140 def xxx_strlen(jitter):
141  ret_ad, args = jitter.func_args_stdcall(["src"])
142  str_src = jitter.get_str_ansi(args.src)
143  jitter.func_ret_stdcall(ret_ad, len(str_src))
144 
def miasm2.os_dep.linux_stdlib.xxx_strncmp (   jitter)

Definition at line 163 of file linux_stdlib.py.

164 def xxx_strncmp(jitter):
165  ret_ad, args = jitter.func_args_stdcall(["ptr_str1", "ptr_str2", "size"])
166  s1 = get_str_ansi(jitter, args.ptr_str1, args.size)
167  s2 = get_str_ansi(jitter, args.ptr_str2, args.size)
168  jitter.func_ret_stdcall(ret_ad, cmp(s1, s2))

+ Here is the call graph for this function:

Variable Documentation

tuple miasm2.os_dep.linux_stdlib.linobjs = c_linobjs()

Definition at line 20 of file linux_stdlib.py.