envi Package

Warning

The documentation for envi hasn’t been touched yet! If you want to contribute (or have ideas for better documentation), feel free to send me a pull request or email me.

envi Package

The Envi framework allows architecutre abstraction through the use of the ArchitectureModule, Opcode, Operand, and Emulator objects.

exception envi.ArchNotImplemented[source]

Bases: envi.EnviException

Raised by various Envi components when the architecture does not implement that envi component.

class envi.ArchitectureModule(archname, maxinst=32)[source]

An architecture module implementes methods to deal with the creation of envi objects for the specified architecture.

archGetBreakInstr()[source]

Return a python string of the byte sequence which corresponds to a breakpoint (if present) for this architecture.

archGetRegCtx()[source]

Return an initialized register context object for the architecture.

getEmulator()[source]

Return a default instance of an emulator for the given arch.

getPointerSize()[source]

Get the size of a pointer in memory on this architecture.

makeOpcode(bytes, offset=0, va=0)[source]

Create a new opcode from the specified bytes (beginning at the specified offset)

pointerString(va)[source]

Return a string representation for a pointer on this arch

exception envi.BreakpointHit(emu, msg=None)[source]

Bases: envi.EmuException

Raised by an emulator when you execute a breakpoint instruction

class envi.CallingConvention[source]

Implement calling conventions for your arch.

getCallArgs(emu, count)[source]
getSymbolikArgs(emu, argv)[source]
setReturnValue(emu, value, ccinfo=None)[source]
setSymbolikReturn(emu, sym, argv)[source]
class envi.DerefOper[source]

Bases: envi.Operand

isDeref()[source]
exception envi.DivideByZero(emu, msg=None)[source]

Bases: envi.EmuException

Raised by an Emulator when a divide/mod has a 0 divisor...

exception envi.EmuException(emu, msg=None)[source]

Bases: envi.EnviException

A parent for all emulation exceptions so catching them can be easy.

class envi.Emulator(archmod=None)[source]

Bases: envi.registers.RegisterContext, envi.memory.MemoryObject

The Emulator class is mostly “Abstract” in the java Interface sense. The emulator should be able to be extended for the architecutures which are included in the envi framework. You must mix in an instance of your architecture abstraction module.

(NOTE: Most users will just use an arch mod and call getEmulator())

The intention is for “light weight” emulation to be implemented mostly for user-space emulation of protected mode execution.

addCallingConvention(name, obj)[source]
executeOpcode(opobj)[source]

This is the core method for the

getArchModule()[source]
getCallArgs(count, cc)[source]

Emulator implementors can implement this method to allow analysis modules a platform/architecture independant way to get stack/reg/whatever args.

Usage: getCallArgs(3, “stdcall”) -> (0, 32, 0xf00)

getCallingConvention(name)[source]
getCallingConventions()[source]
getEmuSnap()[source]

Return the data needed to “snapshot” this emulator. For most archs, this method will be enough (it takes the memory object, and register values with it)

getOperAddr(op, idx)[source]

Return the address that an operand which deref’s memory would read from on getOperValue().

getOperValue(op, idx)[source]

Return the value for the operand at index idx for the given opcode reading memory and register states if necissary.

In partially-defined emulation, this may return None

getSegmentIndex(op)[source]

The default segmentation is none (most arch’s will over-ride). This method may be implemented to return a segment index based on either emulator state or properties of the particular instruction in question.

getSegmentInfo(op)[source]
hasCallingConvention(name)[source]
run(stepcount=None)[source]

Run the emulator until “something” happens. (breakpoint, segv, syscall, etc...)

setEmuSnap(snap)[source]
setOperValue(op, idx, value)[source]

Set the value of the target operand at index idx from opcode op. (obviously OM_IMMEDIATE cannot be set)

setReturnValue(value, cc, argc=0)[source]

Emulator implementors can implement this method to allow analysis modules a platform/architecture independant way to set a function return value. (this should also take care of any argument cleanup or other return time tasks for the calling convention)

setSegmentInfo(idx, base, size)[source]

Set a base and size for a given segment index.

stepi()[source]
exception envi.EnviException[source]

Bases: exceptions.Exception

class envi.ImmedOper[source]

Bases: envi.Operand

isImmed()[source]
exception envi.InvalidInstruction(bytes=None)[source]

Bases: envi.EnviException

Raised by opcode parsers when the specified bytes do not represent a valid opcode

exception envi.MapOverlapException(map1, map2)[source]

Bases: envi.EnviException

Raised when adding a memory map to a MemoryObject which overlaps with another already existing map.

class envi.Opcode(va, opcode, mnem, prefixes, size, operands, iflags=0)[source]

A universal representation for an opcode

getBranches(emu=None)[source]

Return a list of tuples. Each tuple contains the target VA of the branch, and a possible set of flags showing what type of branch it is.

See the BR_FOO types for all the supported envi branch flags.... Example: for bva,bflags in op.getBranches():

getOperValue(idx, emu=None)[source]
getOperands()[source]
getPrefixName()[source]

Get the name of the prefixes associated with the specified architecture specific prefix bitmask.

prefix_names = []
render(mcanv)[source]

Render this opcode to the memory canvas passed in. This is used for both simple printing AND more complex representations.

class envi.Operand[source]

Thses are the expected methods needed by any implemented operand object attached to an envi Opcode. This does not have a constructor of it’s pwn on purpose to cut down on memory use and constructor CPU cost.

getOperAddr(op, emu)[source]

If the operand is a “dereference” operand, this method should use the specified op/emu to resolve the address of the dereference.

NOTE: This API may be passed a None emu and should return what it can
(or None if it can’t be resolved)
getOperValue(op, emu=None)[source]

Get the current value for the operand. If needed, use the given emulator/workspace/trace to resolve things like memory and registers.

NOTE: This API may be passed a None emu and should return what it can
(or None if it can’t be resolved)
isDeref()[source]

If the given operand will dereference memory, this method must return True.

isImmed()[source]

If the given operand represents an immediate value, this must return True.

isReg()[source]

If the given operand represents a register value, this must return True.

render(mcanv, op, idx)[source]

Used by the opcode class when rendering to a memory canvas.

repr(op)[source]

Used by the Opcode class to get a humon readable string for this operand.

setOperValue(op, emu, val)[source]

Set the current value for the operand. If needed, use the given emulator/workspace/trace to assign things like memory and registers.

exception envi.PDEException(emu, msg=None)[source]

Bases: envi.EmuException

This exception is used in partially defined emulation to signal where execution flow becomes un-known due to undefined values. This is considered un-recoverable.

exception envi.PDEUndefinedFlag(emu, msg=None)[source]

Bases: envi.EmuException

This exception is raised when a conditional operation is dependant on a flag state that is unknown.

class envi.RegisterOper[source]

Bases: envi.Operand

isReg()[source]
exception envi.SegmentationViolation(va, msg=None)[source]

Bases: envi.EnviException

Raised by an Emulator extension when you bad-touch memory. (Likely from memobj).

exception envi.UnknownCallingConvention(emu, msg=None)[source]

Bases: envi.EmuException

Raised when the getCallArgs() or setReturnValue() methods are given an unknown calling convention type.

exception envi.UnsupportedInstruction(emu, op)[source]

Bases: envi.EmuException

Raised by emulators when the given instruction is not implemented by the emulator.

envi.getArchModule(name=None)[source]

return an Envi architecture module instance for the following architecture name.

Current architectures include:

i386 - Intel i386 amd64 - The new 64bit AMD spec.

envi.getCurrentArch()[source]

Return an envi normalized name for the current arch.

envi.stealArchMethods(obj, archname)[source]

Used by objects which are expected to inherit from an architecture module but don’t know which one until runtime!

arm Module

bintree Module

class envi.bintree.BinaryTree[source]

A simple binary search tree capable of using integers or string representations of binary integers as inputs.

NOTE: the lookup routines assume once a node is found which has nodeinfo, we have matched. It does not need to walk the rest of the values...

addBinstr(binstr, nodeinfo)[source]
addInt(intval, width, nodeinfo)[source]
getBinstr(binstr)[source]
getInt(intval, width)[source]

Get an element back out of the tree.

width is in bits...

bits Module

A file full of bit twidling helpers

envi.bits.binary(binstr)[source]

Decode a binary string of 1/0’s into a python number

envi.bits.binbytes(binstr)[source]

Decode a binary string of 1/0’s into a python binary string.

envi.bits.binrepr(intval, bitwidth=None)[source]

Return a string of one’s and zero’s for the given value.

envi.bits.buildbytes(value, size, bigend=False)[source]
envi.bits.byteswap(value, size)[source]
envi.bits.hex(value, size=None)[source]
envi.bits.intwidth(val)[source]
envi.bits.is_aux_carry(src, dst)[source]
envi.bits.is_parity(val)[source]
envi.bits.is_parity_byte(bval)[source]

An “optimized” parity checker that looks up the index.

envi.bits.is_signed(value, size)[source]
envi.bits.is_signed_overflow(value, size)[source]
envi.bits.is_unsigned_carry(value, size)[source]
envi.bits.lsb(value)[source]
envi.bits.msb(value, size)[source]
envi.bits.parsebits(bytes, offset, bitoff, bitsize)[source]

Parse bitsize bits from the bit offset bitoff beginning at offset bytes.

Example:

envi.bits.parsebytes(bytes, offset, size, sign=False, bigend=False)[source]

Mostly for pulling immediates out of strings...

envi.bits.sign_extend(value, cursize, newsize)[source]

Take a value and extend it’s size filling in the space with the value of the high order bit.

envi.bits.signed(value, size)[source]

Make a value signed based on it’s size.

envi.bits.slowparsebytes(bytes, offset, size, sign=False, bigend=False)[source]
envi.bits.unsigned(value, size)[source]

Make a value unsigned based on it’s size.

bytesig Module

A byte and mask based decision engine for creating byte sequences (and potential comparison masks) for general purpose signature matching.

Currently used by vivisect function entry sig db and others.

class envi.bytesig.SignatureTree[source]

A byte based decision tree which uses all the RAMs but is really fast....

Signatures consist of a byte sequence and an optional mask sequence. If present each mask byte is used to logical and the byte being compared before comparison. This allows the creation of signatures which have parts of the sig generalized.

FIXME allow sigs to have a reliability rating FIXME allow sig nodes to store depth and truncate the tree early (and then mask the rest)

addSignature(bytes, masks=None, val=None)[source]

Add a signature to the search tree. If masks goes unspecified, it will be assumed to be all ones (xff * len(bytes)).

Additionally, you may specify “val” as the object to get back with getSignature().

getSignature(bytes, offset=0)[source]
isSignature(bytes, offset=0)[source]

cli Module

Unified CLI code for things like vivisect and vdb.

class envi.cli.CliExtMeth(cli, func)[source]

This is used to work around the difference between functions and bound methods for extended command modules

class envi.cli.EnviCli(memobj, config=None, symobj=None)[source]

Bases: cmd.Cmd

cmdloop(intro=None)[source]
doAlias(line)[source]
do_EOF(line)[source]
do_alias(line)[source]

Add an alias to the command line interpreter’s aliases dictionary

Usage: alias <alias_word> rest of the alias command To delete an alias: Usage: alias <alias_word>

do_binstr(line)[source]

Display a binary representation of the given value expression (padded to optional width in bits)

Usage: binstr <val_expr> [<bitwidth_expr>]

do_config(line)[source]

Show or edit a config option from the command line

Usage: config [-S section] [option=value]

do_eval(line)[source]

Evaluate an expression on the CLI to show it’s value.

Usage: eval (ecx+edx)/2

do_maps(line)[source]

Display either a list of all the memory maps or the memory map details for the given address expression.

Usage: maps [addr_expression]

do_mem(line)[source]

Show some memory (with optional formatting and size)

Usage: mem [-F <format>] <addr expression> [size]

NOTE: use -F ? for a list of the formats

do_memcmp(line)[source]

Compare memory at the given locations. Outputs a set of differences showing bytes at their given offsets....

Usage: memcmp <addr_expr1> <addr_expr2> <size_expr>

do_memdump(line)[source]

Dump memory out to a file.

Usage: memdump <addr_expression> <size_expression> <filename>

do_python(line)[source]

Start an interactive python interpreter. The namespace of the interpreter is updated with expression nicities. You may also specify a line of python code as an argument to be exec’d without beginning an interactive python interpreter on the controlling terminal.

Usage: python [pycode]

do_quit(line)[source]

Quit

Usage: quit

do_script(line)[source]

Execute a python file.

The script file is arbitrary python code which is run with the full compliment of expression extensions mapped in as locals.

NOTE: additional command line arguments may be passed in and will
appear as the list “argv” in the script namespace! (They will all be strings)

Usage: script <scriptfile> [<argv[0]>, ...]

Search memory for patterns.

Usage: search [options] <pattern> -e Encode the pattern with a codec (ie utf-16le, hex, etc) -E The specified pattern is an expression (search for numeric values) -r The specified pattern is a regular expression -R <baseexpr:sizeexpr> Search a specific range only. -X The specified pattern is in hex (ie. 414141424242 is AAABBB)

getExpressionLocals()[source]

Over-ride this to have things like the eval command and the python command use more locals than the sybolic defaults.

get_names()[source]
onecmd(line)[source]
parseExpression(expr)[source]
registerCmdExtension(func)[source]
reprPointer(va)[source]

Do your best to create a humon readable name for the value of this pointer.

setCanvas(canvas)[source]

Set a new canvas for the CLI and add all the current renderers to the new one.

vprint(msg, addnl=True)[source]

Print output to the CLI’s output handler. This allows routines to print to the terminal or the GUI depending on which mode we’re in.

Example:
vprint(‘hi mom!’)
write(data)[source]
class envi.cli.EnviMutableCli(memobj, config=None, symobj=None)[source]

Bases: envi.cli.EnviCli

Cli extensions which require a mutable memory object (emulator/trace) rather than a static one (viv workspace)

do_memcpy(line)[source]

Copy memory from one location to another...

Usage: memcpy <dest_expr> <src_expr> <size_expr>

do_memprotect(line)[source]

Change the memory permissions of a given page/map.

Usage: memprotect [options] <addr_expr> <perms> -S <size> Specify the size of the region to change (default == whole memory map) <perms> = “rwx” string “rw”, “rx” “rwx” etc...

do_writemem(args)[source]

Over-write some memory in the target address space. Usage: writemem [options] <addr expression> <string> -X The specified string is in hex (ie 414141 = AAA) -U The specified string needs to be unicode in mem (AAA -> 410041004100)

envi.cli.columnstr(slist)[source]
envi.cli.splitargs(cmdline)[source]

codeflow Module

A module to contain code flow analysis for envi opcode objects...

class envi.codeflow.CodeFlowContext(mem)[source]

Bases: object

A CodeFlowContext is used for code-flow (not linear) based disassembly for an envi MemoryObject (which is responsible for knowing the implementation of parseOpcode(). The CodeFlowContext will optionally notify several callback handlers for different events which occur during disassembly:

self._cb_opcode(va, op, branches) - called for every newly parsed opcode
NOTE: _cb_opcode must return the desired branches for continued flow

self._cb_function(fva, metadict) - called once for every function

self._cb_branchtable(tabva, destva) - called for switch tables

addCodeFlow(va, persist=False, exptable=True)[source]

Do code flow disassembly from the specified address. Returnes a list of the procedural branch targets discovered during code flow...

Set persist=True to store ‘opdone’ and never disassemble the same thing twice Set exptable=True to expand branch tables in this phase

addEntryPoint(va)[source]

Analyze the given procedure entry point and flow downward to find all subsequent code blocks and procedure edges.

addFunctionDef(fva, calls_from)[source]

Add a priori knowledge of a function to the code flow stuff...

getCallsFrom(fva)[source]

config Module

Unified config object for all vtoys.

class envi.config.EnviConfig(filename=None, defaults=None)[source]

Bases: ConfigParser.ConfigParser

readstr(s)[source]
remove_option(sec, opt)[source]
set(sec, opt, val)[source]
syncFile()[source]
envi.config.gethomedir(*paths)[source]
envi.config.getusername()[source]

expression Module

Unified expression helpers.

class envi.expression.ExpressionLocals(symobj=None)[source]

Bases: dict

An object to act as the locals dictionary for the evaluation of envi expressions. You may pass in an envi.resolver.SymbolResolver object to automagically use symbols in your expressions.

class envi.expression.MemoryExpressionLocals(memobj, symobj=None)[source]

Bases: envi.expression.ExpressionLocals

ispoi(addr)[source]

The expression ispoi(value) returns True if the specified value is a valid pointer. Otherwise, False.

mapbase(address)[source]

The expression mapbase(address) returns the base address of the memory mapped area containing “address”

maplen(address)[source]

The expression maplen(address) returns the length of the memory mapped area containing “address”.

mem(addr, size)[source]

Read and return memory.

Example: mem(ecx, 20)

poi(address)[source]

When expression contains “poi(addr)” this will return the address pointed to by addr.

sym(symstr)[source]

An easy to use utility for symbols which have un-pythonic names.

Example x = sym(‘kernel32.??2@$$FYAPAXI@Z’)

envi.expression.evaluate(pycode, locals)[source]

memory Module

class envi.memory.IMemory(archmod=None)[source]

This is the interface spec (and a few helper utils) for the unified memory object interface.

NOTE: If your actual underlying memory format is such that over-riding anything (like isValidPointer!) can be faster than the default implementation, DO IT!

addMemoryMap(mapva, perms, fname, bytes)[source]
allocateMemory(size, perms=7, suggestaddr=0)[source]
findOpcode(opcode=None, loc=None, size=1000, verbose=False)[source]

Starts at the current EIP (self.getProgramCounter()), and searches each instruction for the instruction requested.

Returns the address of the first found opcode, than returns.

Example: # Find the first ‘popad’ opcode

In [1]: popad_loc = trace.findOpcode(opcode=”popad”,verbose=True) [+] 0x1020cd0L pushad [+] 0x1020cd1L mov esi,0x0101a000 [+] 0x1020cd6L lea edi,dword [esi - 102400] [+] 0x1020cdcL push edi [+] 0x1020cddL or ebp,0xffffffff –SNIP– [+] 0x1020e49L push edi [+] 0x1020e4aL call ebp [+] 0x1020e4cL pop eax [+] 0x1020e4dL popad Location - 0x01020E4D
# Using popad’s location, search for the next ‘jmp’
In [2]: jmp = trace.findOpcode(loc=popad_loc.va, opcode=”jmp”, verbose=True) [+] 0x1020e4dL popad [+] 0x1020e4eL lea eax,dword [esp - 128] [+] 0x1020e52L push 0 [+] 0x1020e54L cmp esp,eax [+] 0x1020e56L jnz 0x01020e52 [+] 0x1020e58L sub esp,0xffffff80 [+] 0x1020e5bL jmp 0x01012475 Location - 0x01020E5B

# Or you can do it simply

#TODO Extend to take in expressions.

getMemoryMap(va)[source]

Return a tuple of mapva,size,perms,filename for the memory map which contains the specified address (or None).

getMemoryMaps()[source]
getPointerSize()[source]
getSegmentInfo(id)[source]
isExecutable(va)[source]
isReadable(va)[source]
isShared(va)[source]
isValidPointer(va)[source]
isWriteable(va)[source]
parseOpcode(va)[source]

Parse an opcode from the specified virtual address.

Example: op = m.parseOpcode(0x7c773803)

probeMemory(va, size, perm)[source]

Check to be sure that the given virtual address and size is contained within one memory map, and check that the perms are contained within the permission bits for the memory map. (MM_READ | MM_WRITE | MM_EXEC | ...)

Example probeMemory(0x41414141, 20, envi.memory.MM_WRITE) (check if the memory for 20 bytes at 0x41414141 is writable)

protectMemory(va, size, perms)[source]

Change the protections for the given memory map. On most platforms the va/size must exactly match an existing memory map.

readMemValue(addr, size)[source]
readMemory(va, size)[source]

Read memory from the specified virtual address for size bytes and return it as a python string.

Example: mem.readMemory(0x41414141, 20) -> “A...”

readMemoryFormat(va, fmt)[source]
searchMemory(needle, regex=False)[source]

A quick cheater way to searchMemoryRange() for each of the current memory maps.

searchMemoryRange(needle, address, size, regex=False)[source]

Search the specified memory range (address -> size) for the string needle. Return a list of addresses where the match occurs.

writeMemory(va, bytes)[source]

Write the given bytes to the specified virtual address.

Example: mem.writeMemory(0x41414141, “VISI”)

writeMemoryFormat(va, fmt, *args)[source]

Write a python format sequence of variables out to memory after serializing using struct pack...

Example:
trace.writeMemoryFormat(va, ‘<PBB’, 10, 30, 99)
class envi.memory.MemoryFile(memobj, baseaddr)[source]

A file like object to wrap around a memory object.

read(size)[source]
seek(offset)[source]
write(bytes)[source]
class envi.memory.MemoryObject(archmod=None)[source]

Bases: envi.memory.IMemory

addMemoryMap(va, perms, fname, bytes)[source]

Add a memory map to this object...

getByteDef(va)[source]

An optimized routine which returns the existing segment bytes sequence without creating a new string object AND an offset of va into the buffer. Used internally for optimized memory handling. Returns (offset, bytes)

getMemoryMap(va)[source]

Get the va,size,perms,fname tuple for this memory map

getMemoryMaps()[source]
getMemorySnap()[source]

Take a memory snapshot which may be restored later.

Example: snap = mem.getMemorySnap()

readMemory(va, size)[source]
setMemorySnap(snap)[source]

Restore a previously saved memory snapshot.

Example: mem.setMemorySnap(snap)

writeMemory(va, bytes)[source]
envi.memory.getPermName(perm)[source]

Return the human readable name for a single memory perm enumeration value.

envi.memory.memdiff(bytes1, bytes2)[source]

Return a list of (offset, size) tuples showing any memory differences between the given bytes.

envi.memory.parsePerms(pstr)[source]
envi.memory.reprPerms(mask)[source]

pagelookup Module

A home for the page lookup construct. Basically it is a python object which implements a similar lookup mechanism to the i386 page table lookups...

class envi.pagelookup.MapLookup[source]

A specialized lookup object for large densely populated ranges which are layed out in a sparse field space themselves...

getMapLookup(va)[source]
initMapLookup(va, size, obj=None)[source]
setMapLookup(va, size, obj)[source]
class envi.pagelookup.PageLookup[source]

An object capable of rapid lookups across a sparse address space which will also NOT eat all the RAMS like a straight dictionary full of millions of entries would.

getPageLookup(va)[source]
setPageLookup(va, size, obj)[source]

pyzip Module

envi.pyzip.addSource(z, dname)[source]
envi.pyzip.callback(z, dname, files)[source]
envi.pyzip.main()[source]

registers Module

Similar to the memory subsystem, this is a unified way to access information about objects which contain registers

exception envi.registers.InvalidRegisterName[source]

Bases: exceptions.Exception

class envi.registers.RegisterContext(regdef=(), metas=(), pcindex=None, spindex=None)[source]
addMetaRegister(name, idx, offset, width)[source]

Meta registers are registers which are really just directly addressable parts of already existing registers (eax -> al).

To add a meta register, you give the name, the idx of the real register, the width of the meta reg, and it’s left shifted (in bits) offset into the real register value. The RegisterContext will take care of accesses after that.

getMetaRegInfo(index)[source]

Return the appropriate realreg, shift, mask info for the specified metareg idx (or None if it’s not meta).

Example:
real_reg, lshift, mask = r.getMetaRegInfo(x)
getProgramCounter()[source]

Get the value of the program counter for this register context.

getRegDef()[source]
getRegister(index)[source]

Return the current value of the specified register index.

getRegisterByName(name)[source]
getRegisterIndex(name)[source]

Get a register index by name. (faster to use the index multiple times)

getRegisterInfo(meta=False)[source]

Return an object which can be stored off, and restored to re-initialize a register context. (much like snapshot but it takes the definitions with it)

getRegisterName(index)[source]
getRegisterNameIndexes()[source]

Return a list of all the “real” (non meta) registers and their indexes.

Example: for regname, regidx in x.getRegisterNameIndexes():

getRegisterNames()[source]
getRegisterSnap()[source]

Use this to bulk save off the register state.

getRegisterWidth(index)[source]

Return the width of the register which lives at the specified index (width is always in bits).

getRegisters()[source]

Get all the real registers from this context as a dictionary of name value pairs.

getStackCounter()[source]
isDirty()[source]

Returns true if registers in this context have been modififed since their import.

isMetaRegister(index)[source]
loadRegDef(regdef, defval=0)[source]

Load a register definition. A register definition consists of a list of tuples with the following format: (regname, regwidth)

NOTE: All widths in envi RegisterContexts are in bits.

loadRegMetas(metas)[source]

Load a set of defined “meta” registers for this architecture. Meta registers are defined as registers who exist as a subset of the bits in some other “real” register. The argument metas is a list of tuples with the following format: (regname, reg_shift_offset, reg_width) The given example is for the AX register in the i386 subsystem regname: “ax” reg_shift_offset: 0 reg_width: 16

reprRegister(idx)[source]

This may be used to allow a register context to provide extended repr (flags breakouts, etc) info about a register.

setIsDirty(bool)[source]
setProgramCounter(value)[source]

Set the value of the program counter for this register contex.

setRegister(index, value)[source]

Set a register value by index.

setRegisterByName(name, value)[source]
setRegisterIndexes(pcindex, spindex)[source]
setRegisterInfo(info)[source]

Import the exported data from

setRegisterSnap(snap)[source]

Use this to bulk restore the register state.

NOTE: This may only be used under the assumption that the
RegisterContext has been initialized the same way (like context switches in tracers, or emulaction snaps)
setRegisters(regdict)[source]

For any name value pairs in the specified dictionary, set the current register values in this context.

setStackCounter(value)[source]
envi.registers.addLocalEnums(l, regdef)[source]

Update a dictionary (or module locals) with REG_FOO index values for all the base registers defined in regdef.

envi.registers.addLocalMetas(l, metas)[source]

Update a dictionary (or module locals) with REG_FOO index values for all meta registers defined in metas.

resolver Module

The API describing what it means to be an envi compliant symbol resolver.

class envi.resolver.FileSymbol(fname, base, size, width=4)[source]

Bases: envi.resolver.Symbol, envi.resolver.SymbolResolver

A file symbol is both a symbol resolver of it’s own, and a symbol.

File symbols are used to do heirarchal symbol lookups and don’t actually add anything but the name to their lookup (it is assumed that the parent Resolver of the FileSymbol takes care of addr lookups.

class envi.resolver.FunctionSymbol(name, value, size=0, fname=None)[source]

Bases: envi.resolver.Symbol

Used to represent functions.

class envi.resolver.SectionSymbol(name, value, size=0, fname=None)[source]

Bases: envi.resolver.Symbol

Used for file sections/segments.

class envi.resolver.Symbol(name, value, size=0, fname=None)[source]
class envi.resolver.SymbolResolver(width=4, casesens=True)[source]

NOTE: Nothing should reach directly into a SymbolResolver!

addSymbol(sym)[source]

Add a symbol to the resolver.

delSymbol(sym)[source]

Delete a symbol from the resolver’s namespace

getSymByAddr(va, exact=True)[source]

Return a symbol object for the given virtual address.

getSymByName(name)[source]
getSymHint(va, hidx)[source]

May be used by symbol resolvers who know what type they are resolving to store and retrieve “hints” with indexes.

Used specifically by opcode render methods to resolve any memory dereference info for a given operand.

NOTE: These are mostly symbolic references to FRAME LOCAL
names....
getSymList()[source]

Return a list of the symbols which are contained in this resolver.

threads Module

A couple useful thread related toys...

envi.threads.firethread(func)[source]

A decorator which fires a thread to do the given call.

NOTE: This means these methods may not return anything and callers may not expect sync behavior!

util Module

class envi.util.CopyOnWrite(memobj)[source]

A memory object wrapper you can use to do copy-on-write memory use and be able to simply reset it.

readMemory(va, size)[source]
reset()[source]

Throw away the current writes and be fresh...

writeMemory(va, bytes)[source]