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

Pages: (2): « First [ 1 ] 2 » Last »
Hex Help
Author: Message:
TheGuruSupremacy
Full Member
***

Avatar

Posts: 367
Reputation: 19
34 / Male / Flag
Joined: Nov 2006
O.P. Hex Help
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

This post was edited on 01-16-2007 at 04:23 PM by TheGuruSupremacy.
01-16-2007 04:20 PM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Hex Help
So, if I understand, you have a string like
code:
var thing = "FF00FC";
and you need a function which makes it like this:
code:
var new_thing = "\xFF\x00\xFC";

If so, this should do:
code:
function SetDataPatch(string) {
  var newstring = "";
  for(var i=0; i<string.length; i+=2) {
    var hex = string.substr(i, 2); //The hexadecimal character code
    var dec = parseInt(hex, 16); //The decimal character code
    newstring += String.fromCharCode(dec); //Adds the character to the string
  }
  return newstring;
}

This post was edited on 01-16-2007 at 05:04 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!
01-16-2007 05:04 PM
Profile E-Mail PM Web Find Quote Report
TheGuruSupremacy
Full Member
***

Avatar

Posts: 367
Reputation: 19
34 / Male / Flag
Joined: Nov 2006
O.P. RE: RE: Hex Help
quote:
Originally posted by Mattike
So, if I understand, you have a string like
code:
var thing = "FF00FC";
and you need a function which makes it like this:
code:
var new_thing = "\xFF\x00\xFC";

If so, this should do:
code:
function SetDataPatch(string) {
  var newstring = "";
  for(var i=0; i<string.length; i+=2) {
    var hex = string.substr(i, 2); //The hexadecimal character code
    var dec = parseInt(hex, 16); //The decimal character code
    newstring += String.fromCharCode(dec); //Adds the character to the string
  }
  return newstring;
}


I thank you but this code for me don't work

function SetDataPatch(string) {
  var newstring = "";
    for(var i=0; i<string.length; i+=2) {
    var hex = string.substr(i, 2); //The hexadecimal character code
    var dec = parseInt(hex, 16); //The decimal character code
    newstring += String.fromCharCode(dec); //Adds the character to the string
  }
  Debug.Trace(newstring)
  return newstring;
}
01-16-2007 05:16 PM
Profile PM Find Quote Report
Plik
Veteran Member
*****

Avatar

Posts: 1489
Reputation: 46
35 / Male / –
Joined: Jun 2004
RE: Hex Help
In what way doesn't it work?
Because it works fine here :-/
01-16-2007 07:28 PM
Profile PM Find Quote Report
phalanxii
Full Member
***


Posts: 146
Reputation: 5
32 / Male / Flag
Joined: Aug 2006
Status: Away
RE: Hex Help
I think he wants a function which takes a string like
code:
var string = "ÿü"
and turns it into
code:
var newstring = "\xFF\x00\xFC"
or by the looks of his code
code:
var newstring = "\xFF\x00\xFC\x00"
In other words, he wants to take each character in the string, turn them into the hex unicode notation ("\x__"), insert "\x00" between each character and return the whole thing as a string. For example, SetDataPatch("abc") will return "\x61\x62\x62".

As far as I know, a function like this is completely useless because "a" === "\x61" (someone correct me on this one ^o)). 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;
}

This post was edited on 01-17-2007 at 04:20 AM by phalanxii.
01-17-2007 04:15 AM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
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
TheGuruSupremacy
Full Member
***

Avatar

Posts: 367
Reputation: 19
34 / Male / Flag
Joined: Nov 2006
O.P. RE: RE: RE: Hex Help
OK Thank all boys...I'll try to explain what i want better:
Well...this is the code I used:


code:
function Hex(number) {return number.toString(16).toUpperCase()}//function by CookieRevised

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


function Patch(nAddress, sByteString) {
    var sBuffer = Interop.Allocate(++sByteString.length);
    for (var j = 0; j < sByteString.length; j++) sBuffer.WriteWORD(j, sByteString.charCodeAt(j));
    var hProc = Interop.Call("Kernel32", "GetCurrentProcess");
    Interop.Call("Kernel32", "WriteProcessMemory", hProc, nAddress, sBuffer.DataPtr, sByteString.length, 0);
}//Function By CookieRevised


i need to make a function that return in hex the bytes that i have to write in memory but i don't know i have to do it...example

if i used this code

This code:

code:
Patch(0x5F6D5C,"\x00\xFF\xFC")

it works perfectly

but i need to make the sByteString because it is not the constant and the data i have to write memory is an unicode string so i add to my function + "\x00"....for example if i pass to SetPatchData funtion this string "Example" i need to return

"\x45\x00\x78\x00\x61\x00\x6D\x00\x70\x00\x6C\x00\x65\x00"

that then i pass to Patch function.....if i use "\\x" instead "\x" don't work because the data that return is not in hex...

I hope that you understand me....

Thanks in advice and sorry for my english

This post was edited on 01-17-2007 at 01:52 PM by TheGuruSupremacy.
01-17-2007 01:51 PM
Profile PM Find Quote Report
TheGuruSupremacy
Full Member
***

Avatar

Posts: 367
Reputation: 19
34 / Male / Flag
Joined: Nov 2006
O.P. RE: Hex Help
No one can help me????
01-17-2007 06:06 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Hex Help
quote:
Originally posted by TheGuruSupremacy
No one can help me????
yes we can, but be patient please... In the mean time I very strongly suggest you read up on what strings are, how they are represented in memory and the differences between unicode, ascii and byte string and/or byte arrays. You'll really need this knowledge to understand everything involved. Otherwise, you just be copy/pasting code without knowing what you actually do.

This post will be updated when I finished writing my reply...
So no need to reply to this one either


;)




EDIT: read underlined part... ^o)
I guess I'll make a new post instead of updating this one then...:S

This post was edited on 01-17-2007 at 08:34 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-17-2007 07:00 PM
Profile PM Find Quote Report
TheGuruSupremacy
Full Member
***

Avatar

Posts: 367
Reputation: 19
34 / Male / Flag
Joined: Nov 2006
O.P. RE: RE: Hex Help
quote:
Originally posted by CookieRevised
quote:
Originally posted by TheGuruSupremacy
No one can help me????
yes we can, but be patient please... In the mean time I very strongly suggest you read up on what strings are, how they are represented in memory and the differences between unicode, ascii and byte string and/or byte arrays. You'll really need this knowledge to understand everything involved. Otherwise, you just be copy/pasting code without knowing what you actually do.

This post will be updated when I finished writing my reply...
So no need to reply to this one either

;)



i don't know how represent in memory with jscript the different strings
...if i had known it i would have not to post for help......I'm searching on google how to do it but i didn't find anything...(probably because I not spend too time)....Before posting i always trying to resolve my problems myself and if i can't to do it i'll post for help so i'll be patient but please don't tell me that i ask for help without knowing what i actually do....it's offensive....bye

This post was edited on 01-17-2007 at 07:17 PM by TheGuruSupremacy.
01-17-2007 07:16 PM
Profile PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« 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