Java Code Examples for org.benf.cfr.reader.bytecode.analysis.parse.utils.Pair#make()

The following examples show how to use org.benf.cfr.reader.bytecode.analysis.parse.utils.Pair#make() . 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: CFRDecompiler.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
protected Pair<byte[], String> getSystemClass(String name, String path) throws IOException {
  InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(path);
  if (is != null) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buffer = new byte[4096];
    int n;
    while ((n = is.read(buffer)) > 0) {
      baos.write(buffer, 0, n);
    }
    return Pair.make(baos.toByteArray(), name);
  }
  return null;
}
 
Example 2
Source File: Misc.java    From cfr with MIT License 5 votes vote down vote up
private Pair<Set<Op03SimpleStatement>, Set<Op03SimpleStatement>> privGetBlockReachableAndExits() {
    GraphVisitorDFS<Op03SimpleStatement> reachableInBlock = new GraphVisitorDFS<Op03SimpleStatement>(
            start,
            this
    );
    reachableInBlock.process();
    return Pair.make(found,exits);
}
 
Example 3
Source File: SwitchExpressionRewriter.java    From cfr with MIT License 5 votes vote down vote up
private Pair<StructuredCase, Expression> extractSwitchEntryPair(LValue target, BlockIdentifier blockIdentifier, Op04StructuredStatement item, List<Pair<Op04StructuredStatement, StructuredStatement>> replacements, boolean last) {
    StructuredStatement stm = item.getStatement();
    if (!(stm instanceof StructuredCase)) {
        return null;
    }
    StructuredCase sc = (StructuredCase)stm;
    Expression res = extractSwitchEntry(target, blockIdentifier, sc.getBody(), replacements, last);
    if (res == null) {
        return null;
    }
    return Pair.make(sc, res);
}
 
Example 4
Source File: ConstantPoolUtils.java    From cfr with MIT License 5 votes vote down vote up
private static Pair<List<JavaTypeInstance>, Integer> parseTypeList(String proto, ConstantPool cp) {
    int curridx = 0;
    int len = proto.length();
    List<JavaTypeInstance> res = ListFactory.newList();
    while (curridx < len && proto.charAt(curridx) != '>') {
        String typeTok = getNextTypeTok(proto, curridx);
        res.add(decodeTypeTok(typeTok, cp));
        curridx += typeTok.length();
    }
    return Pair.make(res, curridx);
}
 
Example 5
Source File: BoxingHelper.java    From cfr with MIT License 5 votes vote down vote up
public static Expression sugarUnboxing(MemberFunctionInvokation memberFunctionInvokation) {
    String name = memberFunctionInvokation.getName();
    JavaTypeInstance type = memberFunctionInvokation.getObject().getInferredJavaType().getJavaTypeInstance();
    String rawTypeName = type.getRawName();
    Pair<String, String> testPair = Pair.make(rawTypeName, name);
    if (unboxing.contains(testPair)) {
        Expression expression = memberFunctionInvokation.getObject();
        return expression;
    }
    return memberFunctionInvokation;
}
 
Example 6
Source File: TypeAnnotationTargetInfo.java    From cfr with MIT License 5 votes vote down vote up
static Pair<Long, TypeAnnotationTargetInfo> Read(ByteData raw, long offset) {
    int count = raw.getU2At(offset);
    offset += 2;
    List<LocalVarTarget> targetList = ListFactory.newList();
    for (int x=0;x<count;++x) {
        int start = raw.getU2At(offset);
        offset += 2;
        int length = raw.getU2At(offset);
        offset += 2;
        int index = raw.getU2At(offset);
        offset += 2;
        targetList.add(new LocalVarTarget(start, length, index));
    }
    return Pair.<Long, TypeAnnotationTargetInfo>make(offset, new TypeAnnotationLocalVarTarget(targetList));
}
 
Example 7
Source File: InternalDumperFactoryImpl.java    From cfr with MIT License 5 votes vote down vote up
private Pair<String, Boolean> getPathAndClobber() {
    Troolean clobber = options.getOption(OptionsImpl.CLOBBER_FILES);
    if (options.optionIsSet(OptionsImpl.OUTPUT_DIR)) {
        return Pair.make(options.getOption(OptionsImpl.OUTPUT_DIR), clobber.boolValue(true));
    }
    if (options.optionIsSet(OptionsImpl.OUTPUT_PATH)) {
        return Pair.make(options.getOption(OptionsImpl.OUTPUT_PATH), clobber.boolValue(false));
    }
    return null;
}
 
Example 8
Source File: JavaRefTypeInstance.java    From cfr with MIT License 5 votes vote down vote up
public static Pair<JavaRefTypeInstance, JavaRefTypeInstance> createKnownInnerOuter(String inner, String outer, JavaRefTypeInstance outerType, DCCommonState dcCommonState) {
    if (outerType == null) outerType = new JavaRefTypeInstance(outer, dcCommonState);
    JavaRefTypeInstance innerType;
    if (!inner.startsWith(outer)) {
        // Handle the illegal inner/outer combo.
        innerType = new JavaRefTypeInstance(inner, dcCommonState);
    } else {
        innerType = new JavaRefTypeInstance(inner, outerType, dcCommonState);
    }
    return Pair.make(innerType, outerType);
}
 
Example 9
Source File: Block.java    From cfr with MIT License 5 votes vote down vote up
public Pair<Boolean, Op04StructuredStatement> getOneStatementIfPresent() {
    Op04StructuredStatement res = null;
    for (Op04StructuredStatement statement : containedStatements) {
        if (!(statement.getStatement() instanceof StructuredComment)) {
            if (res == null) {
                res = statement;
            } else {
                return Pair.make(Boolean.FALSE, null);
            }
        }
    }
    return Pair.make(res==null, res);
}
 
Example 10
Source File: TypeAnnotationTargetInfo.java    From cfr with MIT License 4 votes vote down vote up
static Pair<Long, TypeAnnotationTargetInfo> Read(ByteData raw, long offset) {
    int supertype_index = raw.getU2At(offset);
    offset += 2;
    return Pair.<Long, TypeAnnotationTargetInfo>make(offset, new TypeAnnotationSupertypeTarget(supertype_index));
}
 
Example 11
Source File: TypeAnnotationTargetInfo.java    From cfr with MIT License 4 votes vote down vote up
static Pair<Long, TypeAnnotationTargetInfo> Read(ByteData raw, long offset) {
    return Pair.<Long, TypeAnnotationTargetInfo>make(offset, INSTANCE);
}
 
Example 12
Source File: TypeAnnotationTargetInfo.java    From cfr with MIT License 4 votes vote down vote up
static Pair<Long, TypeAnnotationTargetInfo> Read(ByteData raw, long offset) {
    short formal_parameter_index = raw.getU1At(offset++);
    return Pair.<Long, TypeAnnotationTargetInfo>make(offset, new TypeAnnotationFormalParameterTarget(formal_parameter_index));
}
 
Example 13
Source File: TypeAnnotationTargetInfo.java    From cfr with MIT License 4 votes vote down vote up
static Pair<Long, TypeAnnotationTargetInfo> Read(ByteData raw, long offset) {
    int throws_type_index = raw.getU2At(offset);
    offset += 2;
    return Pair.<Long, TypeAnnotationTargetInfo>make(offset, new TypeAnnotationThrowsTarget(throws_type_index));
}
 
Example 14
Source File: TypeAnnotationTargetInfo.java    From cfr with MIT License 4 votes vote down vote up
static Pair<Long, TypeAnnotationTargetInfo> Read(ByteData raw, long offset) {
    short type_parameter_index = raw.getU1At(offset++);
    return Pair.<Long, TypeAnnotationTargetInfo>make(offset, new TypeAnnotationParameterTarget(type_parameter_index));
}
 
Example 15
Source File: IfStatement.java    From cfr with MIT License 4 votes vote down vote up
public Pair<BlockIdentifier, BlockIdentifier> getBlocks() {
    return Pair.make(knownIfBlock, knownElseBlock);
}
 
Example 16
Source File: TypeAnnotationTargetInfo.java    From cfr with MIT License 4 votes vote down vote up
static Pair<Long, TypeAnnotationTargetInfo> Read(ByteData raw, long offset) {
    int offset_val = raw.getU2At(offset);
    offset += 2;
    return Pair.<Long, TypeAnnotationTargetInfo>make(offset, new TypeAnnotationOffsetTarget(offset_val));
}
 
Example 17
Source File: IntervalCount.java    From cfr with MIT License 4 votes vote down vote up
public Pair<Integer, Integer> generateNonIntersection(Integer from, Integer to) {
    if (to < from) return null;

    Map.Entry<Integer, Boolean> prevEntry = op.floorEntry(from);
    Boolean previous = prevEntry == null ? null : prevEntry.getValue();
    boolean braOutside = previous == null || (!previous);

    if (braOutside) {
        op.put(from, true);
    } else {
        from = prevEntry.getKey();
        /*
         * If the new exception entry is entirely subsumed within from -> next ket, then we have
         * a totally redundant exception entry.
         */
        Map.Entry<Integer, Boolean> nextEntry = op.ceilingEntry(from + 1);
        if (nextEntry == null) {
            throw new IllegalStateException("Internal exception pattern invalid");
        }
        if (!nextEntry.getValue()) { // next is a ket
            if (nextEntry.getKey() >= to) {
                // Entirely subsumed within previous entry, redundant.
                return null;
            }
        }
    }

    NavigableMap<Integer, Boolean> afterMap = op.tailMap(from, false);

    Set<Map.Entry<Integer, Boolean>> afterSet = afterMap.entrySet();
    Iterator<Map.Entry<Integer, Boolean>> afterIter = afterSet.iterator();
    while (afterIter.hasNext()) {
        Map.Entry<Integer, Boolean> next = afterIter.next();
        Integer end = next.getKey();
        boolean isKet = Boolean.FALSE == next.getValue();
        if (end > to) {
            if (isKet) {
                // Fine.  We'll just extend the range of the newer one.
                return Pair.make(from, end);
            }
            // Then we'll add another ket, and place it before end.
            op.put(to, false);
            return Pair.make(from, to);
        } else if (end.equals(to)) {
            if (isKet) {
                // Fine, nothing to do.
                return Pair.make(from, end);
            }
            // We remove this bra, and coalesce the ranges.
            afterIter.remove();
            return Pair.make(from, to);
        }

        // end < to.  This means that a more important exception is inner.
        // This is pretty common!
        // Remove the previous one.
        afterIter.remove();
    }
    // Walked off then end?
    op.put(to, false);
    return Pair.make(from, to);
}
 
Example 18
Source File: IterLoopRewriter.java    From cfr with MIT License 4 votes vote down vote up
private static Pair<ConditionalExpression, ConditionalExpression> getSplitAnd(ConditionalExpression cnd) {
    if (!(cnd instanceof BooleanOperation)) return Pair.make(cnd, null);
    BooleanOperation op = (BooleanOperation)cnd;
    if (op.getOp() != BoolOp.AND) return Pair.make(cnd, null);
    return Pair.make(op.getLhs(), op.getRhs());
}
 
Example 19
Source File: InferredJavaType.java    From cfr with MIT License 4 votes vote down vote up
private static Pair<Boolean, JavaTypeInstance> collapseTypeClash2(List<JavaTypeInstance> clashes) {
    Map<JavaTypeInstance, JavaGenericRefTypeInstance> matches = getMatches(clashes);
    if (matches.isEmpty()) {
        return Pair.<Boolean, JavaTypeInstance>make(false, TypeConstants.OBJECT);
    }

    /*
     * Matches defines the common set of parent / actual classes - i.e. the match could be one of these.
     *
     * We now want to remove any which are less derived.
     */
    List<JavaTypeInstance> poss = getMostDerivedType(matches.keySet());
    /*
     * If we still have >1 left, we have to pick one.  Prefer a base class to an interface?
     */
    JavaTypeInstance oneClash = clashes.get(0);
    Map<? extends JavaTypeInstance, BindingSuperContainer.Route> routes = oneClash.getBindingSupers().getBoundSuperRoute();
    if (poss.isEmpty()) {
        // If we ended up with nothing, we've been stupidly aggressive.  Take a guess.
        poss = ListFactory.newList(matches.keySet());
    }
    for (JavaTypeInstance pos : poss) {
        if (BindingSuperContainer.Route.EXTENSION == routes.get(pos)) {
            return Pair.make(true, pos);
        }
    }
    JavaTypeInstance result = poss.get(0);

    JavaGenericRefTypeInstance rhs = matches.get(result);
    betterGen : if (rhs != null) {
        // See PairTest3.
        JavaTypeInstance bindingFor = GenericTypeBinder.extractBindings(rhs, oneClash).getBindingFor(rhs);
        if (bindingFor != null) {
            if (bindingFor instanceof JavaGenericRefTypeInstance) {
                JavaGenericRefTypeInstance genericBindingFor = (JavaGenericRefTypeInstance) bindingFor;
                List<List<JavaTypeInstance>> clashSubs = ListFactory.newList();
                for (JavaTypeInstance typ : genericBindingFor.getGenericTypes()) {
                    clashSubs.add(ListFactory.newList(typ));
                }
                for (int i = 1; i < clashes.size(); ++i) {
                    JavaTypeInstance bindingFor2 = GenericTypeBinder.extractBindings(rhs, clashes.get(i)).getBindingFor(rhs);
                    if (!(bindingFor2 instanceof JavaGenericRefTypeInstance)) {
                        break betterGen;
                    }
                    JavaGenericRefTypeInstance gr2 = (JavaGenericRefTypeInstance)bindingFor2;
                    List<JavaTypeInstance> thisClashSubs = gr2.getGenericTypes();
                    if (thisClashSubs.size() != clashSubs.size()) {
                        break betterGen;
                    }
                    for (int j=0;j<clashSubs.size();++j) {
                        List<JavaTypeInstance> clashSubsPosn = clashSubs.get(j);
                        if (!clashSubsPosn.get(0).equals(thisClashSubs.get(j))) {
                            clashSubsPosn.add(thisClashSubs.get(j));
                        }
                    }
                }
                List<JavaTypeInstance> resolvedSubs = ListFactory.newList();
                //noinspection ForLoopReplaceableByForEach
                for (int i = 0;i < clashSubs.size();++i) {
                    List<JavaTypeInstance> posSub = clashSubs.get(i);
                    if (posSub.size() == 1) {
                        resolvedSubs.add(posSub.get(0));
                    } else {
                        /*
                         * Let's recurse again!
                         */
                        JavaTypeInstance reRes = InferredJavaType.mkClash(posSub).collapseTypeClash().getJavaTypeInstance();
                        resolvedSubs.add(reRes);
                    }
                }
                bindingFor = new JavaGenericRefTypeInstance(genericBindingFor.getTypeInstance(), resolvedSubs);

                result = bindingFor;
            }
        }
    }

    return Pair.make(true, result);
}
 
Example 20
Source File: CodePane.java    From JRemapper with MIT License 4 votes vote down vote up
@Override
public Pair<byte[], String> getClassFileContent(String pathOrName) throws IOException {
	pathOrName = pathOrName.substring(0, pathOrName.length() - ".class".length());
	return Pair.make(resources.get(pathOrName), pathOrName);
}