miasm
Reverse engineering framework
miasm.core.locationdb.LocationDB Class Reference
Inheritance diagram for miasm.core.locationdb.LocationDB:
Collaboration diagram for miasm.core.locationdb.LocationDB:

Public Member Functions

def __init__ (self)
 
def get_location_offset (self, loc_key)
 
def get_location_names (self, loc_key)
 
def get_name_location (self, name)
 
def get_or_create_name_location (self, name)
 
def get_offset_location (self, offset)
 
def get_or_create_offset_location (self, offset)
 
def get_name_offset (self, name)
 
def add_location_name (self, loc_key, name)
 
def remove_location_name (self, loc_key, name)
 
def set_location_offset (self, loc_key, offset, force=False)
 
def unset_location_offset (self, loc_key)
 
def consistency_check (self)
 
def find_free_name (self, name)
 
def add_location (self, name=None, offset=None, strict=True)
 
def remove_location (self, loc_key)
 
def pretty_str (self, loc_key)
 
def loc_keys (self)
 
def names (self)
 
def offsets (self)
 
def __str__ (self)
 
def merge (self, location_db)
 
def canonize_to_exprloc (self, expr)
 
def items (self)
 
def __getitem__ (self, item)
 
def __contains__ (self, item)
 
def loc_key_to_name (self, loc_key)
 
def loc_key_to_offset (self, loc_key)
 
def remove_loc_key (self, loc_key)
 
def del_loc_key_offset (self, loc_key)
 
def getby_offset (self, offset)
 
def getby_name (self, name)
 
def getby_offset_create (self, offset)
 
def getby_name_create (self, name)
 
def rename_location (self, loc_key, newname)
 
def set_offset (self, loc_key, offset)
 
def gen_loc_key (self)
 
def str_loc_key (self, loc_key)
 

Detailed Description

LocationDB is a "database" of information associated to location.

An entry in a LocationDB is uniquely identified with a LocKey.
Additional information which can be associated with a LocKey are:
- an offset (uniq per LocationDB)
- several names (each are uniqs per LocationDB)

As a schema:
loc_key  1 <-> 0..1  offset
         1 <-> 0..n  name

>>> loc_db = LocationDB()
# Add a location with no additional information
>>> loc_key1 = loc_db.add_location()
# Add a location with an offset
>>> loc_key2 = loc_db.add_location(offset=0x1234)
# Add a location with several names
>>> loc_key3 = loc_db.add_location(name="first_name")
>>> loc_db.add_location_name(loc_key3, "second_name")
# Associate an offset to an existing location
>>> loc_db.set_location_offset(loc_key3, 0x5678)
# Remove a name from an existing location
>>> loc_db.remove_location_name(loc_key3, "second_name")

# Get back offset
>>> loc_db.get_location_offset(loc_key1)
None
>>> loc_db.get_location_offset(loc_key2)
0x1234
>>> loc_db.get_location_offset("first_name")
0x5678

# Display a location
>>> loc_db.pretty_str(loc_key1)
loc_key_1
>>> loc_db.pretty_str(loc_key2)
loc_1234
>>> loc_db.pretty_str(loc_key3)
first_name

Constructor & Destructor Documentation

◆ __init__()

def miasm.core.locationdb.LocationDB.__init__ (   self)

Member Function Documentation

◆ __contains__()

def miasm.core.locationdb.LocationDB.__contains__ (   self,
  item 
)

◆ __getitem__()

def miasm.core.locationdb.LocationDB.__getitem__ (   self,
  item 
)

◆ __str__()

def miasm.core.locationdb.LocationDB.__str__ (   self)
Here is the call graph for this function:

◆ add_location()

def miasm.core.locationdb.LocationDB.add_location (   self,
  name = None,
  offset = None,
  strict = True 
)
Add a new location in the locationDB. Returns the corresponding LocKey.
If @name is set, also associate a name to this new location.
If @offset is set, also associate an offset to this new location.

Strict mode (set by @strict, default):
  If a location with @offset or @name already exists, an error will be
raised.
Otherwise:
  If a location with @offset or @name already exists, the corresponding
LocKey may be updated and will be returned.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_location_name()

def miasm.core.locationdb.LocationDB.add_location_name (   self,
  loc_key,
  name 
)
Associate a name @name to a given @loc_key
@name: str instance
@loc_key: LocKey instance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ canonize_to_exprloc()

def miasm.core.locationdb.LocationDB.canonize_to_exprloc (   self,
  expr 
)
If expr is ExprInt, return ExprLoc with corresponding loc_key
Else, return expr

@expr: Expr instance
Here is the call graph for this function:

◆ consistency_check()

def miasm.core.locationdb.LocationDB.consistency_check (   self)
Ensure internal structures are consistent with each others

◆ del_loc_key_offset()

def miasm.core.locationdb.LocationDB.del_loc_key_offset (   self,
  loc_key 
)
[DEPRECATED API], see 'unset_location_offset'
Here is the call graph for this function:

◆ find_free_name()

def miasm.core.locationdb.LocationDB.find_free_name (   self,
  name 
)
If @name is not known in DB, return it
Else append an index to it corresponding to the next unknown name

@name: string
Here is the call graph for this function:

◆ gen_loc_key()

def miasm.core.locationdb.LocationDB.gen_loc_key (   self)
[DEPRECATED API], see 'add_location'
Here is the call graph for this function:

◆ get_location_names()

def miasm.core.locationdb.LocationDB.get_location_names (   self,
  loc_key 
)
Return the frozenset of names associated to @loc_key
@loc_key: LocKey instance
Here is the caller graph for this function:

◆ get_location_offset()

def miasm.core.locationdb.LocationDB.get_location_offset (   self,
  loc_key 
)
Return the offset of @loc_key if any, None otherwise.
@loc_key: LocKey instance
Here is the caller graph for this function:

◆ get_name_location()

def miasm.core.locationdb.LocationDB.get_name_location (   self,
  name 
)
Return the LocKey of @name if any, None otherwise.
@name: target name
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_name_offset()

def miasm.core.locationdb.LocationDB.get_name_offset (   self,
  name 
)
Return the offset of @name if any, None otherwise.
@name: target name
Here is the call graph for this function:

◆ get_offset_location()

def miasm.core.locationdb.LocationDB.get_offset_location (   self,
  offset 
)
Return the LocKey of @offset if any, None otherwise.
@offset: target offset
Here is the caller graph for this function:

◆ get_or_create_name_location()

def miasm.core.locationdb.LocationDB.get_or_create_name_location (   self,
  name 
)
Return the LocKey of @name if any, create one otherwise.
@name: target name
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_or_create_offset_location()

def miasm.core.locationdb.LocationDB.get_or_create_offset_location (   self,
  offset 
)
Return the LocKey of @offset if any, create one otherwise.
@offset: target offset
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getby_name()

def miasm.core.locationdb.LocationDB.getby_name (   self,
  name 
)
[DEPRECATED API], see 'get_name_location'
Here is the call graph for this function:

◆ getby_name_create()

def miasm.core.locationdb.LocationDB.getby_name_create (   self,
  name 
)
[DEPRECATED API], see 'get_or_create_name_location'
Here is the call graph for this function:

◆ getby_offset()

def miasm.core.locationdb.LocationDB.getby_offset (   self,
  offset 
)
[DEPRECATED API], see 'get_offset_location'
Here is the call graph for this function:

◆ getby_offset_create()

def miasm.core.locationdb.LocationDB.getby_offset_create (   self,
  offset 
)
[DEPRECATED API], see 'get_or_create_offset_location'
Here is the call graph for this function:

◆ items()

def miasm.core.locationdb.LocationDB.items (   self)
Return all loc_keys

◆ loc_key_to_name()

def miasm.core.locationdb.LocationDB.loc_key_to_name (   self,
  loc_key 
)
[DEPRECATED API], see 'get_location_names'
Here is the call graph for this function:

◆ loc_key_to_offset()

def miasm.core.locationdb.LocationDB.loc_key_to_offset (   self,
  loc_key 
)
[DEPRECATED API], see 'get_location_offset'
Here is the call graph for this function:

◆ loc_keys()

def miasm.core.locationdb.LocationDB.loc_keys (   self)
Return all loc_keys

◆ merge()

def miasm.core.locationdb.LocationDB.merge (   self,
  location_db 
)
Merge with another LocationDB @location_db

WARNING: old reference to @location_db information (such as LocKeys)
must be retrieved from the updated version of this instance. The
dedicated "get_*" APIs may be used for this task
Here is the call graph for this function:

◆ names()

def miasm.core.locationdb.LocationDB.names (   self)
Return all known names

◆ offsets()

def miasm.core.locationdb.LocationDB.offsets (   self)
Return all known offsets

◆ pretty_str()

def miasm.core.locationdb.LocationDB.pretty_str (   self,
  loc_key 
)
Return a human readable version of @loc_key, according to information
available in this LocationDB instance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_loc_key()

def miasm.core.locationdb.LocationDB.remove_loc_key (   self,
  loc_key 
)
[DEPRECATED API], see 'remove_location'
Here is the call graph for this function:

◆ remove_location()

def miasm.core.locationdb.LocationDB.remove_location (   self,
  loc_key 
)
Delete the location corresponding to @loc_key
@loc_key: LocKey instance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_location_name()

def miasm.core.locationdb.LocationDB.remove_location_name (   self,
  loc_key,
  name 
)
Disassociate a name @name from a given @loc_key
Fail if @name is not already associated to @loc_key
@name: str instance
@loc_key: LocKey instance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rename_location()

def miasm.core.locationdb.LocationDB.rename_location (   self,
  loc_key,
  newname 
)
[DEPRECATED API], see 'add_name_location' and 'remove_location_name'
Here is the call graph for this function:

◆ set_location_offset()

def miasm.core.locationdb.LocationDB.set_location_offset (   self,
  loc_key,
  offset,
  force = False 
)
Associate the offset @offset to an LocKey @loc_key

If @force is set, override silently. Otherwise, if an offset is already
associated to @loc_key, an error will be raised
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_offset()

def miasm.core.locationdb.LocationDB.set_offset (   self,
  loc_key,
  offset 
)
[DEPRECATED API], see 'set_location_offset'
Here is the call graph for this function:

◆ str_loc_key()

def miasm.core.locationdb.LocationDB.str_loc_key (   self,
  loc_key 
)
[DEPRECATED API], see 'pretty_str'
Here is the call graph for this function:

◆ unset_location_offset()

def miasm.core.locationdb.LocationDB.unset_location_offset (   self,
  loc_key 
)
Disassociate LocKey @loc_key's offset

Fail if there is already no offset associate with it
@loc_key: LocKey
Here is the caller graph for this function:

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