Convert REG_MULTI_SZ hex to text

Help with writing and running scripts

Convert REG_MULTI_SZ hex to text

Postby randy_randy » Mon Jun 25, 2007 4:35 pm

In the Registry there are entries with type REG_MULTI_SZ which contain hex values, separated by 00. I wanted to be able to past that into UE and then tell it to convert to text but don't see a function for that. I then thought I could enter it as a hex string in UE and be able to use Ctrl-H to flip from hex view but it assumes I start in text mode and doesn't recognize the string as hex data. Any thoughts on how to get what I want? Here is an example of registry data:

31,00,32,00,33,00,67,00,72,00,65,00,65,00,74,00,69,00,6e,00,67,00,73,00,2e,00,63,00,6f,00,6d,00,00,00

This converts to "123greetings.com"
User avatar
randy_randy
Newbie
 
Posts: 5
Joined: Wed May 03, 2006 11:00 pm

Re: Convert REG_MULTI_SZ hex to text

Postby bobh » Mon Jun 25, 2007 8:19 pm

It's probably just text in 16-bit Unicode format.
User avatar
bobh
Advanced User
Advanced User
 
Posts: 59
Joined: Tue Dec 28, 2004 12:00 am

Re: Convert REG_MULTI_SZ hex to text

Postby jorrasdk » Tue Jun 26, 2007 8:15 am

You don't say which version of UE you use, but if you are a version 13 user, then this simple script might help you:

Code: Select all
iChr = UltraEdit.activeDocument.selection.split(",");
for (i=0;i<iChr.length;i++) {
   if(iChr[i]=="00")
     continue;
   UltraEdit.activeDocument.write( String.fromCharCode(parseInt( iChr[i], 16 )) );
}

Select the hex string in the editor and then invoke the script. Then the hex is converted to text.
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: Convert REG_MULTI_SZ hex to text

Postby randy_randy » Tue Jun 26, 2007 2:21 pm

Wow! Thanks for the script. I have not done almost any of that for UE (I do lots of SQL scripting though :). Would you mind making a tweak to it? My fault - should have pasted a bit more of the string (it is now pasted below).

The data is comma delimited e.g. 2 characters, comma, followed by 00 comma, then 2 more characters, comma, 00 comma etc... There are also backslashes and spaces which can be ignored. I could easily macro a search and replace so the input string was just valid characters and already had each entry on it's own row. In that case, we'd have to keep the line breaks intact.

31,00,32,00,33,00,67,00,72,00,65,00,65,00,74,00,69,00,6e,00,\
67,00,73,00,2e,00,63,00,6f,00,6d,00,00,00,41,00,6c,00,65,00,6d,00,32,00,33,\
00,35,00,38,00,40,00,61,00,6f,00,6c,00,2e,00,63,00,6f,00,6d,00,00,00,42,00,\
65,00,6c,00,6c,00,45,00,78,00,70,00,72,00,65,00,73,00,73,00,56,00,75,00,40,\
00,62,00,65,00,6c,00,6c,00,2e,00,63,00,61,00,00,00,43,00,4e,00,45,00,54,00,\
5f,00,4e,00,65,00,74,00,77,00,6f,00,72,00,6b,00,73,00,5f,00,4d,00,65,00,6d,\
00,62,00,65,00,72,00,5f,00,53,00,65,00,72,00,76,00,69,00,63,00,65,00,73,00,\
40,00,6e,00,65,00,77,00,73,00,6c,00,65,00,74,00,74,00,65,00,72,00,73,00,2e,\
00,6f,00,6e,00,6c,00,69,00,6e,00,65,00,2e,00,63,00,6f,00,6d,00,00,00,44,00,\
50,00,4a,00,6f,00,68,00,6e,00,73,00,74,00,6f,00,6e,00,40,00,73,00,68,00,61,\
00,77,00,2e,00,63,00,61,00,00,00
User avatar
randy_randy
Newbie
 
Posts: 5
Joined: Wed May 03, 2006 11:00 pm

Re: Convert REG_MULTI_SZ hex to text

Postby jorrasdk » Tue Jun 26, 2007 7:24 pm

Ok, I have been tweaking a bit.

Using your exact example - which should be selected (i.e. ctrl+A) - and this script:

Code: Select all
var iLines = UltraEdit.activeDocument.selection; /* get selection - even multi lines are ok */
var iLines = iLines.replace(/[\\ ]/g,""); /* remove spaces and continuation chars */
var iLineArr = iLines.split("\r\n"); /* explode lines into an array */
var chrCount = 0; /* we will ignore every 2nd hex (00) */
var oStr = ""; /* gather output in this */

for (i=0;i<iLineArr.length;i++) { /* run through lines */
   iChr = iLineArr[i].split(","); /* explode single line into array */

   for (j=0;j<iChr.length;j++) {
      if(iChr[j].length==0) { /* just in case */
         continue; /* = skip empty */
      }
      chrCount++; /* hex char counter */
      if(chrCount % 2 == 0) { /* counter modulus 2 */
         continue; /* = skip every 2nd char */
      }

      if(iChr[j]=="00") { /* break at field delimiter */
         oStr = oStr + "\r\n"; /* DOS line terminators: CR LF */
         continue;
      }

      oStr = oStr + String.fromCharCode(parseInt( iChr[j], 16 ));
   }
}
/* write back the text */
UltraEdit.activeDocument.write(oStr);

it will return this output:
Code: Select all
123greetings.com
Alem2358@aol.com
BellExpressVu@bell.ca
CNET_Networks_Member_Services@newsletters.online.com
DPJohnston@shaw.ca

I hope I got the part with line break right, I didn't quite understand this.
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: Convert REG_MULTI_SZ hex to text

Postby Mich » Mon Jun 22, 2009 4:21 am

And is there any function to do the opposite: char to int or char to hexa?
Mich
Newbie
 
Posts: 1
Joined: Fri Jun 19, 2009 6:54 am

Re: Convert REG_MULTI_SZ hex to text

Postby jorrasdk » Mon Jun 22, 2009 4:52 am

Sure, for "char to int" use charCodeAt() method and for "char to hex" use charCodeAt() together to Number.toString().

Example:
Code: Select all
var txt = "j";
UltraEdit.outputWindow.write(txt.charCodeAt(0).toString(16));

Output in the UltraEdit outputWindow will be:

6a
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark


Return to Scripts