mirror of
https://github.com/Guardsquare/proguard.git
synced 2026-03-13 09:50:34 +08:00
Flatten passes.
This commit is contained in:
committed by
James Hamilton
parent
78a49d1e66
commit
ec0d8f03ac
@@ -28,6 +28,7 @@ import proguard.configuration.ConfigurationLoggingAdder;
|
||||
import proguard.evaluation.IncompleteClassHierarchyException;
|
||||
import proguard.configuration.InitialStateInfo;
|
||||
import proguard.mark.Marker;
|
||||
import proguard.obfuscate.ObfuscationPreparation;
|
||||
import proguard.obfuscate.Obfuscator;
|
||||
import proguard.optimize.LineNumberTrimmer;
|
||||
import proguard.optimize.Optimizer;
|
||||
@@ -504,6 +505,8 @@ public class ProGuard
|
||||
System.out.println("Obfuscating...");
|
||||
}
|
||||
|
||||
new ObfuscationPreparation().execute(appView);
|
||||
|
||||
// Perform the actual obfuscation.
|
||||
new Obfuscator().execute(appView);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* ProGuard -- shrinking, optimization, obfuscation, and preverification
|
||||
* of Java bytecode.
|
||||
*
|
||||
* Copyright (c) 2002-2021 Guardsquare NV
|
||||
*/
|
||||
|
||||
package proguard.obfuscate;
|
||||
|
||||
import proguard.AppView;
|
||||
import proguard.classfile.visitor.ClassCleaner;
|
||||
import proguard.pass.Pass;
|
||||
import proguard.util.PrintWriterUtil;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class ObfuscationPreparation implements Pass
|
||||
{
|
||||
@Override
|
||||
public void execute(AppView appView) throws IOException
|
||||
{
|
||||
// We'll apply a mapping, if requested.
|
||||
if (appView.configuration.verbose &&
|
||||
appView.configuration.applyMapping != null)
|
||||
{
|
||||
System.out.println("Applying mapping from [" + PrintWriterUtil.fileName(appView.configuration.applyMapping) + "]...");
|
||||
}
|
||||
|
||||
// Check if we have at least some keep commands.
|
||||
if (appView.configuration.keep == null &&
|
||||
appView.configuration.applyMapping == null &&
|
||||
appView.configuration.printMapping == null)
|
||||
{
|
||||
throw new IOException("You have to specify '-keep' options for the obfuscation step.");
|
||||
}
|
||||
|
||||
// Clean up any old processing info.
|
||||
appView.programClassPool.classesAccept(new ClassCleaner());
|
||||
appView.libraryClassPool.classesAccept(new ClassCleaner());
|
||||
}
|
||||
}
|
||||
@@ -56,23 +56,11 @@ public class Obfuscator implements Pass
|
||||
@Override
|
||||
public void execute(AppView appView) throws IOException
|
||||
{
|
||||
// Check if we have at least some keep commands.
|
||||
if (appView.configuration.keep == null &&
|
||||
appView.configuration.applyMapping == null &&
|
||||
appView.configuration.printMapping == null)
|
||||
{
|
||||
throw new IOException("You have to specify '-keep' options for the obfuscation step.");
|
||||
}
|
||||
|
||||
// We're using the system's default character encoding for writing to
|
||||
// the standard output and error output.
|
||||
PrintWriter out = new PrintWriter(System.out, true);
|
||||
PrintWriter err = new PrintWriter(System.err, true);
|
||||
|
||||
// Clean up any old processing info.
|
||||
appView.programClassPool.classesAccept(new ClassCleaner());
|
||||
appView.libraryClassPool.classesAccept(new ClassCleaner());
|
||||
|
||||
// Link all non-private, non-static methods in all class hierarchies.
|
||||
ClassVisitor memberInfoLinker =
|
||||
new BottomClassFilter(new MethodLinker());
|
||||
@@ -211,13 +199,6 @@ public class Obfuscator implements Pass
|
||||
// override the names of library classes and of library class members.
|
||||
if (appView.configuration.applyMapping != null)
|
||||
{
|
||||
if (appView.configuration.verbose)
|
||||
{
|
||||
out.println("Applying mapping from [" +
|
||||
PrintWriterUtil.fileName(appView.configuration.applyMapping) +
|
||||
"]...");
|
||||
}
|
||||
|
||||
WarningPrinter warningPrinter = new WarningPrinter(err, appView.configuration.warn);
|
||||
|
||||
MappingReader reader = new MappingReader(appView.configuration.applyMapping);
|
||||
|
||||
@@ -46,6 +46,9 @@ import java.util.*;
|
||||
/**
|
||||
* This pass optimizes class pools according to a given configuration.
|
||||
*
|
||||
* This pass is stateful. It tracks when no more optimizations are
|
||||
* possible, and then all further runs of this pass will have no effect.
|
||||
*
|
||||
* @author Eric Lafortune
|
||||
*/
|
||||
public class Optimizer implements Pass
|
||||
|
||||
Reference in New Issue
Block a user