• Login
Community
  • Login

Number conversion feature or plugin

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
13 Posts 4 Posters 8.5k Views
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.
  • M
    mylittleplaceholder @William-Abbot
    last edited by Aug 4, 2022, 4:42 PM

    @William-Abbot The conversion panel for me has ASCII and Decimal and just converts back and forth between a single ASCII character and its ASC value. I have NPP Converter v4.4. Does a different version have other number bases or is there a different converter?

    Thank you.

    P 1 Reply Last reply Aug 4, 2022, 4:46 PM Reply Quote 0
    • P
      PeterJones @mylittleplaceholder
      last edited by PeterJones Aug 4, 2022, 4:49 PM Aug 4, 2022, 4:46 PM

      @mylittleplaceholder

      58c8a91d-3272-46d6-a2b6-84205f965700-image.png

      37bf2213-ca5b-4530-9017-3026af224dd6-image.png

      M 1 Reply Last reply Aug 4, 2022, 4:57 PM Reply Quote 1
      • M
        mylittleplaceholder @PeterJones
        last edited by Aug 4, 2022, 4:51 PM

        @PeterJones Thank you, that’s very helpful. I run perl under Cygwin, but I can probably get that to work or install a native exe.

        Is there a way to define different named and predefined “run” functions under a menu, so I could do “convert to decimal,” “convert to hex,” etc.? Also is it possible to paste it in automatically to replace the selection (not that hitting ^V is all that hard, just wondering).

        Thanks.

        1 Reply Last reply Reply Quote 0
        • M
          mylittleplaceholder @PeterJones
          last edited by Aug 4, 2022, 4:57 PM

          Haha, my popup window for that opens as a small area and I never thought to stretch it open! It didn’t look resizable to me. Thanks.

          conversion.png

          That will help some, though it doesn’t help with a string of characters of numbers, which is usually what I’m doing.

          A 1 Reply Last reply Aug 4, 2022, 5:03 PM Reply Quote 0
          • A
            Alan Kilborn @mylittleplaceholder
            last edited by PeterJones Aug 4, 2022, 5:46 PM Aug 4, 2022, 5:03 PM

            @mylittleplaceholder

            If you give a real solid example of what you want to do, it can be scripted more formally in Notepad++ with a scripting plugin. Pretty much anything would be possible, overcoming all of the limitations you’ve discussed.

            M 1 Reply Last reply Aug 4, 2022, 6:23 PM Reply Quote 0
            • M
              mylittleplaceholder @Alan Kilborn
              last edited by Aug 4, 2022, 6:23 PM

              @Alan-Kilborn Thank you.

              I usually use these conversions when reverse engineering malicious emails or broken websites and related things when I don’t want to drop to writing a script to analyze it. Most of the functions (e.g., b64, html, or URL encoding/decoding) are in Notepad++, so I can get pretty far with deobfuscating them just by looking at the source there.

              An example is a script containing:
              60, 97, 32, 104, 114, 101, 102

              I can convert that to hex and then ASCII. Converting directly to ASCII would be helpful, but really just converting it to hex and back would really be all I’d need.

              3C 61 20 68 72 65 66
              <a href

              A technique I’ve used in the past is use a regex to convert to HTML entities
              <a href
              and then use TextFX “Strip HTML Tags” to convert to ASCII.

              It’s just faster than trying to reverse it in JS or Perl.

              A 1 Reply Last reply Aug 4, 2022, 7:38 PM Reply Quote 0
              • A
                Alan Kilborn @mylittleplaceholder
                last edited by Alan Kilborn Aug 4, 2022, 7:39 PM Aug 4, 2022, 7:38 PM

                @mylittleplaceholder

                So here’s a little PythonScript demo’ing some capability:

                # -*- coding: utf-8 -*-
                from __future__ import print_function
                
                # references:
                #  https://community.notepad-plus-plus.org/topic/23341/number-conversion-feature-or-plugin
                
                from Npp import *
                import inspect
                import os
                
                #-------------------------------------------------------------------------------
                
                class T23341(object):
                
                    def __init__(self):
                        self.this_script_name = inspect.getframeinfo(inspect.currentframe()).filename.split(os.sep)[-1].rsplit('.', 1)[0]
                        sel_start = editor.getSelectionStart()
                        sel_end = editor.getSelectionEnd()
                        if sel_start != sel_end:
                            while True:
                                user_input = self.prompt('Enter D if numbers are currently in decimal; H if hex')
                                if user_input == None: return  # user cancel
                                if user_input in [ 'H', 'h' ]:
                                    self.to_hex = False
                                    break
                                if user_input in [ 'D', 'd' ]:
                                    self.to_hex = True
                                    break
                            doc_len_start = editor.getLength()
                            editor.rereplace(r'\b[0-9]+\b' if self.to_hex else r'\b[0-9A-F]+\b', lambda m: self.replace_function(m), 0, sel_start, sel_end)
                            len_delta = editor.getLength() - doc_len_start
                            editor.setSelection(sel_end + len_delta, sel_start)
                
                    def replace_function(self, m):
                        fmt = '{:X}' if self.to_hex else '{}'
                        return fmt.format(int(m.group(0), 10 if self.to_hex else 16))
                
                    def prompt(self, prompt_text, default_text=''):
                        if '\n' not in prompt_text: prompt_text = '\r\n' + prompt_text
                        prompt_text += ':'
                        return notepad.prompt(prompt_text, self.this_script_name, default_text)
                
                #-------------------------------------------------------------------------------
                
                if __name__ == '__main__': T23341()
                

                Before running the script, select some text, maybe like so:

                2d232801-23d5-46ef-8f65-ca577100b79c-image.png

                and then run the script and it will prompt you thusly:

                6592fefe-e7e6-4c53-a5c1-0dda2743103c-image.png

                Type D (or d works too) and click OK and it will change the selected text to:

                36bd902b-fd7b-4ebc-944b-811e05dd7909-image.png

                A M 2 Replies Last reply Aug 5, 2022, 12:31 PM Reply Quote 3
                • A Alan Kilborn referenced this topic on Aug 4, 2022, 7:38 PM
                • A
                  Alan Kilborn @Alan Kilborn
                  last edited by Aug 5, 2022, 12:31 PM

                  and then run the script and it will prompt you…

                  If you’re wondering why the prompting is needed, let me point out that all of the numbers in 60, 97, 32, ... are equally valid decimal OR hexadecimal, so the script has to be told what to do.

                  M 1 Reply Last reply Aug 12, 2022, 5:00 PM Reply Quote 0
                  • M
                    mylittleplaceholder @Alan Kilborn
                    last edited by Aug 12, 2022, 4:50 PM

                    @Alan-Kilborn Pretty nice. Thanks for working on this. That will be helpful.

                    1 Reply Last reply Reply Quote 1
                    • M
                      mylittleplaceholder @Alan Kilborn
                      last edited by Aug 12, 2022, 5:00 PM

                      @Alan-Kilborn I think I’ll duplicate it and make “hex to decimal.py” and “decimal to hex.py” to skip the dialog. Very helpful.

                      1 Reply Last reply Reply Quote 2
                      • First post
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors