Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Can you add java .class file decompiler plugin?

    Plugin Development
    3
    3
    551
    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 Expert
      Get Expert last edited by

      Can you add java .class file decompiler plugin?

      PeterJones 1 Reply Last reply Reply Quote 0
      • PeterJones
        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.

        R 1 Reply Last reply Reply Quote 1
        • R
          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
          • First post
            Last post
          Copyright © 2014 NodeBB Forums | Contributors