Java Code Examples for com.strobel.decompiler.DecompilerSettings#setShowSyntheticMembers()

The following examples show how to use com.strobel.decompiler.DecompilerSettings#setShowSyntheticMembers() . 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: ProcyonDecompiler.java    From java-disassembler with GNU General Public License v3.0 6 votes vote down vote up
public DecompilerSettings getDecompilerSettings() {
        DecompilerSettings procyonSettings = new DecompilerSettings();
        procyonSettings.setFlattenSwitchBlocks(settings.getEntry("fsb").getBool());
        procyonSettings.setForceExplicitImports(!settings.getEntry("ci").getBool());
        procyonSettings.setForceExplicitTypeArguments(settings.getEntry("ei").getBool());
        procyonSettings.setRetainRedundantCasts(settings.getEntry("ec").getBool());
        procyonSettings.setShowSyntheticMembers(settings.getEntry("ss").getBool());
        procyonSettings.setExcludeNestedTypes(settings.getEntry("ent").getBool());
//        procyonSettings.setOutputDirectory(options.getOutputDirectory());
        procyonSettings.setIncludeLineNumbersInBytecode(settings.getEntry("dl").getBool());
        procyonSettings.setRetainPointlessSwitches(settings.getEntry("ps").getBool());
        procyonSettings.setUnicodeOutputEnabled(settings.getEntry("unicode").getBool());
        procyonSettings.setMergeVariables(settings.getEntry("mv").getBool());
        procyonSettings.setShowDebugLineNumbers(settings.getEntry("dl").getBool());
        procyonSettings.setSimplifyMemberReferences(settings.getEntry("sm").getBool());
        procyonSettings.setDisableForEachTransforms(settings.getEntry("disable-foreach").getBool());
        procyonSettings.setTypeLoader(new InputTypeLoader());
//        procyonSettings.setLanguage(Languages.bytecode());
//        procyonSettings.setLanguage(settings.getEntry("Unoptimized AST").getBool() ? Languages.bytecodeAstUnoptimized() : Languages.bytecodeAst());
        return procyonSettings;
    }
 
Example 2
Source File: ProcyonDecompiler.java    From steady with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public File decompileClassFile(File inputClassFile) {

	//Default settings for the decompilers
	final DecompilerSettings settings = new DecompilerSettings();
	settings.setShowSyntheticMembers(true);
	settings.setSimplifyMemberReferences(true);
	settings.setExcludeNestedTypes(true);

	String classFilePath = inputClassFile.getPath();
	String fileNameWithOutExt = FilenameUtils.removeExtension(inputClassFile.getName());
	File outFile = new File(inputClassFile.getParent(), fileNameWithOutExt + ".java");

	try {

		final FileOutputStream stream = new FileOutputStream(outFile.toString());
		final OutputStreamWriter writer = new OutputStreamWriter(stream, FileUtil.getCharset());

		try {
			Decompiler.decompile(
					classFilePath,
					new PlainTextOutput(writer),
					settings
					);
		}
		finally {
			writer.close();
			stream.close();
		}
	}
	catch (final IOException e) {
		log.debug(e.getMessage());
	}

	return outFile;
}
 
Example 3
Source File: ProcyonDecompiler.java    From Recaf with MIT License 5 votes vote down vote up
@Override
public String decompile(String name) {
    ITypeLoader loader = new ComposedTypeLoader(Arrays.asList(
            new RecafTypeLoader(getController()), new InputTypeLoader()
    ));
    Map<String, Boolean> options = getOptions();
    DecompilerSettings settings = new DecompilerSettings();
    settings.setFlattenSwitchBlocks(options.get("flatten-switch-blocks"));
    settings.setForceExplicitImports(!options.get("collapse-imports"));
    settings.setForceExplicitTypeArguments(options.get("force-explicit-type-arguments"));
    settings.setRetainRedundantCasts(options.get("retain-redundant-casts"));
    settings.setShowSyntheticMembers(options.get("show-synthetic-members"));
    settings.setExcludeNestedTypes(options.get("exclude-nested-types"));
    settings.setRetainPointlessSwitches(options.get("retain-pointless-switches"));
    settings.setUnicodeOutputEnabled(options.get("unicode-output"));
    settings.setMergeVariables(options.get("merge-variables"));
    settings.setShowDebugLineNumbers(options.get("show-debug-line-numbers"));
    settings.setSimplifyMemberReferences(options.get("simplify-member-references"));
    settings.setForceFullyQualifiedReferences(options.get("force-fully-qualified-references"));
    settings.setDisableForEachTransforms(options.get("disable-for-each-transforms"));
    settings.setTypeLoader(loader);
    settings.setJavaFormattingOptions(JavaFormattingOptions.createDefault());
    MetadataSystem system = new MetadataSystem(loader);
    system.setEagerMethodLoadingEnabled(options.get("eager-methods-loading"));
    TypeReference ref = system.lookupType(name);
    DecompilationOptions decompilationOptions = new DecompilationOptions();
    decompilationOptions.setSettings(settings);
    decompilationOptions.setFullDecompilation(true);
    StringWriter writer = new StringWriter();
    settings.getLanguage().decompileType(ref.resolve(), new PlainTextOutput(writer), decompilationOptions);
    return writer.toString();
}
 
Example 4
Source File: ClassFile.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private static CompilationUnit decompileClassFile(TypeReference typeRef) {
  TypeDefinition typeDef = typeRef.resolve();
  DeobfuscationUtilities.processType(typeDef);
  DecompilationOptions options = new DecompilationOptions();
  DecompilerSettings settings = DecompilerSettings.javaDefaults();
  settings.setShowSyntheticMembers(true);
  options.setSettings(settings);
  options.setFullDecompilation(true);
  return Languages.java().decompileTypeToAst(typeDef, options);
}
 
Example 5
Source File: ProcyonDecompiler.java    From bytecode-viewer with GNU General Public License v3.0 5 votes vote down vote up
public DecompilerSettings getDecompilerSettings() {
    DecompilerSettings settings = new DecompilerSettings();
    settings.setAlwaysGenerateExceptionVariableForCatchBlocks(BytecodeViewer.viewer.chckbxmntmNewCheckItem_6
            .isSelected());
    settings.setExcludeNestedTypes(BytecodeViewer.viewer.chckbxmntmNewCheckItem_11
            .isSelected());
    settings.setShowDebugLineNumbers(BytecodeViewer.viewer.chckbxmntmShowDebugLine
            .isSelected());
    settings.setIncludeLineNumbersInBytecode(BytecodeViewer.viewer.chckbxmntmNewCheckItem_3
            .isSelected());
    settings.setIncludeErrorDiagnostics(BytecodeViewer.viewer.chckbxmntmNewCheckItem_4
            .isSelected());
    settings.setShowSyntheticMembers(BytecodeViewer.viewer.chckbxmntmNewCheckItem_7
            .isSelected());
    settings.setSimplifyMemberReferences(BytecodeViewer.viewer.chckbxmntmSimplifyMemberReferences
            .isSelected());
    settings.setMergeVariables(BytecodeViewer.viewer.mnMergeVariables
            .isSelected());
    settings.setForceExplicitTypeArguments(BytecodeViewer.viewer.chckbxmntmNewCheckItem_8
            .isSelected());
    settings.setForceExplicitImports(BytecodeViewer.viewer.chckbxmntmNewCheckItem_9
            .isSelected());
    settings.setFlattenSwitchBlocks(BytecodeViewer.viewer.chckbxmntmNewCheckItem_10
            .isSelected());
    settings.setRetainPointlessSwitches(BytecodeViewer.viewer.chckbxmntmNewCheckItem_2
            .isSelected());
    settings.setRetainRedundantCasts(BytecodeViewer.viewer.chckbxmntmNewCheckItem_5
            .isSelected());
    settings.setUnicodeOutputEnabled(BytecodeViewer.viewer.chckbxmntmNewCheckItem_1
            .isSelected());
    settings.setJavaFormattingOptions(JavaFormattingOptions.createDefault());
    return settings;
}
 
Example 6
Source File: ConfigSaver.java    From Luyten with Apache License 2.0 5 votes vote down vote up
/**
 * Do not load, get the loaded instance
 */
private void loadConfig() {
	decompilerSettings = new DecompilerSettings();
	if (decompilerSettings.getJavaFormattingOptions() == null) {
		decompilerSettings.setJavaFormattingOptions(JavaFormattingOptions.createDefault());
	}
	luytenPreferences = new LuytenPreferences();
	mainWindowPosition = new WindowPosition();
	findWindowPosition = new WindowPosition();
	try {
		Preferences prefs = Preferences.userNodeForPackage(ConfigSaver.class);
		if (!prefs.get(LANGUAGE_NAME_ID, decompilerSettings.getLanguage().getName())
				.equals(decompilerSettings.getLanguage().getName()))
			prefs.put(LANGUAGE_NAME_ID, decompilerSettings.getLanguage().getName());

		decompilerSettings.setFlattenSwitchBlocks(
				prefs.getBoolean(FLATTEN_SWITCH_BLOCKS_ID, decompilerSettings.getFlattenSwitchBlocks()));
		decompilerSettings.setForceExplicitImports(
				prefs.getBoolean(FORCE_EXPLICIT_IMPORTS_ID, decompilerSettings.getForceExplicitImports()));
		decompilerSettings.setShowSyntheticMembers(
				prefs.getBoolean(SHOW_SYNTHETIC_MEMBERS_ID, decompilerSettings.getShowSyntheticMembers()));
		decompilerSettings.setExcludeNestedTypes(
				prefs.getBoolean(EXCLUDE_NESTED_TYPES_ID, decompilerSettings.getExcludeNestedTypes()));
		decompilerSettings.setForceExplicitTypeArguments(prefs.getBoolean(FORCE_EXPLICIT_TYPE_ARGUMENTS_ID,
				decompilerSettings.getForceExplicitTypeArguments()));
		decompilerSettings.setRetainRedundantCasts(
				prefs.getBoolean(RETAIN_REDUNDANT_CASTS_ID, decompilerSettings.getRetainRedundantCasts()));
		decompilerSettings.setIncludeErrorDiagnostics(
				prefs.getBoolean(INCLUDE_ERROR_DIAGNOSTICS_ID, decompilerSettings.getIncludeErrorDiagnostics()));
		decompilerSettings.setLanguage(
				findLanguageByName(prefs.get(LANGUAGE_NAME_ID, decompilerSettings.getLanguage().getName())));
		decompilerSettings.setUnicodeOutputEnabled(prefs.getBoolean(UNICODE_REPLACE_ENABLED_ID, false));

		mainWindowPosition = loadWindowPosition(prefs, MAIN_WINDOW_ID_PREFIX);
		findWindowPosition = loadWindowPosition(prefs, FIND_WINDOW_ID_PREFIX);
		luytenPreferences = loadLuytenPreferences(prefs);
	} catch (Exception e) {
		Luyten.showExceptionDialog("Exception!", e);
	}
}
 
Example 7
Source File: FileSaver.java    From Luyten with Apache License 2.0 5 votes vote down vote up
private DecompilerSettings cloneSettings() {
	DecompilerSettings settings = ConfigSaver.getLoadedInstance().getDecompilerSettings();
	DecompilerSettings newSettings = new DecompilerSettings();
	if (newSettings.getJavaFormattingOptions() == null) {
		newSettings.setJavaFormattingOptions(JavaFormattingOptions.createDefault());
	}
	// synchronized: against main menu changes
	synchronized (settings) {
		newSettings.setExcludeNestedTypes(settings.getExcludeNestedTypes());
		newSettings.setFlattenSwitchBlocks(settings.getFlattenSwitchBlocks());
		newSettings.setForceExplicitImports(settings.getForceExplicitImports());
		newSettings.setForceExplicitTypeArguments(settings.getForceExplicitTypeArguments());
		newSettings.setOutputFileHeaderText(settings.getOutputFileHeaderText());
		newSettings.setLanguage(settings.getLanguage());
		newSettings.setShowSyntheticMembers(settings.getShowSyntheticMembers());
		newSettings.setAlwaysGenerateExceptionVariableForCatchBlocks(
				settings.getAlwaysGenerateExceptionVariableForCatchBlocks());
		newSettings.setOutputDirectory(settings.getOutputDirectory());
		newSettings.setRetainRedundantCasts(settings.getRetainRedundantCasts());
		newSettings.setIncludeErrorDiagnostics(settings.getIncludeErrorDiagnostics());
		newSettings.setIncludeLineNumbersInBytecode(settings.getIncludeLineNumbersInBytecode());
		newSettings.setRetainPointlessSwitches(settings.getRetainPointlessSwitches());
		newSettings.setUnicodeOutputEnabled(settings.isUnicodeOutputEnabled());
		newSettings.setMergeVariables(settings.getMergeVariables());
		newSettings.setShowDebugLineNumbers(settings.getShowDebugLineNumbers());
	}
	return newSettings;
}
 
Example 8
Source File: ProcyonDecompiler.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Default settings set type loader to ClasspathTypeLoader if not set before.
 */
private DecompilerSettings getDefaultSettings(File outputDir)
{
    DecompilerSettings settings = new DecompilerSettings();
    procyonConf.setDecompilerSettings(settings);
    settings.setOutputDirectory(outputDir.getPath());
    settings.setShowSyntheticMembers(false);
    settings.setForceExplicitImports(true);

    if (settings.getTypeLoader() == null)
        settings.setTypeLoader(new ClasspathTypeLoader());
    return settings;
}
 
Example 9
Source File: ProcyonDecompiler.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
public String decompile(byte[] b, MethodNode mn) {
  try {
  //TODO decompile method only
    DecompilerSettings settings = new DecompilerSettings();
    try {
      for (Field f : settings.getClass().getDeclaredFields()) {
        if (f.getType() == boolean.class) {
          f.setAccessible(true);
          f.setBoolean(settings, JByteMod.ops.get("procyon" + f.getName()).getBoolean());
        }
      }
    } catch (Throwable t) {
      t.printStackTrace();
    }
    settings.setShowSyntheticMembers(true);
    MetadataSystem metadataSystem = new MetadataSystem(new ITypeLoader() {
      private InputTypeLoader backLoader = new InputTypeLoader();

      @Override
      public boolean tryLoadType(String s, Buffer buffer) {
        if (s.equals(cn.name)) {
          buffer.putByteArray(b, 0, b.length);
          buffer.position(0);
          return true;
        } else {
          return backLoader.tryLoadType(s, buffer);
        }
      }
    });
    TypeReference type = metadataSystem.lookupType(cn.name);
    DecompilationOptions decompilationOptions = new DecompilationOptions();
    decompilationOptions.setSettings(DecompilerSettings.javaDefaults());
    decompilationOptions.setFullDecompilation(true);
    TypeDefinition resolvedType = null;
    if (type == null || ((resolvedType = type.resolve()) == null)) {
      new ErrorDisplay("Unable to resolve type.");
      return "error";
    }
    StringWriter stringwriter = new StringWriter();
    settings.getLanguage().decompileType(resolvedType, new PlainTextOutput(stringwriter), decompilationOptions);
    String decompiledSource = stringwriter.toString();
    return decompiledSource;
  } catch (Exception e) {
    e.printStackTrace();
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    return sw.toString();
  }
}