Search in sources :

Example 1 with CompleteResolvingJarDumper

use of org.mapleir.app.service.CompleteResolvingJarDumper in project maple-ir by LLVM-but-worse.

the class Boot method dumpJar.

private static void dumpJar(ApplicationClassSource app, SingleJarDownloader<ClassNode> dl, PassGroup masterGroup, String outputFile) throws IOException {
    (new CompleteResolvingJarDumper(dl.getJarContents(), app) {

        @Override
        public int dumpResource(JarOutputStream out, String name, byte[] file) throws IOException {
            // }
            if (name.equals("META-INF/MANIFEST.MF")) {
                ClassRenamerPass renamer = (ClassRenamerPass) masterGroup.getPass(e -> e.is(ClassRenamerPass.class));
                if (renamer != null) {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(baos));
                    BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(file)));
                    String line;
                    while ((line = br.readLine()) != null) {
                        String[] parts = line.split(": ", 2);
                        if (parts.length != 2) {
                            bw.write(line);
                            continue;
                        }
                        if (parts[0].equals("Main-Class")) {
                            String newMain = renamer.getRemappedName(parts[1].replace(".", "/")).replace("/", ".");
                            LOGGER.info(String.format("%s -> %s%n", parts[1], newMain));
                            parts[1] = newMain;
                        }
                        bw.write(parts[0]);
                        bw.write(": ");
                        bw.write(parts[1]);
                        bw.write(System.lineSeparator());
                    }
                    br.close();
                    bw.close();
                    file = baos.toByteArray();
                }
            }
            return super.dumpResource(out, name, file);
        }
    }).dump(new File(outputFile));
}
Also used : DeadCodeEliminationPass(org.mapleir.deob.passes.DeadCodeEliminationPass) CompleteResolvingJarDumper(org.mapleir.app.service.CompleteResolvingJarDumper) IRCache(org.mapleir.context.IRCache) BoissinotDestructor(org.mapleir.ir.algorithms.BoissinotDestructor) Deque(java.util.Deque) ControlFlowGraph(org.mapleir.ir.cfg.ControlFlowGraph) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ClassPrinter(org.mapleir.ir.printer.ClassPrinter) Logger(org.apache.log4j.Logger) MethodNode(org.objectweb.asm.tree.MethodNode) JarInfo(org.topdank.byteengineer.commons.data.JarInfo) AnalysisContext(org.mapleir.context.AnalysisContext) ConstantExpressionReorderPass(org.mapleir.deob.passes.ConstantExpressionReorderPass) SingleJarDownloader(org.topdank.byteio.in.SingleJarDownloader) IPass(org.mapleir.deob.IPass) FieldNodePrinter(org.mapleir.ir.printer.FieldNodePrinter) LinkedList(java.util.LinkedList) JarOutputStream(java.util.jar.JarOutputStream) PropertyHelper(org.mapleir.propertyframework.util.PropertyHelper) PassGroup(org.mapleir.deob.PassGroup) SimpleApplicationContext(org.mapleir.app.client.SimpleApplicationContext) ControlFlowGraphBuilder(org.mapleir.ir.cfg.builder.ControlFlowGraphBuilder) ClassHelper(org.mapleir.stdlib.collections.ClassHelper) ApplicationClassSource(org.mapleir.app.service.ApplicationClassSource) Set(java.util.Set) BasicAnalysisContext(org.mapleir.context.BasicAnalysisContext) RenamingHeuristic(org.mapleir.deob.util.RenamingHeuristic) IRCallTracer(org.mapleir.deob.interproc.IRCallTracer) MethodNodePrinter(org.mapleir.ir.printer.MethodNodePrinter) LibraryClassSource(org.mapleir.app.service.LibraryClassSource) ControlFlowGraphDumper(org.mapleir.ir.algorithms.ControlFlowGraphDumper) TabbedStringWriter(org.mapleir.stdlib.util.TabbedStringWriter) ClassRenamerPass(org.mapleir.deob.passes.rename.ClassRenamerPass) java.io(java.io) IPropertyDictionary(org.mapleir.propertyframework.api.IPropertyDictionary) Entry(java.util.Map.Entry) ClassNode(org.objectweb.asm.tree.ClassNode) InstalledRuntimeClassSource(org.mapleir.app.service.InstalledRuntimeClassSource) JarOutputStream(java.util.jar.JarOutputStream) CompleteResolvingJarDumper(org.mapleir.app.service.CompleteResolvingJarDumper) ClassRenamerPass(org.mapleir.deob.passes.rename.ClassRenamerPass)

Aggregations

java.io (java.io)1 ArrayList (java.util.ArrayList)1 Deque (java.util.Deque)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 JarOutputStream (java.util.jar.JarOutputStream)1 Logger (org.apache.log4j.Logger)1 SimpleApplicationContext (org.mapleir.app.client.SimpleApplicationContext)1 ApplicationClassSource (org.mapleir.app.service.ApplicationClassSource)1 CompleteResolvingJarDumper (org.mapleir.app.service.CompleteResolvingJarDumper)1 InstalledRuntimeClassSource (org.mapleir.app.service.InstalledRuntimeClassSource)1 LibraryClassSource (org.mapleir.app.service.LibraryClassSource)1 AnalysisContext (org.mapleir.context.AnalysisContext)1 BasicAnalysisContext (org.mapleir.context.BasicAnalysisContext)1 IRCache (org.mapleir.context.IRCache)1 IPass (org.mapleir.deob.IPass)1 PassGroup (org.mapleir.deob.PassGroup)1 IRCallTracer (org.mapleir.deob.interproc.IRCallTracer)1