-1

So, I'm making a C# code editor for Minecraft java edition modding. I want to add a decompile feature, like IntelliJ Idea has, so that I can re-create a mod's source code with just a few clicks. To clarify, I want a way to decompile Java .class files in my C# program. I've done a bunch of research, and I can't find anything like that. I don't want to add a separate program to my program, since I want it to be integrated into my program. I have seen JD GUI, but again, that's java, and it doesn't look the best. Help please?

2 Answers2

0

You will likely not find such functionality in C#. Thus I'd search for "java decompiler", find sites like

and try to find a command line tool that you can invoke from C#.

Queeg
  • 7,748
  • 1
  • 16
  • 42
  • I downloaded the first link, and it looks pretty good. How would I find a way to run the decompile feature from my program? – The Typholorian Sep 01 '23 at 15:20
  • @TheTypholorian I'd be careful with using JD-Core. That project looks abandoned (no commits on the master branch since Feb 2020, no releases since Dec 2019). That likely means it won't work well with Java code compiled using the latest versions of Java. And my Minecraft (1.20.1) appears to run on Java 17, which was released in 2021, though I don't know if they target Java 17 when compiling. – Slaw Sep 01 '23 at 15:30
  • In that case the fernflower in the other answer might be more appropriate. I do not use decompilers myself. – Queeg Sep 02 '23 at 06:10
0

You can maybe use https://github.com/fesh0r/fernflower and call the jar file as arguement in c# process with class file path

 ProcessStartInfo startInfo = new ProcessStartInfo
    {
        FileName = "java",
        Arguments = $"-jar \"{fernflowerPath}\" \"{classFilePath}\" \"{outputDirectory}\"",
        RedirectStandardOutput = true,
        UseShellExecute = false,
        CreateNoWindow = true
    };

something like this