private FieldDescriptor(String descriptor) { type = new VarType(descriptor); descriptorString = descriptor; }
public VarType decreaseArrayDim() { if (arrayDim > 0) { return new VarType(type, arrayDim - 1, value); } else { //throw new RuntimeException("array dimension equals 0!"); FIXME: investigate this case return this; } }
public VarType resizeArrayDim(int newArrayDim) { return new VarType(type, newArrayDim, value, typeFamily, stackSize, falseBoolean); }
public VarType copy(boolean forceFalseBoolean) { return new VarType(type, arrayDim, value, typeFamily, stackSize, falseBoolean || forceFalseBoolean); }
public VarType getVariable(int index) { if (index < localVariables.size()) { return localVariables.get(index); } else { return new VarType(CodeConstants.TYPE_NOTINITIALIZED); } }
public void setVariable(int index, VarType value) { if (index >= localVariables.size()) { for (int i = localVariables.size(); i <= index; i++) { localVariables.add(new VarType(CodeConstants.TYPE_NOTINITIALIZED)); } } localVariables.set(index, value); }
private static VarType buildNewType(VarType type, NewClassNameBuilder builder) { if (type.type == CodeConstants.TYPE_OBJECT) { String newClassName = builder.buildNewClassname(type.value); if (newClassName != null) { return new VarType(type.type, type.arrayDim, newClassName); } } return null; }
@Override public String buildNewClassname(String className) { VarType vt = new VarType(className, true); String newName = interceptor.getName(vt.value); if (newName != null) { StringBuilder buffer = new StringBuilder(); if (vt.arrayDim > 0) { for (int i = 0; i < vt.arrayDim; i++) { buffer.append('['); } buffer.append('L').append(newName).append(';'); } else { buffer.append(newName); } return buffer.toString(); } return null; }
@Override public Statement getSimpleCopy() { CatchStatement cs = new CatchStatement(); for (List<String> exc : this.exctstrings) { cs.exctstrings.add(new ArrayList<>(exc)); cs.vars.add(new VarExprent(DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER), new VarType(CodeConstants.TYPE_OBJECT, 0, exc.get(0)), DecompilerContext.getVarProcessor())); } return cs; }
public String buildNewDescriptor(NewClassNameBuilder builder) { if (type.type == CodeConstants.TYPE_OBJECT) { String newClassName = builder.buildNewClassname(type.value); if (newClassName != null) { return new VarType(type.type, type.arrayDim, newClassName).toString(); } } return null; }
public static AnnotationExprent parseAnnotation(DataInputStream data, ConstantPool pool) throws IOException { String className = pool.getPrimitiveConstant(data.readUnsignedShort()).getString(); List<String> names; List<Exprent> values; int len = data.readUnsignedShort(); if (len > 0) { names = new ArrayList<>(len); values = new ArrayList<>(len); for (int i = 0; i < len; i++) { names.add(pool.getPrimitiveConstant(data.readUnsignedShort()).getString()); values.add(parseAnnotationElement(data, pool)); } } else { names = Collections.emptyList(); values = Collections.emptyList(); } return new AnnotationExprent(new VarType(className).value, names, values); }
private CatchStatement(Statement head, Statement next, Set<Statement> setHandlers) { this(); first = head; stats.addWithKey(first, first.id); for (StatEdge edge : head.getSuccessorEdges(StatEdge.TYPE_EXCEPTION)) { Statement stat = edge.getDestination(); if (setHandlers.contains(stat)) { stats.addWithKey(stat, stat.id); exctstrings.add(new ArrayList<>(edge.getExceptions())); vars.add(new VarExprent(DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER), new VarType(CodeConstants.TYPE_OBJECT, 0, edge.getExceptions().get(0)), // FIXME: for now simply the first type. Should get the first common superclass when possible. DecompilerContext.getVarProcessor())); } } if (next != null) { post = next; } }
private CatchAllStatement(Statement head, Statement handler) { this(); first = head; stats.addWithKey(head, head.id); this.handler = handler; stats.addWithKey(handler, handler.id); List<StatEdge> lstSuccs = head.getSuccessorEdges(STATEDGE_DIRECT_ALL); if (!lstSuccs.isEmpty()) { StatEdge edge = lstSuccs.get(0); if (edge.getType() == StatEdge.TYPE_REGULAR) { post = edge.getDestination(); } } vars.add(new VarExprent(DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER), new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Throwable"), DecompilerContext.getVarProcessor())); }
@Override public Statement getSimpleCopy() { CatchAllStatement cas = new CatchAllStatement(); cas.isFinally = this.isFinally; if (this.monitor != null) { cas.monitor = new VarExprent(DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER), VarType.VARTYPE_INT, DecompilerContext.getVarProcessor()); } if (!this.vars.isEmpty()) { cas.vars.add(new VarExprent(DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER), new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Throwable"), DecompilerContext.getVarProcessor())); } return cas; }
public static DataPoint getInitialDataPoint(StructMethod mt) { DataPoint point = new DataPoint(); MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor()); int k = 0; if (!mt.hasModifier(CodeConstants.ACC_STATIC)) { point.setVariable(k++, new VarType(CodeConstants.TYPE_OBJECT, 0, null)); } for (int i = 0; i < md.params.length; i++) { VarType var = md.params[i]; point.setVariable(k++, var); if (var.stackSize == 2) { point.setVariable(k++, new VarType(CodeConstants.TYPE_GROUP2EMPTY)); } } return point; }
private static Exprent isLambda(Exprent exprent, StructClass cl) { List<Exprent> lst = exprent.getAllExprents(); for (Exprent expr : lst) { Exprent ret = isLambda(expr, cl); if (ret != null) { exprent.replaceExprent(expr, ret); } } if (exprent.type == Exprent.EXPRENT_INVOCATION) { InvocationExprent in = (InvocationExprent)exprent; if (in.getInvocationTyp() == InvocationExprent.INVOKE_DYNAMIC) { String lambda_class_name = cl.qualifiedName + in.getInvokeDynamicClassSuffix(); ClassNode lambda_class = DecompilerContext.getClassProcessor().getMapRootClasses().get(lambda_class_name); if (lambda_class != null) { // real lambda class found, replace invocation with an anonymous class NewExprent newExpr = new NewExprent(new VarType(lambda_class_name, true), null, 0, in.bytecode); newExpr.setConstructor(in); // note: we don't set the instance to null with in.setInstance(null) like it is done for a common constructor invocation // lambda can also be a reference to a virtual method (e.g. String x; ...(x::toString);) // in this case instance will hold the corresponding object return newExpr; } } } return null; }
public ClassNode(String content_class_name, String content_method_name, String content_method_descriptor, int content_method_invocation_type, String lambda_class_name, String lambda_method_name, String lambda_method_descriptor, StructClass classStruct) { // lambda class constructor this.type = CLASS_LAMBDA; this.classStruct = classStruct; // 'parent' class containing the static function lambdaInformation = new LambdaInformation(); lambdaInformation.method_name = lambda_method_name; lambdaInformation.method_descriptor = lambda_method_descriptor; lambdaInformation.content_class_name = content_class_name; lambdaInformation.content_method_name = content_method_name; lambdaInformation.content_method_descriptor = content_method_descriptor; lambdaInformation.content_method_invocation_type = content_method_invocation_type; lambdaInformation.content_method_key = InterpreterUtil.makeUniqueKey(lambdaInformation.content_method_name, lambdaInformation.content_method_descriptor); anonymousClassType = new VarType(lambda_class_name, true); boolean is_method_reference = (content_class_name != classStruct.qualifiedName); if (!is_method_reference) { // content method in the same class, check synthetic flag StructMethod mt = classStruct.getMethod(content_method_name, content_method_descriptor); is_method_reference = !mt.isSynthetic(); // if not synthetic -> method reference } lambdaInformation.is_method_reference = is_method_reference; lambdaInformation.is_content_method_static = (lambdaInformation.content_method_invocation_type == CodeConstants.CONSTANT_MethodHandle_REF_invokeStatic); // FIXME: redundant? }
if (cst.getStats().size() == 2 && cst.getFirst().type == Statement.TYPE_BASICBLOCK && cst.getStats().get(1).type == Statement.TYPE_BASICBLOCK && cst.getVars().get(0).getVarType().equals(new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/ClassNotFoundException"))) {
String descriptor = attr.getDescriptor(originalIndex, visibleOffset); if (descriptor != null) { buffer.append(ExprProcessor.getCastTypeName(new VarType(descriptor))); return;