├── .classpath ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── bin └── .gitignore └── src ├── me ├── lpk │ ├── CorrelationMapper.java │ ├── Main.java │ ├── analysis │ │ ├── InsnAnalyzer.java │ │ ├── InsnValue.java │ │ ├── Sandbox.java │ │ ├── StackFrame.java │ │ ├── StackHelper.java │ │ └── StackUtil.java │ ├── antis │ │ ├── AntiBase.java │ │ └── impl │ │ │ ├── AntiAllatori.java │ │ │ ├── AntiDashO.java │ │ │ ├── AntiStringer.java │ │ │ ├── AntiVertex.java │ │ │ ├── AntiZKM5.java │ │ │ ├── AntiZKM8.java │ │ │ └── AntiZKM8_2.java │ ├── gui │ │ ├── AntiWindow.java │ │ ├── ErrorDialog.java │ │ ├── MappingWindow.java │ │ └── drop │ │ │ ├── IDropUser.java │ │ │ └── JarDropHandler.java │ ├── log │ │ └── Logger.java │ ├── mapping │ │ ├── MappedClass.java │ │ ├── MappedMember.java │ │ ├── MappedObject.java │ │ ├── MappingClassWriter.java │ │ ├── MappingFactory.java │ │ ├── MappingProcessor.java │ │ ├── MappingRenamer.java │ │ ├── SkidRemapper.java │ │ ├── loaders │ │ │ ├── EnigmaLoader.java │ │ │ ├── MappingLoader.java │ │ │ ├── ProguardLoader.java │ │ │ └── SRGLoader.java │ │ └── remap │ │ │ ├── MappingMode.java │ │ │ └── impl │ │ │ ├── ModeNone.java │ │ │ ├── ModeRandom.java │ │ │ ├── ModeSimple.java │ │ │ └── ModeUnicodeEvil.java │ └── util │ │ ├── ASMUtils.java │ │ ├── AccessHelper.java │ │ ├── AntiSynthetic.java │ │ ├── Characters.java │ │ ├── Classpather.java │ │ ├── InjectedClassLoader.java │ │ ├── JarClassLoader.java │ │ ├── JarUtils.java │ │ ├── OpUtils.java │ │ ├── ParentUtils.java │ │ ├── Reference.java │ │ ├── ReferenceUtils.java │ │ ├── RegexUtils.java │ │ ├── Setup.java │ │ ├── StringUtils.java │ │ ├── SwingUtils.java │ │ └── Timer.java └── nov │ └── dashostrings │ ├── DashODeobf.java │ ├── Deobfuscation.java │ └── utils │ ├── DashOUtils.java │ ├── InstructionUtils.java │ └── MethodUtils.java └── org ├── apache └── commons │ └── io │ ├── ByteOrderMark.java │ ├── Charsets.java │ ├── CopyUtils.java │ ├── DirectoryWalker.java │ ├── EndianUtils.java │ ├── FileCleaner.java │ ├── FileCleaningTracker.java │ ├── FileDeleteStrategy.java │ ├── FileExistsException.java │ ├── FileSystemUtils.java │ ├── FileUtils.java │ ├── FilenameUtils.java │ ├── HexDump.java │ ├── IOCase.java │ ├── IOExceptionWithCause.java │ ├── IOUtils.java │ ├── LineIterator.java │ ├── TaggedIOException.java │ ├── ThreadMonitor.java │ ├── comparator │ ├── AbstractFileComparator.java │ ├── CompositeFileComparator.java │ ├── DefaultFileComparator.java │ ├── DirectoryFileComparator.java │ ├── ExtensionFileComparator.java │ ├── LastModifiedFileComparator.java │ ├── NameFileComparator.java │ ├── PathFileComparator.java │ ├── ReverseComparator.java │ └── SizeFileComparator.java │ ├── filefilter │ ├── AbstractFileFilter.java │ ├── AgeFileFilter.java │ ├── AndFileFilter.java │ ├── CanReadFileFilter.java │ ├── CanWriteFileFilter.java │ ├── ConditionalFileFilter.java │ ├── DelegateFileFilter.java │ ├── DirectoryFileFilter.java │ ├── EmptyFileFilter.java │ ├── FalseFileFilter.java │ ├── FileFileFilter.java │ ├── FileFilterUtils.java │ ├── HiddenFileFilter.java │ ├── IOFileFilter.java │ ├── MagicNumberFileFilter.java │ ├── NameFileFilter.java │ ├── NotFileFilter.java │ ├── OrFileFilter.java │ ├── PrefixFileFilter.java │ ├── RegexFileFilter.java │ ├── SizeFileFilter.java │ ├── SuffixFileFilter.java │ ├── TrueFileFilter.java │ ├── WildcardFileFilter.java │ └── WildcardFilter.java │ ├── input │ ├── AutoCloseInputStream.java │ ├── BOMInputStream.java │ ├── BoundedInputStream.java │ ├── BrokenInputStream.java │ ├── CharSequenceInputStream.java │ ├── CharSequenceReader.java │ ├── ClassLoaderObjectInputStream.java │ ├── CloseShieldInputStream.java │ ├── ClosedInputStream.java │ ├── CountingInputStream.java │ ├── DemuxInputStream.java │ ├── NullInputStream.java │ ├── NullReader.java │ ├── ProxyInputStream.java │ ├── ProxyReader.java │ ├── ReaderInputStream.java │ ├── ReversedLinesFileReader.java │ ├── SwappedDataInputStream.java │ ├── TaggedInputStream.java │ ├── Tailer.java │ ├── TailerListener.java │ ├── TailerListenerAdapter.java │ ├── TeeInputStream.java │ ├── XmlStreamReader.java │ └── XmlStreamReaderException.java │ ├── monitor │ ├── FileAlterationListener.java │ ├── FileAlterationListenerAdaptor.java │ ├── FileAlterationMonitor.java │ ├── FileAlterationObserver.java │ └── FileEntry.java │ └── output │ ├── BrokenOutputStream.java │ ├── ByteArrayOutputStream.java │ ├── CloseShieldOutputStream.java │ ├── ClosedOutputStream.java │ ├── CountingOutputStream.java │ ├── DeferredFileOutputStream.java │ ├── DemuxOutputStream.java │ ├── FileWriterWithEncoding.java │ ├── LockableFileWriter.java │ ├── NullOutputStream.java │ ├── NullWriter.java │ ├── ProxyOutputStream.java │ ├── ProxyWriter.java │ ├── StringBuilderWriter.java │ ├── TaggedOutputStream.java │ ├── TeeOutputStream.java │ ├── ThresholdingOutputStream.java │ ├── WriterOutputStream.java │ └── XmlStreamWriter.java └── objectweb └── asm ├── AnnotationVisitor.java ├── AnnotationWriter.java ├── Attribute.java ├── ByteVector.java ├── ClassReader.java ├── ClassVisitor.java ├── ClassWriter.java ├── Context.java ├── Edge.java ├── FieldVisitor.java ├── FieldWriter.java ├── Frame.java ├── Handle.java ├── Handler.java ├── Item.java ├── Label.java ├── MethodVisitor.java ├── MethodWriter.java ├── Opcodes.java ├── Type.java ├── TypePath.java ├── TypeReference.java ├── commons ├── AdviceAdapter.java ├── AnalyzerAdapter.java ├── AnnotationRemapper.java ├── ClassRemapper.java ├── CodeSizeEvaluator.java ├── FieldRemapper.java ├── GeneratorAdapter.java ├── InstructionAdapter.java ├── LocalVariablesSorter.java ├── Method.java ├── MethodRemapper.java ├── Remapper.java ├── RemappingAnnotationAdapter.java ├── RemappingClassAdapter.java ├── RemappingFieldAdapter.java ├── RemappingMethodAdapter.java ├── RemappingSignatureAdapter.java ├── SerialVersionUIDAdder.java ├── SignatureRemapper.java ├── SimpleRemapper.java ├── StaticInitMerger.java ├── TableSwitchGenerator.java └── TryCatchBlockSorter.java ├── optimizer ├── AnnotationConstantsCollector.java ├── ClassConstantsCollector.java ├── ClassOptimizer.java ├── Constant.java ├── ConstantPool.java ├── FieldConstantsCollector.java ├── JarOptimizer.java ├── MethodConstantsCollector.java ├── MethodOptimizer.java ├── NameMapping.java └── Shrinker.java ├── signature ├── SignatureReader.java ├── SignatureVisitor.java └── SignatureWriter.java ├── tree ├── AbstractInsnNode.java ├── AnnotationNode.java ├── ClassNode.java ├── FieldInsnNode.java ├── FieldNode.java ├── FrameNode.java ├── IincInsnNode.java ├── InnerClassNode.java ├── InsnList.java ├── InsnNode.java ├── IntInsnNode.java ├── InvokeDynamicInsnNode.java ├── JumpInsnNode.java ├── LabelNode.java ├── LdcInsnNode.java ├── LineNumberNode.java ├── LocalVariableAnnotationNode.java ├── LocalVariableNode.java ├── LookupSwitchInsnNode.java ├── MethodInsnNode.java ├── MethodNode.java ├── MultiANewArrayInsnNode.java ├── ParameterNode.java ├── TableSwitchInsnNode.java ├── TryCatchBlockNode.java ├── TypeAnnotationNode.java ├── TypeInsnNode.java ├── VarInsnNode.java └── analysis │ ├── Analyzer.java │ ├── AnalyzerException.java │ ├── BasicInterpreter.java │ ├── BasicValue.java │ ├── BasicVerifier.java │ ├── Frame.java │ ├── Interpreter.java │ ├── SimpleVerifier.java │ ├── SmallSet.java │ ├── SourceInterpreter.java │ ├── SourceValue.java │ ├── Subroutine.java │ └── Value.java └── util ├── ASMifiable.java ├── ASMifier.java ├── CheckAnnotationAdapter.java ├── CheckClassAdapter.java ├── CheckFieldAdapter.java ├── CheckMethodAdapter.java ├── CheckSignatureAdapter.java ├── Printer.java ├── Textifiable.java ├── Textifier.java ├── TraceAnnotationVisitor.java ├── TraceClassVisitor.java ├── TraceFieldVisitor.java ├── TraceMethodVisitor.java └── TraceSignatureVisitor.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | DashO String Deobfuscator 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.8 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.8 12 | -------------------------------------------------------------------------------- /bin/.gitignore: -------------------------------------------------------------------------------- 1 | /me/ 2 | /org/ 3 | -------------------------------------------------------------------------------- /src/me/lpk/Main.java: -------------------------------------------------------------------------------- 1 | package me.lpk; 2 | 3 | import java.io.File; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.objectweb.asm.tree.ClassNode; 8 | 9 | import me.lpk.antis.AntiBase; 10 | import me.lpk.antis.impl.*; 11 | import me.lpk.log.Logger; 12 | import me.lpk.mapping.MappedClass; 13 | import me.lpk.mapping.MappingProcessor; 14 | import me.lpk.util.JarUtils; 15 | import me.lpk.util.Setup; 16 | 17 | public class Main { 18 | 19 | public static void main(String[] args) { 20 | try { 21 | runAnti(new File("ZKMNew.jar")); 22 | } catch (Exception e) { 23 | e.printStackTrace(); 24 | } 25 | } 26 | 27 | private static void runAnti(File jar) throws Exception { 28 | Setup.setBypassSetup(); 29 | Setup lsm = Setup.get(jar.getAbsolutePath(), true); 30 | for (String className : lsm.getNodes().keySet()) { 31 | AntiBase anti = new AntiZKM8(jar); 32 | ClassNode node = lsm.getNodes().get(className); 33 | lsm.getNodes().put(className, anti.scan(node)); 34 | } 35 | Map out = MappingProcessor.process(lsm.getNodes(), new HashMap(), true); 36 | out.putAll(JarUtils.loadNonClassEntries(jar)); 37 | Logger.logLow("Saving..."); 38 | JarUtils.saveAsJar(out, jar.getName() + "-re.jar"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/me/lpk/analysis/StackUtil.java: -------------------------------------------------------------------------------- 1 | package me.lpk.analysis; 2 | 3 | import org.objectweb.asm.tree.MethodNode; 4 | import org.objectweb.asm.tree.analysis.AnalyzerException; 5 | 6 | public class StackUtil { 7 | 8 | public static StackFrame[] getFrames(MethodNode mn) { 9 | InsnAnalyzer a = new InsnAnalyzer(new StackHelper()); 10 | StackFrame[] sfs = null; 11 | try { 12 | sfs = a.analyze(mn.owner, mn); 13 | } catch (AnalyzerException e) { 14 | //e.printStackTrace(); 15 | } 16 | return sfs; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/me/lpk/antis/AntiBase.java: -------------------------------------------------------------------------------- 1 | package me.lpk.antis; 2 | 3 | import java.util.Map; 4 | 5 | import org.objectweb.asm.tree.ClassNode; 6 | 7 | public abstract class AntiBase { 8 | private final Map nodes; 9 | 10 | public AntiBase(Map nodes) { 11 | this.nodes = nodes; 12 | } 13 | 14 | public abstract ClassNode scan(ClassNode node); 15 | 16 | protected final Map getNodes() { 17 | return nodes; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/me/lpk/antis/impl/AntiAllatori.java: -------------------------------------------------------------------------------- 1 | package me.lpk.antis.impl; 2 | 3 | import java.util.Map; 4 | 5 | import org.objectweb.asm.Opcodes; 6 | import org.objectweb.asm.tree.AbstractInsnNode; 7 | import org.objectweb.asm.tree.ClassNode; 8 | import org.objectweb.asm.tree.JumpInsnNode; 9 | import org.objectweb.asm.tree.LdcInsnNode; 10 | import org.objectweb.asm.tree.MethodInsnNode; 11 | import org.objectweb.asm.tree.MethodNode; 12 | 13 | import me.lpk.analysis.Sandbox; 14 | import me.lpk.antis.AntiBase; 15 | import me.lpk.util.AntiSynthetic; 16 | import me.lpk.util.OpUtils; 17 | 18 | public class AntiAllatori extends AntiBase { 19 | private final boolean callProxy; 20 | 21 | public AntiAllatori(Map nodes, boolean callProxy) { 22 | super(nodes); 23 | this.callProxy = callProxy; 24 | } 25 | 26 | @Override 27 | public ClassNode scan(ClassNode node) { 28 | for (MethodNode mnode : node.methods) { 29 | replace(mnode); 30 | } 31 | return node; 32 | } 33 | 34 | private void replace(MethodNode method) { 35 | if(!method.name.startsWith("access")) { 36 | try { 37 | method.access = AntiSynthetic.inverseSynthetic(method.access); 38 | } catch (Exception e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | AbstractInsnNode ain = method.instructions.getFirst(); 43 | L1: 44 | while (ain != null && ain.getNext() != null) { 45 | if(ain.getOpcode() == Opcodes.ICONST_0 || ain.getOpcode() == Opcodes.ICONST_1) { 46 | boolean eq = ain.getOpcode() == Opcodes.ICONST_0; 47 | if(ain.getNext().getOpcode() == Opcodes.IFEQ || ain.getNext().getOpcode() == Opcodes.IFNE) { 48 | boolean ifeq = ain.getNext().getOpcode() == Opcodes.IFEQ; 49 | if(eq != ifeq) { 50 | //never invoked 51 | method.instructions.remove(ain.getNext()); 52 | method.instructions.remove(ain); 53 | } else { 54 | method.instructions.set(ain.getNext(), new JumpInsnNode(Opcodes.GOTO, ((JumpInsnNode)ain.getNext()).label)); 55 | } 56 | } 57 | } 58 | AbstractInsnNode nod = ain.getNext(); 59 | if(ain.getType() == AbstractInsnNode.LDC_INSN) { 60 | while(nod == null || nod.getType() == AbstractInsnNode.LABEL || nod.getType() == AbstractInsnNode.FRAME) { 61 | if(nod == null) { 62 | ain = ain.getNext(); 63 | continue L1; 64 | } 65 | nod = nod.getNext(); 66 | } 67 | if(nod.getOpcode() != Opcodes.INVOKESTATIC) { 68 | ain = ain.getNext(); 69 | continue; 70 | } 71 | } else { 72 | ain = ain.getNext(); 73 | continue; 74 | } 75 | MethodInsnNode min = (MethodInsnNode) nod; 76 | if (!min.desc.endsWith("(Ljava/lang/String;)Ljava/lang/String;")) { 77 | ain = ain.getNext(); 78 | continue; 79 | } 80 | ClassNode owner = getNodes().get(min.owner); 81 | if (owner == null) { 82 | ain = ain.getNext(); 83 | continue; 84 | } 85 | LdcInsnNode ldc = (LdcInsnNode) ain; 86 | Object o = ldc.cst; 87 | if (o instanceof String) { 88 | Object ret = callProxy ? Sandbox.getProxyIsolatedReturn(method, owner, min, new Object[] { o }) : Sandbox.getIsolatedReturn(owner, min, new Object[] { o }); 89 | if (ret != null) { 90 | int index = OpUtils.getIndex(ain); 91 | LdcInsnNode newLdc = new LdcInsnNode(ret); 92 | method.instructions.remove(min); 93 | method.instructions.set(ldc, newLdc); 94 | ain = method.instructions.get(index).getNext(); 95 | } else { 96 | ain = ain.getNext(); 97 | } 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/me/lpk/gui/ErrorDialog.java: -------------------------------------------------------------------------------- 1 | package me.lpk.gui; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Dimension; 5 | import java.awt.Font; 6 | 7 | import javax.swing.JDialog; 8 | import javax.swing.JLabel; 9 | import javax.swing.JTextArea; 10 | 11 | public class ErrorDialog extends JDialog { 12 | private static final long serialVersionUID = 1L; 13 | private final JLabel title; 14 | private final JTextArea data = new JTextArea(""); 15 | 16 | public ErrorDialog() { 17 | title = new JLabel("", JLabel.CENTER); 18 | title.setFont(new Font(title.getFont().getName(), Font.BOLD, 22)); 19 | data.setBackground(title.getBackground()); 20 | data.setEditable(false); 21 | setLayout(new BorderLayout()); 22 | add(title, BorderLayout.NORTH); 23 | add(data, BorderLayout.CENTER); 24 | setPreferredSize(new Dimension(600, 500)); 25 | setMinimumSize(getPreferredSize()); 26 | } 27 | 28 | public void setTitlee(String txt) { 29 | title.setText(txt); 30 | } 31 | 32 | public void setData(String txt) { 33 | data.setText(txt); 34 | } 35 | 36 | public static void show(Exception e) { 37 | ErrorDialog dialog = new ErrorDialog(); 38 | dialog.setTitle("Error"); 39 | dialog.setTitlee(e.getClass().getSimpleName()); 40 | String pre = ""; 41 | if (e.getMessage() != null){ 42 | pre = e.getMessage() + "\n---------------------------------\n"; 43 | } 44 | dialog.setData(pre + getLoc(e)); 45 | dialog.setVisible(true); 46 | } 47 | 48 | private static String getLoc(Exception e) { 49 | String s = e.getStackTrace()[0] + "\n"; 50 | for (int i = 1; i < e.getStackTrace().length; i++){ 51 | s += " " + e.getStackTrace()[i] + "\n"; 52 | } 53 | return s; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/me/lpk/gui/drop/IDropUser.java: -------------------------------------------------------------------------------- 1 | package me.lpk.gui.drop; 2 | 3 | import java.io.File; 4 | 5 | public interface IDropUser { 6 | public void preLoadJars(int id ); 7 | public void onJarLoad(int id, File input); 8 | } 9 | -------------------------------------------------------------------------------- /src/me/lpk/gui/drop/JarDropHandler.java: -------------------------------------------------------------------------------- 1 | package me.lpk.gui.drop; 2 | 3 | import java.awt.datatransfer.DataFlavor; 4 | import java.awt.datatransfer.Transferable; 5 | import java.io.File; 6 | import java.util.List; 7 | 8 | import javax.swing.TransferHandler; 9 | 10 | public class JarDropHandler extends TransferHandler { 11 | private static final long serialVersionUID = 1232L; 12 | private final IDropUser user; 13 | private final int id; 14 | public JarDropHandler(IDropUser user, int id){ 15 | this.user = user; 16 | this.id = id; 17 | } 18 | 19 | @Override 20 | public boolean canImport(TransferHandler.TransferSupport info) { 21 | return info.isDataFlavorSupported(DataFlavor.javaFileListFlavor); 22 | } 23 | 24 | @SuppressWarnings("unchecked") 25 | @Override 26 | public boolean importData(TransferHandler.TransferSupport info) { 27 | if (!info.isDrop()) 28 | return false; 29 | Transferable t = info.getTransferable(); 30 | List data = null; 31 | try { 32 | data = (List) t.getTransferData(DataFlavor.javaFileListFlavor); 33 | } catch (Exception e) { 34 | return false; 35 | } 36 | user.preLoadJars(id); 37 | for (File jar : data) { 38 | if (jar.getName().toLowerCase().endsWith(".jar")) { 39 | user.onJarLoad(id, jar); 40 | } 41 | } 42 | return true; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/me/lpk/log/Logger.java: -------------------------------------------------------------------------------- 1 | package me.lpk.log; 2 | 3 | /** 4 | * Too lazy to setup Log4J. Made this instead. 5 | */ 6 | public class Logger { 7 | public static final int VERY_HIGH = 0, HIGH = 1, MEDIUM = 2, LOW = 3; 8 | private static int level = HIGH; 9 | 10 | public static void logVeryHigh(String s) { 11 | log(s, VERY_HIGH); 12 | } 13 | 14 | public static void logHigh(String s) { 15 | log(s, HIGH); 16 | } 17 | 18 | public static void logMedium(String s) { 19 | log(s, MEDIUM); 20 | } 21 | 22 | public static void logLow(String s) { 23 | log(s, LOW); 24 | } 25 | 26 | public static void errVeryHigh(String s) { 27 | err(s, VERY_HIGH); 28 | } 29 | 30 | public static void errHigh(String s) { 31 | err(s, HIGH); 32 | } 33 | 34 | public static void errMedium(String s) { 35 | err(s, MEDIUM); 36 | } 37 | 38 | public static void errLow(String s) { 39 | err(s, LOW); 40 | } 41 | 42 | private static void log(String s, int i) { 43 | if (i >= level) { 44 | System.out.println(s); 45 | } 46 | } 47 | 48 | private static void err(String s, int i) { 49 | if (i >= level) { 50 | System.err.println(s); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/me/lpk/mapping/MappedObject.java: -------------------------------------------------------------------------------- 1 | package me.lpk.mapping; 2 | 3 | class MappedObject { 4 | private final String nameOriginal; 5 | private String desc, nameNew; 6 | private boolean isRenamedOverride, isLibrary; 7 | 8 | public MappedObject(String desc, String nameOriginal, String nameNew) { 9 | this.desc = desc; 10 | this.nameOriginal = nameOriginal; 11 | this.nameNew = nameNew; 12 | } 13 | 14 | /** 15 | * Returns the bytecode description of the object. 16 | * 17 | * @return 18 | */ 19 | public String getDesc() { 20 | return desc; 21 | } 22 | 23 | /** 24 | * Returns the original name of the object. 25 | * 26 | * @return 27 | */ 28 | public String getOriginalName() { 29 | return nameOriginal; 30 | } 31 | 32 | /** 33 | * Returns the new name of the object. 34 | * 35 | * @return 36 | */ 37 | public String getNewName() { 38 | return nameNew; 39 | } 40 | 41 | /** 42 | * Updates the new name. 43 | * 44 | * @param nameNew 45 | */ 46 | public void setNewName(String nameNew) { 47 | if (isLibrary){ 48 | return; 49 | } 50 | this.nameNew = nameNew; 51 | } 52 | 53 | /** 54 | * Updates the new desc. 55 | */ 56 | public void setDesc(String desc) { 57 | this.desc = desc; 58 | } 59 | 60 | /** 61 | * Returns if the object has been renamed. 62 | * 63 | * @return 64 | */ 65 | public boolean isRenamed() { 66 | return isTruelyRenamed() || isRenamedOverride; 67 | } 68 | 69 | public boolean isTruelyRenamed() { 70 | return !nameOriginal.equals(nameNew) || isLibrary; 71 | } 72 | 73 | /** 74 | * Sets the override for isRenamed(). 75 | * 76 | * @param isRenamedOverride 77 | */ 78 | public void setRenamedOverride(boolean isRenamedOverride) { 79 | this.isRenamedOverride = isRenamedOverride; 80 | } 81 | 82 | /** 83 | * Returns true if the Mapped object is considered to be a library object. 84 | * Library objects are not to be modified. 85 | * 86 | * @return 87 | */ 88 | public boolean isLibrary() { 89 | return isLibrary; 90 | } 91 | 92 | /** 93 | * Sets isLibrary. See {@link #isLibrary()} for details. 94 | * 95 | * @param isLibrary 96 | */ 97 | public void setIsLibrary(boolean isLibrary) { 98 | this.isLibrary = isLibrary; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/me/lpk/mapping/MappingClassWriter.java: -------------------------------------------------------------------------------- 1 | package me.lpk.mapping; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.objectweb.asm.ClassWriter; 7 | 8 | import me.lpk.util.ParentUtils; 9 | 10 | /** 11 | * A ClassWriter that works off of MappedClasses. Does not require classes being 12 | * loaded into the JVM like a standard ClassWriter. 13 | */ 14 | public class MappingClassWriter extends ClassWriter { 15 | private final Map mappings; 16 | private final Map mappingsInv = new HashMap(); 17 | 18 | public MappingClassWriter(Map mappings, int i) { 19 | super(i); 20 | this.mappings = mappings; 21 | for (MappedClass mc : mappings.values()) { 22 | mappingsInv.put(mc.getNewName(), mc); 23 | } 24 | } 25 | 26 | @Override 27 | protected String getCommonSuperClass(final String type1, final String type2) { 28 | MappedClass mc1 = mappings.getOrDefault(type1, mappingsInv.get(type1)); 29 | MappedClass mc2 = mappings.getOrDefault(type2, mappingsInv.get(type2)); 30 | if (mc1 == null || mc2 == null) { 31 | return "java/lang/Object"; 32 | } 33 | MappedClass common = ParentUtils.findCommonParent(mc1, mc2); 34 | if (common == null) { 35 | return "java/lang/Object"; 36 | } 37 | return common.getOriginalName(); 38 | } 39 | } -------------------------------------------------------------------------------- /src/me/lpk/mapping/MappingProcessor.java: -------------------------------------------------------------------------------- 1 | package me.lpk.mapping; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.objectweb.asm.ClassVisitor; 7 | import org.objectweb.asm.ClassWriter; 8 | import org.objectweb.asm.commons.ClassRemapper; 9 | import org.objectweb.asm.tree.ClassNode; 10 | 11 | public class MappingProcessor { 12 | 13 | /** 14 | * Given a map of ClassNodes and mappings, returns a map of class names to 15 | * class bytes. 16 | * 17 | * @param nodes 18 | * @param mappings 19 | * @return 20 | */ 21 | public static Map process(Map nodes, Map mappings, boolean useMaxs) { 22 | Map out = new HashMap(); 23 | SkidRemapper mapper = new SkidRemapper(mappings); 24 | try { 25 | for (ClassNode cn : nodes.values()) { 26 | ClassWriter cw = new MappingClassWriter(mappings, useMaxs ? ClassWriter.COMPUTE_MAXS : ClassWriter.COMPUTE_FRAMES); 27 | ClassVisitor remapper = new ClassRemapper(cw, mapper); 28 | cn.accept(remapper); 29 | out.put(mappings.containsKey(cn.name) ? mappings.get(cn.name).getNewName() : cn.name, cw.toByteArray()); 30 | } 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | } 34 | return out; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/me/lpk/mapping/loaders/MappingLoader.java: -------------------------------------------------------------------------------- 1 | package me.lpk.mapping.loaders; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileReader; 6 | import java.util.Map; 7 | 8 | import org.objectweb.asm.tree.ClassNode; 9 | 10 | import me.lpk.mapping.MappedClass; 11 | 12 | public abstract class MappingLoader { 13 | protected final Map nodes; 14 | 15 | /** 16 | * Instantiates the loader with a map of classnodes to be mapped. 17 | * 18 | * @param nodes 19 | */ 20 | public MappingLoader(Map nodes) { 21 | this.nodes = nodes; 22 | } 23 | 24 | public abstract Map read(FileReader in); 25 | 26 | public abstract Map read(BufferedReader fileReader) throws Exception; 27 | 28 | public abstract void save(Map mappings, File file); 29 | 30 | /** 31 | * Creates a fake node containing only a name attribute. 32 | * 33 | * @param name 34 | * @return 35 | */ 36 | protected ClassNode fakeNode(String name) { 37 | ClassNode cn = new ClassNode(); 38 | cn.name = name; 39 | return cn; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/me/lpk/mapping/remap/MappingMode.java: -------------------------------------------------------------------------------- 1 | package me.lpk.mapping.remap; 2 | 3 | import me.lpk.mapping.MappedClass; 4 | import me.lpk.mapping.MappedMember; 5 | 6 | public abstract class MappingMode { 7 | /** 8 | * Creates a new name for a given class 9 | * 10 | * @param cn 11 | * @return 12 | */ 13 | public abstract String getClassName(MappedClass cn); 14 | 15 | /** 16 | * Creates a new name for a given method 17 | * 18 | * @param mn 19 | * @return 20 | */ 21 | public abstract String getMethodName(MappedMember mn); 22 | 23 | /** 24 | * Creates a new name for a given field 25 | * 26 | * @param fn 27 | * @return 28 | */ 29 | public abstract String getFieldName(MappedMember fn); 30 | } -------------------------------------------------------------------------------- /src/me/lpk/mapping/remap/impl/ModeNone.java: -------------------------------------------------------------------------------- 1 | package me.lpk.mapping.remap.impl; 2 | 3 | import me.lpk.mapping.MappedClass; 4 | import me.lpk.mapping.MappedMember; 5 | import me.lpk.mapping.remap.MappingMode; 6 | 7 | public class ModeNone extends MappingMode { 8 | @Override 9 | public String getClassName(MappedClass cn) { 10 | return cn.getOriginalName(); 11 | } 12 | 13 | @Override 14 | public String getMethodName(MappedMember mn) { 15 | return mn.getOriginalName(); 16 | } 17 | 18 | @Override 19 | public String getFieldName(MappedMember fn) { 20 | return fn.getOriginalName(); 21 | } 22 | } -------------------------------------------------------------------------------- /src/me/lpk/mapping/remap/impl/ModeRandom.java: -------------------------------------------------------------------------------- 1 | package me.lpk.mapping.remap.impl; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import me.lpk.mapping.MappedClass; 7 | import me.lpk.mapping.MappedMember; 8 | import me.lpk.mapping.remap.MappingMode; 9 | import me.lpk.util.Characters; 10 | 11 | public class ModeRandom extends MappingMode { 12 | private Set used = new HashSet(); 13 | private int len; 14 | 15 | public ModeRandom(int len) { 16 | this.len = len; 17 | } 18 | 19 | @Override 20 | public String getClassName(MappedClass cn) { 21 | return randName(); 22 | } 23 | 24 | @Override 25 | public String getMethodName(MappedMember mn) { 26 | return randName(); 27 | } 28 | 29 | @Override 30 | public String getFieldName(MappedMember fn) { 31 | return randName(); 32 | } 33 | 34 | private String randName() { 35 | StringBuilder sb = new StringBuilder(); 36 | while (len > sb.length() || used.contains(sb.toString())) { 37 | int randIndex = (int) (Math.random() * Characters.ALPHABET_BOTH.length); 38 | sb.append(Characters.ALPHABET_BOTH[randIndex]); 39 | } 40 | used.add(sb.toString()); 41 | return sb.toString(); 42 | } 43 | } -------------------------------------------------------------------------------- /src/me/lpk/mapping/remap/impl/ModeSimple.java: -------------------------------------------------------------------------------- 1 | package me.lpk.mapping.remap.impl; 2 | 3 | import org.objectweb.asm.tree.MethodNode; 4 | 5 | import me.lpk.mapping.MappedClass; 6 | import me.lpk.mapping.MappedMember; 7 | import me.lpk.mapping.remap.MappingMode; 8 | 9 | public class ModeSimple extends MappingMode { 10 | private int classIndex, methodIndex, fieldIndex; 11 | 12 | @Override 13 | public String getClassName(MappedClass cn) { 14 | for (MethodNode mn : cn.getNode().methods) { 15 | if (mn.name.equals("main") && mn.desc.equals("([Ljava/lang/String;)V")) { 16 | return cn.getOriginalName(); 17 | } 18 | } 19 | return "Class" + classIndex++; 20 | } 21 | 22 | @Override 23 | public String getMethodName(MappedMember mn) { 24 | switch (mn.getDesc()) { 25 | case "([Ljava/lang/String;)V": 26 | if (mn.getOriginalName().equals("main")) { 27 | return "main"; 28 | } else { 29 | break; 30 | } 31 | case "()I": 32 | return "getInt" + methodIndex++; 33 | case "()J": 34 | return "getLong" + methodIndex++; 35 | case "()Z": 36 | return "getBoolean" + methodIndex++; 37 | case "()Ljava/lang/String": 38 | return "getString" + methodIndex++; 39 | case "()Ljava.util.Set;": 40 | case "()Ljava.util.HashSet;": 41 | return "getSet" + methodIndex++; 42 | case "()Ljava.util.List;": 43 | case "()Ljava.util.ArrayList;": 44 | return "getList" + methodIndex++; 45 | case "()Ljava.util.Map;": 46 | case "()Ljava.util.HashMap;": 47 | return "getMap" + methodIndex++; 48 | case "Ljava/lang/Class;": 49 | return "getClass" + methodIndex++; 50 | case "()F": 51 | return "getFloat" + methodIndex++; 52 | case "()D": 53 | return "getDouble" + methodIndex++; 54 | } 55 | return "method" + methodIndex++; 56 | } 57 | 58 | @Override 59 | public String getFieldName(MappedMember fn) { 60 | switch (fn.getDesc()) { 61 | case "I": 62 | return "int" + fieldIndex++; 63 | case "C": 64 | return "char" + fieldIndex++; 65 | case "J": 66 | return "long" + fieldIndex++; 67 | case "F": 68 | return "float" + fieldIndex++; 69 | case "D": 70 | return "double" + fieldIndex++; 71 | case "Z": 72 | return "boolean" + fieldIndex++; 73 | case "Ljava/lang/String;": 74 | return "string" + fieldIndex++; 75 | case "Ljava/util/Collection;": 76 | return "collection" + fieldIndex++; 77 | case "Ljava/util/Set;": 78 | case "Ljava/util/HashSet;": 79 | case "Ljava/util/LinkedHashSet;": 80 | return "set" + fieldIndex++; 81 | case "Ljava/util/List;": 82 | case "Ljava/util/ArrayList;": 83 | case "Ljava/util/LinkedList;": 84 | return "list" + fieldIndex++; 85 | case "Ljava/util/Map;": 86 | case "Ljava/util/HashMap;": 87 | case "Ljava/util/LinkedHashMap;": 88 | return "map" + fieldIndex++; 89 | case "Ljava/lang/Class;": 90 | return "class" + fieldIndex++; 91 | } 92 | if (fn.getDesc().startsWith("[")) { 93 | return "array" + fieldIndex++; 94 | } 95 | return "field" + fieldIndex++; 96 | } 97 | } -------------------------------------------------------------------------------- /src/me/lpk/mapping/remap/impl/ModeUnicodeEvil.java: -------------------------------------------------------------------------------- 1 | package me.lpk.mapping.remap.impl; 2 | import java.util.HashSet; 3 | import java.util.Set; 4 | 5 | import me.lpk.mapping.MappedClass; 6 | import me.lpk.mapping.MappedMember; 7 | import me.lpk.mapping.remap.MappingMode; 8 | import me.lpk.util.Characters; 9 | 10 | public class ModeUnicodeEvil extends MappingMode { 11 | public static final int UNICODE_MAX_LENGTH = 166; 12 | private Set used = new HashSet(); 13 | 14 | @Override 15 | public String getClassName(MappedClass cn) { 16 | return randName(); 17 | } 18 | 19 | @Override 20 | public String getMethodName(MappedMember mn) { 21 | return randName(); 22 | } 23 | 24 | @Override 25 | public String getFieldName(MappedMember fn) { 26 | return randName(); 27 | } 28 | 29 | private String randName() { 30 | StringBuilder sb = new StringBuilder(); 31 | while (sb.length() < UNICODE_MAX_LENGTH || used.contains(sb.toString())) { 32 | int randIndex = (int) (Math.random() * Characters.UNICODE.length); 33 | sb.append(Characters.UNICODE[randIndex]); 34 | } 35 | used.add(sb.toString()); 36 | return sb.toString(); 37 | } 38 | } -------------------------------------------------------------------------------- /src/me/lpk/util/AntiSynthetic.java: -------------------------------------------------------------------------------- 1 | package me.lpk.util; 2 | 3 | 4 | import java.lang.reflect.Field; 5 | 6 | import org.objectweb.asm.Opcodes; 7 | 8 | public class AntiSynthetic implements Opcodes { 9 | public static int inverseSynthetic(int access) throws Exception { 10 | int i = 0; 11 | for (Field f : Opcodes.class.getFields()) { 12 | if (f.getName().startsWith("ACC_") && !f.getName().equals("ACC_SYNTHETIC")) { 13 | int accval = (int) f.get(null); 14 | if(hasAccess(access, accval)) { 15 | i |= accval; 16 | } 17 | } 18 | } 19 | return i; 20 | } 21 | 22 | private static boolean hasAccess(int mod, int access) { 23 | return (mod & access) != 0; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/me/lpk/util/Characters.java: -------------------------------------------------------------------------------- 1 | package me.lpk.util; 2 | import java.util.ArrayList; 3 | import java.util.List; 4 | 5 | public class Characters { 6 | public static final String[] ALPHABET_BOTH = { "A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h", "I", "i", "J", "j", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", "P", "p", "Q", "q", "R", "r", "S", "s", "T", "t", "U", "u", "V", "v", "W", "w", "X", "x", "Y", "y", "Z", "z" }; 7 | public static final String[] ALPHABET_UPPER = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", }; 8 | public static final String[] ALPHABET_LOWER = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", }; 9 | // Aside from normal english text, unicode begins at 160 10 | public static final String[] UNICODE = genUnicode(1000, 9000); 11 | 12 | private static String[] genUnicode(int min, int max) { 13 | List list = new ArrayList(); 14 | for (int i = min; i < max; i++) { 15 | char c = (char) i; 16 | list.add(String.valueOf(c)); 17 | } 18 | return list.toArray(new String[list.size()]); 19 | } 20 | } -------------------------------------------------------------------------------- /src/me/lpk/util/Classpather.java: -------------------------------------------------------------------------------- 1 | package me.lpk.util; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.lang.reflect.Method; 6 | import java.net.URL; 7 | import java.net.URLClassLoader; 8 | 9 | /** 10 | * Adds jar files to the classpath. 11 | */ 12 | public class Classpather { 13 | private static final Class[] parameters = new Class[] { URL.class }; 14 | 15 | /** 16 | * Add a file to the classpath. 17 | * 18 | * @param s 19 | * @throws IOException 20 | */ 21 | public static void addFile(String s) throws IOException { 22 | File f = new File(s); 23 | addFile(f); 24 | } 25 | 26 | /** 27 | * Add a file to the classpath. 28 | * 29 | * @param s 30 | * @throws IOException 31 | */ 32 | @SuppressWarnings("deprecation") 33 | public static void addFile(File f) throws IOException { 34 | addURL(f.toURL()); 35 | } 36 | 37 | private static void addURL(URL u) throws IOException { 38 | URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader(); 39 | Class sysclass = URLClassLoader.class; 40 | try { 41 | Method method = sysclass.getDeclaredMethod("addURL", parameters); 42 | method.setAccessible(true); 43 | method.invoke(sysloader, new Object[] { u }); 44 | } catch (Throwable t) { 45 | t.printStackTrace(); 46 | throw new IOException("Error, could not add URL to system classloader"); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/me/lpk/util/InjectedClassLoader.java: -------------------------------------------------------------------------------- 1 | package me.lpk.util; 2 | 3 | import java.net.URL; 4 | import java.net.URLClassLoader; 5 | import java.util.HashMap; 6 | 7 | import org.objectweb.asm.ClassWriter; 8 | import org.objectweb.asm.tree.ClassNode; 9 | 10 | import me.lpk.analysis.Sandbox; 11 | 12 | public class InjectedClassLoader extends URLClassLoader { 13 | public static final HashMap extraClassDefs = new HashMap(); 14 | public static final HashMap nodes = new HashMap(); 15 | 16 | public InjectedClassLoader(URL[] urls, ClassLoader parent) { 17 | super(urls, parent); 18 | } 19 | 20 | @Override 21 | protected Class findClass(String name) throws ClassNotFoundException { 22 | try { 23 | ClassNode cn = nodes.get(name); 24 | if (cn != null) { 25 | ClassWriter cw = new ClassWriter(0); 26 | cn.accept(new Sandbox.VisitorImpl(cw)); 27 | byte[] b = cw.toByteArray(); 28 | return defineClass(cn.name, b, 0, b.length); 29 | } 30 | } catch (Throwable e) { 31 | try { 32 | return super.findClass(name); 33 | } catch (ClassNotFoundException e1) { 34 | e1.printStackTrace(); 35 | } 36 | } 37 | return null; 38 | } 39 | 40 | @Override 41 | public Class loadClass(String s) { 42 | try { 43 | ClassNode cn = nodes.get(s); 44 | if (cn != null) { 45 | ClassWriter cw = new ClassWriter(0); 46 | cn.accept(new Sandbox.VisitorImpl(cw)); 47 | byte[] b = cw.toByteArray(); 48 | return defineClass(cn.name, b, 0, b.length); 49 | } 50 | } catch (Throwable e) { 51 | try { 52 | return super.loadClass(s); 53 | } catch (ClassNotFoundException e1) { 54 | e1.printStackTrace(); 55 | } 56 | } 57 | return null; 58 | } 59 | } -------------------------------------------------------------------------------- /src/me/lpk/util/JarClassLoader.java: -------------------------------------------------------------------------------- 1 | package me.lpk.util; 2 | 3 | import java.io.File; 4 | import java.io.InputStream; 5 | import java.net.MalformedURLException; 6 | import java.net.URL; 7 | import java.net.URLClassLoader; 8 | 9 | public class JarClassLoader extends URLClassLoader { 10 | 11 | public JarClassLoader(String... jar) throws MalformedURLException { 12 | super(getURLArr(jar)); 13 | } 14 | 15 | @Override 16 | public InputStream getResourceAsStream(String name) { 17 | return super.getResourceAsStream(name); 18 | } 19 | private static URL[] getURLArr(String[] jar) throws MalformedURLException { 20 | URL[] arr = new URL[jar.length]; 21 | for (int i = 0; i < jar.length; i++) { 22 | arr[i] = new File(jar[i]).toURI().toURL(); 23 | } 24 | return arr; 25 | } 26 | } -------------------------------------------------------------------------------- /src/me/lpk/util/Reference.java: -------------------------------------------------------------------------------- 1 | package me.lpk.util; 2 | 3 | import org.objectweb.asm.tree.AbstractInsnNode; 4 | import org.objectweb.asm.tree.ClassNode; 5 | import org.objectweb.asm.tree.MethodNode; 6 | 7 | public class Reference { 8 | private final ClassNode node; 9 | private final MethodNode method; 10 | private final AbstractInsnNode ain; 11 | 12 | public Reference(ClassNode node, MethodNode method, AbstractInsnNode ain) { 13 | this.node = node; 14 | this.method = method; 15 | this.ain = ain; 16 | } 17 | 18 | public ClassNode getNode() { 19 | return node; 20 | } 21 | 22 | public MethodNode getMethod() { 23 | return method; 24 | } 25 | 26 | public AbstractInsnNode getAin() { 27 | return ain; 28 | } 29 | } -------------------------------------------------------------------------------- /src/me/lpk/util/RegexUtils.java: -------------------------------------------------------------------------------- 1 | package me.lpk.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.regex.Matcher; 6 | import java.util.regex.Pattern; 7 | 8 | public class RegexUtils { 9 | /** 10 | * Returns a list of all class matches in a description. 11 | * 12 | * @param desc 13 | * @return 14 | */ 15 | public static List matchDescriptionClasses(String desc) { 16 | String pattern = "(?<=L).*?(?=[<;(])"; 17 | Pattern pat = Pattern.compile(pattern); 18 | Matcher m = pat.matcher(desc); 19 | List matches = new ArrayList(); 20 | while (m.find()) { 21 | matches.add(m.group()); 22 | } 23 | return matches; 24 | } 25 | 26 | /** 27 | * Returns a list of all numbers found in a given string. 28 | * 29 | * @param text 30 | * @return 31 | */ 32 | public static List matchNumbers(String text) { 33 | String pattern = "\\d+[0-9]+"; 34 | Pattern pat = Pattern.compile(pattern); 35 | Matcher m = pat.matcher(text); 36 | List matches = new ArrayList(); 37 | while (m.find()) { 38 | matches.add(m.group()); 39 | } 40 | return matches; 41 | } 42 | 43 | /** 44 | * Returns true if text matches a given pattern. 45 | * 46 | * @param pattern 47 | * @param text 48 | * @return 49 | */ 50 | public static boolean isMatch(String pattern, String text) { 51 | Pattern pat = Pattern.compile(pattern); 52 | Matcher m = pat.matcher(text); 53 | while (m.find()) { 54 | return true; 55 | } 56 | return false; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/me/lpk/util/SwingUtils.java: -------------------------------------------------------------------------------- 1 | package me.lpk.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | import javax.swing.tree.DefaultMutableTreeNode; 8 | 9 | public class SwingUtils { 10 | /** 11 | * Method by Adrian: [ 12 | * StackOverflow ] 13 | * & Mike: [ 15 | * StackOverflow ] 16 | * 17 | * @param node 18 | * @return 19 | */ 20 | @SuppressWarnings("unchecked") 21 | public static DefaultMutableTreeNode sort(DefaultMutableTreeNode node) { 22 | List children = Collections.list(node.children()); 23 | List orgCnames = new ArrayList(); 24 | List cNames = new ArrayList(); 25 | DefaultMutableTreeNode temParent = new DefaultMutableTreeNode(); 26 | for (DefaultMutableTreeNode child : children) { 27 | DefaultMutableTreeNode ch = (DefaultMutableTreeNode) child; 28 | temParent.insert(ch, 0); 29 | String uppser = ch.toString().toUpperCase(); 30 | // Not dependent on package name, so if duplicates are found 31 | // they will later on be confused. Adding this is of 32 | // very little consequence and fixes the issue. 33 | if (cNames.contains(uppser)){ 34 | uppser += "$COPY"; 35 | } 36 | cNames.add(uppser); 37 | orgCnames.add(uppser); 38 | if (!child.isLeaf()) { 39 | sort(child); 40 | } 41 | } 42 | Collections.sort(cNames); 43 | for (String name : cNames) { 44 | int indx = orgCnames.indexOf(name); 45 | int insertIndex = node.getChildCount(); 46 | node.insert(children.get(indx), insertIndex); 47 | } 48 | // Fixing folder placement 49 | for (int i = 0; i < node.getChildCount() - 1; i++) { 50 | DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i); 51 | for (int j = i + 1; j <= node.getChildCount() - 1; j++) { 52 | DefaultMutableTreeNode prevNode = (DefaultMutableTreeNode) node.getChildAt(j); 53 | if (!prevNode.isLeaf() && child.isLeaf()) { 54 | node.insert(child, j); 55 | node.insert(prevNode, i); 56 | } 57 | } 58 | } 59 | return node; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/me/lpk/util/Timer.java: -------------------------------------------------------------------------------- 1 | package me.lpk.util; 2 | 3 | import me.lpk.log.Logger; 4 | 5 | public class Timer { 6 | final long init; 7 | long then, now; 8 | 9 | public Timer() { 10 | init = System.currentTimeMillis(); 11 | then = System.currentTimeMillis(); 12 | } 13 | 14 | public void log(String s) { 15 | now = System.currentTimeMillis(); 16 | Logger.logLow(s + (now - then)); 17 | then = now; 18 | } 19 | 20 | public void logTotal(String s) { 21 | now = System.currentTimeMillis(); 22 | Logger.logLow(s + (now - init)); 23 | then = now; 24 | } 25 | } -------------------------------------------------------------------------------- /src/me/nov/dashostrings/DashODeobf.java: -------------------------------------------------------------------------------- 1 | package me.nov.dashostrings; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.Map; 6 | 7 | import org.objectweb.asm.ClassWriter; 8 | import org.objectweb.asm.tree.ClassNode; 9 | 10 | import me.lpk.util.JarUtils; 11 | 12 | public class DashODeobf { 13 | 14 | public static void main(String[] args) throws IOException { 15 | File input = new File("input.jar"); 16 | Map classes = JarUtils.loadClasses(input); 17 | Map out = JarUtils.loadNonClassEntries(input); 18 | 19 | Deobfuscation de = new Deobfuscation(classes); 20 | de.start(); 21 | 22 | if (de.isSuccess()) { 23 | for (ClassNode cn : classes.values()) { 24 | ClassWriter cw = new ClassWriter(0); 25 | cn.accept(cw); 26 | out.put(cn.name, cw.toByteArray()); 27 | } 28 | JarUtils.saveAsJar(out, "output.jar"); 29 | } else { 30 | System.err.println("Finished without success."); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/me/nov/dashostrings/utils/DashOUtils.java: -------------------------------------------------------------------------------- 1 | package me.nov.dashostrings.utils; 2 | 3 | import java.util.Map; 4 | 5 | import org.objectweb.asm.Opcodes; 6 | import org.objectweb.asm.tree.AbstractInsnNode; 7 | import org.objectweb.asm.tree.ClassNode; 8 | import org.objectweb.asm.tree.InsnList; 9 | import org.objectweb.asm.tree.InsnNode; 10 | import org.objectweb.asm.tree.MethodInsnNode; 11 | import org.objectweb.asm.tree.MethodNode; 12 | 13 | import me.lpk.util.OpUtils; 14 | 15 | public class DashOUtils implements Opcodes { 16 | 17 | private static MethodNode cloneMethod(MethodNode mn) { 18 | MethodNode mn2 = new MethodNode(mn.access, mn.name, mn.desc, null, null); // construct 19 | mn2.instructions = MethodUtils.clone(mn.instructions, null); 20 | mn2.localVariables = null; 21 | mn2.maxLocals = mn.maxLocals; 22 | mn2.maxStack = mn.maxStack; 23 | return mn2; 24 | } 25 | 26 | public static ClassNode generateInvocation(Map classes, MethodInsnNode orig, InsnList insn) { 27 | for(AbstractInsnNode ain : insn.toArray()) { 28 | if(ain.getOpcode() == INVOKESTATIC) { 29 | MethodInsnNode min = (MethodInsnNode) ain; 30 | min.owner = "dasho_obfuscated"; 31 | } 32 | } 33 | //add return 34 | insn.add(new InsnNode(ARETURN)); 35 | ClassNode decryptNode = new ClassNode(); 36 | decryptNode.name = "dasho_obfuscated"; 37 | decryptNode.superName = "java/lang/Object"; 38 | decryptNode.version = 49; 39 | decryptNode.access = 1; 40 | MethodNode decrypt = new MethodNode(ACC_PUBLIC | ACC_STATIC, "decrypt_dasho", "()Ljava/lang/String;", null, null); // construct 41 | decrypt.instructions = insn; 42 | decrypt.localVariables = null; 43 | decrypt.maxLocals = 3; 44 | decrypt.maxStack = 3; 45 | decryptNode.methods.add(decrypt); 46 | decryptNode.methods.add(cloneMethod(MethodUtils.getMethod(classes.get(orig.owner), orig.name, orig.desc))); 47 | return decryptNode; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/me/nov/dashostrings/utils/InstructionUtils.java: -------------------------------------------------------------------------------- 1 | package me.nov.dashostrings.utils; 2 | 3 | import org.objectweb.asm.Opcodes; 4 | import org.objectweb.asm.tree.AbstractInsnNode; 5 | import org.objectweb.asm.tree.InsnNode; 6 | import org.objectweb.asm.tree.IntInsnNode; 7 | import org.objectweb.asm.tree.LdcInsnNode; 8 | 9 | public class InstructionUtils implements Opcodes { 10 | 11 | public static boolean isNumber(AbstractInsnNode ain) { 12 | if (ain.getOpcode() == BIPUSH || ain.getOpcode() == SIPUSH) { 13 | return true; 14 | } 15 | if (ain.getOpcode() >= ICONST_M1 && ain.getOpcode() <= ICONST_5) { 16 | return true; 17 | } 18 | if (ain instanceof LdcInsnNode) { 19 | LdcInsnNode ldc = (LdcInsnNode) ain; 20 | if (ldc.cst instanceof Number) { 21 | return true; 22 | } 23 | } 24 | return false; 25 | } 26 | 27 | public static AbstractInsnNode generateIntPush(int i) { 28 | if (i <= 5 && i >= -1) { 29 | return new InsnNode(i + 3); //iconst_i 30 | } 31 | if (i >= -128 && i <= 127) { 32 | return new IntInsnNode(BIPUSH, i); 33 | } 34 | 35 | if (i >= -32768 && i <= 32767) { 36 | return new IntInsnNode(SIPUSH, i); 37 | } 38 | return new LdcInsnNode(i); 39 | } 40 | 41 | public static int getIntValue(AbstractInsnNode node) { 42 | if (node.getOpcode() >= ICONST_M1 && node.getOpcode() <= ICONST_5) { 43 | return node.getOpcode() - 3; 44 | } 45 | if (node.getOpcode() == SIPUSH || node.getOpcode() == BIPUSH) { 46 | return ((IntInsnNode) node).operand; 47 | } 48 | if(node instanceof LdcInsnNode) { 49 | LdcInsnNode ldc = (LdcInsnNode) node; 50 | return Integer.parseInt(ldc.cst.toString()); 51 | } 52 | return 0; 53 | } 54 | 55 | public static String getStringValue(AbstractInsnNode node) { 56 | if (node.getType() == AbstractInsnNode.LDC_INSN) { 57 | LdcInsnNode ldc = (LdcInsnNode) node; 58 | return ldc.cst.toString(); 59 | } 60 | return ""; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/FileExistsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | 22 | /** 23 | * Indicates that a file already exists. 24 | * 25 | * @version $Id: FileExistsException.java 1304052 2012-03-22 20:55:29Z ggregory $ 26 | * @since 2.0 27 | */ 28 | public class FileExistsException extends IOException { 29 | 30 | /** 31 | * Defines the serial version UID. 32 | */ 33 | private static final long serialVersionUID = 1L; 34 | 35 | /** 36 | * Default Constructor. 37 | */ 38 | public FileExistsException() { 39 | super(); 40 | } 41 | 42 | /** 43 | * Construct an instance with the specified message. 44 | * 45 | * @param message The error message 46 | */ 47 | public FileExistsException(String message) { 48 | super(message); 49 | } 50 | 51 | /** 52 | * Construct an instance with the specified file. 53 | * 54 | * @param file The file that exists 55 | */ 56 | public FileExistsException(File file) { 57 | super("File " + file + " exists"); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/IOExceptionWithCause.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.io; 19 | 20 | import java.io.IOException; 21 | 22 | /** 23 | * Subclasses IOException with the {@link Throwable} constructors missing before Java 6. If you are using Java 6, 24 | * consider this class deprecated and use {@link IOException}. 25 | * 26 | * @version $Id: IOExceptionWithCause.java 1307459 2012-03-30 15:11:44Z ggregory $ 27 | * @since 1.4 28 | */ 29 | public class IOExceptionWithCause extends IOException { 30 | 31 | /** 32 | * Defines the serial version UID. 33 | */ 34 | private static final long serialVersionUID = 1L; 35 | 36 | /** 37 | * Constructs a new instance with the given message and cause. 38 | *

39 | * As specified in {@link Throwable}, the message in the given cause is not used in this instance's 40 | * message. 41 | *

42 | * 43 | * @param message 44 | * the message (see {@link #getMessage()}) 45 | * @param cause 46 | * the cause (see {@link #getCause()}). A {@code null} value is allowed. 47 | */ 48 | public IOExceptionWithCause(String message, Throwable cause) { 49 | super(message); 50 | this.initCause(cause); 51 | } 52 | 53 | /** 54 | * Constructs a new instance with the given cause. 55 | *

56 | * The message is set to cause==null ? null : cause.toString(), which by default contains the class 57 | * and message of cause. This constructor is useful for call sites that just wrap another throwable. 58 | *

59 | * 60 | * @param cause 61 | * the cause (see {@link #getCause()}). A {@code null} value is allowed. 62 | */ 63 | public IOExceptionWithCause(Throwable cause) { 64 | super(cause == null ? null : cause.toString()); 65 | this.initCause(cause); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/comparator/AbstractFileComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.comparator; 18 | 19 | import java.io.File; 20 | import java.util.Arrays; 21 | import java.util.Collections; 22 | import java.util.Comparator; 23 | import java.util.List; 24 | 25 | /** 26 | * Abstract file {@link Comparator} which provides sorting for file arrays and lists. 27 | * 28 | * @version $Id: AbstractFileComparator.java 1304052 2012-03-22 20:55:29Z ggregory $ 29 | * @since 2.0 30 | */ 31 | abstract class AbstractFileComparator implements Comparator { 32 | 33 | /** 34 | * Sort an array of files. 35 | *

36 | * This method uses {@link Arrays#sort(Object[], Comparator)} 37 | * and returns the original array. 38 | * 39 | * @param files The files to sort, may be null 40 | * @return The sorted array 41 | * @since 2.0 42 | */ 43 | public File[] sort(File... files) { 44 | if (files != null) { 45 | Arrays.sort(files, this); 46 | } 47 | return files; 48 | } 49 | 50 | /** 51 | * Sort a List of files. 52 | *

53 | * This method uses {@link Collections#sort(List, Comparator)} 54 | * and returns the original list. 55 | * 56 | * @param files The files to sort, may be null 57 | * @return The sorted list 58 | * @since 2.0 59 | */ 60 | public List sort(List files) { 61 | if (files != null) { 62 | Collections.sort(files, this); 63 | } 64 | return files; 65 | } 66 | 67 | /** 68 | * String representation of this file comparator. 69 | * 70 | * @return String representation of this file comparator 71 | */ 72 | @Override 73 | public String toString() { 74 | return getClass().getSimpleName(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/comparator/DefaultFileComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.comparator; 18 | 19 | import java.io.File; 20 | import java.io.Serializable; 21 | import java.util.Comparator; 22 | 23 | /** 24 | * Compare two files using the default {@link File#compareTo(File)} method. 25 | *

26 | * This comparator can be used to sort lists or arrays of files 27 | * by using the default file comparison. 28 | *

29 | * Example of sorting a list of files using the 30 | * {@link #DEFAULT_COMPARATOR} singleton instance: 31 | *

32 |  *       List<File> list = ...
33 |  *       DefaultFileComparator.DEFAULT_COMPARATOR.sort(list);
34 |  * 
35 | *

36 | * Example of doing a reverse sort of an array of files using the 37 | * {@link #DEFAULT_REVERSE} singleton instance: 38 | *

39 |  *       File[] array = ...
40 |  *       DefaultFileComparator.DEFAULT_REVERSE.sort(array);
41 |  * 
42 | *

43 | * 44 | * @version $Id: DefaultFileComparator.java 1304052 2012-03-22 20:55:29Z ggregory $ 45 | * @since 1.4 46 | */ 47 | public class DefaultFileComparator extends AbstractFileComparator implements Serializable { 48 | private static final long serialVersionUID = 1L; 49 | /** Singleton default comparator instance */ 50 | public static final Comparator DEFAULT_COMPARATOR = new DefaultFileComparator(); 51 | 52 | /** Singleton reverse default comparator instance */ 53 | public static final Comparator DEFAULT_REVERSE = new ReverseComparator(DEFAULT_COMPARATOR); 54 | 55 | /** 56 | * Compare the two files using the {@link File#compareTo(File)} method. 57 | * 58 | * @param file1 The first file to compare 59 | * @param file2 The second file to compare 60 | * @return the result of calling file1's 61 | * {@link File#compareTo(File)} with file2 as the parameter. 62 | */ 63 | public int compare(File file1, File file2) { 64 | return file1.compareTo(file2); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/comparator/DirectoryFileComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.comparator; 18 | 19 | import java.io.File; 20 | import java.io.Serializable; 21 | import java.util.Comparator; 22 | 23 | /** 24 | * Compare two files using the {@link File#isDirectory()} method. 25 | *

26 | * This comparator can be used to sort lists or arrays by directories and files. 27 | *

28 | * Example of sorting a list of files/directories using the 29 | * {@link #DIRECTORY_COMPARATOR} singleton instance: 30 | *

31 |  *       List<File> list = ...
32 |  *       DirectoryFileComparator.DIRECTORY_COMPARATOR.sort(list);
33 |  * 
34 | *

35 | * Example of doing a reverse sort of an array of files/directories using the 36 | * {@link #DIRECTORY_REVERSE} singleton instance: 37 | *

38 |  *       File[] array = ...
39 |  *       DirectoryFileComparator.DIRECTORY_REVERSE.sort(array);
40 |  * 
41 | *

42 | * 43 | * @version $Id: DirectoryFileComparator.java 1304052 2012-03-22 20:55:29Z ggregory $ 44 | * @since 2.0 45 | */ 46 | public class DirectoryFileComparator extends AbstractFileComparator implements Serializable { 47 | private static final long serialVersionUID = 1L; 48 | /** Singleton default comparator instance */ 49 | public static final Comparator DIRECTORY_COMPARATOR = new DirectoryFileComparator(); 50 | 51 | /** Singleton reverse default comparator instance */ 52 | public static final Comparator DIRECTORY_REVERSE = new ReverseComparator(DIRECTORY_COMPARATOR); 53 | 54 | /** 55 | * Compare the two files using the {@link File#isDirectory()} method. 56 | * 57 | * @param file1 The first file to compare 58 | * @param file2 The second file to compare 59 | * @return the result of calling file1's 60 | * {@link File#compareTo(File)} with file2 as the parameter. 61 | */ 62 | public int compare(File file1, File file2) { 63 | return getType(file1) - getType(file2); 64 | } 65 | 66 | /** 67 | * Convert type to numeric value. 68 | * 69 | * @param file The file 70 | * @return 1 for directories and 2 for files 71 | */ 72 | private int getType(File file) { 73 | if (file.isDirectory()) { 74 | return 1; 75 | } else { 76 | return 2; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/comparator/LastModifiedFileComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.comparator; 18 | 19 | import java.io.File; 20 | import java.io.Serializable; 21 | import java.util.Comparator; 22 | 23 | /** 24 | * Compare the last modified date/time of two files for order 25 | * (see {@link File#lastModified()}). 26 | *

27 | * This comparator can be used to sort lists or arrays of files 28 | * by their last modified date/time. 29 | *

30 | * Example of sorting a list of files using the 31 | * {@link #LASTMODIFIED_COMPARATOR} singleton instance: 32 | *

33 |  *       List<File> list = ...
34 |  *       LastModifiedFileComparator.LASTMODIFIED_COMPARATOR.sort(list);
35 |  * 
36 | *

37 | * Example of doing a reverse sort of an array of files using the 38 | * {@link #LASTMODIFIED_REVERSE} singleton instance: 39 | *

40 |  *       File[] array = ...
41 |  *       LastModifiedFileComparator.LASTMODIFIED_REVERSE.sort(array);
42 |  * 
43 | *

44 | * 45 | * @version $Id: LastModifiedFileComparator.java 1304052 2012-03-22 20:55:29Z ggregory $ 46 | * @since 1.4 47 | */ 48 | public class LastModifiedFileComparator extends AbstractFileComparator implements Serializable { 49 | private static final long serialVersionUID = 1L; 50 | /** Last modified comparator instance */ 51 | public static final Comparator LASTMODIFIED_COMPARATOR = new LastModifiedFileComparator(); 52 | 53 | /** Reverse last modified comparator instance */ 54 | public static final Comparator LASTMODIFIED_REVERSE = new ReverseComparator(LASTMODIFIED_COMPARATOR); 55 | 56 | /** 57 | * Compare the last the last modified date/time of two files. 58 | * 59 | * @param file1 The first file to compare 60 | * @param file2 The second file to compare 61 | * @return a negative value if the first file's lastmodified date/time 62 | * is less than the second, zero if the lastmodified date/time are the 63 | * same and a positive value if the first files lastmodified date/time 64 | * is greater than the second file. 65 | * 66 | */ 67 | public int compare(File file1, File file2) { 68 | long result = file1.lastModified() - file2.lastModified(); 69 | if (result < 0) { 70 | return -1; 71 | } else if (result > 0) { 72 | return 1; 73 | } else { 74 | return 0; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/comparator/ReverseComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.comparator; 18 | 19 | import java.io.File; 20 | import java.io.Serializable; 21 | import java.util.Comparator; 22 | 23 | /** 24 | * Reverses the result of comparing two objects using 25 | * the delegate {@link Comparator}. 26 | * 27 | * @version $Id: ReverseComparator.java 1304052 2012-03-22 20:55:29Z ggregory $ 28 | * @since 1.4 29 | */ 30 | class ReverseComparator extends AbstractFileComparator implements Serializable { 31 | private static final long serialVersionUID = 1L; 32 | private final Comparator delegate; 33 | 34 | /** 35 | * Construct an instance with the sepecified delegate {@link Comparator}. 36 | * 37 | * @param delegate The comparator to delegate to 38 | */ 39 | public ReverseComparator(Comparator delegate) { 40 | if (delegate == null) { 41 | throw new IllegalArgumentException("Delegate comparator is missing"); 42 | } 43 | this.delegate = delegate; 44 | } 45 | 46 | /** 47 | * Compare using the delegate Comparator, but reversing the result. 48 | * 49 | * @param file1 The first file to compare 50 | * @param file2 The second file to compare 51 | * @return the result from the delegate {@link Comparator#compare(Object, Object)} 52 | * reversing the value (i.e. positive becomes negative and vice versa) 53 | */ 54 | public int compare(File file1, File file2) { 55 | return delegate.compare(file2, file1); // parameters switched round 56 | } 57 | 58 | /** 59 | * String representation of this file comparator. 60 | * 61 | * @return String representation of this file comparator 62 | */ 63 | @Override 64 | public String toString() { 65 | return super.toString() + "[" + delegate.toString() + "]"; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/filefilter/AbstractFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.filefilter; 18 | 19 | import java.io.File; 20 | 21 | /** 22 | * An abstract class which implements the Java FileFilter and FilenameFilter 23 | * interfaces via the IOFileFilter interface. 24 | *

25 | * Note that a subclass must override one of the accept methods, 26 | * otherwise your class will infinitely loop. 27 | * 28 | * @since 1.0 29 | * @version $Id: AbstractFileFilter.java 1304052 2012-03-22 20:55:29Z ggregory $ 30 | */ 31 | public abstract class AbstractFileFilter implements IOFileFilter { 32 | 33 | /** 34 | * Checks to see if the File should be accepted by this filter. 35 | * 36 | * @param file the File to check 37 | * @return true if this file matches the test 38 | */ 39 | public boolean accept(File file) { 40 | return accept(file.getParentFile(), file.getName()); 41 | } 42 | 43 | /** 44 | * Checks to see if the File should be accepted by this filter. 45 | * 46 | * @param dir the directory File to check 47 | * @param name the filename within the directory to check 48 | * @return true if this file matches the test 49 | */ 50 | public boolean accept(File dir, String name) { 51 | return accept(new File(dir, name)); 52 | } 53 | 54 | /** 55 | * Provide a String representaion of this file filter. 56 | * 57 | * @return a String representaion 58 | */ 59 | @Override 60 | public String toString() { 61 | return getClass().getSimpleName(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/filefilter/CanReadFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.filefilter; 18 | 19 | import java.io.File; 20 | import java.io.Serializable; 21 | 22 | /** 23 | * This filter accepts Files that can be read. 24 | *

25 | * Example, showing how to print out a list of the 26 | * current directory's readable files: 27 | * 28 | *

29 |  * File dir = new File(".");
30 |  * String[] files = dir.list( CanReadFileFilter.CAN_READ );
31 |  * for ( int i = 0; i < files.length; i++ ) {
32 |  *     System.out.println(files[i]);
33 |  * }
34 |  * 
35 | * 36 | *

37 | * Example, showing how to print out a list of the 38 | * current directory's un-readable files: 39 | * 40 | *

41 |  * File dir = new File(".");
42 |  * String[] files = dir.list( CanReadFileFilter.CANNOT_READ );
43 |  * for ( int i = 0; i < files.length; i++ ) {
44 |  *     System.out.println(files[i]);
45 |  * }
46 |  * 
47 | * 48 | *

49 | * Example, showing how to print out a list of the 50 | * current directory's read-only files: 51 | * 52 | *

53 |  * File dir = new File(".");
54 |  * String[] files = dir.list( CanReadFileFilter.READ_ONLY );
55 |  * for ( int i = 0; i < files.length; i++ ) {
56 |  *     System.out.println(files[i]);
57 |  * }
58 |  * 
59 | * 60 | * @since 1.3 61 | * @version $Id: CanReadFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $ 62 | */ 63 | public class CanReadFileFilter extends AbstractFileFilter implements Serializable { 64 | private static final long serialVersionUID = 1L; 65 | /** Singleton instance of readable filter */ 66 | public static final IOFileFilter CAN_READ = new CanReadFileFilter(); 67 | 68 | /** Singleton instance of not readable filter */ 69 | public static final IOFileFilter CANNOT_READ = new NotFileFilter(CAN_READ); 70 | 71 | /** Singleton instance of read-only filter */ 72 | public static final IOFileFilter READ_ONLY = new AndFileFilter(CAN_READ, 73 | CanWriteFileFilter.CANNOT_WRITE); 74 | 75 | /** 76 | * Restrictive consructor. 77 | */ 78 | protected CanReadFileFilter() { 79 | } 80 | 81 | /** 82 | * Checks to see if the file can be read. 83 | * 84 | * @param file the File to check. 85 | * @return {@code true} if the file can be 86 | * read, otherwise {@code false}. 87 | */ 88 | @Override 89 | public boolean accept(File file) { 90 | return file.canRead(); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/filefilter/CanWriteFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.filefilter; 18 | 19 | import java.io.File; 20 | import java.io.Serializable; 21 | 22 | /** 23 | * This filter accepts Files that can be written to. 24 | *

25 | * Example, showing how to print out a list of the 26 | * current directory's writable files: 27 | * 28 | *

29 |  * File dir = new File(".");
30 |  * String[] files = dir.list( CanWriteFileFilter.CAN_WRITE );
31 |  * for ( int i = 0; i < files.length; i++ ) {
32 |  *     System.out.println(files[i]);
33 |  * }
34 |  * 
35 | * 36 | *

37 | * Example, showing how to print out a list of the 38 | * current directory's un-writable files: 39 | * 40 | *

41 |  * File dir = new File(".");
42 |  * String[] files = dir.list( CanWriteFileFilter.CANNOT_WRITE );
43 |  * for ( int i = 0; i < files.length; i++ ) {
44 |  *     System.out.println(files[i]);
45 |  * }
46 |  * 
47 | * 48 | *

49 | * N.B. For read-only files, use 50 | * CanReadFileFilter.READ_ONLY. 51 | * 52 | * @since 1.3 53 | * @version $Id: CanWriteFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $ 54 | */ 55 | public class CanWriteFileFilter extends AbstractFileFilter implements Serializable { 56 | private static final long serialVersionUID = 1L; 57 | /** Singleton instance of writable filter */ 58 | public static final IOFileFilter CAN_WRITE = new CanWriteFileFilter(); 59 | 60 | /** Singleton instance of not writable filter */ 61 | public static final IOFileFilter CANNOT_WRITE = new NotFileFilter(CAN_WRITE); 62 | 63 | /** 64 | * Restrictive consructor. 65 | */ 66 | protected CanWriteFileFilter() { 67 | } 68 | 69 | /** 70 | * Checks to see if the file can be written to. 71 | * 72 | * @param file the File to check 73 | * @return {@code true} if the file can be 74 | * written to, otherwise {@code false}. 75 | */ 76 | @Override 77 | public boolean accept(File file) { 78 | return file.canWrite(); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/filefilter/ConditionalFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.filefilter; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * Defines operations for conditional file filters. 23 | * 24 | * @since 1.1 25 | * @version $Id: ConditionalFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $ 26 | */ 27 | public interface ConditionalFileFilter { 28 | 29 | /** 30 | * Adds the specified file filter to the list of file filters at the end of 31 | * the list. 32 | * 33 | * @param ioFileFilter the filter to be added 34 | * @since 1.1 35 | */ 36 | void addFileFilter(IOFileFilter ioFileFilter); 37 | 38 | /** 39 | * Returns this conditional file filter's list of file filters. 40 | * 41 | * @return the file filter list 42 | * @since 1.1 43 | */ 44 | List getFileFilters(); 45 | 46 | /** 47 | * Removes the specified file filter. 48 | * 49 | * @param ioFileFilter filter to be removed 50 | * @return {@code true} if the filter was found in the list, 51 | * {@code false} otherwise 52 | * @since 1.1 53 | */ 54 | boolean removeFileFilter(IOFileFilter ioFileFilter); 55 | 56 | /** 57 | * Sets the list of file filters, replacing any previously configured 58 | * file filters on this filter. 59 | * 60 | * @param fileFilters the list of filters 61 | * @since 1.1 62 | */ 63 | void setFileFilters(List fileFilters); 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/filefilter/DelegateFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.filefilter; 18 | 19 | import java.io.File; 20 | import java.io.FileFilter; 21 | import java.io.FilenameFilter; 22 | import java.io.Serializable; 23 | 24 | /** 25 | * This class turns a Java FileFilter or FilenameFilter into an IO FileFilter. 26 | * 27 | * @since 1.0 28 | * @version $Id: DelegateFileFilter.java 1304052 2012-03-22 20:55:29Z ggregory $ 29 | * 30 | * @see FileFilterUtils#asFileFilter(FileFilter) 31 | * @see FileFilterUtils#asFileFilter(FilenameFilter) 32 | */ 33 | public class DelegateFileFilter extends AbstractFileFilter implements Serializable { 34 | private static final long serialVersionUID = 1L; 35 | /** The Filename filter */ 36 | private final FilenameFilter filenameFilter; 37 | /** The File filter */ 38 | private final FileFilter fileFilter; 39 | 40 | /** 41 | * Constructs a delegate file filter around an existing FilenameFilter. 42 | * 43 | * @param filter the filter to decorate 44 | */ 45 | public DelegateFileFilter(FilenameFilter filter) { 46 | if (filter == null) { 47 | throw new IllegalArgumentException("The FilenameFilter must not be null"); 48 | } 49 | this.filenameFilter = filter; 50 | this.fileFilter = null; 51 | } 52 | 53 | /** 54 | * Constructs a delegate file filter around an existing FileFilter. 55 | * 56 | * @param filter the filter to decorate 57 | */ 58 | public DelegateFileFilter(FileFilter filter) { 59 | if (filter == null) { 60 | throw new IllegalArgumentException("The FileFilter must not be null"); 61 | } 62 | this.fileFilter = filter; 63 | this.filenameFilter = null; 64 | } 65 | 66 | /** 67 | * Checks the filter. 68 | * 69 | * @param file the file to check 70 | * @return true if the filter matches 71 | */ 72 | @Override 73 | public boolean accept(File file) { 74 | if (fileFilter != null) { 75 | return fileFilter.accept(file); 76 | } else { 77 | return super.accept(file); 78 | } 79 | } 80 | 81 | /** 82 | * Checks the filter. 83 | * 84 | * @param dir the directory 85 | * @param name the filename in the directory 86 | * @return true if the filter matches 87 | */ 88 | @Override 89 | public boolean accept(File dir, String name) { 90 | if (filenameFilter != null) { 91 | return filenameFilter.accept(dir, name); 92 | } else { 93 | return super.accept(dir, name); 94 | } 95 | } 96 | 97 | /** 98 | * Provide a String representaion of this file filter. 99 | * 100 | * @return a String representaion 101 | */ 102 | @Override 103 | public String toString() { 104 | String delegate = fileFilter != null ? fileFilter.toString() : filenameFilter.toString(); 105 | return super.toString() + "(" + delegate + ")"; 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/filefilter/DirectoryFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.filefilter; 18 | 19 | import java.io.File; 20 | import java.io.Serializable; 21 | 22 | /** 23 | * This filter accepts Files that are directories. 24 | *

25 | * For example, here is how to print out a list of the 26 | * current directory's subdirectories: 27 | * 28 | *

29 |  * File dir = new File(".");
30 |  * String[] files = dir.list( DirectoryFileFilter.INSTANCE );
31 |  * for ( int i = 0; i < files.length; i++ ) {
32 |  *     System.out.println(files[i]);
33 |  * }
34 |  * 
35 | * 36 | * @since 1.0 37 | * @version $Id: DirectoryFileFilter.java 1304052 2012-03-22 20:55:29Z ggregory $ 38 | * 39 | * @see FileFilterUtils#directoryFileFilter() 40 | */ 41 | public class DirectoryFileFilter extends AbstractFileFilter implements Serializable { 42 | private static final long serialVersionUID = 1L; 43 | /** 44 | * Singleton instance of directory filter. 45 | * @since 1.3 46 | */ 47 | public static final IOFileFilter DIRECTORY = new DirectoryFileFilter(); 48 | /** 49 | * Singleton instance of directory filter. 50 | * Please use the identical DirectoryFileFilter.DIRECTORY constant. 51 | * The new name is more JDK 1.5 friendly as it doesn't clash with other 52 | * values when using static imports. 53 | */ 54 | public static final IOFileFilter INSTANCE = DIRECTORY; 55 | 56 | /** 57 | * Restrictive consructor. 58 | */ 59 | protected DirectoryFileFilter() { 60 | } 61 | 62 | /** 63 | * Checks to see if the file is a directory. 64 | * 65 | * @param file the File to check 66 | * @return true if the file is a directory 67 | */ 68 | @Override 69 | public boolean accept(File file) { 70 | return file.isDirectory(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/filefilter/EmptyFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.filefilter; 18 | 19 | import java.io.File; 20 | import java.io.Serializable; 21 | 22 | /** 23 | * This filter accepts files or directories that are empty. 24 | *

25 | * If the File is a directory it checks that 26 | * it contains no files. 27 | *

28 | * Example, showing how to print out a list of the 29 | * current directory's empty files/directories: 30 | * 31 | *

32 |  * File dir = new File(".");
33 |  * String[] files = dir.list( EmptyFileFilter.EMPTY );
34 |  * for ( int i = 0; i < files.length; i++ ) {
35 |  *     System.out.println(files[i]);
36 |  * }
37 |  * 
38 | * 39 | *

40 | * Example, showing how to print out a list of the 41 | * current directory's non-empty files/directories: 42 | * 43 | *

44 |  * File dir = new File(".");
45 |  * String[] files = dir.list( EmptyFileFilter.NOT_EMPTY );
46 |  * for ( int i = 0; i < files.length; i++ ) {
47 |  *     System.out.println(files[i]);
48 |  * }
49 |  * 
50 | * 51 | * @since 1.3 52 | * @version $Id: EmptyFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $ 53 | */ 54 | public class EmptyFileFilter extends AbstractFileFilter implements Serializable { 55 | private static final long serialVersionUID = 1L; 56 | /** Singleton instance of empty filter */ 57 | public static final IOFileFilter EMPTY = new EmptyFileFilter(); 58 | 59 | /** Singleton instance of not-empty filter */ 60 | public static final IOFileFilter NOT_EMPTY = new NotFileFilter(EMPTY); 61 | 62 | /** 63 | * Restrictive consructor. 64 | */ 65 | protected EmptyFileFilter() { 66 | } 67 | 68 | /** 69 | * Checks to see if the file is empty. 70 | * 71 | * @param file the file or directory to check 72 | * @return {@code true} if the file or directory 73 | * is empty, otherwise {@code false}. 74 | */ 75 | @Override 76 | public boolean accept(File file) { 77 | if (file.isDirectory()) { 78 | File[] files = file.listFiles(); 79 | return files == null || files.length == 0; 80 | } else { 81 | return file.length() == 0; 82 | } 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/filefilter/FalseFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.filefilter; 18 | 19 | import java.io.File; 20 | import java.io.Serializable; 21 | 22 | /** 23 | * A file filter that always returns false. 24 | * 25 | * @since 1.0 26 | * @version $Id: FalseFileFilter.java 1304058 2012-03-22 21:02:43Z sebb $ 27 | * 28 | * @see FileFilterUtils#falseFileFilter() 29 | */ 30 | public class FalseFileFilter implements IOFileFilter, Serializable { 31 | private static final long serialVersionUID = 1L; 32 | /** 33 | * Singleton instance of false filter. 34 | * @since 1.3 35 | */ 36 | public static final IOFileFilter FALSE = new FalseFileFilter(); 37 | /** 38 | * Singleton instance of false filter. 39 | * Please use the identical FalseFileFilter.FALSE constant. 40 | * The new name is more JDK 1.5 friendly as it doesn't clash with other 41 | * values when using static imports. 42 | */ 43 | public static final IOFileFilter INSTANCE = FALSE; 44 | 45 | /** 46 | * Restrictive consructor. 47 | */ 48 | protected FalseFileFilter() { 49 | } 50 | 51 | /** 52 | * Returns false. 53 | * 54 | * @param file the file to check (ignored) 55 | * @return false 56 | */ 57 | public boolean accept(File file) { 58 | return false; 59 | } 60 | 61 | /** 62 | * Returns false. 63 | * 64 | * @param dir the directory to check (ignored) 65 | * @param name the filename (ignored) 66 | * @return false 67 | */ 68 | public boolean accept(File dir, String name) { 69 | return false; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/filefilter/FileFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.filefilter; 18 | 19 | import java.io.File; 20 | import java.io.Serializable; 21 | 22 | /** 23 | * This filter accepts Files that are files (not directories). 24 | *

25 | * For example, here is how to print out a list of the real files 26 | * within the current directory: 27 | * 28 | *

29 |  * File dir = new File(".");
30 |  * String[] files = dir.list( FileFileFilter.FILE );
31 |  * for ( int i = 0; i < files.length; i++ ) {
32 |  *     System.out.println(files[i]);
33 |  * }
34 |  * 
35 | * 36 | * @since 1.3 37 | * @version $Id: FileFileFilter.java 1304052 2012-03-22 20:55:29Z ggregory $ 38 | * @see FileFilterUtils#fileFileFilter() 39 | */ 40 | public class FileFileFilter extends AbstractFileFilter implements Serializable { 41 | private static final long serialVersionUID = 1L; 42 | /** Singleton instance of file filter */ 43 | public static final IOFileFilter FILE = new FileFileFilter(); 44 | 45 | /** 46 | * Restrictive consructor. 47 | */ 48 | protected FileFileFilter() { 49 | } 50 | 51 | /** 52 | * Checks to see if the file is a file. 53 | * 54 | * @param file the File to check 55 | * @return true if the file is a file 56 | */ 57 | @Override 58 | public boolean accept(File file) { 59 | return file.isFile(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/filefilter/HiddenFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.filefilter; 18 | 19 | import java.io.File; 20 | import java.io.Serializable; 21 | 22 | /** 23 | * This filter accepts Files that are hidden. 24 | *

25 | * Example, showing how to print out a list of the 26 | * current directory's hidden files: 27 | * 28 | *

29 |  * File dir = new File(".");
30 |  * String[] files = dir.list( HiddenFileFilter.HIDDEN );
31 |  * for ( int i = 0; i < files.length; i++ ) {
32 |  *     System.out.println(files[i]);
33 |  * }
34 |  * 
35 | * 36 | *

37 | * Example, showing how to print out a list of the 38 | * current directory's visible (i.e. not hidden) files: 39 | * 40 | *

41 |  * File dir = new File(".");
42 |  * String[] files = dir.list( HiddenFileFilter.VISIBLE );
43 |  * for ( int i = 0; i < files.length; i++ ) {
44 |  *     System.out.println(files[i]);
45 |  * }
46 |  * 
47 | * 48 | * @since 1.3 49 | * @version $Id: HiddenFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $ 50 | */ 51 | public class HiddenFileFilter extends AbstractFileFilter implements Serializable { 52 | private static final long serialVersionUID = 1L; 53 | /** Singleton instance of hidden filter */ 54 | public static final IOFileFilter HIDDEN = new HiddenFileFilter(); 55 | 56 | /** Singleton instance of visible filter */ 57 | public static final IOFileFilter VISIBLE = new NotFileFilter(HIDDEN); 58 | 59 | /** 60 | * Restrictive consructor. 61 | */ 62 | protected HiddenFileFilter() { 63 | } 64 | 65 | /** 66 | * Checks to see if the file is hidden. 67 | * 68 | * @param file the File to check 69 | * @return {@code true} if the file is 70 | * hidden, otherwise {@code false}. 71 | */ 72 | @Override 73 | public boolean accept(File file) { 74 | return file.isHidden(); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/filefilter/IOFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.filefilter; 18 | 19 | import java.io.File; 20 | import java.io.FileFilter; 21 | import java.io.FilenameFilter; 22 | 23 | /** 24 | * An interface which brings the FileFilter and FilenameFilter 25 | * interfaces together. 26 | * 27 | * @since 1.0 28 | * @version $Id: IOFileFilter.java 1304052 2012-03-22 20:55:29Z ggregory $ 29 | */ 30 | public interface IOFileFilter extends FileFilter, FilenameFilter { 31 | 32 | /** 33 | * Checks to see if the File should be accepted by this filter. 34 | *

35 | * Defined in {@link java.io.FileFilter}. 36 | * 37 | * @param file the File to check 38 | * @return true if this file matches the test 39 | */ 40 | boolean accept(File file); 41 | 42 | /** 43 | * Checks to see if the File should be accepted by this filter. 44 | *

45 | * Defined in {@link java.io.FilenameFilter}. 46 | * 47 | * @param dir the directory File to check 48 | * @param name the filename within the directory to check 49 | * @return true if this file matches the test 50 | */ 51 | boolean accept(File dir, String name); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/filefilter/NotFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.filefilter; 18 | 19 | import java.io.File; 20 | import java.io.Serializable; 21 | 22 | /** 23 | * This filter produces a logical NOT of the filters specified. 24 | * 25 | * @since 1.0 26 | * @version $Id: NotFileFilter.java 1304052 2012-03-22 20:55:29Z ggregory $ 27 | * @see FileFilterUtils#notFileFilter(IOFileFilter) 28 | */ 29 | public class NotFileFilter extends AbstractFileFilter implements Serializable { 30 | private static final long serialVersionUID = 1L; 31 | /** The filter */ 32 | private final IOFileFilter filter; 33 | 34 | /** 35 | * Constructs a new file filter that NOTs the result of another filter. 36 | * 37 | * @param filter the filter, must not be null 38 | * @throws IllegalArgumentException if the filter is null 39 | */ 40 | public NotFileFilter(IOFileFilter filter) { 41 | if (filter == null) { 42 | throw new IllegalArgumentException("The filter must not be null"); 43 | } 44 | this.filter = filter; 45 | } 46 | 47 | /** 48 | * Returns the logical NOT of the underlying filter's return value for the same File. 49 | * 50 | * @param file the File to check 51 | * @return true if the filter returns false 52 | */ 53 | @Override 54 | public boolean accept(File file) { 55 | return ! filter.accept(file); 56 | } 57 | 58 | /** 59 | * Returns the logical NOT of the underlying filter's return value for the same arguments. 60 | * 61 | * @param file the File directory 62 | * @param name the filename 63 | * @return true if the filter returns false 64 | */ 65 | @Override 66 | public boolean accept(File file, String name) { 67 | return ! filter.accept(file, name); 68 | } 69 | 70 | /** 71 | * Provide a String representaion of this file filter. 72 | * 73 | * @return a String representaion 74 | */ 75 | @Override 76 | public String toString() { 77 | return super.toString() + "(" + filter.toString() + ")"; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/filefilter/TrueFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.filefilter; 18 | 19 | import java.io.File; 20 | import java.io.Serializable; 21 | 22 | /** 23 | * A file filter that always returns true. 24 | * 25 | * @since 1.0 26 | * @version $Id: TrueFileFilter.java 1304058 2012-03-22 21:02:43Z sebb $ 27 | * @see FileFilterUtils#trueFileFilter() 28 | */ 29 | public class TrueFileFilter implements IOFileFilter, Serializable { 30 | private static final long serialVersionUID = 1L; 31 | /** 32 | * Singleton instance of true filter. 33 | * @since 1.3 34 | */ 35 | public static final IOFileFilter TRUE = new TrueFileFilter(); 36 | /** 37 | * Singleton instance of true filter. 38 | * Please use the identical TrueFileFilter.TRUE constant. 39 | * The new name is more JDK 1.5 friendly as it doesn't clash with other 40 | * values when using static imports. 41 | */ 42 | public static final IOFileFilter INSTANCE = TRUE; 43 | 44 | /** 45 | * Restrictive consructor. 46 | */ 47 | protected TrueFileFilter() { 48 | } 49 | 50 | /** 51 | * Returns true. 52 | * 53 | * @param file the file to check (ignored) 54 | * @return true 55 | */ 56 | public boolean accept(File file) { 57 | return true; 58 | } 59 | 60 | /** 61 | * Returns true. 62 | * 63 | * @param dir the directory to check (ignored) 64 | * @param name the filename (ignored) 65 | * @return true 66 | */ 67 | public boolean accept(File dir, String name) { 68 | return true; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/input/AutoCloseInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.input; 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | 22 | /** 23 | * Proxy stream that closes and discards the underlying stream as soon as the 24 | * end of input has been reached or when the stream is explicitly closed. 25 | * Not even a reference to the underlying stream is kept after it has been 26 | * closed, so any allocated in-memory buffers can be freed even if the 27 | * client application still keeps a reference to the proxy stream. 28 | *

29 | * This class is typically used to release any resources related to an open 30 | * stream as soon as possible even if the client application (by not explicitly 31 | * closing the stream when no longer needed) or the underlying stream (by not 32 | * releasing resources once the last byte has been read) do not do that. 33 | * 34 | * @version $Id: AutoCloseInputStream.java 1304052 2012-03-22 20:55:29Z ggregory $ 35 | * @since 1.4 36 | */ 37 | public class AutoCloseInputStream extends ProxyInputStream { 38 | 39 | /** 40 | * Creates an automatically closing proxy for the given input stream. 41 | * 42 | * @param in underlying input stream 43 | */ 44 | public AutoCloseInputStream(InputStream in) { 45 | super(in); 46 | } 47 | 48 | /** 49 | * Closes the underlying input stream and replaces the reference to it 50 | * with a {@link ClosedInputStream} instance. 51 | *

52 | * This method is automatically called by the read methods when the end 53 | * of input has been reached. 54 | *

55 | * Note that it is safe to call this method any number of times. The original 56 | * underlying input stream is closed and discarded only once when this 57 | * method is first called. 58 | * 59 | * @throws IOException if the underlying input stream can not be closed 60 | */ 61 | @Override 62 | public void close() throws IOException { 63 | in.close(); 64 | in = new ClosedInputStream(); 65 | } 66 | 67 | /** 68 | * Automatically closes the stream if the end of stream was reached. 69 | * 70 | * @param n number of bytes read, or -1 if no more bytes are available 71 | * @throws IOException if the stream could not be closed 72 | * @since 2.0 73 | */ 74 | @Override 75 | protected void afterRead(int n) throws IOException { 76 | if (n == -1) { 77 | close(); 78 | } 79 | } 80 | 81 | /** 82 | * Ensures that the stream is closed before it gets garbage-collected. 83 | * As mentioned in {@link #close()}, this is a no-op if the stream has 84 | * already been closed. 85 | * @throws Throwable if an error occurs 86 | */ 87 | @Override 88 | protected void finalize() throws Throwable { 89 | close(); 90 | super.finalize(); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/input/BrokenInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.input; 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | 22 | /** 23 | * Broken input stream. This stream always throws an {@link IOException} from 24 | * all the {@link InputStream} methods where the exception is declared. 25 | *

26 | * This class is mostly useful for testing error handling in code that uses an 27 | * input stream. 28 | * 29 | * @since 2.0 30 | */ 31 | public class BrokenInputStream extends InputStream { 32 | 33 | /** 34 | * The exception that is thrown by all methods of this class. 35 | */ 36 | private final IOException exception; 37 | 38 | /** 39 | * Creates a new stream that always throws the given exception. 40 | * 41 | * @param exception the exception to be thrown 42 | */ 43 | public BrokenInputStream(IOException exception) { 44 | this.exception = exception; 45 | } 46 | 47 | /** 48 | * Creates a new stream that always throws an {@link IOException} 49 | */ 50 | public BrokenInputStream() { 51 | this(new IOException("Broken input stream")); 52 | } 53 | 54 | /** 55 | * Throws the configured exception. 56 | * 57 | * @return nothing 58 | * @throws IOException always thrown 59 | */ 60 | @Override 61 | public int read() throws IOException { 62 | throw exception; 63 | } 64 | 65 | /** 66 | * Throws the configured exception. 67 | * 68 | * @return nothing 69 | * @throws IOException always thrown 70 | */ 71 | @Override 72 | public int available() throws IOException { 73 | throw exception; 74 | } 75 | 76 | /** 77 | * Throws the configured exception. 78 | * 79 | * @param n ignored 80 | * @return nothing 81 | * @throws IOException always thrown 82 | */ 83 | @Override 84 | public long skip(long n) throws IOException { 85 | throw exception; 86 | } 87 | 88 | /** 89 | * Throws the configured exception. 90 | * 91 | * @throws IOException always thrown 92 | */ 93 | @Override 94 | public void reset() throws IOException { 95 | throw exception; 96 | } 97 | 98 | /** 99 | * Throws the configured exception. 100 | * 101 | * @throws IOException always thrown 102 | */ 103 | @Override 104 | public void close() throws IOException { 105 | throw exception; 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/input/CloseShieldInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.input; 18 | 19 | import java.io.InputStream; 20 | 21 | /** 22 | * Proxy stream that prevents the underlying input stream from being closed. 23 | *

24 | * This class is typically used in cases where an input stream needs to be 25 | * passed to a component that wants to explicitly close the stream even if 26 | * more input would still be available to other components. 27 | * 28 | * @version $Id: CloseShieldInputStream.java 1304052 2012-03-22 20:55:29Z ggregory $ 29 | * @since 1.4 30 | */ 31 | public class CloseShieldInputStream extends ProxyInputStream { 32 | 33 | /** 34 | * Creates a proxy that shields the given input stream from being 35 | * closed. 36 | * 37 | * @param in underlying input stream 38 | */ 39 | public CloseShieldInputStream(InputStream in) { 40 | super(in); 41 | } 42 | 43 | /** 44 | * Replaces the underlying input stream with a {@link ClosedInputStream} 45 | * sentinel. The original input stream will remain open, but this proxy 46 | * will appear closed. 47 | */ 48 | @Override 49 | public void close() { 50 | in = new ClosedInputStream(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/input/ClosedInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.input; 18 | 19 | import java.io.InputStream; 20 | 21 | /** 22 | * Closed input stream. This stream returns -1 to all attempts to read 23 | * something from the stream. 24 | *

25 | * Typically uses of this class include testing for corner cases in methods 26 | * that accept input streams and acting as a sentinel value instead of a 27 | * {@code null} input stream. 28 | * 29 | * @version $Id: ClosedInputStream.java 1307459 2012-03-30 15:11:44Z ggregory $ 30 | * @since 1.4 31 | */ 32 | public class ClosedInputStream extends InputStream { 33 | 34 | /** 35 | * A singleton. 36 | */ 37 | public static final ClosedInputStream CLOSED_INPUT_STREAM = new ClosedInputStream(); 38 | 39 | /** 40 | * Returns -1 to indicate that the stream is closed. 41 | * 42 | * @return always -1 43 | */ 44 | @Override 45 | public int read() { 46 | return -1; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/input/DemuxInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.input; 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | 22 | /** 23 | * Data written to this stream is forwarded to a stream that has been associated 24 | * with this thread. 25 | * 26 | * @version $Id: DemuxInputStream.java 1302056 2012-03-18 03:03:38Z ggregory $ 27 | */ 28 | public class DemuxInputStream 29 | extends InputStream 30 | { 31 | private final InheritableThreadLocal m_streams = new InheritableThreadLocal(); 32 | 33 | /** 34 | * Bind the specified stream to the current thread. 35 | * 36 | * @param input the stream to bind 37 | * @return the InputStream that was previously active 38 | */ 39 | public InputStream bindStream( InputStream input ) 40 | { 41 | InputStream oldValue = m_streams.get(); 42 | m_streams.set( input ); 43 | return oldValue; 44 | } 45 | 46 | /** 47 | * Closes stream associated with current thread. 48 | * 49 | * @throws IOException if an error occurs 50 | */ 51 | @Override 52 | public void close() 53 | throws IOException 54 | { 55 | InputStream input = m_streams.get(); 56 | if( null != input ) 57 | { 58 | input.close(); 59 | } 60 | } 61 | 62 | /** 63 | * Read byte from stream associated with current thread. 64 | * 65 | * @return the byte read from stream 66 | * @throws IOException if an error occurs 67 | */ 68 | @Override 69 | public int read() 70 | throws IOException 71 | { 72 | InputStream input = m_streams.get(); 73 | if( null != input ) 74 | { 75 | return input.read(); 76 | } 77 | else 78 | { 79 | return -1; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/input/TailerListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.input; 18 | 19 | /** 20 | * Listener for events from a {@link Tailer}. 21 | * 22 | * @version $Id: TailerListener.java 1304052 2012-03-22 20:55:29Z ggregory $ 23 | * @since 2.0 24 | */ 25 | public interface TailerListener { 26 | 27 | /** 28 | * The tailer will call this method during construction, 29 | * giving the listener a method of stopping the tailer. 30 | * @param tailer the tailer. 31 | */ 32 | void init(Tailer tailer); 33 | 34 | /** 35 | * This method is called if the tailed file is not found. 36 | *

37 | * Note: this is called from the tailer thread. 38 | */ 39 | void fileNotFound(); 40 | 41 | /** 42 | * Called if a file rotation is detected. 43 | * 44 | * This method is called before the file is reopened, and fileNotFound may 45 | * be called if the new file has not yet been created. 46 | *

47 | * Note: this is called from the tailer thread. 48 | */ 49 | void fileRotated(); 50 | 51 | /** 52 | * Handles a line from a Tailer. 53 | *

54 | * Note: this is called from the tailer thread. 55 | * @param line the line. 56 | */ 57 | void handle(String line); 58 | 59 | /** 60 | * Handles an Exception . 61 | *

62 | * Note: this is called from the tailer thread. 63 | * @param ex the exception. 64 | */ 65 | void handle(Exception ex); 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/input/TailerListenerAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.input; 18 | 19 | /** 20 | * {@link TailerListener} Adapter. 21 | * 22 | * @version $Id: TailerListenerAdapter.java 1304052 2012-03-22 20:55:29Z ggregory $ 23 | * @since 2.0 24 | */ 25 | public class TailerListenerAdapter implements TailerListener { 26 | 27 | /** 28 | * The tailer will call this method during construction, 29 | * giving the listener a method of stopping the tailer. 30 | * @param tailer the tailer. 31 | */ 32 | public void init(Tailer tailer) { 33 | } 34 | 35 | /** 36 | * This method is called if the tailed file is not found. 37 | */ 38 | public void fileNotFound() { 39 | } 40 | 41 | /** 42 | * Called if a file rotation is detected. 43 | * 44 | * This method is called before the file is reopened, and fileNotFound may 45 | * be called if the new file has not yet been created. 46 | */ 47 | public void fileRotated() { 48 | } 49 | 50 | /** 51 | * Handles a line from a Tailer. 52 | * @param line the line. 53 | */ 54 | public void handle(String line) { 55 | } 56 | 57 | /** 58 | * Handles an Exception . 59 | * @param ex the exception. 60 | */ 61 | public void handle(Exception ex) { 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/monitor/FileAlterationListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.monitor; 18 | import java.io.File; 19 | 20 | /** 21 | * A listener that receives events of file system modifications. 22 | *

23 | * Register {@link FileAlterationListener}s with a {@link FileAlterationObserver}. 24 | * 25 | * @see FileAlterationObserver 26 | * @version $Id: FileAlterationListener.java 1304052 2012-03-22 20:55:29Z ggregory $ 27 | * @since 2.0 28 | */ 29 | public interface FileAlterationListener { 30 | 31 | /** 32 | * File system observer started checking event. 33 | * 34 | * @param observer The file system observer 35 | */ 36 | void onStart(final FileAlterationObserver observer); 37 | 38 | /** 39 | * Directory created Event. 40 | * 41 | * @param directory The directory created 42 | */ 43 | void onDirectoryCreate(final File directory); 44 | 45 | /** 46 | * Directory changed Event. 47 | * 48 | * @param directory The directory changed 49 | */ 50 | void onDirectoryChange(final File directory); 51 | 52 | /** 53 | * Directory deleted Event. 54 | * 55 | * @param directory The directory deleted 56 | */ 57 | void onDirectoryDelete(final File directory); 58 | 59 | /** 60 | * File created Event. 61 | * 62 | * @param file The file created 63 | */ 64 | void onFileCreate(final File file); 65 | 66 | /** 67 | * File changed Event. 68 | * 69 | * @param file The file changed 70 | */ 71 | void onFileChange(final File file); 72 | 73 | /** 74 | * File deleted Event. 75 | * 76 | * @param file The file deleted 77 | */ 78 | void onFileDelete(final File file); 79 | 80 | /** 81 | * File system observer finished checking event. 82 | * 83 | * @param observer The file system observer 84 | */ 85 | void onStop(final FileAlterationObserver observer); 86 | } 87 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/monitor/FileAlterationListenerAdaptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.monitor; 18 | 19 | import java.io.File; 20 | 21 | /** 22 | * Convenience {@link FileAlterationListener} implementation that does nothing. 23 | * 24 | * @see FileAlterationObserver 25 | * @version $Id: FileAlterationListenerAdaptor.java 1304062 2012-03-22 21:10:46Z sebb $ 26 | * @since 2.0 27 | */ 28 | public class FileAlterationListenerAdaptor implements FileAlterationListener { 29 | 30 | /** 31 | * File system observer started checking event. 32 | * 33 | * @param observer The file system observer (ignored) 34 | */ 35 | public void onStart(final FileAlterationObserver observer) { 36 | } 37 | 38 | /** 39 | * Directory created Event. 40 | * 41 | * @param directory The directory created (ignored) 42 | */ 43 | public void onDirectoryCreate(final File directory) { 44 | } 45 | 46 | /** 47 | * Directory changed Event. 48 | * 49 | * @param directory The directory changed (ignored) 50 | */ 51 | public void onDirectoryChange(final File directory) { 52 | } 53 | 54 | /** 55 | * Directory deleted Event. 56 | * 57 | * @param directory The directory deleted (ignored) 58 | */ 59 | public void onDirectoryDelete(final File directory) { 60 | } 61 | 62 | /** 63 | * File created Event. 64 | * 65 | * @param file The file created (ignored) 66 | */ 67 | public void onFileCreate(final File file) { 68 | } 69 | 70 | /** 71 | * File changed Event. 72 | * 73 | * @param file The file changed (ignored) 74 | */ 75 | public void onFileChange(final File file) { 76 | } 77 | 78 | /** 79 | * File deleted Event. 80 | * 81 | * @param file The file deleted (ignored) 82 | */ 83 | public void onFileDelete(final File file) { 84 | } 85 | 86 | /** 87 | * File system observer finished checking event. 88 | * 89 | * @param observer The file system observer (ignored) 90 | */ 91 | public void onStop(final FileAlterationObserver observer) { 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/output/BrokenOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.output; 18 | 19 | import java.io.IOException; 20 | import java.io.OutputStream; 21 | 22 | /** 23 | * Broken output stream. This stream always throws an {@link IOException} from 24 | * all {@link OutputStream} methods. 25 | *

26 | * This class is mostly useful for testing error handling in code that uses an 27 | * output stream. 28 | * 29 | * @since 2.0 30 | */ 31 | public class BrokenOutputStream extends OutputStream { 32 | 33 | /** 34 | * The exception that is thrown by all methods of this class. 35 | */ 36 | private final IOException exception; 37 | 38 | /** 39 | * Creates a new stream that always throws the given exception. 40 | * 41 | * @param exception the exception to be thrown 42 | */ 43 | public BrokenOutputStream(IOException exception) { 44 | this.exception = exception; 45 | } 46 | 47 | /** 48 | * Creates a new stream that always throws an {@link IOException} 49 | */ 50 | public BrokenOutputStream() { 51 | this(new IOException("Broken output stream")); 52 | } 53 | 54 | /** 55 | * Throws the configured exception. 56 | * 57 | * @param b ignored 58 | * @throws IOException always thrown 59 | */ 60 | @Override 61 | public void write(int b) throws IOException { 62 | throw exception; 63 | } 64 | 65 | /** 66 | * Throws the configured exception. 67 | * 68 | * @throws IOException always thrown 69 | */ 70 | @Override 71 | public void flush() throws IOException { 72 | throw exception; 73 | } 74 | 75 | /** 76 | * Throws the configured exception. 77 | * 78 | * @throws IOException always thrown 79 | */ 80 | @Override 81 | public void close() throws IOException { 82 | throw exception; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/output/CloseShieldOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.output; 18 | 19 | import java.io.OutputStream; 20 | 21 | /** 22 | * Proxy stream that prevents the underlying output stream from being closed. 23 | *

24 | * This class is typically used in cases where an output stream needs to be 25 | * passed to a component that wants to explicitly close the stream even if 26 | * other components would still use the stream for output. 27 | * 28 | * @version $Id: CloseShieldOutputStream.java 1304052 2012-03-22 20:55:29Z ggregory $ 29 | * @since 1.4 30 | */ 31 | public class CloseShieldOutputStream extends ProxyOutputStream { 32 | 33 | /** 34 | * Creates a proxy that shields the given output stream from being 35 | * closed. 36 | * 37 | * @param out underlying output stream 38 | */ 39 | public CloseShieldOutputStream(OutputStream out) { 40 | super(out); 41 | } 42 | 43 | /** 44 | * Replaces the underlying output stream with a {@link ClosedOutputStream} 45 | * sentinel. The original output stream will remain open, but this proxy 46 | * will appear closed. 47 | */ 48 | @Override 49 | public void close() { 50 | out = new ClosedOutputStream(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/output/ClosedOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.output; 18 | 19 | import java.io.IOException; 20 | import java.io.OutputStream; 21 | 22 | /** 23 | * Closed output stream. This stream throws an exception on all attempts to 24 | * write something to the stream. 25 | *

26 | * Typically uses of this class include testing for corner cases in methods 27 | * that accept an output stream and acting as a sentinel value instead of 28 | * a {@code null} output stream. 29 | * 30 | * @version $Id: ClosedOutputStream.java 1307459 2012-03-30 15:11:44Z ggregory $ 31 | * @since 1.4 32 | */ 33 | public class ClosedOutputStream extends OutputStream { 34 | 35 | /** 36 | * A singleton. 37 | */ 38 | public static final ClosedOutputStream CLOSED_OUTPUT_STREAM = new ClosedOutputStream(); 39 | 40 | /** 41 | * Throws an {@link IOException} to indicate that the stream is closed. 42 | * 43 | * @param b ignored 44 | * @throws IOException always thrown 45 | */ 46 | @Override 47 | public void write(int b) throws IOException { 48 | throw new IOException("write(" + b + ") failed: stream is closed"); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/output/DemuxOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.output; 18 | 19 | import java.io.IOException; 20 | import java.io.OutputStream; 21 | 22 | /** 23 | * Data written to this stream is forwarded to a stream that has been associated 24 | * with this thread. 25 | * 26 | * @version $Id: DemuxOutputStream.java 1302056 2012-03-18 03:03:38Z ggregory $ 27 | */ 28 | public class DemuxOutputStream 29 | extends OutputStream 30 | { 31 | private final InheritableThreadLocal m_streams = new InheritableThreadLocal(); 32 | 33 | /** 34 | * Bind the specified stream to the current thread. 35 | * 36 | * @param output the stream to bind 37 | * @return the OutputStream that was previously active 38 | */ 39 | public OutputStream bindStream( OutputStream output ) 40 | { 41 | OutputStream stream = m_streams.get(); 42 | m_streams.set( output ); 43 | return stream; 44 | } 45 | 46 | /** 47 | * Closes stream associated with current thread. 48 | * 49 | * @throws IOException if an error occurs 50 | */ 51 | @Override 52 | public void close() 53 | throws IOException 54 | { 55 | OutputStream output = m_streams.get(); 56 | if( null != output ) 57 | { 58 | output.close(); 59 | } 60 | } 61 | 62 | /** 63 | * Flushes stream associated with current thread. 64 | * 65 | * @throws IOException if an error occurs 66 | */ 67 | @Override 68 | public void flush() 69 | throws IOException 70 | { 71 | OutputStream output = m_streams.get(); 72 | if( null != output ) 73 | { 74 | output.flush(); 75 | } 76 | } 77 | 78 | /** 79 | * Writes byte to stream associated with current thread. 80 | * 81 | * @param ch the byte to write to stream 82 | * @throws IOException if an error occurs 83 | */ 84 | @Override 85 | public void write( int ch ) 86 | throws IOException 87 | { 88 | OutputStream output = m_streams.get(); 89 | if( null != output ) 90 | { 91 | output.write( ch ); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/output/NullOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.output; 18 | 19 | import java.io.IOException; 20 | import java.io.OutputStream; 21 | 22 | /** 23 | * This OutputStream writes all data to the famous /dev/null. 24 | *

25 | * This output stream has no destination (file/socket etc.) and all 26 | * bytes written to it are ignored and lost. 27 | * 28 | * @version $Id: NullOutputStream.java 1302056 2012-03-18 03:03:38Z ggregory $ 29 | */ 30 | public class NullOutputStream extends OutputStream { 31 | 32 | /** 33 | * A singleton. 34 | */ 35 | public static final NullOutputStream NULL_OUTPUT_STREAM = new NullOutputStream(); 36 | 37 | /** 38 | * Does nothing - output to /dev/null. 39 | * @param b The bytes to write 40 | * @param off The start offset 41 | * @param len The number of bytes to write 42 | */ 43 | @Override 44 | public void write(byte[] b, int off, int len) { 45 | //to /dev/null 46 | } 47 | 48 | /** 49 | * Does nothing - output to /dev/null. 50 | * @param b The byte to write 51 | */ 52 | @Override 53 | public void write(int b) { 54 | //to /dev/null 55 | } 56 | 57 | /** 58 | * Does nothing - output to /dev/null. 59 | * @param b The bytes to write 60 | * @throws IOException never 61 | */ 62 | @Override 63 | public void write(byte[] b) throws IOException { 64 | //to /dev/null 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/org/apache/commons/io/output/TeeOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.io.output; 18 | 19 | import java.io.IOException; 20 | import java.io.OutputStream; 21 | 22 | /** 23 | * Classic splitter of OutputStream. Named after the unix 'tee' 24 | * command. It allows a stream to be branched off so there 25 | * are now two streams. 26 | * 27 | * @version $Id: TeeOutputStream.java 1302056 2012-03-18 03:03:38Z ggregory $ 28 | */ 29 | public class TeeOutputStream extends ProxyOutputStream { 30 | 31 | /** the second OutputStream to write to */ 32 | protected OutputStream branch; 33 | 34 | /** 35 | * Constructs a TeeOutputStream. 36 | * @param out the main OutputStream 37 | * @param branch the second OutputStream 38 | */ 39 | public TeeOutputStream(OutputStream out, OutputStream branch) { 40 | super(out); 41 | this.branch = branch; 42 | } 43 | 44 | /** 45 | * Write the bytes to both streams. 46 | * @param b the bytes to write 47 | * @throws IOException if an I/O error occurs 48 | */ 49 | @Override 50 | public synchronized void write(byte[] b) throws IOException { 51 | super.write(b); 52 | this.branch.write(b); 53 | } 54 | 55 | /** 56 | * Write the specified bytes to both streams. 57 | * @param b the bytes to write 58 | * @param off The start offset 59 | * @param len The number of bytes to write 60 | * @throws IOException if an I/O error occurs 61 | */ 62 | @Override 63 | public synchronized void write(byte[] b, int off, int len) throws IOException { 64 | super.write(b, off, len); 65 | this.branch.write(b, off, len); 66 | } 67 | 68 | /** 69 | * Write a byte to both streams. 70 | * @param b the byte to write 71 | * @throws IOException if an I/O error occurs 72 | */ 73 | @Override 74 | public synchronized void write(int b) throws IOException { 75 | super.write(b); 76 | this.branch.write(b); 77 | } 78 | 79 | /** 80 | * Flushes both streams. 81 | * @throws IOException if an I/O error occurs 82 | */ 83 | @Override 84 | public void flush() throws IOException { 85 | super.flush(); 86 | this.branch.flush(); 87 | } 88 | 89 | /** 90 | * Closes both output streams. 91 | * 92 | * If closing the main output stream throws an exception, attempt to close the branch output stream. 93 | * 94 | * If closing the main and branch output streams both throw exceptions, which exceptions is thrown by this method is 95 | * currently unspecified and subject to change. 96 | * 97 | * @throws IOException 98 | * if an I/O error occurs 99 | */ 100 | @Override 101 | public void close() throws IOException { 102 | try { 103 | super.close(); 104 | } finally { 105 | this.branch.close(); 106 | } 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/Edge.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm; 31 | 32 | /** 33 | * An edge in the control flow graph of a method body. See {@link Label Label}. 34 | * 35 | * @author Eric Bruneton 36 | */ 37 | class Edge { 38 | 39 | /** 40 | * Denotes a normal control flow graph edge. 41 | */ 42 | static final int NORMAL = 0; 43 | 44 | /** 45 | * Denotes a control flow graph edge corresponding to an exception handler. 46 | * More precisely any {@link Edge} whose {@link #info} is strictly positive 47 | * corresponds to an exception handler. The actual value of {@link #info} is 48 | * the index, in the {@link ClassWriter} type table, of the exception that 49 | * is catched. 50 | */ 51 | static final int EXCEPTION = 0x7FFFFFFF; 52 | 53 | /** 54 | * Information about this control flow graph edge. If 55 | * {@link ClassWriter#COMPUTE_MAXS} is used this field is the (relative) 56 | * stack size in the basic block from which this edge originates. This size 57 | * is equal to the stack size at the "jump" instruction to which this edge 58 | * corresponds, relatively to the stack size at the beginning of the 59 | * originating basic block. If {@link ClassWriter#COMPUTE_FRAMES} is used, 60 | * this field is the kind of this control flow graph edge (i.e. NORMAL or 61 | * EXCEPTION). 62 | */ 63 | int info; 64 | 65 | /** 66 | * The successor block of the basic block from which this edge originates. 67 | */ 68 | Label successor; 69 | 70 | /** 71 | * The next edge in the list of successors of the originating basic block. 72 | * See {@link Label#successors successors}. 73 | */ 74 | Edge next; 75 | } 76 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/commons/AnnotationRemapper.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | package org.objectweb.asm.commons; 32 | 33 | import org.objectweb.asm.AnnotationVisitor; 34 | import org.objectweb.asm.Opcodes; 35 | 36 | /** 37 | * An {@link AnnotationVisitor} adapter for type remapping. 38 | * 39 | * @author Eugene Kuleshov 40 | */ 41 | public class AnnotationRemapper extends AnnotationVisitor { 42 | 43 | protected final Remapper remapper; 44 | 45 | public AnnotationRemapper(final AnnotationVisitor av, 46 | final Remapper remapper) { 47 | this(Opcodes.ASM5, av, remapper); 48 | } 49 | 50 | protected AnnotationRemapper(final int api, final AnnotationVisitor av, 51 | final Remapper remapper) { 52 | super(api, av); 53 | this.remapper = remapper; 54 | } 55 | 56 | @Override 57 | public void visit(String name, Object value) { 58 | av.visit(name, remapper.mapValue(value)); 59 | } 60 | 61 | @Override 62 | public void visitEnum(String name, String desc, String value) { 63 | av.visitEnum(name, remapper.mapDesc(desc), value); 64 | } 65 | 66 | @Override 67 | public AnnotationVisitor visitAnnotation(String name, String desc) { 68 | AnnotationVisitor v = av.visitAnnotation(name, remapper.mapDesc(desc)); 69 | return v == null ? null : (v == av ? this : new AnnotationRemapper(v, 70 | remapper)); 71 | } 72 | 73 | @Override 74 | public AnnotationVisitor visitArray(String name) { 75 | AnnotationVisitor v = av.visitArray(name); 76 | return v == null ? null : (v == av ? this : new AnnotationRemapper(v, 77 | remapper)); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/commons/FieldRemapper.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | package org.objectweb.asm.commons; 32 | 33 | import org.objectweb.asm.AnnotationVisitor; 34 | import org.objectweb.asm.FieldVisitor; 35 | import org.objectweb.asm.Opcodes; 36 | import org.objectweb.asm.TypePath; 37 | 38 | /** 39 | * A {@link FieldVisitor} adapter for type remapping. 40 | * 41 | * @author Eugene Kuleshov 42 | */ 43 | public class FieldRemapper extends FieldVisitor { 44 | 45 | private final Remapper remapper; 46 | 47 | public FieldRemapper(final FieldVisitor fv, final Remapper remapper) { 48 | this(Opcodes.ASM5, fv, remapper); 49 | } 50 | 51 | protected FieldRemapper(final int api, final FieldVisitor fv, 52 | final Remapper remapper) { 53 | super(api, fv); 54 | this.remapper = remapper; 55 | } 56 | 57 | @Override 58 | public AnnotationVisitor visitAnnotation(String desc, boolean visible) { 59 | AnnotationVisitor av = fv.visitAnnotation(remapper.mapDesc(desc), 60 | visible); 61 | return av == null ? null : new AnnotationRemapper(av, remapper); 62 | } 63 | 64 | @Override 65 | public AnnotationVisitor visitTypeAnnotation(int typeRef, 66 | TypePath typePath, String desc, boolean visible) { 67 | AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, 68 | remapper.mapDesc(desc), visible); 69 | return av == null ? null : new AnnotationRemapper(av, remapper); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/commons/RemappingAnnotationAdapter.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | package org.objectweb.asm.commons; 32 | 33 | import org.objectweb.asm.AnnotationVisitor; 34 | import org.objectweb.asm.Opcodes; 35 | 36 | /** 37 | * An {@link AnnotationVisitor} adapter for type remapping. 38 | * 39 | * @deprecated use {@link AnnotationRemapper} instead. 40 | * @author Eugene Kuleshov 41 | */ 42 | @Deprecated 43 | public class RemappingAnnotationAdapter extends AnnotationVisitor { 44 | 45 | protected final Remapper remapper; 46 | 47 | public RemappingAnnotationAdapter(final AnnotationVisitor av, 48 | final Remapper remapper) { 49 | this(Opcodes.ASM5, av, remapper); 50 | } 51 | 52 | protected RemappingAnnotationAdapter(final int api, 53 | final AnnotationVisitor av, final Remapper remapper) { 54 | super(api, av); 55 | this.remapper = remapper; 56 | } 57 | 58 | @Override 59 | public void visit(String name, Object value) { 60 | av.visit(name, remapper.mapValue(value)); 61 | } 62 | 63 | @Override 64 | public void visitEnum(String name, String desc, String value) { 65 | av.visitEnum(name, remapper.mapDesc(desc), value); 66 | } 67 | 68 | @Override 69 | public AnnotationVisitor visitAnnotation(String name, String desc) { 70 | AnnotationVisitor v = av.visitAnnotation(name, remapper.mapDesc(desc)); 71 | return v == null ? null : (v == av ? this 72 | : new RemappingAnnotationAdapter(v, remapper)); 73 | } 74 | 75 | @Override 76 | public AnnotationVisitor visitArray(String name) { 77 | AnnotationVisitor v = av.visitArray(name); 78 | return v == null ? null : (v == av ? this 79 | : new RemappingAnnotationAdapter(v, remapper)); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/commons/RemappingFieldAdapter.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | package org.objectweb.asm.commons; 32 | 33 | import org.objectweb.asm.AnnotationVisitor; 34 | import org.objectweb.asm.FieldVisitor; 35 | import org.objectweb.asm.Opcodes; 36 | import org.objectweb.asm.TypePath; 37 | 38 | /** 39 | * A {@link FieldVisitor} adapter for type remapping. 40 | * 41 | * @deprecated use {@link FieldRemapper} instead. 42 | * @author Eugene Kuleshov 43 | */ 44 | @Deprecated 45 | public class RemappingFieldAdapter extends FieldVisitor { 46 | 47 | private final Remapper remapper; 48 | 49 | public RemappingFieldAdapter(final FieldVisitor fv, final Remapper remapper) { 50 | this(Opcodes.ASM5, fv, remapper); 51 | } 52 | 53 | protected RemappingFieldAdapter(final int api, final FieldVisitor fv, 54 | final Remapper remapper) { 55 | super(api, fv); 56 | this.remapper = remapper; 57 | } 58 | 59 | @Override 60 | public AnnotationVisitor visitAnnotation(String desc, boolean visible) { 61 | AnnotationVisitor av = fv.visitAnnotation(remapper.mapDesc(desc), 62 | visible); 63 | return av == null ? null : new RemappingAnnotationAdapter(av, remapper); 64 | } 65 | 66 | @Override 67 | public AnnotationVisitor visitTypeAnnotation(int typeRef, 68 | TypePath typePath, String desc, boolean visible) { 69 | AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, 70 | remapper.mapDesc(desc), visible); 71 | return av == null ? null : new RemappingAnnotationAdapter(av, remapper); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/commons/SimpleRemapper.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | package org.objectweb.asm.commons; 32 | 33 | import java.util.Collections; 34 | import java.util.Map; 35 | 36 | /** 37 | * A {@link Remapper} using a {@link Map} to define its mapping. 38 | * 39 | * @author Eugene Kuleshov 40 | */ 41 | public class SimpleRemapper extends Remapper { 42 | 43 | private final Map mapping; 44 | 45 | public SimpleRemapper(Map mapping) { 46 | this.mapping = mapping; 47 | } 48 | 49 | public SimpleRemapper(String oldName, String newName) { 50 | this.mapping = Collections.singletonMap(oldName, newName); 51 | } 52 | 53 | @Override 54 | public String mapMethodName(String owner, String name, String desc) { 55 | String s = map(owner + '.' + name + desc); 56 | return s == null ? name : s; 57 | } 58 | 59 | @Override 60 | public String mapInvokeDynamicMethodName(String name, String desc) { 61 | String s = map('.' + name + desc); 62 | return s == null ? name : s; 63 | } 64 | 65 | @Override 66 | public String mapFieldName(String owner, String name, String desc) { 67 | String s = map(owner + '.' + name); 68 | return s == null ? name : s; 69 | } 70 | 71 | @Override 72 | public String map(String key) { 73 | return mapping.get(key); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/commons/TableSwitchGenerator.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.commons; 31 | 32 | import org.objectweb.asm.Label; 33 | 34 | /** 35 | * A code generator for switch statements. 36 | * 37 | * @author Juozas Baliuka 38 | * @author Chris Nokleberg 39 | * @author Eric Bruneton 40 | */ 41 | public interface TableSwitchGenerator { 42 | 43 | /** 44 | * Generates the code for a switch case. 45 | * 46 | * @param key 47 | * the switch case key. 48 | * @param end 49 | * a label that corresponds to the end of the switch statement. 50 | */ 51 | void generateCase(int key, Label end); 52 | 53 | /** 54 | * Generates the code for the default switch case. 55 | */ 56 | void generateDefault(); 57 | } 58 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/optimizer/FieldConstantsCollector.java: -------------------------------------------------------------------------------- 1 | package org.objectweb.asm.optimizer; 2 | 3 | import org.objectweb.asm.AnnotationVisitor; 4 | import org.objectweb.asm.Attribute; 5 | import org.objectweb.asm.FieldVisitor; 6 | import org.objectweb.asm.Opcodes; 7 | import org.objectweb.asm.TypePath; 8 | 9 | /** 10 | * A {@link FieldVisitor} that collects the {@link Constant}s of the fields it 11 | * visits. 12 | * 13 | * @author Eric Bruneton 14 | */ 15 | public class FieldConstantsCollector extends FieldVisitor { 16 | 17 | private final ConstantPool cp; 18 | 19 | public FieldConstantsCollector(final FieldVisitor fv, final ConstantPool cp) { 20 | super(Opcodes.ASM5, fv); 21 | this.cp = cp; 22 | } 23 | 24 | @Override 25 | public AnnotationVisitor visitAnnotation(final String desc, 26 | final boolean visible) { 27 | cp.newUTF8(desc); 28 | if (visible) { 29 | cp.newUTF8("RuntimeVisibleAnnotations"); 30 | } else { 31 | cp.newUTF8("RuntimeInvisibleAnnotations"); 32 | } 33 | return new AnnotationConstantsCollector(fv.visitAnnotation(desc, 34 | visible), cp); 35 | } 36 | 37 | @Override 38 | public AnnotationVisitor visitTypeAnnotation(int typeRef, 39 | TypePath typePath, String desc, boolean visible) { 40 | cp.newUTF8(desc); 41 | if (visible) { 42 | cp.newUTF8("RuntimeVisibleTypeAnnotations"); 43 | } else { 44 | cp.newUTF8("RuntimeInvisibleTypeAnnotations"); 45 | } 46 | return new AnnotationConstantsCollector(fv.visitAnnotation(desc, 47 | visible), cp); 48 | } 49 | 50 | @Override 51 | public void visitAttribute(final Attribute attr) { 52 | // can do nothing 53 | fv.visitAttribute(attr); 54 | } 55 | 56 | @Override 57 | public void visitEnd() { 58 | fv.visitEnd(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/optimizer/NameMapping.java: -------------------------------------------------------------------------------- 1 | package org.objectweb.asm.optimizer; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.util.HashSet; 8 | import java.util.Properties; 9 | import java.util.Set; 10 | 11 | import org.objectweb.asm.Type; 12 | 13 | /** 14 | * A MAPPING from names to names, used to rename classes, fields and methods. 15 | * 16 | * @author Eric Bruneton 17 | */ 18 | public class NameMapping { 19 | 20 | public final Properties mapping; 21 | 22 | public final Set unused; 23 | 24 | public NameMapping(final String file) throws IOException { 25 | mapping = new Properties(); 26 | InputStream is = null; 27 | try { 28 | is = new BufferedInputStream(new FileInputStream(file)); 29 | mapping.load(is); 30 | unused = new HashSet(mapping.keySet()); 31 | } finally { 32 | if (is != null) { 33 | is.close(); 34 | } 35 | } 36 | } 37 | 38 | public String map(final String name) { 39 | String s = (String) mapping.get(name); 40 | if (s == null) { 41 | int p = name.indexOf('.'); 42 | if (p == -1) { 43 | s = name; 44 | } else { 45 | int q = name.indexOf('('); 46 | if (q == -1) { 47 | s = name.substring(p + 1); 48 | } else { 49 | s = name.substring(p + 1, q); 50 | } 51 | } 52 | } else { 53 | unused.remove(name); 54 | } 55 | return s; 56 | } 57 | 58 | public String fix(final String desc) { 59 | if (desc.startsWith("(")) { 60 | Type[] arguments = Type.getArgumentTypes(desc); 61 | Type result = Type.getReturnType(desc); 62 | for (int i = 0; i < arguments.length; ++i) { 63 | arguments[i] = fix(arguments[i]); 64 | } 65 | result = fix(result); 66 | return Type.getMethodDescriptor(result, arguments); 67 | } else { 68 | return fix(Type.getType(desc)).getDescriptor(); 69 | } 70 | } 71 | 72 | private Type fix(final Type t) { 73 | if (t.getSort() == Type.OBJECT) { 74 | return Type.getObjectType(map(t.getInternalName())); 75 | } else if (t.getSort() == Type.ARRAY) { 76 | String s = fix(t.getElementType()).getDescriptor(); 77 | for (int i = 0; i < t.getDimensions(); ++i) { 78 | s = '[' + s; 79 | } 80 | return Type.getType(s); 81 | } else { 82 | return t; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/IincInsnNode.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree; 31 | 32 | import java.util.Map; 33 | 34 | import org.objectweb.asm.MethodVisitor; 35 | import org.objectweb.asm.Opcodes; 36 | 37 | /** 38 | * A node that represents an IINC instruction. 39 | * 40 | * @author Eric Bruneton 41 | */ 42 | public class IincInsnNode extends AbstractInsnNode { 43 | 44 | /** 45 | * Index of the local variable to be incremented. 46 | */ 47 | public int var; 48 | 49 | /** 50 | * Amount to increment the local variable by. 51 | */ 52 | public int incr; 53 | 54 | /** 55 | * Constructs a new {@link IincInsnNode}. 56 | * 57 | * @param var 58 | * index of the local variable to be incremented. 59 | * @param incr 60 | * increment amount to increment the local variable by. 61 | */ 62 | public IincInsnNode(final int var, final int incr) { 63 | super(Opcodes.IINC); 64 | this.var = var; 65 | this.incr = incr; 66 | } 67 | 68 | @Override 69 | public int getType() { 70 | return IINC_INSN; 71 | } 72 | 73 | @Override 74 | public void accept(final MethodVisitor mv) { 75 | mv.visitIincInsn(var, incr); 76 | acceptAnnotations(mv); 77 | } 78 | 79 | @Override 80 | public AbstractInsnNode clone(final Map labels) { 81 | return new IincInsnNode(var, incr).cloneAnnotations(this); 82 | } 83 | } -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/IntInsnNode.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree; 31 | 32 | import java.util.Map; 33 | 34 | import org.objectweb.asm.MethodVisitor; 35 | 36 | /** 37 | * A node that represents an instruction with a single int operand. 38 | * 39 | * @author Eric Bruneton 40 | */ 41 | public class IntInsnNode extends AbstractInsnNode { 42 | 43 | /** 44 | * The operand of this instruction. 45 | */ 46 | public int operand; 47 | 48 | /** 49 | * Constructs a new {@link IntInsnNode}. 50 | * 51 | * @param opcode 52 | * the opcode of the instruction to be constructed. This opcode 53 | * must be BIPUSH, SIPUSH or NEWARRAY. 54 | * @param operand 55 | * the operand of the instruction to be constructed. 56 | */ 57 | public IntInsnNode(final int opcode, final int operand) { 58 | super(opcode); 59 | this.operand = operand; 60 | } 61 | 62 | /** 63 | * Sets the opcode of this instruction. 64 | * 65 | * @param opcode 66 | * the new instruction opcode. This opcode must be BIPUSH, SIPUSH 67 | * or NEWARRAY. 68 | */ 69 | public void setOpcode(final int opcode) { 70 | this.opcode = opcode; 71 | } 72 | 73 | @Override 74 | public int getType() { 75 | return INT_INSN; 76 | } 77 | 78 | @Override 79 | public void accept(final MethodVisitor mv) { 80 | mv.visitIntInsn(opcode, operand); 81 | acceptAnnotations(mv); 82 | } 83 | 84 | @Override 85 | public AbstractInsnNode clone(final Map labels) { 86 | return new IntInsnNode(opcode, operand).cloneAnnotations(this); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/InvokeDynamicInsnNode.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree; 31 | 32 | import java.util.Map; 33 | 34 | import org.objectweb.asm.Handle; 35 | import org.objectweb.asm.MethodVisitor; 36 | import org.objectweb.asm.Opcodes; 37 | 38 | /** 39 | * A node that represents an invokedynamic instruction. 40 | * 41 | * @author Remi Forax 42 | */ 43 | public class InvokeDynamicInsnNode extends AbstractInsnNode { 44 | 45 | /** 46 | * Invokedynamic name. 47 | */ 48 | public String name; 49 | 50 | /** 51 | * Invokedynamic descriptor. 52 | */ 53 | public String desc; 54 | 55 | /** 56 | * Bootstrap method 57 | */ 58 | public Handle bsm; 59 | 60 | /** 61 | * Bootstrap constant arguments 62 | */ 63 | public Object[] bsmArgs; 64 | 65 | /** 66 | * Constructs a new {@link InvokeDynamicInsnNode}. 67 | * 68 | * @param name 69 | * invokedynamic name. 70 | * @param desc 71 | * invokedynamic descriptor (see {@link org.objectweb.asm.Type}). 72 | * @param bsm 73 | * the bootstrap method. 74 | * @param bsmArgs 75 | * the boostrap constant arguments. 76 | */ 77 | public InvokeDynamicInsnNode(final String name, final String desc, 78 | final Handle bsm, final Object... bsmArgs) { 79 | super(Opcodes.INVOKEDYNAMIC); 80 | this.name = name; 81 | this.desc = desc; 82 | this.bsm = bsm; 83 | this.bsmArgs = bsmArgs; 84 | } 85 | 86 | @Override 87 | public int getType() { 88 | return INVOKE_DYNAMIC_INSN; 89 | } 90 | 91 | @Override 92 | public void accept(final MethodVisitor mv) { 93 | mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs); 94 | acceptAnnotations(mv); 95 | } 96 | 97 | @Override 98 | public AbstractInsnNode clone(final Map labels) { 99 | return new InvokeDynamicInsnNode(name, desc, bsm, bsmArgs) 100 | .cloneAnnotations(this); 101 | } 102 | } -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/LabelNode.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree; 31 | 32 | import java.util.Map; 33 | 34 | import org.objectweb.asm.Label; 35 | import org.objectweb.asm.MethodVisitor; 36 | 37 | /** 38 | * An {@link AbstractInsnNode} that encapsulates a {@link Label}. 39 | */ 40 | public class LabelNode extends AbstractInsnNode { 41 | 42 | private Label label; 43 | 44 | public LabelNode() { 45 | super(-1); 46 | } 47 | 48 | public LabelNode(final Label label) { 49 | super(-1); 50 | this.label = label; 51 | } 52 | 53 | @Override 54 | public int getType() { 55 | return LABEL; 56 | } 57 | 58 | public Label getLabel() { 59 | if (label == null) { 60 | label = new Label(); 61 | } 62 | return label; 63 | } 64 | 65 | @Override 66 | public void accept(final MethodVisitor cv) { 67 | cv.visitLabel(getLabel()); 68 | } 69 | 70 | @Override 71 | public AbstractInsnNode clone(final Map labels) { 72 | return labels.get(this); 73 | } 74 | 75 | public void resetLabel() { 76 | label = null; 77 | } 78 | } -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/LdcInsnNode.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree; 31 | 32 | import java.util.Map; 33 | 34 | import org.objectweb.asm.MethodVisitor; 35 | import org.objectweb.asm.Opcodes; 36 | 37 | /** 38 | * A node that represents an LDC instruction. 39 | * 40 | * @author Eric Bruneton 41 | */ 42 | public class LdcInsnNode extends AbstractInsnNode { 43 | 44 | /** 45 | * The constant to be loaded on the stack. This parameter must be a non null 46 | * {@link Integer}, a {@link Float}, a {@link Long}, a {@link Double}, a 47 | * {@link String} or a {@link org.objectweb.asm.Type}. 48 | */ 49 | public Object cst; 50 | 51 | /** 52 | * Constructs a new {@link LdcInsnNode}. 53 | * 54 | * @param cst 55 | * the constant to be loaded on the stack. This parameter must be 56 | * a non null {@link Integer}, a {@link Float}, a {@link Long}, a 57 | * {@link Double} or a {@link String}. 58 | */ 59 | public LdcInsnNode(final Object cst) { 60 | super(Opcodes.LDC); 61 | this.cst = cst; 62 | } 63 | 64 | @Override 65 | public int getType() { 66 | return LDC_INSN; 67 | } 68 | 69 | @Override 70 | public void accept(final MethodVisitor mv) { 71 | mv.visitLdcInsn(cst); 72 | acceptAnnotations(mv); 73 | } 74 | 75 | @Override 76 | public AbstractInsnNode clone(final Map labels) { 77 | return new LdcInsnNode(cst).cloneAnnotations(this); 78 | } 79 | } -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/LineNumberNode.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree; 31 | 32 | import java.util.Map; 33 | 34 | import org.objectweb.asm.MethodVisitor; 35 | 36 | /** 37 | * A node that represents a line number declaration. These nodes are pseudo 38 | * instruction nodes in order to be inserted in an instruction list. 39 | * 40 | * @author Eric Bruneton 41 | */ 42 | public class LineNumberNode extends AbstractInsnNode { 43 | 44 | /** 45 | * A line number. This number refers to the source file from which the class 46 | * was compiled. 47 | */ 48 | public int line; 49 | 50 | /** 51 | * The first instruction corresponding to this line number. 52 | */ 53 | public LabelNode start; 54 | 55 | /** 56 | * Constructs a new {@link LineNumberNode}. 57 | * 58 | * @param line 59 | * a line number. This number refers to the source file from 60 | * which the class was compiled. 61 | * @param start 62 | * the first instruction corresponding to this line number. 63 | */ 64 | public LineNumberNode(final int line, final LabelNode start) { 65 | super(-1); 66 | this.line = line; 67 | this.start = start; 68 | } 69 | 70 | @Override 71 | public int getType() { 72 | return LINE; 73 | } 74 | 75 | @Override 76 | public void accept(final MethodVisitor mv) { 77 | mv.visitLineNumber(line, start.getLabel()); 78 | } 79 | 80 | @Override 81 | public AbstractInsnNode clone(final Map labels) { 82 | return new LineNumberNode(line, clone(start, labels)); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/MultiANewArrayInsnNode.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree; 31 | 32 | import java.util.Map; 33 | 34 | import org.objectweb.asm.MethodVisitor; 35 | import org.objectweb.asm.Opcodes; 36 | 37 | /** 38 | * A node that represents a MULTIANEWARRAY instruction. 39 | * 40 | * @author Eric Bruneton 41 | */ 42 | public class MultiANewArrayInsnNode extends AbstractInsnNode { 43 | 44 | /** 45 | * An array type descriptor (see {@link org.objectweb.asm.Type}). 46 | */ 47 | public String desc; 48 | 49 | /** 50 | * Number of dimensions of the array to allocate. 51 | */ 52 | public int dims; 53 | 54 | /** 55 | * Constructs a new {@link MultiANewArrayInsnNode}. 56 | * 57 | * @param desc 58 | * an array type descriptor (see {@link org.objectweb.asm.Type}). 59 | * @param dims 60 | * number of dimensions of the array to allocate. 61 | */ 62 | public MultiANewArrayInsnNode(final String desc, final int dims) { 63 | super(Opcodes.MULTIANEWARRAY); 64 | this.desc = desc; 65 | this.dims = dims; 66 | } 67 | 68 | @Override 69 | public int getType() { 70 | return MULTIANEWARRAY_INSN; 71 | } 72 | 73 | @Override 74 | public void accept(final MethodVisitor mv) { 75 | mv.visitMultiANewArrayInsn(desc, dims); 76 | acceptAnnotations(mv); 77 | } 78 | 79 | @Override 80 | public AbstractInsnNode clone(final Map labels) { 81 | return new MultiANewArrayInsnNode(desc, dims).cloneAnnotations(this); 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/ParameterNode.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree; 31 | 32 | import org.objectweb.asm.MethodVisitor; 33 | 34 | /** 35 | * A node that represents a parameter access and name. 36 | * 37 | * @author Remi Forax 38 | */ 39 | public class ParameterNode { 40 | /** 41 | * The parameter's name. 42 | */ 43 | public String name; 44 | 45 | /** 46 | * The parameter's access flags (see {@link org.objectweb.asm.Opcodes}). 47 | * Valid values are ACC_FINAL, ACC_SYNTHETIC and 48 | * ACC_MANDATED. 49 | */ 50 | public int access; 51 | 52 | /** 53 | * Constructs a new {@link ParameterNode}. 54 | * 55 | * @param access 56 | * The parameter's access flags. Valid values are 57 | * ACC_FINAL, ACC_SYNTHETIC or/and 58 | * ACC_MANDATED (see {@link org.objectweb.asm.Opcodes}). 59 | * @param name 60 | * the parameter's name. 61 | */ 62 | public ParameterNode(final String name, final int access) { 63 | this.name = name; 64 | this.access = access; 65 | } 66 | 67 | /** 68 | * Makes the given visitor visit this parameter declaration. 69 | * 70 | * @param mv 71 | * a method visitor. 72 | */ 73 | public void accept(final MethodVisitor mv) { 74 | mv.visitParameter(name, access); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/TypeInsnNode.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree; 31 | 32 | import java.util.Map; 33 | 34 | import org.objectweb.asm.MethodVisitor; 35 | 36 | /** 37 | * A node that represents a type instruction. A type instruction is an 38 | * instruction that takes a type descriptor as parameter. 39 | * 40 | * @author Eric Bruneton 41 | */ 42 | public class TypeInsnNode extends AbstractInsnNode { 43 | 44 | /** 45 | * The operand of this instruction. This operand is an internal name (see 46 | * {@link org.objectweb.asm.Type}). 47 | */ 48 | public String desc; 49 | 50 | /** 51 | * Constructs a new {@link TypeInsnNode}. 52 | * 53 | * @param opcode 54 | * the opcode of the type instruction to be constructed. This 55 | * opcode must be NEW, ANEWARRAY, CHECKCAST or INSTANCEOF. 56 | * @param desc 57 | * the operand of the instruction to be constructed. This operand 58 | * is an internal name (see {@link org.objectweb.asm.Type}). 59 | */ 60 | public TypeInsnNode(final int opcode, final String desc) { 61 | super(opcode); 62 | this.desc = desc; 63 | } 64 | 65 | /** 66 | * Sets the opcode of this instruction. 67 | * 68 | * @param opcode 69 | * the new instruction opcode. This opcode must be NEW, 70 | * ANEWARRAY, CHECKCAST or INSTANCEOF. 71 | */ 72 | public void setOpcode(final int opcode) { 73 | this.opcode = opcode; 74 | } 75 | 76 | @Override 77 | public int getType() { 78 | return TYPE_INSN; 79 | } 80 | 81 | @Override 82 | public void accept(final MethodVisitor mv) { 83 | mv.visitTypeInsn(opcode, desc); 84 | acceptAnnotations(mv); 85 | } 86 | 87 | @Override 88 | public AbstractInsnNode clone(final Map labels) { 89 | return new TypeInsnNode(opcode, desc).cloneAnnotations(this); 90 | } 91 | } -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/VarInsnNode.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree; 31 | 32 | import java.util.Map; 33 | 34 | import org.objectweb.asm.MethodVisitor; 35 | 36 | /** 37 | * A node that represents a local variable instruction. A local variable 38 | * instruction is an instruction that loads or stores the value of a local 39 | * variable. 40 | * 41 | * @author Eric Bruneton 42 | */ 43 | public class VarInsnNode extends AbstractInsnNode { 44 | 45 | /** 46 | * The operand of this instruction. This operand is the index of a local 47 | * variable. 48 | */ 49 | public int var; 50 | 51 | /** 52 | * Constructs a new {@link VarInsnNode}. 53 | * 54 | * @param opcode 55 | * the opcode of the local variable instruction to be 56 | * constructed. This opcode must be ILOAD, LLOAD, FLOAD, DLOAD, 57 | * ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET. 58 | * @param var 59 | * the operand of the instruction to be constructed. This operand 60 | * is the index of a local variable. 61 | */ 62 | public VarInsnNode(final int opcode, final int var) { 63 | super(opcode); 64 | this.var = var; 65 | } 66 | 67 | /** 68 | * Sets the opcode of this instruction. 69 | * 70 | * @param opcode 71 | * the new instruction opcode. This opcode must be ILOAD, LLOAD, 72 | * FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or 73 | * RET. 74 | */ 75 | public void setOpcode(final int opcode) { 76 | this.opcode = opcode; 77 | } 78 | 79 | @Override 80 | public int getType() { 81 | return VAR_INSN; 82 | } 83 | 84 | @Override 85 | public void accept(final MethodVisitor mv) { 86 | mv.visitVarInsn(opcode, var); 87 | acceptAnnotations(mv); 88 | } 89 | 90 | @Override 91 | public AbstractInsnNode clone(final Map labels) { 92 | return new VarInsnNode(opcode, var).cloneAnnotations(this); 93 | } 94 | } -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/analysis/AnalyzerException.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree.analysis; 31 | 32 | import org.objectweb.asm.tree.AbstractInsnNode; 33 | 34 | /** 35 | * Thrown if a problem occurs during the analysis of a method. 36 | * 37 | * @author Bing Ran 38 | * @author Eric Bruneton 39 | */ 40 | @SuppressWarnings("serial") 41 | public class AnalyzerException extends Exception { 42 | 43 | public final AbstractInsnNode node; 44 | 45 | public AnalyzerException(final AbstractInsnNode node, final String msg) { 46 | super(msg); 47 | this.node = node; 48 | } 49 | 50 | public AnalyzerException(final AbstractInsnNode node, final String msg, 51 | final Throwable exception) { 52 | super(msg, exception); 53 | this.node = node; 54 | } 55 | 56 | public AnalyzerException(final AbstractInsnNode node, final String msg, 57 | final Object expected, final Value encountered) { 58 | super((msg == null ? "Expected " : msg + ": expected ") + expected 59 | + ", but found " + encountered); 60 | this.node = node; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/analysis/SourceValue.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree.analysis; 31 | 32 | import java.util.Set; 33 | 34 | import org.objectweb.asm.tree.AbstractInsnNode; 35 | 36 | /** 37 | * A {@link Value} that is represented by its type in a two types type system. 38 | * This type system distinguishes the ONEWORD and TWOWORDS types. 39 | * 40 | * @author Eric Bruneton 41 | */ 42 | public class SourceValue implements Value { 43 | 44 | /** 45 | * The size of this value. 46 | */ 47 | public final int size; 48 | 49 | /** 50 | * The instructions that can produce this value. For example, for the Java 51 | * code below, the instructions that can produce the value of i at 52 | * line 5 are the txo ISTORE instructions at line 1 and 3: 53 | * 54 | *
55 |      * 1: i = 0;
56 |      * 2: if (...) {
57 |      * 3:   i = 1;
58 |      * 4: }
59 |      * 5: return i;
60 |      * 
61 | * 62 | * This field is a set of {@link AbstractInsnNode} objects. 63 | */ 64 | public final Set insns; 65 | 66 | public SourceValue(final int size) { 67 | this(size, SmallSet. emptySet()); 68 | } 69 | 70 | public SourceValue(final int size, final AbstractInsnNode insn) { 71 | this.size = size; 72 | this.insns = new SmallSet(insn, null); 73 | } 74 | 75 | public SourceValue(final int size, final Set insns) { 76 | this.size = size; 77 | this.insns = insns; 78 | } 79 | 80 | public int getSize() { 81 | return size; 82 | } 83 | 84 | @Override 85 | public boolean equals(final Object value) { 86 | if (!(value instanceof SourceValue)) { 87 | return false; 88 | } 89 | SourceValue v = (SourceValue) value; 90 | return size == v.size && insns.equals(v.insns); 91 | } 92 | 93 | @Override 94 | public int hashCode() { 95 | return insns.hashCode(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/analysis/Subroutine.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree.analysis; 31 | 32 | import java.util.ArrayList; 33 | import java.util.List; 34 | 35 | import org.objectweb.asm.tree.JumpInsnNode; 36 | import org.objectweb.asm.tree.LabelNode; 37 | 38 | /** 39 | * A method subroutine (corresponds to a JSR instruction). 40 | * 41 | * @author Eric Bruneton 42 | */ 43 | public class Subroutine { 44 | 45 | public LabelNode start; 46 | 47 | public boolean[] access; 48 | 49 | public List callers; 50 | 51 | private Subroutine() { 52 | } 53 | 54 | public Subroutine(final LabelNode start, final int maxLocals, 55 | final JumpInsnNode caller) { 56 | this.start = start; 57 | this.access = new boolean[maxLocals]; 58 | this.callers = new ArrayList(); 59 | callers.add(caller); 60 | } 61 | 62 | public Subroutine copy() { 63 | Subroutine result = new Subroutine(); 64 | result.start = start; 65 | result.access = new boolean[access.length]; 66 | System.arraycopy(access, 0, result.access, 0, access.length); 67 | result.callers = new ArrayList(callers); 68 | return result; 69 | } 70 | 71 | public boolean merge(final Subroutine subroutine) throws AnalyzerException { 72 | boolean changes = false; 73 | for (int i = 0; i < access.length; ++i) { 74 | if (subroutine.access[i] && !access[i]) { 75 | access[i] = true; 76 | changes = true; 77 | } 78 | } 79 | if (subroutine.start == start) { 80 | for (int i = 0; i < subroutine.callers.size(); ++i) { 81 | JumpInsnNode caller = subroutine.callers.get(i); 82 | if (!callers.contains(caller)) { 83 | callers.add(caller); 84 | changes = true; 85 | } 86 | } 87 | } 88 | return changes; 89 | } 90 | } -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/analysis/Value.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.tree.analysis; 31 | 32 | /** 33 | * An immutable symbolic value for semantic interpretation of bytecode. 34 | * 35 | * @author Eric Bruneton 36 | */ 37 | public interface Value { 38 | 39 | /** 40 | * Returns the size of this value in words. 41 | * 42 | * @return either 1 or 2. 43 | */ 44 | int getSize(); 45 | } 46 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/util/ASMifiable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.util; 31 | 32 | import java.util.Map; 33 | 34 | import org.objectweb.asm.Label; 35 | 36 | /** 37 | * An {@link org.objectweb.asm.Attribute Attribute} that can print the ASM code 38 | * to create an equivalent attribute. 39 | * 40 | * @author Eugene Kuleshov 41 | */ 42 | public interface ASMifiable { 43 | 44 | /** 45 | * Prints the ASM code to create an attribute equal to this attribute. 46 | * 47 | * @param buf 48 | * a buffer used for printing Java code. 49 | * @param varName 50 | * name of the variable in a printed code used to store attribute 51 | * instance. 52 | * @param labelNames 53 | * map of label instances to their names. 54 | */ 55 | void asmify(StringBuffer buf, String varName, Map labelNames); 56 | } 57 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/util/Textifiable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.util; 31 | 32 | import java.util.Map; 33 | 34 | import org.objectweb.asm.Label; 35 | 36 | /** 37 | * An {@link org.objectweb.asm.Attribute Attribute} that can print a readable 38 | * representation of itself. 39 | * 40 | * Implementations should construct readable output from an attribute data 41 | * structure. Such representation could be used in unit test assertions. 42 | * 43 | * @author Eugene Kuleshov 44 | */ 45 | public interface Textifiable { 46 | 47 | /** 48 | * Build a human readable representation of this attribute. 49 | * 50 | * @param buf 51 | * a buffer used for printing Java code. 52 | * @param labelNames 53 | * map of label instances to their names. 54 | */ 55 | void textify(StringBuffer buf, Map labelNames); 56 | } 57 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/util/TraceAnnotationVisitor.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.util; 31 | 32 | import org.objectweb.asm.AnnotationVisitor; 33 | import org.objectweb.asm.Opcodes; 34 | 35 | /** 36 | * An {@link AnnotationVisitor} that prints the annotations it visits with a 37 | * {@link Printer}. 38 | * 39 | * @author Eric Bruneton 40 | */ 41 | public final class TraceAnnotationVisitor extends AnnotationVisitor { 42 | 43 | private final Printer p; 44 | 45 | public TraceAnnotationVisitor(final Printer p) { 46 | this(null, p); 47 | } 48 | 49 | public TraceAnnotationVisitor(final AnnotationVisitor av, final Printer p) { 50 | super(Opcodes.ASM5, av); 51 | this.p = p; 52 | } 53 | 54 | @Override 55 | public void visit(final String name, final Object value) { 56 | p.visit(name, value); 57 | super.visit(name, value); 58 | } 59 | 60 | @Override 61 | public void visitEnum(final String name, final String desc, 62 | final String value) { 63 | p.visitEnum(name, desc, value); 64 | super.visitEnum(name, desc, value); 65 | } 66 | 67 | @Override 68 | public AnnotationVisitor visitAnnotation(final String name, 69 | final String desc) { 70 | Printer p = this.p.visitAnnotation(name, desc); 71 | AnnotationVisitor av = this.av == null ? null : this.av 72 | .visitAnnotation(name, desc); 73 | return new TraceAnnotationVisitor(av, p); 74 | } 75 | 76 | @Override 77 | public AnnotationVisitor visitArray(final String name) { 78 | Printer p = this.p.visitArray(name); 79 | AnnotationVisitor av = this.av == null ? null : this.av 80 | .visitArray(name); 81 | return new TraceAnnotationVisitor(av, p); 82 | } 83 | 84 | @Override 85 | public void visitEnd() { 86 | p.visitAnnotationEnd(); 87 | super.visitEnd(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/util/TraceFieldVisitor.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package org.objectweb.asm.util; 31 | 32 | import org.objectweb.asm.AnnotationVisitor; 33 | import org.objectweb.asm.Attribute; 34 | import org.objectweb.asm.FieldVisitor; 35 | import org.objectweb.asm.Opcodes; 36 | import org.objectweb.asm.TypePath; 37 | 38 | /** 39 | * A {@link FieldVisitor} that prints the fields it visits with a 40 | * {@link Printer}. 41 | * 42 | * @author Eric Bruneton 43 | */ 44 | public final class TraceFieldVisitor extends FieldVisitor { 45 | 46 | public final Printer p; 47 | 48 | public TraceFieldVisitor(final Printer p) { 49 | this(null, p); 50 | } 51 | 52 | public TraceFieldVisitor(final FieldVisitor fv, final Printer p) { 53 | super(Opcodes.ASM5, fv); 54 | this.p = p; 55 | } 56 | 57 | @Override 58 | public AnnotationVisitor visitAnnotation(final String desc, 59 | final boolean visible) { 60 | Printer p = this.p.visitFieldAnnotation(desc, visible); 61 | AnnotationVisitor av = fv == null ? null : fv.visitAnnotation(desc, 62 | visible); 63 | return new TraceAnnotationVisitor(av, p); 64 | } 65 | 66 | @Override 67 | public AnnotationVisitor visitTypeAnnotation(int typeRef, 68 | TypePath typePath, String desc, boolean visible) { 69 | Printer p = this.p.visitFieldTypeAnnotation(typeRef, typePath, desc, 70 | visible); 71 | AnnotationVisitor av = fv == null ? null : fv.visitTypeAnnotation( 72 | typeRef, typePath, desc, visible); 73 | return new TraceAnnotationVisitor(av, p); 74 | } 75 | 76 | @Override 77 | public void visitAttribute(final Attribute attr) { 78 | p.visitFieldAttribute(attr); 79 | super.visitAttribute(attr); 80 | } 81 | 82 | @Override 83 | public void visitEnd() { 84 | p.visitFieldEnd(); 85 | super.visitEnd(); 86 | } 87 | } 88 | --------------------------------------------------------------------------------