Search in sources :

Example 1 with Main

use of org.mapleir.Main in project maple-ir by LLVM-but-worse.

the class RunCommand method dumpJar.

private 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.print(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 : PassResult(org.mapleir.deob.PassResult) LiveDataFlowAnalysisImpl(org.mapleir.deob.dataflow.LiveDataFlowAnalysisImpl) java.util(java.util) CompleteResolvingJarDumper(org.mapleir.app.service.CompleteResolvingJarDumper) IRCache(org.mapleir.context.IRCache) Callable(java.util.concurrent.Callable) BoissinotDestructor(org.mapleir.ir.algorithms.BoissinotDestructor) ControlFlowGraph(org.mapleir.ir.cfg.ControlFlowGraph) Logger(org.apache.log4j.Logger) Main(org.mapleir.Main) JarInfo(org.topdank.byteengineer.commons.data.JarInfo) AnalysisContext(org.mapleir.context.AnalysisContext) SingleJarDownloader(org.topdank.byteio.in.SingleJarDownloader) IPass(org.mapleir.deob.IPass) JarOutputStream(java.util.jar.JarOutputStream) CommandLine(picocli.CommandLine) MethodNode(org.mapleir.asm.MethodNode) PassGroup(org.mapleir.deob.PassGroup) SimpleApplicationContext(org.mapleir.app.client.SimpleApplicationContext) ControlFlowGraphBuilder(org.mapleir.ir.cfg.builder.ControlFlowGraphBuilder) PassContext(org.mapleir.deob.PassContext) ApplicationClassSource(org.mapleir.app.service.ApplicationClassSource) BasicAnalysisContext(org.mapleir.context.BasicAnalysisContext) RenamingHeuristic(org.mapleir.deob.util.RenamingHeuristic) ControlFlowGraphDumper(org.mapleir.ir.codegen.ControlFlowGraphDumper) Boot(org.mapleir.Boot) LibraryClassSource(org.mapleir.app.service.LibraryClassSource) ClassRenamerPass(org.mapleir.deob.passes.rename.ClassRenamerPass) LocalsReallocator(org.mapleir.ir.algorithms.LocalsReallocator) java.io(java.io) CliLog(org.mapleir.cli.CliLog) ClassNode(org.mapleir.asm.ClassNode) DefaultInvocationResolver(org.mapleir.DefaultInvocationResolver) ExceptionFixerPass(org.mapleir.deob.passes.fixer.ExceptionFixerPass) JarOutputStream(java.util.jar.JarOutputStream) CompleteResolvingJarDumper(org.mapleir.app.service.CompleteResolvingJarDumper) ClassRenamerPass(org.mapleir.deob.passes.rename.ClassRenamerPass)

Aggregations

java.io (java.io)1 java.util (java.util)1 Callable (java.util.concurrent.Callable)1 JarOutputStream (java.util.jar.JarOutputStream)1 Logger (org.apache.log4j.Logger)1 Boot (org.mapleir.Boot)1 DefaultInvocationResolver (org.mapleir.DefaultInvocationResolver)1 Main (org.mapleir.Main)1 SimpleApplicationContext (org.mapleir.app.client.SimpleApplicationContext)1 ApplicationClassSource (org.mapleir.app.service.ApplicationClassSource)1 CompleteResolvingJarDumper (org.mapleir.app.service.CompleteResolvingJarDumper)1 LibraryClassSource (org.mapleir.app.service.LibraryClassSource)1 ClassNode (org.mapleir.asm.ClassNode)1 MethodNode (org.mapleir.asm.MethodNode)1 CliLog (org.mapleir.cli.CliLog)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 PassContext (org.mapleir.deob.PassContext)1