What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Unicode string to hex not working

Unicode string to hex not working
Author: Message:
GNSPS
Junior Member
**

Avatar
Coding is man's best friend...

Posts: 40
32 / Male / Flag
Joined: Oct 2006
O.P. Unicode string to hex not working
Why does this:

code:
function SetDataPatch(sUnicodeString) {
    var newstring = "";
    for (var i = 0; i < sUnicodeString.length; i++) {
        var charCode = sUnicodeString.charCodeAt( i );
        newstring += String.fromCharCode(charCode & 0xFF);
        newstring += String.fromCharCode(charCode >>> 8);
    }
    return newstring;
}


Always output the first letter of the unicode string??? Can't figure it out...

Edit: more debuging showed me that the bitwise AND is outputing the charcode itself and the right bit shift is outputing "0".

This post was edited on 08-14-2007 at 01:32 AM by GNSPS.
08-14-2007 01:08 AM
Profile E-Mail PM Find Quote Report
Adeptus
Senior Member
****


Posts: 732
Reputation: 40
Joined: Oct 2005
RE: Unicode string to hex not working
What is this supposed to do?  It may be best if you can post a small sampe of input and desired output.

The title of your post seems to suggest that you want to convert a string to its hexadecimal represenation?  If so, I can see a number of reasons why this won't work.
08-14-2007 02:03 AM
Profile E-Mail PM Find Quote Report
GNSPS
Junior Member
**

Avatar
Coding is man's best friend...

Posts: 40
32 / Male / Flag
Joined: Oct 2006
O.P. RE: Unicode string to hex not working
it's ok... I really wanted to get the unicode string divided into bytes for memory patching... But now I realised that the function splitting is working, what's not working is the 'for' loop... Strange... XD
08-14-2007 02:55 AM
Profile E-Mail PM Find Quote Report
Adeptus
Senior Member
****


Posts: 732
Reputation: 40
Joined: Oct 2005
RE: Unicode string to hex not working
quote:
Originally posted by GNSPS
it's ok... I really wanted to get the unicode string divided into bytes for memory patching... But now I realised that the function splitting is working, what's not working is the 'for' loop... Strange... XD
I suspect the "for" loop is working fine. 

Since all the character codes of the English and Western European alphabets, digits and punctuation are below 255, the behavior you describe -- the bitwise "and" producing a value equal to the character code and the shift producing a zero -- is exactly what I'd expect. 

If you are expecting some other result and still need help with it, please describe what it should be.
08-14-2007 03:34 AM
Profile E-Mail PM Find Quote Report
GNSPS
Junior Member
**

Avatar
Coding is man's best friend...

Posts: 40
32 / Male / Flag
Joined: Oct 2006
O.P. RE: Unicode string to hex not working
Yeah I know that it was the expected behavior of this function, but I don't get why in the end the variable 'newstring' outputs just the first letter of the unicode string... And that's not supposed to happen! :P
08-14-2007 11:59 AM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Unicode string to hex not working
Well, String.fromCharCode(0) would give you a null-character, and a null-character means the end of a string. So, if you trace the result, the debugger will only show the first letter. If you try to send a Unicode-only character to the function (e.g. "€"), it'll give you "¬ " as output.

I don't get the purpose of this function, so I can't really help you with it.

This post was edited on 08-14-2007 at 12:44 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
08-14-2007 12:40 PM
Profile E-Mail PM Web Find Quote Report
GNSPS
Junior Member
**

Avatar
Coding is man's best friend...

Posts: 40
32 / Male / Flag
Joined: Oct 2006
O.P. RE: Unicode string to hex not working
but i don't get it then, this function is made by CookieRevised and it worked in the beginning... Now it's not working... it was supposed to add to the "newstring" string the first high order byte and then the low order one of the char... "sigh" is equal to this:" 0x73 0x00 0x69 0x00 0x67 0x00 0x68 0x00 " or this:" \x73\x69\x67\x68" and that's why the every char of the string is being divided into the high order byte and low order one (which should be the 0x00 part of the byte string not the terminating character XD). Did you get it already? But thanks for explaining me why the 'newstring' was always the first letter of the unicode string, I hadn't thought about it.
08-14-2007 01:09 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Unicode string to hex not working
In that case, I think you should just drop the String.fromCharCode(). It'll convert your number into a character, and since you want numbers you just have to leave them out, no?

But if you want the high-order byte first, you'll need to swap the two around, because at the moment the low-order is first.
code:
function SetDataPatch(sUnicodeString) {
    var newstring = "";
    for (var i = 0; i < sUnicodeString.length; i++) {
        var charCode = sUnicodeString.charCodeAt( i );
        newstring += charCode >>> 8; //High-order
        newstring += charCode & 0xFF; //Low-order
    }
    return newstring;
}
But this functions will only join the decimal numbers together... Do you want spaces between the numbers? Do you want the numbers to be hexadecimal? You really should give us a clear explanation of what your function has to do.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
08-14-2007 03:33 PM
Profile E-Mail PM Web Find Quote Report
GNSPS
Junior Member
**

Avatar
Coding is man's best friend...

Posts: 40
32 / Male / Flag
Joined: Oct 2006
O.P. RE: Unicode string to hex not working
I got the answer to my problem it appears that WLM 8.5 changes the font address in memory everytime it runs... =S And so it can't be patched so the problem wasn't the funtion at all was the address I was supplying to the WriteProcessMemory function xD Thanks for your great help anyway Mattike!

Edit: Does anyone know if WLM has now got the address protected with DMA? Kind of strange isn't it?

This post was edited on 08-14-2007 at 09:37 PM by GNSPS.
08-14-2007 08:14 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


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