Convert REG_MULTI_SZ hex to text

Convert REG_MULTI_SZ hex to text

5

    Jun 25, 2007#1

    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"

    61
    Advanced UserAdvanced User
    61

      Jun 26, 2007#2

      It's probably just text in 16-bit Unicode format.

      262
      MasterMaster
      262

        Jun 26, 2007#3

        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.

        5

          Jun 26, 2007#4

          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

          262
          MasterMaster
          262

            Jun 27, 2007#5

            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: I hope I got the part with line break right, I didn't quite understand this.

            1
            NewbieNewbie
            1

              Jun 22, 2009#6

              And is there any function to do the opposite: char to int or char to hexa?

              262
              MasterMaster
              262

                Jun 22, 2009#7

                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