Interface IDGlobalContext


@Ser public interface IDGlobalContext
dexdec IR global context. This object also provides factory methods to create non-instruction elements. (IR instructions can be created using a method context).
  • Method Details

    • getDex

      IDexUnit getDex()
      Retrieve the underlying dex unit object.
      Returns:
      underlying Dex unit
    • getDecompiler

      IDexDecompilerUnit getDecompiler()
      Retrieve the managing dex decompiler object.
      Returns:
      managing Dex decompiler unit
    • getOperatorFactory

      IJavaOperatorFactory getOperatorFactory()
      Retrieve the global high-level operator factory. The type factory can be used to create all operators, including conditionals, string concatenation, and create cast operators.
      Returns:
      high-level operator factory
    • getTypeFactory

      IJavaTypeFactory getTypeFactory()
      Retrieve the global high-level type factory.
      Returns:
      high-level type factory
    • getTypeInfoProvider

      IDTypeInfoProvider getTypeInfoProvider()
      Retrieve the type information provider. This provider can access additional, user-provided libraries (jar, dex) to retrieve information on types referenced but not defined in the underlying dex unit.
      Returns:
      type information provider
    • createMasterOptimizer

      IDMasterOptimizer createMasterOptimizer(IDMethodContext methodContext, boolean registerBuiltinOptimizers, boolean initializeWithDexdecSettings, boolean registerExternalOptimizers)
      Create a master optimizer targeting the provided method.
      Parameters:
      methodContext - target method context
      registerBuiltinOptimizers - true to register built-in optimizers
      initializeWithDexdecSettings - true to initialize the optimizer with Dex decompiler settings
      registerExternalOptimizers - true to register external optimizers
      Returns:
      master optimizer
    • createMasterOptimizer

      default IDMasterOptimizer createMasterOptimizer(IDMethodContext methodContext)
      Create a pre-initialized master optimizer targeting the provided method. This convenience method is equivalent to createMasterOptimizer(ctx, true, true, true).
      Parameters:
      methodContext - target method context
      Returns:
      master optimizer
    • getThreadSharedState

      IDState getThreadSharedState()
      Retrieve the current IR state associated with the current thread. Each thread has its own associated State: the first time this method is called by thread T, a new state object will be created; the subsequent times this method is called by thread T, the previously created state is returned.
      Returns:
      the IR state associated with the running thread
    • getEmulator

      IDState getEmulator()
      Retrieve the current IR state associated with the current thread. Each thread has its own associated State: the first time this method is called by thread T, a new state object will be created; the subsequent times this method is called by thread T, the previously created state is returned.

      This method also performs two important tasks:
      - the first time it is called, the State is initialized with settings to allow for practical emulation (large emulation count and timeout, emulation and sandboxing enabled, etc.)
      - each time this method is called, settings from the global dexdec emulator configuration file (dexdec-emu.cfg in your plugins folder) is pulled and applied to the State if they have changed

      Returns:
      the IR state associated with the running thread
    • createState

      IDState createState()
      Create a fresh, uninitialized IR state. The IR state is context-less (no context is created). Settings are left on default values, in particular, the maximum iteration count and duration are set to the default values (see IDState.DEFAULT_MAX_ITERCOUNT, IDState.DEFAULT_MAX_DURATION). The emulator and sandbox are disabled. The client should use the State's setters before proceeding with emulation.
      Returns:
      a new IR state
    • createState

      IDState createState(boolean initForEmulation, boolean loadDexdecEmuSettings)
      Create a fresh IR state. The IR state is context-less (no context is created).
      Parameters:
      initForEmulation - if true, the state settings are changed to allow for IR emulation
      loadDexdecEmuSettings - if true, the global dexdec emulator configuration file (dexdec-emu.cfg in your plugins folder) is used to further configure the State
      Returns:
      a new IR state
    • setData

      Object setData(String key, Object value)
      Store an arbitrary object in this global context.

      Note: As of JEB 5.39, these objects are persisted in a JDB2 database.

      Parameters:
      key - non-null key
      value - a serializable object; null means remove the entry
      Returns:
      the previous value associated with the key
    • getData

      Object getData(String key)
      Retrieve an arbitrary object in this global context.

      Note: As of JEB 5.39, these objects are persisted in a JDB2 database.

      Parameters:
      key - non-null key
      Returns:
      the value or null if none is associated with the key
    • getData

      Object getData(String key, Function<String,Object> creator)
      Retrieve or create (and register) an arbitrary object in this global context.

      Note: As of JEB 5.39, these objects are persisted in a JDB2 database.

      Parameters:
      key - non-null key
      creator - the optional creator function is called if no value is mapped to the provided key
      Returns:
      the value (existing or newly created)
    • getDataKeys

      Set<String> getDataKeys()
      Retrieve the set of objects keys for persisted data elements.

      Note: As of JEB 5.39, these objects are persisted in a JDB2 database.

      Returns:
      a read-only collection
    • setTransientData

      Object setTransientData(String key, Object value)
      Store a non-persisted object in this global context.
      Parameters:
      key - non-null key
      value - null means remove the entry
      Returns:
      the previous value associated with the key
    • getTransientData

      Object getTransientData(String key)
      Retrieve a non-persisted object in this global context.
      Parameters:
      key - non-null key
      Returns:
      the value (existing or newly created)
    • getTransientData

      Object getTransientData(String key, Function<String,Object> creator)
      Retrieve or create a non-persisted object in this global context.
      Parameters:
      key - non-null key
      creator - the optional creator function is called if no value is mapped to the provided key
      Returns:
      the value (existing or newly created)
    • getTransientDataKeys

      Set<String> getTransientDataKeys()
      Retrieve the set of objects keys for non-persisted objects stored in this global context.
      Returns:
      a read-only collection
    • resetDeobfuscatorCounters

      void resetDeobfuscatorCounters()
      Reset deobfuscators counters, generally updated by IR optimizers that rely on IR emulation. Counters are used to track emulation successes and failures for methods. Some optimizers may check the counters to avoid attempting to emulate methods for which too many failures were reported. Calling this method resets such counters, allowing emulation to be re-attempted.

      This method resets all counters.

    • resetDeobfuscatorCounters

      void resetDeobfuscatorCounters(String entryName)
      Reset deobfuscators counters, generally updated by IR optimizers that rely on IR emulation. Counters are used to track emulation successes and failures for methods. Some optimizers may check the counters to avoid attempting to emulate methods for which too many failures were reported. Calling this method resets such counters, allowing emulation to be re-attempted.

      This method resets a specific counter.

      Parameters:
      entryName - counter name; generally, a method fully-qualified name, e.g. Lcom/abc/Foo->bar(I)V
    • createConstant

      default IDImm createConstant(long rawvalue, IJavaType type)
      Create immediate constants. The same as createImm(long, IJavaType).
      Parameters:
      rawvalue - raw constant value
      type - constant type
      Returns:
      immediate constant
    • createImm

      IDImm createImm(long rawvalue, IJavaType type)
      Create immediate constants.
      Parameters:
      rawvalue - raw constant value
      type - constant type
      Returns:
      immediate constant
    • createRef

      IDImm createRef(int refid, IJavaType reftype)
      Create an object reference.
      Parameters:
      refid - object reference id
      reftype - optional object type; if null is provided, the generic wildcard object type is used
      Returns:
      an imm representing an object reference
    • createRef

      IDImm createRef(int refid)
      Create an object reference. The type of the reference will be the generic wildcard object type
      Parameters:
      refid - object reference id
      Returns:
      an imm representing an object reference
    • createBoolean

      IDImm createBoolean(boolean value)
      Wrapper used to create boolean constants.
      Parameters:
      value - boolean value
      Returns:
      immediate constant
    • createByte

      IDImm createByte(byte value)
      Wrapper used to create byte constants.
      Parameters:
      value - byte value
      Returns:
      immediate constant
    • createChar

      IDImm createChar(char value)
      Wrapper used to create char constants.
      Parameters:
      value - char value
      Returns:
      immediate constant
    • createShort

      IDImm createShort(short value)
      Wrapper used to create short constants.
      Parameters:
      value - short value
      Returns:
      immediate constant
    • createInt

      IDImm createInt(int value)
      Wrapper used to create int constants.
      Parameters:
      value - int value
      Returns:
      immediate constant
    • createLong

      IDImm createLong(long value)
      Wrapper used to create long constants.
      Parameters:
      value - long value
      Returns:
      immediate constant
    • createFloat

      IDImm createFloat(float value)
      Wrapper used to create float constants.
      Parameters:
      value - float value
      Returns:
      immediate constant
    • createDouble

      IDImm createDouble(double value)
      Wrapper used to create double constants.
      Parameters:
      value - double value
      Returns:
      immediate constant
    • createNull

      IDImm createNull()
      Wrapper used to create the null constant.
      Returns:
      null immediate constant
    • createString

      IDImm createString(String value)
      Wrapper used to create string constants.
      Parameters:
      value - string value
      Returns:
      immediate constant
    • createString

      IDImm createString(IDIndex stringIndex)
      Wrapper used to create string constants.
      Parameters:
      stringIndex - Dex string pool index
      Returns:
      immediate constant
    • createArrayElt

      IDArrayElt createArrayElt(IDExpression array, IDExpression index, IJavaType type)
      Create an array element.
      Parameters:
      array - array expression
      index - element index expression
      type - element type
      Returns:
      array element expression
    • createOperation

      IDOperation createOperation(IJavaType type, JavaOperatorType optype, IDExpression opnd1, IDExpression opnd2)
      Create an operation element with at most two operands, such an an arithmetic or bitwise expression, string concatenation, or cast operation.
      Parameters:
      type - may be left null to let a basic type for the expression be auto-determined
      optype - operator type
      opnd1 - first operand
      opnd2 - optional second operand
      Returns:
      operation expression
    • createOperation

      IDOperation createOperation(IJavaType type, IDExpression left, IJavaOperator operator, IDExpression right)
      Create an operation element, such an an arithmetic or bitwise expression, conditional, string concatenation, or cast operation.
      Parameters:
      type - operation type
      left - left operand
      operator - operator
      right - right operand
      Returns:
      operation expression
    • createCastOperation

      IDOperation createCastOperation(IJavaType castType, IDExpression exp)
      Create a cast operation.
      Parameters:
      castType - target cast type
      exp - expression to cast
      Returns:
      cast operation expression
    • createCastOperation

      IDOperation createCastOperation(String castTypeSignature, IDExpression exp)
      Create a cast operation.
      Parameters:
      castTypeSignature - target cast type signature
      exp - expression to cast
      Returns:
      cast operation expression
    • createConditional

      IDOperation createConditional(IJavaType type, IDExpression pred, IDExpression expTrue, IDExpression expFalse)
      Convenience operation.
      Parameters:
      type - result type
      pred - predicate expression
      expTrue - expression evaluated when the predicate is true
      expFalse - expression evaluated when the predicate is false
      Returns:
      conditional operation expression
    • createPredicate

      IDOperation createPredicate(JavaOperatorType optype, IDExpression opnd1, IDExpression opnd2)
      Create a predicate operation (typed boolean).
      Parameters:
      optype - a logical operator
      opnd1 - first operand
      opnd2 - optional second operand
      Returns:
      predicate operation expression
    • createPredicate

      IDOperation createPredicate(IDExpression left, IJavaOperator operator, IDExpression right)
      Create a predicate operation (typed boolean).
      Parameters:
      left - left operand
      operator - a logical operator
      right - right operand
      Returns:
      predicate operation expression
    • createReferenceType

      IDReferenceType createReferenceType(IDIndex cindex, IJavaType ctype)
      Create a reference type expression.
      Parameters:
      cindex - class type index
      ctype - class type
      Returns:
      reference type expression
    • createReferenceType

      IDReferenceType createReferenceType(String csig)
      Create a reference type expression.
      Parameters:
      csig - class signature
      Returns:
      reference type expression
    • createIndex

      IDIndex createIndex(int value)
      Create an immutable pool index value.
      Parameters:
      value - index value
      Returns:
      the index object
    • createStaticField

      IDStaticField createStaticField(String fsig)
      Create a static field expression from a field signature.
      Parameters:
      fsig - field signature
      Returns:
      static field expression
    • createStaticField

      IDStaticField createStaticField(String fsig, boolean createRefIfDoesNotExist)
      Create a static field expression from a field signature.
      Parameters:
      fsig - field signature
      createRefIfDoesNotExist - true to create a reference if the field is not found
      Returns:
      static field expression
    • createStaticField

      IDStaticField createStaticField(IDexField f)
      Create a static field expression from a dex field.
      Parameters:
      f - dex field
      Returns:
      static field expression
    • createStaticField

      IDStaticField createStaticField(IDIndex index, IJavaType fieldtype, String csig, String fieldname)
      Create a static field expression.
      Parameters:
      index - field index
      fieldtype - field type
      csig - owner class signature
      fieldname - field name
      Returns:
      static field expression
    • createInstanceField

      IDInstanceField createInstanceField(IDExpression instance, String fsig)
      Create an instance field expression from a field signature.
      Parameters:
      instance - object instance expression
      fsig - field signature
      Returns:
      instance field expression
    • createInstanceField

      IDInstanceField createInstanceField(IDExpression instance, String fsig, boolean createRefIfDoesNotExist)
      Create an instance field expression from a field signature.
      Parameters:
      instance - object instance expression
      fsig - field signature
      createRefIfDoesNotExist - true to create a reference if the field is not found
      Returns:
      instance field expression
    • createInstanceField

      IDInstanceField createInstanceField(IDExpression instance, IDexField f)
      Create an instance field expression from a dex field.
      Parameters:
      instance - object instance expression
      f - dex field
      Returns:
      instance field expression
    • createInstanceField

      IDInstanceField createInstanceField(IDExpression instance, IDIndex index, IJavaType fieldtype, String fieldname)
      Create an instance field expression.
      Parameters:
      instance - object instance expression
      index - field index
      fieldtype - field type
      fieldname - field name
      Returns:
      instance field expression
    • createClassObject

      IDStaticField createClassObject(String csig)
      Create a class object pseudo-field expression.
      Parameters:
      csig - class signature
      Returns:
      class object expression
    • createArrayLength

      IDInstanceField createArrayLength(IDExpression instance)
      Create an array-length expression.
      Parameters:
      instance - array instance expression
      Returns:
      array-length expression
    • createCallInfo

      IDCallInfo createCallInfo(IDIndex methodindex, IDExpression[] arguments, IJavaType returntype, String methodsig, DInvokeType invoketype)
      Create call information for an invocation.
      Parameters:
      methodindex - method pool index
      arguments - invocation arguments
      returntype - return type
      methodsig - method signature
      invoketype - invocation type
      Returns:
      call information
    • createCallInfo

      IDCallInfo createCallInfo(IDIndex methodindex, List<IDExpression> arguments, IJavaType returntype, String methodsig, DInvokeType invoketype)
      Create call information for an invocation.
      Parameters:
      methodindex - method pool index
      arguments - invocation arguments
      returntype - return type
      methodsig - method signature
      invoketype - invocation type
      Returns:
      call information
    • createCallInfo

      IDCallInfo createCallInfo(DInvokeType invoketype, int methodindex, List<IDExpression> arguments)
      Create call information for an invocation.
      Parameters:
      invoketype - invocation type
      methodindex - method pool index
      arguments - invocation arguments
      Returns:
      call information
    • createCallInfo

      IDCallInfo createCallInfo(DInvokeType invoketype, String msig, List<IDExpression> arguments)
      Create call information for an invocation.
      Parameters:
      invoketype - invocation type
      msig - method signature
      arguments - invocation arguments
      Returns:
      call information
    • createAllocObjectInfo

      IDAllocObjectInfo createAllocObjectInfo(IJavaType objectType)
      Create object allocation information.
      Parameters:
      objectType - allocated object type
      Returns:
      allocation information
    • createAllocObjectInfo

      IDAllocObjectInfo createAllocObjectInfo(String objectType)
      Create object allocation information.
      Parameters:
      objectType - allocated object type signature
      Returns:
      allocation information
    • createNewInfo

      IDNewInfo createNewInfo(String constructorSig, IDExpression... arguments)
      Convenience method to create a new SomeObject(..) operand.
      Parameters:
      constructorSig - constructor signature
      arguments - constructor arguments
      Returns:
      new-instance information
    • createNewInfo

      IDNewInfo createNewInfo(IJavaType objecttype, IJavaType constclasstype, IDIndex constructorindex, IDExpression[] arguments, String methodsig)
      Create new-instance information.
      Parameters:
      objecttype - allocated object type
      constclasstype - constant class type
      constructorindex - constructor method index
      arguments - constructor arguments
      methodsig - constructor signature
      Returns:
      new-instance information
    • createNewInfo

      IDNewInfo createNewInfo(IJavaType objecttype, IJavaType constclasstype, IDIndex constructorindex, List<IDExpression> arguments, String methodsig)
      Create new-instance information.
      Parameters:
      objecttype - allocated object type
      constclasstype - constant class type
      constructorindex - constructor method index
      arguments - constructor arguments
      methodsig - constructor signature
      Returns:
      new-instance information
    • createNewArrayInfo

      IDNewArrayInfo createNewArrayInfo(IJavaType type, IDExpression size, List<IDExpression> initvals)
      Create new-array information.
      Parameters:
      type - array type
      size - size expression
      initvals - optional initial values
      Returns:
      new-array information
    • createBooleanArray

      IDNewArrayInfo createBooleanArray(boolean[] values)
      Create boolean-array information from concrete values.
      Parameters:
      values - initial values
      Returns:
      new-array information
    • createByteArray

      IDNewArrayInfo createByteArray(byte[] values)
      Create byte-array information from concrete values.
      Parameters:
      values - initial values
      Returns:
      new-array information
    • createCharArray

      IDNewArrayInfo createCharArray(char[] values)
      Create char-array information from concrete values.
      Parameters:
      values - initial values
      Returns:
      new-array information
    • createShortArray

      IDNewArrayInfo createShortArray(short[] values)
      Create short-array information from concrete values.
      Parameters:
      values - initial values
      Returns:
      new-array information
    • createIntArray

      IDNewArrayInfo createIntArray(int[] values)
      Create int-array information from concrete values.
      Parameters:
      values - initial values
      Returns:
      new-array information
    • createLongArray

      IDNewArrayInfo createLongArray(long[] values)
      Create long-array information from concrete values.
      Parameters:
      values - initial values
      Returns:
      new-array information
    • createFloatArray

      IDNewArrayInfo createFloatArray(float[] values)
      Create float-array information from concrete values.
      Parameters:
      values - initial values
      Returns:
      new-array information
    • createDoubleArray

      IDNewArrayInfo createDoubleArray(double[] values)
      Create double-array information from concrete values.
      Parameters:
      values - initial values
      Returns:
      new-array information
    • createStringArray

      IDNewArrayInfo createStringArray(String[] values)
      Create string-array information from concrete values.
      Parameters:
      values - initial values
      Returns:
      new-array information
    • createTarget

      IDTarget createTarget(int offset)
      Create a branch target.
      Parameters:
      offset - target offset
      Returns:
      branch target
    • createSwitchData

      IDSwitchData createSwitchData()
      Create a switch data element used in Switch instructions.
      Returns:
      empty switch data element