org.benf.cfr.reader.util.getopt.OptionsImpl Java Examples
The following examples show how to use
org.benf.cfr.reader.util.getopt.OptionsImpl.
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: FileSummaryDumper.java From cfr with MIT License | 6 votes |
private void notifyAdditionalAtEnd() { try { List<DecompilerComment> comments = additionalComments != null ? additionalComments.getComments() : null; if (comments != null && !comments.isEmpty()) { writer.write("\n"); for (DecompilerComment comment : comments) { writer.write(comment.toString() + "\n"); // It's also handy to see these on console. if (!options.getOption(OptionsImpl.SILENT)) { System.err.println(comment.toString()); } } } } catch (IOException e) { throw new IllegalStateException(e); } }
Example #2
Source File: FileDumper.java From cfr with MIT License | 6 votes |
FileDumper(String dir, boolean clobber, JavaTypeInstance type, SummaryDumper summaryDumper, TypeUsageInformation typeUsageInformation, Options options, IllegalIdentifierDump illegalIdentifierDump) { super(typeUsageInformation, options, illegalIdentifierDump, new MovableDumperContext()); this.type = type; this.summaryDumper = summaryDumper; Pair<String, String> names = ClassNameUtils.getPackageAndClassNames(type); try { String fileName = mkFilename(dir, names, summaryDumper); File file = new File(fileName); File parent = file.getParentFile(); if (!parent.exists() && !parent.mkdirs()) { throw new IllegalStateException("Couldn't create dir: " + parent); } if (file.exists() && !clobber) { throw new CannotCreate("File already exists, and option '" + OptionsImpl.CLOBBER_FILES.getName() + "' not set"); } path = fileName; writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); } catch (FileNotFoundException e) { throw new CannotCreate(e); } }
Example #3
Source File: StaticInitReturnRewriter.java From cfr with MIT License | 6 votes |
public static List<Op03SimpleStatement> rewrite(Options options, Method method, List<Op03SimpleStatement> statementList) { if (!method.getName().equals(MiscConstants.STATIC_INIT_METHOD)) return statementList; if (!options.getOption(OptionsImpl.STATIC_INIT_RETURN)) return statementList; /* * if the final statement is a return, then replace all other returns with a jump to that. */ Op03SimpleStatement last = statementList.get(statementList.size()-1); if (last.getStatement().getClass() != ReturnNothingStatement.class) return statementList; for (int x =0, len=statementList.size()-1;x<len;++x) { Op03SimpleStatement stm = statementList.get(x); if (stm.getStatement().getClass() == ReturnNothingStatement.class) { stm.replaceStatement(new GotoStatement()); stm.addTarget(last); last.addSource(stm); } } return statementList; }
Example #4
Source File: EnumClassRewriter.java From cfr with MIT License | 6 votes |
public static void rewriteEnumClass(ClassFile classFile, DCCommonState state) { Options options = state.getOptions(); ClassFileVersion classFileVersion = classFile.getClassFileVersion(); if (!options.getOption(OptionsImpl.ENUM_SUGAR, classFileVersion)) return; JavaTypeInstance classType = classFile.getClassType(); if (!classFile.getBindingSupers().containsBase(TypeConstants.ENUM)) { return; } EnumClassRewriter c = new EnumClassRewriter(classFile, classType, state); if (!c.rewrite()) { c.removeAllRemainingSupers(); } }
Example #5
Source File: Main.java From cfr with MIT License | 6 votes |
public static void main(String[] args) { GetOptParser getOptParser = new GetOptParser(); Options options = null; List<String> files = null; try { Pair<List<String>, Options> processedArgs = getOptParser.parse(args, OptionsImpl.getFactory()); files = processedArgs.getFirst(); options = processedArgs.getSecond(); if (files.size() == 0) { throw new IllegalArgumentException("Insufficient unqualified parameters - provide at least one filename."); } } catch (Exception e) { getOptParser.showHelp(e); System.exit(1); } if (options.optionIsSet(OptionsImpl.HELP) || files.isEmpty()) { getOptParser.showOptionHelp(OptionsImpl.getFactory(), options, OptionsImpl.HELP); return; } CfrDriver cfrDriver = new CfrDriver.Builder().withBuiltOptions(options).build(); cfrDriver.analyse(files); }
Example #6
Source File: ClassRenamer.java From cfr with MIT License | 6 votes |
public static ClassRenamer create(Options options) { Set<String> invalidNames = OsInfo.OS().getIllegalNames(); // We still fetch the insensitivity flag from options, to allow it to be forced. boolean renameCase = (options.getOption(OptionsImpl.CASE_INSENSITIVE_FS_RENAME)); List<ClassNameFunction> functions = ListFactory.newList(); if (!invalidNames.isEmpty()) { functions.add(new ClassNameFunctionInvalid(renameCase, invalidNames)); } if (renameCase) { functions.add(new ClassNameFunctionCase()); } if (functions.isEmpty()) { return null; } return new ClassRenamer(functions); }
Example #7
Source File: ConditionalCondenser.java From cfr with MIT License | 5 votes |
static void collapseAssignmentsIntoConditionals(List<Op03SimpleStatement> statements, Options options, ClassFileVersion classFileVersion) { // find all conditionals. List<Op03SimpleStatement> ifStatements = Functional.filter(statements, new TypeFilter<IfStatement>(IfStatement.class)); if (ifStatements.isEmpty()) return; boolean testEclipse = options.getOption(OptionsImpl.ECLIPSE); boolean notBeforeInstanceOf = options.getOption(OptionsImpl.INSTANCEOF_PATTERN, classFileVersion); ConditionalCondenser c = new ConditionalCondenser(testEclipse, notBeforeInstanceOf); for (Op03SimpleStatement statement : ifStatements) { c.collapseAssignmentsIntoConditional(statement); } }
Example #8
Source File: SynchronizedRewriter.java From cfr with MIT License | 5 votes |
static void removeSynchronizedCatchBlocks(Options options, List<Op03SimpleStatement> in) { if (!options.getOption(OptionsImpl.TIDY_MONITORS)) return; // find all the block statements which are the first statement in a CATCHBLOCK. List<Op03SimpleStatement> catchStarts = Functional.filter(in, new FindBlockStarts(BlockType.CATCHBLOCK)); if (catchStarts.isEmpty()) return; boolean effect = false; for (Op03SimpleStatement catchStart : catchStarts) { effect = removeSynchronizedCatchBlock(catchStart, in) || effect; } if (effect) { Op03Rewriters.removePointlessJumps(in); } }
Example #9
Source File: WhileRewriter.java From cfr with MIT License | 5 votes |
static void rewriteWhilesAsFors(Options options, List<Op03SimpleStatement> statements) { // Find all the while loops beginnings. List<Op03SimpleStatement> whileStarts = Functional.filter(statements, new Predicate<Op03SimpleStatement>() { @Override public boolean test(Op03SimpleStatement in) { return (in.getStatement() instanceof WhileStatement) && ((WhileStatement) in.getStatement()).getBlockIdentifier().getBlockType() == BlockType.WHILELOOP; } }); boolean aggcapture = options.getOption(OptionsImpl.FOR_LOOP_CAPTURE) == Troolean.TRUE; for (Op03SimpleStatement whileStart : whileStarts) { rewriteWhileAsFor(whileStart, aggcapture); } }
Example #10
Source File: SwitchStringRewriter.java From cfr with MIT License | 5 votes |
@Override public void rewrite(Op04StructuredStatement root) { if (!(options.getOption(OptionsImpl.STRING_SWITCH, classFileVersion) || bytecodeMeta.has(BytecodeMeta.CodeInfoFlag.STRING_SWITCHES)) ) return; List<StructuredStatement> structuredStatements = MiscStatementTools.linearise(root); if (structuredStatements == null) return; rewriteComplex(structuredStatements); rewriteEmpty(structuredStatements); }
Example #11
Source File: CFRDecompiler.java From java-disassembler with GNU General Public License v3.0 | 5 votes |
@Override public String decompileClassNode(FileContainer container, ClassNode cn) { try { byte[] bytes = JDA.getClassBytes(container, cn); GetOptParser getOptParser = new GetOptParser(); Pair processedArgs = getOptParser.parse(generateMainMethod(), OptionsImpl.getFactory()); List files = (List)processedArgs.getFirst(); Options options = (Options)processedArgs.getSecond(); ClassFileSourceImpl classFileSource = new ClassFileSourceImpl(options); DCCommonState dcCommonState = new DCCommonState(options, classFileSource); return doClass(dcCommonState, bytes); } catch (Exception e) { return parseException(e); } }
Example #12
Source File: InternalDumperFactoryImpl.java From cfr with MIT License | 5 votes |
public InternalDumperFactoryImpl(Options options) { this.checkDupes = OsInfo.OS().isCaseInsensitive() && !options.getOption(OptionsImpl.CASE_INSENSITIVE_FS_RENAME); this.options = options; if (!options.getOption(OptionsImpl.SILENT) && (options.optionIsSet(OptionsImpl.OUTPUT_DIR) || options.optionIsSet(OptionsImpl.OUTPUT_PATH))) { progressDumper = new ProgressDumperStdErr(); } else { progressDumper = ProgressDumperNop.INSTANCE; } this.prefix = ""; }
Example #13
Source File: CodeAnalyserWholeClass.java From cfr with MIT License | 5 votes |
public static void wholeClassAnalysisPass3(ClassFile classFile, DCCommonState state, TypeUsageCollectingDumper typeUsage) { Options options = state.getOptions(); if (options.getOption(OptionsImpl.REMOVE_BOILERPLATE)) { removeRedundantSupers(classFile); } if (options.getOption(OptionsImpl.REMOVE_DEAD_METHODS)) { removeDeadMethods(classFile); } rewriteUnreachableStatics(classFile, typeUsage); detectFakeMethods(classFile, typeUsage); }
Example #14
Source File: InternalDumperFactoryImpl.java From cfr with MIT License | 5 votes |
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 #15
Source File: StreamDumper.java From cfr with MIT License | 5 votes |
StreamDumper(TypeUsageInformation typeUsageInformation, Options options, IllegalIdentifierDump illegalIdentifierDump, MovableDumperContext context) { super(context); this.typeUsageInformation = typeUsageInformation; this.options = options; this.illegalIdentifierDump = illegalIdentifierDump; this.convertUTF = options.getOption(OptionsImpl.HIDE_UTF8); this.emitted = SetFactory.newSet(); }
Example #16
Source File: AttributeInnerClasses.java From cfr with MIT License | 5 votes |
public AttributeInnerClasses(ByteData raw, ConstantPool cp) { Boolean forbidMethodScopedClasses = cp.getDCCommonState().getOptions().getOption(OptionsImpl.FORBID_METHOD_SCOPED_CLASSES); Boolean forbidAnonymousClasses = cp.getDCCommonState().getOptions().getOption(OptionsImpl.FORBID_ANONYMOUS_CLASSES); this.length = raw.getS4At(OFFSET_OF_ATTRIBUTE_LENGTH); int numberInnerClasses = raw.getU2At(OFFSET_OF_NUMBER_OF_CLASSES); long offset = OFFSET_OF_CLASS_ARRAY; for (int x = 0; x < numberInnerClasses; ++x) { int innerClassInfoIdx = raw.getU2At(offset); offset += 2; int outerClassInfoIdx = raw.getU2At(offset); offset += 2; int innerNameIdx = raw.getU2At(offset); offset += 2; int innerAccessFlags = raw.getU2At(offset); offset += 2; Pair<JavaTypeInstance, JavaTypeInstance> innerOuter = getInnerOuter(innerClassInfoIdx, outerClassInfoIdx, cp); JavaTypeInstance innerClassType = innerOuter.getFirst(); JavaTypeInstance outerClassType = innerOuter.getSecond(); // MarkAnonymous feels like a bit of a hack, but otherwise we need to propagate this information // the whole way down the type creation path, and this is the only place we care about it. // May add that in later. if (outerClassType == null) { // This option has to be set manually, because it affects state generated // which is shared between fallback passes. if (forbidMethodScopedClasses) { outerClassType = innerClassType.getInnerClassHereInfo().getOuterClass(); } else { boolean isAnonymous = !forbidAnonymousClasses && innerNameIdx == 0; innerClassType.getInnerClassHereInfo().markMethodScoped(isAnonymous); } } innerClassAttributeInfoList.add(new InnerClassAttributeInfo( innerClassType, outerClassType, getOptName(innerNameIdx, cp), AccessFlag.build(innerAccessFlags) )); } }
Example #17
Source File: ClassFile.java From cfr with MIT License | 5 votes |
private void analyseSyntheticTags(Method method, Options options) { try { Op04StructuredStatement code = method.getAnalysis(); if (code == null) return; if (options.getOption(OptionsImpl.REWRITE_TRY_RESOURCES, getClassFileVersion())) { boolean isResourceRelease = Op04StructuredStatement.isTryWithResourceSynthetic(method, code); if (isResourceRelease) { method.getAccessFlags().add(AccessFlagMethod.ACC_FAKE_END_RESOURCE); } } } catch (Exception e) { // ignore. } }
Example #18
Source File: TypeUsageInformationImpl.java From cfr with MIT License | 5 votes |
public TypeUsageInformationImpl(Options options, JavaRefTypeInstance analysisType, Set<JavaRefTypeInstance> usedRefTypes, Set<DetectedStaticImport> staticImports) { this.allowShorten = MiscUtils.mkRegexFilter(options.getOption(OptionsImpl.IMPORT_FILTER), true); this.analysisType = analysisType; this.iid = IllegalIdentifierDump.Factory.getOrNull(options); this.staticImports = staticImports; initialiseFrom(usedRefTypes); }
Example #19
Source File: StreamDumper.java From cfr with MIT License | 5 votes |
StreamDumper(TypeUsageInformation typeUsageInformation, Options options, IllegalIdentifierDump illegalIdentifierDump, MovableDumperContext context, Set<JavaTypeInstance> emitted) { super(context); this.typeUsageInformation = typeUsageInformation; this.options = options; this.illegalIdentifierDump = illegalIdentifierDump; this.convertUTF = options.getOption(OptionsImpl.HIDE_UTF8); this.emitted = emitted; }
Example #20
Source File: CfrDriverImpl.java From cfr with MIT License | 5 votes |
@Override public void analyse(List<String> toAnalyse) { /* * There's an interesting question here - do we want to skip inner classes, if we've been given a wildcard? * (or a wildcard expanded by the operating system). * * Assume yes. */ boolean skipInnerClass = toAnalyse.size() > 1 && options.getOption(OptionsImpl.SKIP_BATCH_INNER_CLASSES); Collections.sort(toAnalyse); for (String path : toAnalyse) { // TODO : We shouldn't have to discard state here. But we do, because // it causes test fails. (used class name table retains useful symbols). classFileSource.informAnalysisRelativePathDetail(null, null); // Note - both of these need to be reset, as they have caches. DCCommonState dcCommonState = new DCCommonState(options, classFileSource); DumperFactory dumperFactory = outputSinkFactory != null ? new SinkDumperFactory(outputSinkFactory, options) : new InternalDumperFactoryImpl(options); AnalysisType type = options.getOption(OptionsImpl.ANALYSE_AS); if (type == null || type == AnalysisType.DETECT) { type = dcCommonState.detectClsJar(path); } if (type == AnalysisType.JAR || type == AnalysisType.WAR) { Driver.doJar(dcCommonState, path, type, dumperFactory); } else if (type == AnalysisType.CLASS) { Driver.doClass(dcCommonState, path, skipInnerClass, dumperFactory); } } }
Example #21
Source File: IllegalIdentifierDump.java From cfr with MIT License | 5 votes |
public static IllegalIdentifierDump get(Options options) { if (options.getOption(OptionsImpl.RENAME_ILLEGAL_IDENTS)) { return IllegalIdentifierReplacement.getInstance(); } else { return Nop.getInstance(); } }
Example #22
Source File: IllegalIdentifierDump.java From cfr with MIT License | 5 votes |
public static IllegalIdentifierDump getOrNull(Options options) { if (options.getOption(OptionsImpl.RENAME_ILLEGAL_IDENTS)) { return IllegalIdentifierReplacement.getInstance(); } else { return null; } }
Example #23
Source File: PluginRunner.java From cfr with MIT License | 5 votes |
private static DCCommonState initDCState(Map<String, String> optionsMap, ClassFileSource classFileSource) { OptionsImpl options = new OptionsImpl(optionsMap); ClassFileSource2 source = classFileSource == null ? new ClassFileSourceImpl(options) : new ClassFileSourceWrapper(classFileSource); return new DCCommonState(options, source); }
Example #24
Source File: MappingFactory.java From cfr with MIT License | 5 votes |
public static ObfuscationMapping get(Options options, DCCommonState state) { String path = options.getOption(OptionsImpl.OBFUSCATION_PATH); if (path == null) { return NullMapping.INSTANCE; } return new MappingFactory(options, state.getClassCache()).createFromPath(path); }
Example #25
Source File: StringBuilderRewriter.java From cfr with MIT License | 4 votes |
public StringBuilderRewriter(Options options, ClassFileVersion classFileVersion) { this.stringBufferEnabled = options.getOption(OptionsImpl.SUGAR_STRINGBUFFER, classFileVersion); this.stringBuilderEnabled = options.getOption(OptionsImpl.SUGAR_STRINGBUILDER, classFileVersion); this.stringConcatFactoryEnabled = options.getOption(OptionsImpl.SUGAR_STRINGCONCATFACTORY, classFileVersion); }
Example #26
Source File: LValueScopeDiscoverImpl.java From cfr with MIT License | 4 votes |
public LValueScopeDiscoverImpl(Options options, MethodPrototype prototype, VariableFactory variableFactory, ClassFileVersion version) { super(options, prototype, variableFactory); instanceOfDefines = options.getOption(OptionsImpl.INSTANCEOF_PATTERN, version); }
Example #27
Source File: MethodPrototype.java From cfr with MIT License | 4 votes |
public MethodPrototype(DCCommonState state, ClassFile classFile, JavaTypeInstance classType, String name, boolean instanceMethod, Method.MethodConstructor constructorFlag, List<FormalTypeParameter> formalTypeParameters, List<JavaTypeInstance> args, JavaTypeInstance result, List<JavaTypeInstance> exceptionTypes, boolean varargs, VariableNamer variableNamer, boolean synthetic) { this.formalTypeParameters = formalTypeParameters; this.instanceMethod = instanceMethod; /* * We add a fake String and Int argument onto NON SYNTHETIC methods. * Can't add onto synthetic methods, as they don't get mutilated to have their args removed. * * Strictly speaking, we should check to see if this is a forwarding method, not just check the synthetic flag. */ /* * SOME methods already have the synthetic args baked into the constructors!! * How do we tell in advance? It doesn't seem like there's a legit way to do this - * we could check to see if #given args matches #used args, but that would break when * unused args exist! */ if (( constructorFlag == Method.MethodConstructor.ENUM_CONSTRUCTOR || constructorFlag == Method.MethodConstructor.ECLIPSE_ENUM_CONSTRUCTOR ) && !synthetic) { List<JavaTypeInstance> args2 = ListFactory.newList(); /* * ECJ will generate a signature which apparently has 2 arguments. * Javac will not. */ if (constructorFlag != Method.MethodConstructor.ECLIPSE_ENUM_CONSTRUCTOR) { args2.add(TypeConstants.STRING); args2.add(RawJavaType.INT); } args2.addAll(args); if (state == null || state.getOptions().getOption(OptionsImpl.ENUM_SUGAR, classFile.getClassFileVersion())) { hide(0); hide(1); } args = args2; } this.args = args; JavaTypeInstance resultType; if (MiscConstants.INIT_METHOD.equals(name)) { if (classFile == null) { resultType = classType; } else { resultType = null; } } else { resultType = result; } this.result = resultType; this.exceptionTypes = exceptionTypes; this.varargs = varargs; this.variableNamer = variableNamer; this.name = name; this.fixedName = null; this.classFile = classFile; }
Example #28
Source File: ProgressDumperStdErr.java From cfr with MIT License | 4 votes |
@Override public void analysingPath(String path) { System.err.println("Processing " + path + " (use " + OptionsImpl.SILENT.getName() + " to silence)"); }
Example #29
Source File: Op04StructuredStatement.java From cfr with MIT License | 4 votes |
public static void removePrimitiveDeconversion(Options options, Method method, Op04StructuredStatement root) { if (!options.getOption(OptionsImpl.SUGAR_BOXING)) return; root.transform(new ExpressionRewriterTransformer(new PrimitiveBoxingRewriter()), new StructuredScope()); }
Example #30
Source File: JumpsIntoLoopCloneRewriter.java From cfr with MIT License | 4 votes |
JumpsIntoLoopCloneRewriter(Options options) { this.maxDepth = options.getOption(OptionsImpl.AGGRESSIVE_DO_COPY); }