Number conversion feature or plugin
-
@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 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.
-
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.
That will help some, though it doesn’t help with a string of characters of numbers, which is usually what I’m doing.
-
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.
-
@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, 102I 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 hrefA 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.
-
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:
and then run the script and it will prompt you thusly:
Type
D
(ord
works too) and click OK and it will change the selected text to: -
-
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. -
@Alan-Kilborn Pretty nice. Thanks for working on this. That will be helpful.
-
@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.