Community

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

    Number conversion feature or plugin

    Help wanted · · · – – – · · ·
    4
    13
    1429
    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.
    • mylittleplaceholder
      mylittleplaceholder @William-Abbot last edited by

      @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.

      PeterJones 1 Reply Last reply Reply Quote 0
      • PeterJones
        PeterJones @mylittleplaceholder last edited by PeterJones

        @mylittleplaceholder

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

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

        mylittleplaceholder 1 Reply Last reply Reply Quote 1
        • mylittleplaceholder
          mylittleplaceholder @PeterJones last edited by

          @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
          • mylittleplaceholder
            mylittleplaceholder @PeterJones last edited by

            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.

            Alan Kilborn 1 Reply Last reply Reply Quote 0
            • Alan Kilborn
              Alan Kilborn @mylittleplaceholder last edited by PeterJones

              @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.

              mylittleplaceholder 1 Reply Last reply Reply Quote 0
              • mylittleplaceholder
                mylittleplaceholder @Alan Kilborn last edited by

                @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.

                Alan Kilborn 1 Reply Last reply Reply Quote 0
                • Alan Kilborn
                  Alan Kilborn @mylittleplaceholder last edited by Alan Kilborn

                  @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

                  Alan Kilborn mylittleplaceholder 2 Replies Last reply Reply Quote 3
                  • Referenced by  Alan Kilborn Alan Kilborn 
                  • Alan Kilborn
                    Alan Kilborn @Alan Kilborn last edited by

                    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.

                    mylittleplaceholder 1 Reply Last reply Reply Quote 0
                    • mylittleplaceholder
                      mylittleplaceholder @Alan Kilborn last edited by

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

                      1 Reply Last reply Reply Quote 1
                      • mylittleplaceholder
                        mylittleplaceholder @Alan Kilborn last edited by

                        @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
                        Copyright © 2014 NodeBB Forums | Contributors