What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Hex Help

Hex Help
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: Hex Help
quote:
Originally posted by TheGuruSupremacy
Hi man, i need help....:I make this function:

function SetDataPatch(string){
var newstring =""
for (var i=0;i<string.length;i++){
newstring += "\x" + Hex(string.charCodeAt( i)) + "\x00"}
Debug.Trace(newstring)
return newstring}}

but plus found this error,this is in italian but i'll try to translate it in english:

Lo script è stato fermato(the script has been stopped)
Errore: Prevista cifra esadecimale.(Error: expect digit hex)
       Linea: 43 Codice: -2146827265(line:43 Code: -2146827265)

i need to make a string like this "\xFF\x00\xFC" CAN SOMEONE HELP ME PLEASE??? Sorry for my english

The error is because the function Hex doesn't exist in JScript. And if you've made your own Hex function then note that "\x" must always be followed by a 2 digit hexadecimal number.
Thus "\xE" will not work either, it must be "\x0E".

PS: If you get such errors, try to split up the line which caused the error to see what part exactly triggered it...

Anyways, even if Hex existed and it does always return a 2 digit number, your function wouldn't work in all cases either though, see below.

Also "\x00" will make a string with the ascii code character 0, not a string which will display \x00. The "\" character is an escape character, meaning it has special function if used inside a string (like defining a character by its hexadecimal code). To show the slash ("\") you must escape it with the escape character, thus "\\".

quote:
Originally posted by phalanxii
As far as I know, a function like this is completely useless because "a" === "\x61" (someone correct me on this one ^o)).
Not always (it would only be useless in option a, see below).

Seeing the function name ("patch") I suspect he wants to add null characters between the original characters (thus option b, see below). In other words convert a string to its unicode counterpart. Or to put in in context with JScript: to convert a unicode string to double unicode notation...

eg: to convert the this byte data
    FF 00 0A 00 0E 14
to
    FF 00 00 00 0A 00 00 00 0E 00 14 00
where 00 are the added bytes

This could be usefull for patching and other related stuff...



--------------------------



However, TheGuruSupremacy,

Always specify exactly and in detail what you want and what the purpose of the function is when you request help. As you see above, the solution highly depends on what you exactly want with that function. Be very specific and give clear examples.

In situation likes this, it is even recommended to show the entire script so people can clearly see what the purpose it.

Since this function deals with unicode, ascii code, string literals, screen outputs, etc, it is very important to state clearly what is what.

eg: assuming the input string contains the two characters 0xFF and 0xFC (you didn't specify this either), when you say "i need to make a string like this "\xFF\x00\xFC" ", then what do you mean by 'string':

a) Do you mean a 2 character long string containing the unicode characters FF and FC

b) Do you mean a 4 character long string containing the characters FF, 00, FC and 00

c) Do you mean you want a 'string' which would literally display \xFF\x00\xFC\x00



To helpers: Try not to guess. If you aren't sure what is requested ask details and examples first ;)



--------------------------



For now I assume that phalanxii guessed correctly and that you want to show literally the hexadecimal codes which make up a string, thus option c:

quote:
Originally posted by phalanxii
However, if the function is to give "\\xFF\\x00\\xFC\\x00" (which will display as "\xFF\x00\xFC\x00" to the user), you can use this:
code:
function SetDataPatch(string) {
   var newstring = "";
   for(var i = 0; i < string.length; i++) {
      newstring += "\\x" + string.charCodeAt(i).toString(16) + "\\x00";
   }
   Debug.Trace(newstring);
   return newstring;
}

But don't assume the characters in the string are always between ASCII 0 and 255, they can be anything from 0 to 65535. In other words they are always unicode.

Thus charCodeAt(i) can return anything from 0 to 65535.

This means that you should never just add "\x00" to the string.

Thus, toString(16) will not always return a 2 digit hexadecimal number, it might just be 1 digit or even up to 4 digits (and it will always be lowercased). This also means that in the case of 1 digit the function will fail too (see reply to TheGuruSupremacy above).

The fixed function:
code:
function SetDataPatch(string) {
    var newstring = "";
    for (var i = 0; i < string.length; i++) {
        // Get character and convert to hexadecimal

        var charHexcode = string.charCodeAt(i).toString(16).toUpperCase();
        // Since hexcode can be anything from 1 to 4 digits long
        // we need to properly format it by adding 0's.
        charHexcode = ("000" + charHexcode).substr(charHexcode.length-1);
        // The least significant part (last 2 digits) is the
        // first part to return in LE (little endian) format
        newstring += "\\x" + charHexcode.substr(2);
        // The most significant part (first 2 digits) is the
        // last part to return in LE (little endian) format
        newstring += "\\x" + charHexcode.substring(0, 2);
    }
    Debug.Trace(newstring);
    return newstring;
}

This post was edited on 01-17-2007 at 06:12 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-17-2007 05:13 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Hex Help - by TheGuruSupremacy on 01-16-2007 at 04:20 PM
RE: Hex Help - by Matti on 01-16-2007 at 05:04 PM
RE: RE: Hex Help - by TheGuruSupremacy on 01-16-2007 at 05:16 PM
RE: Hex Help - by Plik on 01-16-2007 at 07:28 PM
RE: Hex Help - by phalanxii on 01-17-2007 at 04:15 AM
RE: RE: Hex Help - by CookieRevised on 01-17-2007 at 05:13 AM
RE: RE: RE: Hex Help - by TheGuruSupremacy on 01-17-2007 at 01:51 PM
RE: Hex Help - by TheGuruSupremacy on 01-17-2007 at 06:06 PM
RE: Hex Help - by CookieRevised on 01-17-2007 at 07:00 PM
RE: RE: Hex Help - by TheGuruSupremacy on 01-17-2007 at 07:16 PM
RE: Hex Help - by CookieRevised on 01-17-2007 at 08:29 PM
RE: RE: Hex Help - by TheGuruSupremacy on 01-17-2007 at 09:35 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On