Community
    • Login

    Can you add java .class file decompiler plugin?

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    3 Posts 3 Posters 4.4k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Get ExpertG Offline
      Get Expert
      last edited by

      Can you add java .class file decompiler plugin?

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP Offline
        PeterJones @Get Expert
        last edited by

        @Get-Expert ,

        The Notepad++ application developer doesn’t develop most of the plugins – he leaves it up to other people to develop plugins that they are interested in.

        That said, “decompilers” are rather complicated applications on their own, and there’s no good reason to embed one as a “plugin” to a text editor. Find some external decompiler (if such a creature exists for a java .class), run it to produce the reverse-engineered source code, and open that resulting text-based file in Notepad++. I cannot see how having a plugin do it would make the process any easier than the two-step process I just described.

        rdipardoR 1 Reply Last reply Reply Quote 1
        • rdipardoR Offline
          rdipardo @PeterJones
          last edited by

          if such a creature exists for a java .class

          Several, in fact: https://www.libhunt.com/l/java/topic/decompiler

          I cannot see how having a plugin do it would make the process any easier

          Maybe a script instead?

          # -*- coding: utf-8 -*-
          
          from __future__ import print_function # for py 2.7
          import sys
          import subprocess
          import tempfile
          from os import path
          from Npp import notepad
          
          
          """
           Shells out to the Procyon decompiler and opens the generated source in Notepad++
           https://github.com/mstrobel/procyon/wiki/Java-Decompiler
          
           ASSUMPTIONS
           -----------
           1. a JAVA_HOME environment variable is set, or the path to java.exe is on the PATH
           2. procyon.jar is on the class path; otherwise provide the absolute path,
              e.g., r'C:\java\tools\procyon\0.5.36\procyon.jar'
          """
          def show_decompiled():
              try:
                  binary = notepad.prompt('File path to the compiled class/jar:', 'Java Decompiler Script', 'Hello.class')
                  if binary is None:
                      # assume current file is a Java source file that's been compiled *in situ*
                      binary = path.splitext(notepad.getCurrentFilename())[0] + '.class'
                  elif not path.exists(binary):
                      raise IOError('Can''t find class/jar "%s"!' % binary)
          
                  CMD = [
                      'java',
                      '-jar',
                      'procyon.jar',
                      '-dl', # debug line numbers
                      binary
                  ]
          
                  if subprocess.check_call(CMD, shell=True) == 0:
                      decompiled = subprocess.check_output(CMD, shell=True).decode('utf-8')
                      _, java_src =  tempfile.mkstemp(suffix='.java', text=True)
                      if java_src:
                          with open(java_src, 'w') as file:
                              file.write(decompiled)
          
                          notepad.open(java_src)
          
              except (subprocess.CalledProcessError, IOError) as exc:
                  notepad.messageBox(str(exc), 'Java Decompiler Script')
                  print(exc, file=sys.stderr)
          
          
          if __name__ == '__main__':
              show_decompiled()
          

          jdecomp-py-select
          jdecomp-py-enter
          jdecomp-py-profit

          1 Reply Last reply Reply Quote 2

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors