Java Code Examples for org.jf.dexlib2.iface.ExceptionHandler#getExceptionType()

The following examples show how to use org.jf.dexlib2.iface.ExceptionHandler#getExceptionType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseExceptionHandler.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(@Nonnull ExceptionHandler o) {
    int res;
    String exceptionType = getExceptionType();
    if (exceptionType == null) {
        if (o.getExceptionType() != null) {
            return 1;
        }
    } else {
        String otherExceptionType = o.getExceptionType();
        if (otherExceptionType == null) {
            return -1;
        }
        res = exceptionType.compareTo(o.getExceptionType());
        if (res != 0) return res;
    }
    return Ints.compare(getHandlerCodeAddress(), o.getHandlerCodeAddress());
}
 
Example 2
Source File: TryListBuilder.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
public void addHandler(@Nonnull EH handler) {
    for (ExceptionHandler existingHandler: exceptionHandlers) {
        String existingType = existingHandler.getExceptionType();
        String newType = handler.getExceptionType();

        // Don't add it if we already have a handler of the same type
        if (existingType == null) {
            if (newType == null) {
                if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) {
                    throw new InvalidTryException(
                            "Multiple overlapping catch all handlers with different handlers");
                }
                return;
            }
        } else if (existingType.equals(newType)) {
            if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) {
                throw new InvalidTryException(
                        "Multiple overlapping catches for %s with different handlers", existingType);
            }
            return;
        }
    }

    exceptionHandlers.add(handler);
}
 
Example 3
Source File: BaseExceptionHandler.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(@Nonnull ExceptionHandler o) {
    int res;
    String exceptionType = getExceptionType();
    if (exceptionType == null) {
        if (o.getExceptionType() != null) {
            return 1;
        }
    } else {
        String otherExceptionType = o.getExceptionType();
        if (otherExceptionType == null) {
            return -1;
        }
        res = exceptionType.compareTo(o.getExceptionType());
        if (res != 0) return res;
    }
    return Ints.compare(getHandlerCodeAddress(), o.getHandlerCodeAddress());
}
 
Example 4
Source File: TryListBuilder.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
public void addHandler(@Nonnull EH handler) {
    for (ExceptionHandler existingHandler: exceptionHandlers) {
        String existingType = existingHandler.getExceptionType();
        String newType = handler.getExceptionType();

        // Don't add it if we already have a handler of the same type
        if (existingType == null) {
            if (newType == null) {
                if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) {
                    throw new InvalidTryException(
                            "Multiple overlapping catch all handlers with different handlers");
                }
                return;
            }
        } else if (existingType.equals(newType)) {
            if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) {
                throw new InvalidTryException(
                        "Multiple overlapping catches for %s with different handlers", existingType);
            }
            return;
        }
    }

    exceptionHandlers.add(handler);
}
 
Example 5
Source File: BaseExceptionHandler.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(@Nonnull ExceptionHandler o) {
    int res;
    String exceptionType = getExceptionType();
    if (exceptionType == null) {
        if (o.getExceptionType() != null) {
            return 1;
        }
    } else {
        String otherExceptionType = o.getExceptionType();
        if (otherExceptionType == null) {
            return -1;
        }
        res = exceptionType.compareTo(o.getExceptionType());
        if (res != 0) return res;
    }
    return Ints.compare(getHandlerCodeAddress(), o.getHandlerCodeAddress());
}
 
Example 6
Source File: DexBody.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Return the types that are used in this body.
 */
public Set<Type> usedTypes() {
    Set<Type> types = new HashSet<Type>();
    for (DexlibAbstractInstruction i : instructions)
        types.addAll(i.introducedTypes());

    if(tries!=null) {
     for (TryBlock<? extends ExceptionHandler> tryItem : tries) {
         List<? extends ExceptionHandler> hList = tryItem.getExceptionHandlers();
      for (ExceptionHandler handler: hList) {
          String exType = handler.getExceptionType();
          if (exType == null) // for handler which capture all Exceptions
              continue;
          types.add(DexType.toSoot(exType));
      }
     }
    }

    return types;
}
 
Example 7
Source File: TryListBuilder.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
public void addHandler(@Nonnull EH handler) {
    for (ExceptionHandler existingHandler: exceptionHandlers) {
        String existingType = existingHandler.getExceptionType();
        String newType = handler.getExceptionType();

        // Don't add it if we already have a handler of the same type
        if (existingType == null) {
            if (newType == null) {
                if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) {
                    throw new InvalidTryException(
                            "Multiple overlapping catch all handlers with different handlers");
                }
                return;
            }
        } else if (existingType.equals(newType)) {
            if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) {
                throw new InvalidTryException(
                        "Multiple overlapping catches for %s with different handlers", existingType);
            }
            return;
        }
    }

    exceptionHandlers.add(handler);
}
 
Example 8
Source File: BaseExceptionHandler.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(@Nonnull ExceptionHandler o) {
    int res;
    String exceptionType = getExceptionType();
    if (exceptionType == null) {
        if (o.getExceptionType() != null) {
            return 1;
        }
    } else {
        String otherExceptionType = o.getExceptionType();
        if (otherExceptionType == null) {
            return -1;
        }
        res = exceptionType.compareTo(o.getExceptionType());
        if (res != 0) return res;
    }
    return Ints.compare(getHandlerCodeAddress(), o.getHandlerCodeAddress());
}
 
Example 9
Source File: TryListBuilder.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
public void addHandler(@Nonnull EH handler) {
    for (ExceptionHandler existingHandler: exceptionHandlers) {
        String existingType = existingHandler.getExceptionType();
        String newType = handler.getExceptionType();

        // Don't add it if we already have a handler of the same type
        if (existingType == null) {
            if (newType == null) {
                if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) {
                    throw new InvalidTryException(
                            "Multiple overlapping catch all handlers with different handlers");
                }
                return;
            }
        } else if (existingType.equals(newType)) {
            if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) {
                throw new InvalidTryException(
                        "Multiple overlapping catches for %s with different handlers", existingType);
            }
            return;
        }
    }

    exceptionHandlers.add(handler);
}
 
Example 10
Source File: BaseExceptionHandler.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Override public int compare(ExceptionHandler o1, ExceptionHandler o2) {
    String exceptionType1 = o1.getExceptionType();
    if (exceptionType1 == null) {
        if (o2.getExceptionType() != null) {
            return 1;
        }
        return 0;
    } else {
        String exceptionType2 = o2.getExceptionType();
        if (exceptionType2 == null) {
            return -1;
        }
        return exceptionType1.compareTo(o2.getExceptionType());
    }
}
 
Example 11
Source File: ImmutableExceptionHandler.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) {
    if (exceptionHandler instanceof ImmutableExceptionHandler) {
        return (ImmutableExceptionHandler)exceptionHandler;
    }
    return new ImmutableExceptionHandler(
            exceptionHandler.getExceptionType(),
            exceptionHandler.getHandlerCodeAddress());
}
 
Example 12
Source File: ImmutableExceptionHandler.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) {
    if (exceptionHandler instanceof ImmutableExceptionHandler) {
        return (ImmutableExceptionHandler)exceptionHandler;
    }
    return new ImmutableExceptionHandler(
            exceptionHandler.getExceptionType(),
            exceptionHandler.getHandlerCodeAddress());
}
 
Example 13
Source File: BaseExceptionHandler.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Override public int compare(ExceptionHandler o1, ExceptionHandler o2) {
    String exceptionType1 = o1.getExceptionType();
    if (exceptionType1 == null) {
        if (o2.getExceptionType() != null) {
            return 1;
        }
        return 0;
    } else {
        String exceptionType2 = o2.getExceptionType();
        if (exceptionType2 == null) {
            return -1;
        }
        return exceptionType1.compareTo(o2.getExceptionType());
    }
}
 
Example 14
Source File: ImmutableExceptionHandler.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) {
    if (exceptionHandler instanceof ImmutableExceptionHandler) {
        return (ImmutableExceptionHandler)exceptionHandler;
    }
    return new ImmutableExceptionHandler(
            exceptionHandler.getExceptionType(),
            exceptionHandler.getHandlerCodeAddress());
}
 
Example 15
Source File: BaseExceptionHandler.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Override public int compare(ExceptionHandler o1, ExceptionHandler o2) {
    String exceptionType1 = o1.getExceptionType();
    if (exceptionType1 == null) {
        if (o2.getExceptionType() != null) {
            return 1;
        }
        return 0;
    } else {
        String exceptionType2 = o2.getExceptionType();
        if (exceptionType2 == null) {
            return -1;
        }
        return exceptionType1.compareTo(o2.getExceptionType());
    }
}
 
Example 16
Source File: BaseExceptionHandler.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Override public int compare(ExceptionHandler o1, ExceptionHandler o2) {
    String exceptionType1 = o1.getExceptionType();
    if (exceptionType1 == null) {
        if (o2.getExceptionType() != null) {
            return 1;
        }
        return 0;
    } else {
        String exceptionType2 = o2.getExceptionType();
        if (exceptionType2 == null) {
            return -1;
        }
        return exceptionType1.compareTo(o2.getExceptionType());
    }
}
 
Example 17
Source File: ImmutableExceptionHandler.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) {
    if (exceptionHandler instanceof ImmutableExceptionHandler) {
        return (ImmutableExceptionHandler)exceptionHandler;
    }
    return new ImmutableExceptionHandler(
            exceptionHandler.getExceptionType(),
            exceptionHandler.getHandlerCodeAddress());
}
 
Example 18
Source File: DexBody.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
  * Add the traps of this body.
  *
  * Should only be called at the end jimplify.
  */
 private void addTraps() {
   for (TryBlock<? extends ExceptionHandler> tryItem : tries) {
         int startAddress = tryItem.getStartCodeAddress();
         Debug.printDbg(" start : 0x", Integer.toHexString(startAddress));
         int length = tryItem.getCodeUnitCount();//.getTryLength();
         Debug.printDbg(" length: 0x", Integer.toHexString(length));
         Debug.printDbg(" end   : 0x", Integer.toHexString(startAddress + length));
         int endAddress = startAddress + length;// - 1;
         Unit beginStmt = instructionAtAddress(startAddress).getUnit();
         // (startAddress + length) typically points to the first byte of the first instruction after the try block
         // except if there is no instruction after the try block in which case it points to the last byte of the last
         // instruction of the try block. Removing 1 from (startAddress + length) always points to "somewhere" in
         // the last instruction of the try block since the smallest instruction is on two bytes (nop = 0x0000).
         Unit endStmt =  instructionAtAddress (endAddress).getUnit();
// if the try block ends on the last instruction of the body, add a
// nop instruction so Soot can include
// the last instruction in the try block.
if (jBody.getUnits().getLast() == endStmt
		&& instructionAtAddress(endAddress - 1).getUnit() == endStmt) {
	Unit nop = Jimple.v().newNopStmt();
	jBody.getUnits().insertAfter(nop, endStmt);
	endStmt = nop;
}
Debug.printDbg("begin instruction (0x",
		Integer.toHexString(startAddress), "): ",
		instructionAtAddress(startAddress).getUnit(), " --- ",
		beginStmt);
Debug.printDbg("end instruction   (0x",
		Integer.toHexString(endAddress), "): ",
		instructionAtAddress(endAddress).getUnit(), " --- ",
		endStmt);


         List<? extends ExceptionHandler> hList = tryItem.getExceptionHandlers();
         for (ExceptionHandler handler: hList) {
           int handlerAddress = handler.getHandlerCodeAddress();
           Debug.printDbg("handler   (0x",
         		  Integer.toHexString(handlerAddress),
         		  "): ",
         		  instructionAtAddress (handlerAddress).getUnit(),
         		  " --- ",
         		  handlerAddress > 0 ? instructionAtAddress (handlerAddress-1).getUnit() : "<unknown>");
           String exceptionType = handler.getExceptionType();
           if (exceptionType == null)
               exceptionType = "Ljava/lang/Throwable;";
           Type t = DexType.toSoot(exceptionType);
             // exceptions can only be of RefType
             if (t instanceof RefType) {
                 SootClass exception = ((RefType) t).getSootClass();
                 DexlibAbstractInstruction instruction = instructionAtAddress(handler.getHandlerCodeAddress());
                 if (! (instruction instanceof MoveExceptionInstruction))
                     Debug.printDbg("First instruction of trap handler unit not MoveException but " , instruction.getClass());
                 else
                   ((MoveExceptionInstruction) instruction).setRealType(this, exception.getType());

                 Trap trap = Jimple.v().newTrap(exception, beginStmt, endStmt, instruction.getUnit());
                 jBody.getTraps().add(trap);
             }
         }
     }
 }