Class UnitUtil

java.lang.Object
com.pnfsoftware.jeb.core.units.UnitUtil

public class UnitUtil extends Object
Utility methods for units.
  • Constructor Details

    • UnitUtil

      public UnitUtil()
  • Method Details

    • notifyGenericChange

      public static void notifyGenericChange(IUnit unit)
      Issue a generic J.UnitChange event to all listeners of the provided unit.
      Parameters:
      unit - a unit
    • logI

      public static void logI(IUnit unit, String address, ILogger logger, String format, Object... params)
      Log an internal message.
      Parameters:
      unit -
      address -
      logger -
      format -
      params -
    • logTrace

      public static void logTrace(IUnit unit, String address, ILogger logger, String format, Object... params)
      Log a trace message.
      Parameters:
      unit -
      address -
      logger -
      format -
      params -
    • logInfo

      public static void logInfo(IUnit unit, String address, boolean recordNotification, ILogger logger, String format, Object... params)
      Log an informational message and optionally record a unit notification.
      Parameters:
      unit -
      address -
      recordNotification -
      logger -
      format -
      params -
    • logWarn

      public static void logWarn(IUnit unit, String address, boolean recordNotification, ILogger logger, String format, Object... params)
      Log a warning and optionally record a unit notification.
      Parameters:
      unit -
      address -
      recordNotification -
      logger -
      format -
      params -
    • logError

      public static void logError(IUnit unit, String address, boolean recordNotification, ILogger logger, String format, Object... params)
      Log an error and optionally record a unit notification.
      Parameters:
      unit -
      address -
      recordNotification -
      logger -
      format -
      params -
    • logException

      public static void logException(IUnit unit, ILogger logger, Exception e)
      Log an exception and optionally record a unit notification.
      Parameters:
      unit -
      logger -
      e -
    • filterDescendants

      public static List<IUnit> filterDescendants(IUnit base, int maxDepth, IUnitFilter filter)
      Retrieve a list of descendants of the provided unit that pass the provided filter test and do not exceeded the maximum depth.
      Parameters:
      base -
      maxDepth - use -1 to go as deep as possible
      filter -
      Returns:
    • findDescendantsByType

      public static <T extends IUnit> List<T> findDescendantsByType(IUnit base, int maxDepth, Class<T> classtype, boolean exactClasstype)
      Retrieve a list of descendant units of the provided unit that are of the provided classtype (exact or derived) and do not exceeded the maximum depth.
      Parameters:
      base -
      maxDepth - use -1 to go as deep as possible
      classtype - wanted classtype
      exactClasstype - if true, only units of the exact classtype will be returned
      Returns:
    • findChildrenByType

      public static <T extends IUnit> List<T> findChildrenByType(IUnit base, Class<T> classtype, boolean exactClasstype)
    • findChildByType

      public static <T extends IUnit> T findChildByType(IUnit base, Class<T> classtype, boolean exactClasstype, int index)
    • findFirstChildByType

      public static <T extends IUnit> T findFirstChildByType(IUnit base, Class<T> classtype, boolean exactClasstype)
    • findDescendantsByType

      public static <T extends IUnit> List<T> findDescendantsByType(IUnit base, Class<T> classtype, boolean exactClasstype)
    • findDescendantsByName

      public static List<IUnit> findDescendantsByName(IUnit base, int maxDepth, String name)
      Retrieve a list of descendant units of the provided unit that have the provided name.
      Parameters:
      base -
      maxDepth - use -1 to go as deep as possible
      name -
      Returns:
    • findDescendantsByName

      public static List<IUnit> findDescendantsByName(IUnit base, String name)
    • findChildrenByName

      public static List<IUnit> findChildrenByName(IUnit base, String name)
    • findChildByName

      public static IUnit findChildByName(IUnit base, String name, int index)
    • findFirstChildByName

      public static IUnit findFirstChildByName(IUnit base, String name)
    • retrieve

      public static IUnit retrieve(IUnit base, String... pathElements)
      Retrieve a unit rooted in the provided base, and whose relative path from that base consists of the provided path elements.
      Parameters:
      base - a root unit
      pathElements - 1 or more sub-unit names
      Returns:
      the unit corresponding to the last path element, null if not found - the unit may not have been processed
    • retrieveProcessed

      public static IUnit retrieveProcessed(boolean processIfUnprocessed, IUnit base, String... pathElements)
      Retrieve a unit rooted in the provided base, and whose relative path from that base consists of the provided path elements. The returned unit is guaranteed to be processed.
      Parameters:
      processIfUnprocessed - attempt to process the unit if it is unprocessed
      base -
      pathElements -
      Returns:
      a unit (processed) or null
    • findDescendants

      public static <T extends IUnit> List<T> findDescendants(IUnit base, int maxDepth, String name, Class<T> classtype, boolean exactClasstype)
      Convenience function to find descendant units by type and/or name.
      Parameters:
      base -
      maxDepth - use -1 to go as deep as possible
      name - optional
      classtype - optional
      exactClasstype -
      Returns:
    • findChildren

      public static <T extends IUnit> List<T> findChildren(IUnit base, String name, Class<T> c, boolean strict)
    • findChild

      public static <T extends IUnit> T findChild(IUnit base, String name, Class<T> c, boolean strict, int index)
    • findDescendants

      public static <T extends IUnit> List<T> findDescendants(ILiveArtifact base, int level, String name, Class<T> c, boolean strict)
    • findAll

      public static <T extends IUnit> List<T> findAll(String name, Class<T> c, boolean strict)
    • findDescendantsByFormatType

      public static <T extends IUnit> List<T> findDescendantsByFormatType(IUnit base, int level, String formatType)
    • findDescendantsByFormatType

      public static List<IUnit> findDescendantsByFormatType(IUnit base, String formatType)
    • findChildrenByFormatType

      public static List<IUnit> findChildrenByFormatType(IUnit base, String formatType)
    • findChildByFormatType

      public static IUnit findChildByFormatType(IUnit base, String formatType, int index)
    • findFirstChildByFormatType

      public static IUnit findFirstChildByFormatType(IUnit base, String formatType)
    • findAncestor

      public static <T extends IUnitCreator> T findAncestor(IUnit unit, Class<T> c, boolean strict)
      Find the closest ancestor of an IUnit that matches a Class.
      Parameters:
      unit - a children element
      c - the class to match. Can be an interface.
      strict - if true, only units of the exact classtype will be returned
      Returns:
      the closest ancestor that matches, or null if not found
    • isAncestorOf

      public static boolean isAncestorOf(IUnit unit, IUnit expectedAncestor)
    • isAncestorOf

      public static boolean isAncestorOf(IUnit unit, IUnit expectedAncestor, boolean strictAncestor)
    • buildFullyQualifiedCandidateUnitPath

      public static String buildFullyQualifiedCandidateUnitPath(String candidateUnitName, IUnitCreator parent, boolean includeArtifact, String separator)
      Build the fully-qualified path of a potential unit whose only the name is provided.
      Parameters:
      candidateUnitName -
      parent -
      includeArtifact -
      separator -
      Returns:
    • buildFullyQualifiedUnitPath

      public static String buildFullyQualifiedUnitPath(IUnit unit, boolean includeArtifact, String separator)
      Build a fully-qualified unit path.
      Parameters:
      unit -
      includeArtifact -
      separator -
      Returns:
    • buildFullyQualifiedUnitPathList

      public static List<String> buildFullyQualifiedUnitPathList(IUnitCreator unit, boolean includeArtifact)
      Build a fully-qualified unit path as list of unit names.
      Parameters:
      unit -
      includeArtifact -
      Returns:
    • buildFullyQualifiedUnitPath

      public static String buildFullyQualifiedUnitPath(IUnit unit)
      Build a unit path of the artifact name and its parent units, such as:artifact > unit > unit > ... > unit
      Parameters:
      unit -
      Returns:
    • isTopLevelUnit

      public static boolean isTopLevelUnit(IUnit unit)
      Parameters:
      unit -
      Returns:
    • unitProperty

      public static String unitProperty(IUnitIdentifier ident, String propertyName)
      Generate a fully-qualified property name used by a unit.
      Parameters:
      ident - a unit identifier
      propertyName - simple property name
      Returns:
      a FQ name
    • unitProperty

      public static String unitProperty(IUnit unit, String propertyName)
      Generate a fully-qualified property name used by a unit.
      Parameters:
      unit - a unit
      propertyName - simple property name
      Returns:
      a FQ name
    • unitProperty

      public static String unitProperty(IEnginesContext engctx, String unitType, String propertyName)
      Generate a fully-qualified property name used by a unit.
      Parameters:
      engctx - JEB engines context
      unitType - unit type
      propertyName - simple property name
      Returns:
      a FQ name
    • decompilerProperty

      public static String decompilerProperty(IEnginesContext engctx, String codeType, String propertyName)
      Generate a fully-qualified property name used by a decompiler unit.
      Parameters:
      engctx - JEB engines context
      codeType - code unit type (not a decompiler unit)
      propertyName - simple property name
      Returns:
    • debuggerProperty

      public static String debuggerProperty(IEnginesContext engctx, String codeType, String propertyName)
      Generate a fully-qualified property name used by a decompiler unit.
      Parameters:
      engctx - JEB engines context
      codeType - code unit type (not a debugger unit)
      propertyName - simple property name
      Returns:
    • getUnitsFromPathList

      public static List<IUnit> getUnitsFromPathList(IRuntimeProject prj, List<String> path)
      Retrieve the targets IUnit from its path (built from buildFullyQualifiedUnitPathList(IUnitCreator, boolean) for example). Note that result target will be unique in most of the cases.
      Parameters:
      prj -
      path -
      Returns: