Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | List of all members
miasm2.jitter.jitcore.JitCore Class Reference
+ Inheritance diagram for miasm2.jitter.jitcore.JitCore:
+ Collaboration diagram for miasm2.jitter.jitcore.JitCore:

Public Member Functions

def __init__
 
def set_options
 
def add_disassembly_splits
 
def remove_disassembly_splits
 
def load
 
def get_bloc_min_max
 
def add_bloc_to_mem_interval
 
def jitirblocs
 
def add_bloc
 
def disbloc
 
def jit_call
 
def runbloc
 
def blocs2memrange
 
def del_bloc_in_range
 
def updt_automod_code
 
def automod_cb
 

Public Attributes

 ir_arch
 
 bs
 
 known_blocs
 
 lbl2jitbloc
 
 lbl2bloc
 
 log_mn
 
 log_regs
 
 log_newbloc
 
 segm_to_do
 
 job_done
 
 jitcount
 
 addr2obj
 
 addr2objref
 
 blocs_mem_interval
 
 disasm_cb
 
 split_dis
 
 addr_mod
 
 options
 

Static Public Attributes

 jitted_block_delete_cb = None
 
int jitted_block_max_size = 10000
 

Private Member Functions

def __updt_jitcode_mem_range
 

Detailed Description

Definition at line 24 of file jitcore.py.

Constructor & Destructor Documentation

def miasm2.jitter.jitcore.JitCore.__init__ (   self,
  ir_arch,
  bs = None 
)
Initialise a JitCore instance.
@ir_arch: ir instance for current architecture
@bs: bitstream

Definition at line 31 of file jitcore.py.

31 
32  def __init__(self, ir_arch, bs=None):
33  """Initialise a JitCore instance.
34  @ir_arch: ir instance for current architecture
35  @bs: bitstream
36  """
37 
38  self.ir_arch = ir_arch
39  self.bs = bs
40  self.known_blocs = {}
42  delete_cb=self.jitted_block_delete_cb)
43  self.lbl2bloc = {}
44  self.log_mn = False
45  self.log_regs = False
46  self.log_newbloc = False
47  self.segm_to_do = set()
48  self.job_done = set()
49  self.jitcount = 0
50  self.addr2obj = {}
51  self.addr2objref = {}
53  self.disasm_cb = None
54  self.split_dis = set()
55  self.addr_mod = interval()
56 
57  self.options = {"jit_maxline": 50 # Maximum number of line jitted
58  }

Member Function Documentation

def miasm2.jitter.jitcore.JitCore.__updt_jitcode_mem_range (   self,
  vm 
)
private
Rebuild the VM blocs address memory range
@vm: VmMngr instance

Definition at line 195 of file jitcore.py.

196  def __updt_jitcode_mem_range(self, vm):
197  """Rebuild the VM blocs address memory range
198  @vm: VmMngr instance
199  """
200 
201  # Reset the current pool
202  vm.reset_code_bloc_pool()
203 
204  # Add blocs in the pool
205  for a, b in self.blocs_mem_interval:
206  vm.add_code_bloc(a, b + 1)

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.add_bloc (   self,
  b 
)
Add a bloc to JiT and JiT it.
@b: the bloc to add

Definition at line 102 of file jitcore.py.

103  def add_bloc(self, b):
104  """Add a bloc to JiT and JiT it.
105  @b: the bloc to add
106  """
107 
108  irblocs = self.ir_arch.add_bloc(b, gen_pc_updt = True)
109  b.irblocs = irblocs
110  self.jitirblocs(b.label, irblocs)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.add_bloc_to_mem_interval (   self,
  vm,
  bloc 
)

Definition at line 85 of file jitcore.py.

85 
86  def add_bloc_to_mem_interval(self, vm, bloc):
87  "Update vm to include bloc addresses in its memory range"
88 
89  self.blocs_mem_interval += interval([(bloc.ad_min, bloc.ad_max - 1)])
90 
91  vm.reset_code_bloc_pool()
92  for a, b in self.blocs_mem_interval:
93  vm.add_code_bloc(a, b + 1)

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.add_disassembly_splits (   self,
  args 
)
The disassembly engine will stop on address in args if they
are not at the block beginning

Definition at line 64 of file jitcore.py.

64 
65  def add_disassembly_splits(self, *args):
66  """The disassembly engine will stop on address in args if they
67  are not at the block beginning"""
68  self.split_dis.update(set(args))
def miasm2.jitter.jitcore.JitCore.automod_cb (   self,
  addr = 0,
  size = 0 
)

Definition at line 260 of file jitcore.py.

261  def automod_cb(self, addr=0, size=0):
262  self.addr_mod += interval([(addr, addr + size / 8 - 1)])
263  return None
def miasm2.jitter.jitcore.JitCore.blocs2memrange (   self,
  blocs 
)
Return an interval instance standing for blocs addresses
@blocs: list of asm_bloc instances

Definition at line 183 of file jitcore.py.

184  def blocs2memrange(self, blocs):
185  """Return an interval instance standing for blocs addresses
186  @blocs: list of asm_bloc instances
187  """
188 
189  mem_range = interval()
190 
191  for b in blocs:
192  mem_range += interval([(b.ad_min, b.ad_max - 1)])
193 
194  return mem_range

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.del_bloc_in_range (   self,
  ad1,
  ad2 
)
Find and remove jitted bloc in range [ad1, ad2].
Return the list of bloc removed.
@ad1: First address
@ad2: Last address

Definition at line 207 of file jitcore.py.

208  def del_bloc_in_range(self, ad1, ad2):
209  """Find and remove jitted bloc in range [ad1, ad2].
210  Return the list of bloc removed.
211  @ad1: First address
212  @ad2: Last address
213  """
214 
215  # Find concerned blocs
216  modified_blocs = set()
217  for b in self.lbl2bloc.values():
218  if not b.lines:
219  continue
220  if b.ad_max <= ad1 or b.ad_min >= ad2:
221  # Bloc not modified
222  pass
223  else:
224  # Modified blocs
225  modified_blocs.add(b)
226 
227  # Generate interval to delete
228  del_interval = self.blocs2memrange(modified_blocs)
229 
230  # Remove interval from monitored interval list
231  self.blocs_mem_interval -= del_interval
232 
233  # Remove modified blocs
234  for b in modified_blocs:
235  try:
236  for irbloc in b.irblocs:
237 
238  # Remove offset -> jitted bloc link
239  if irbloc.label.offset in self.lbl2jitbloc:
240  del(self.lbl2jitbloc[irbloc.label.offset])
241 
242  except AttributeError:
243  # The bloc has never been translated in IR
244  if b.label.offset in self.lbl2jitbloc:
245  del(self.lbl2jitbloc[b.label.offset])
246 
247  # Remove label -> bloc link
248  del(self.lbl2bloc[b.label])
249 
250  return modified_blocs

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.disbloc (   self,
  addr,
  cpu,
  vm 
)

Definition at line 111 of file jitcore.py.

112  def disbloc(self, addr, cpu, vm):
113  "Disassemble a new bloc and JiT it"
114 
115  # Get the bloc
116  if isinstance(addr, asmbloc.asm_label):
117  addr = addr.offset
118 
119  l = self.ir_arch.symbol_pool.getby_offset_create(addr)
120  cur_bloc = asmbloc.asm_bloc(l)
121 
122  # Disassemble it
123  try:
124  asmbloc.dis_bloc(self.ir_arch.arch, self.bs, cur_bloc, addr,
125  set(), self.ir_arch.symbol_pool, [],
126  follow_call=False, dontdis_retcall=False,
127  lines_wd=self.options["jit_maxline"],
128  # max 10 asm lines
129  attrib=self.ir_arch.attrib,
130  split_dis=self.split_dis)
131  except IOError:
132  # vm_exception_flag is set
133  pass
134 
135  # Logging
136  if self.log_newbloc:
137  print cur_bloc
138  if self.disasm_cb is not None:
139  self.disasm_cb(cur_bloc)
140 
141  # Check for empty blocks
142  if not cur_bloc.lines:
143  raise ValueError("Cannot JIT a block without any assembly line")
144 
145  # Update label -> bloc
146  self.lbl2bloc[l] = cur_bloc
147 
148  # Store min/max bloc address needed in jit automod code
149  self.get_bloc_min_max(cur_bloc)
150 
151  # JiT it
152  self.add_bloc(cur_bloc)
153 
154  # Update jitcode mem range
155  self.add_bloc_to_mem_interval(vm, cur_bloc)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.get_bloc_min_max (   self,
  cur_bloc 
)

Definition at line 78 of file jitcore.py.

78 
79  def get_bloc_min_max(self, cur_bloc):
80  "Update cur_bloc to set min/max address"
81 
82  if cur_bloc.lines:
83  cur_bloc.ad_min = cur_bloc.lines[0].offset
84  cur_bloc.ad_max = cur_bloc.lines[-1].offset + cur_bloc.lines[-1].l

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.jit_call (   self,
  label,
  cpu,
  _vmmngr,
  breakpoints 
)
Call the function label with cpu and vmmngr states
@label: function's label
@cpu: JitCpu instance
@breakpoints: Dict instance of used breakpoints

Definition at line 156 of file jitcore.py.

157  def jit_call(self, label, cpu, _vmmngr, breakpoints):
158  """Call the function label with cpu and vmmngr states
159  @label: function's label
160  @cpu: JitCpu instance
161  @breakpoints: Dict instance of used breakpoints
162  """
163  return self.exec_wrapper(label, cpu, self.lbl2jitbloc.data, breakpoints)

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.jitirblocs (   self,
  label,
  irblocs 
)
JiT a group of irblocs.
@label: the label of the irblocs
@irblocs: a gorup of irblocs

Definition at line 94 of file jitcore.py.

94 
95  def jitirblocs(self, label, irblocs):
96  """JiT a group of irblocs.
97  @label: the label of the irblocs
98  @irblocs: a gorup of irblocs
99  """
100 
101  raise NotImplementedError("Abstract class")

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.load (   self,
  arch,
  attrib 
)

Definition at line 73 of file jitcore.py.

73 
74  def load(self, arch, attrib):
75  "Initialise the Jitter according to arch and attrib"
76 
77  raise NotImplementedError("Abstract class")
def miasm2.jitter.jitcore.JitCore.remove_disassembly_splits (   self,
  args 
)
The disassembly engine will no longer stop on address in args

Definition at line 69 of file jitcore.py.

69 
70  def remove_disassembly_splits(self, *args):
71  """The disassembly engine will no longer stop on address in args"""
72  self.split_dis.difference_update(set(args))
def miasm2.jitter.jitcore.JitCore.runbloc (   self,
  cpu,
  vm,
  lbl,
  breakpoints 
)
Run the bloc starting at lbl.
@cpu: JitCpu instance
@vm: VmMngr instance
@lbl: target label

Definition at line 164 of file jitcore.py.

165  def runbloc(self, cpu, vm, lbl, breakpoints):
166  """Run the bloc starting at lbl.
167  @cpu: JitCpu instance
168  @vm: VmMngr instance
169  @lbl: target label
170  """
171 
172  if lbl is None:
173  lbl = cpu.get_gpreg()[self.ir_arch.pc.name]
174 
175  if not lbl in self.lbl2jitbloc:
176  # Need to JiT the bloc
177  self.disbloc(lbl, cpu, vm)
178 
179  # Run the bloc and update cpu/vmmngr state
180  ret = self.jit_call(lbl, cpu, vm, breakpoints)
181 
182  return ret

+ Here is the call graph for this function:

def miasm2.jitter.jitcore.JitCore.set_options (   self,
  kwargs 
)

Definition at line 59 of file jitcore.py.

59 
60  def set_options(self, **kwargs):
61  "Set options relative to the backend"
62 
63  self.options.update(kwargs)
def miasm2.jitter.jitcore.JitCore.updt_automod_code (   self,
  vm 
)
Remove code jitted in range self.addr_mod
@vm: VmMngr instance

Definition at line 251 of file jitcore.py.

252  def updt_automod_code(self, vm):
253  """Remove code jitted in range self.addr_mod
254  @vm: VmMngr instance
255  """
256  for addr_start, addr_stop in self.addr_mod:
257  self.del_bloc_in_range(addr_start, addr_stop + 1)
258  self.__updt_jitcode_mem_range(vm)
259  self.addr_mod = interval()

+ Here is the call graph for this function:

Member Data Documentation

miasm2.jitter.jitcore.JitCore.addr2obj

Definition at line 49 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.addr2objref

Definition at line 50 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.addr_mod

Definition at line 54 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.blocs_mem_interval

Definition at line 51 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.bs

Definition at line 38 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.disasm_cb

Definition at line 52 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.ir_arch

Definition at line 37 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.jitcount

Definition at line 48 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.jitted_block_delete_cb = None
static

Definition at line 28 of file jitcore.py.

int miasm2.jitter.jitcore.JitCore.jitted_block_max_size = 10000
static

Definition at line 29 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.job_done

Definition at line 47 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.known_blocs

Definition at line 39 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.lbl2bloc

Definition at line 42 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.lbl2jitbloc

Definition at line 40 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.log_mn

Definition at line 43 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.log_newbloc

Definition at line 45 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.log_regs

Definition at line 44 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.options

Definition at line 56 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.segm_to_do

Definition at line 46 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.split_dis

Definition at line 53 of file jitcore.py.


The documentation for this class was generated from the following file: