Hex Help - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4) +---- Forum: Scripting (/forumdisplay.php?fid=39) +----- Thread: Hex Help (/showthread.php?tid=70751) Hex Help by TheGuruSupremacy on 01-16-2007 at 04:20 PM
Hi man, i need help....:I make this function: RE: Hex Help by Matti on 01-16-2007 at 05:04 PM
So, if I understand, you have a string like code:and you need a function which makes it like this: code: If so, this should do: code: RE: RE: Hex Help by TheGuruSupremacy on 01-16-2007 at 05:16 PM
quote: 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; } RE: Hex Help by Plik on 01-16-2007 at 07:28 PM
In what way doesn't it work? RE: Hex Help by phalanxii on 01-17-2007 at 04:15 AM I think he wants a function which takes a string like code:and turns it into code:or by the looks of his code code: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 ). 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: RE: RE: Hex Help by CookieRevised on 01-17-2007 at 05:13 AM
quote: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: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: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: RE: RE: RE: Hex Help by TheGuruSupremacy on 01-17-2007 at 01:51 PM
OK Thank all boys...I'll try to explain what i want better: code: 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: 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 RE: Hex Help by TheGuruSupremacy on 01-17-2007 at 06:06 PM No one can help me???? RE: Hex Help by CookieRevised on 01-17-2007 at 07:00 PM
quote: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... I guess I'll make a new post instead of updating this one then... RE: RE: Hex Help by TheGuruSupremacy on 01-17-2007 at 07:16 PM
quote: 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 RE: Hex Help by CookieRevised on 01-17-2007 at 08:29 PM
quote:I understand, and I already suspected you wanted to do that, but it involves a very good knowledge of ascii, unicode, and how everything is stored in memory. Thus: quote:This is correct as you state it, but do you exactly know what you just stated? Don't get me wrong though, I simply ask this because there can be a lot of confusion if one isn't used to deal with unicode vs. ascii vs. bytes. And as I said earlier it is absolutely vital that you post it in the correct form. eg: "\x45" is not the same as 0x45... "\x45" is 0x45 0x00 "Example" is the same as "\x45\x78\x61\x6D\x70\x6C\x65". So if you meant to show the byte representation of this string with "\x45\x00\x78\x00..." then you got the bytes correct but you posted a totally wrong thing. Because "\x45\x00\x78\x00etc" actually consists of the bytes 0x45 0x00 0x00 0x00 0x78 0x00 0x00 0x00. So you should have said: "I need to return 0x45 0x00 0x78 0x00.". But in that case you got the wrong idea in what needs to be passed to the Patch() function and thus it wouldn't be correct...... Again, I say this because if you thought you needed to pass 0x45 0x00 0x78 0x00 (but used the wrong form in your post), and I said you where correct, then I might teach you the wrong thing. ----------- Anyways, You first need to take the unicode value of each character. This is a number between 0x0000 and 0xFFFF. It is after the high order and after the low order of that number that you need to add the "\x00", because that is what is being ignored by the Patch function since it expects a byte string, aka: a string consisting of only ascii characters from 0x00 to 0xFF. To make it clear with an example: The normal JScript string (thus which is always unicode) "This" has the bytes: 0x54 0x00 0x68 0x00 0x69 0x00 0x73 0x00 But this string, and let's say # is a unicode character: "#This" has the bytes: 0x11 0xEF 0x54 0x00 0x68 0x00 0x69 0x00 0x73 0x00 Notice that the character # does not have a null byte! It takes two bytes to represent a character in a unicode string, and that is also what you need to patch, 2 bytes per character. Thus what you need to pass to the Patch function is not: 0x11 0xEF 0x54 0x00 0x68 0x00 0x69 0x00 0x73 0x00 but 0x11 0x00 0xEF 0x00 0x54 0x00 0x00 0x00 0x68 0x00 0x00 0x00 0x69 0x00 0x00 0x00 0x73 0x00 0x00 0x00 where 0x00 are the added null bytes which will be ignored. This is indeed what your original function intends to do: code:However there are some problems with it which I also already told you in my first reply in this thread though.... You can not simply add a string like "EF" to the string "\x" and expect it to be the string "\xEF". For starters, the Hex() function can return a string of any length (in this case 1 to 4 digits) since characters can be anything from code 0x0 to 0xFFFF... But even if it did always return 2 digits, then "\x" would still be invalid, since \x is not an actual string consisting of the characters '\' and 'x' but an escape command, and the whole escape command must be \x?? where ?? must be a 2 digit hexadecimal number. What SetDataPatch() must do is putting a null byte (0x00) after each byte of the string and that can only be done by manipulating the original string on byte level. To do this forget about using the Hex() function, you don't need that. There are more ways than using the escape command \x?? to add characters to a string. What you need is the function fromCharCode(). First do what the previous posted SetDataPatch() does: get each character of the string one by one and split the unicode code up into the lower order and higher order byte. Then append these bytes (0 to 255) as being new characters to a string. code:Note that fromCharCode() will write a unicode character! Thus if you say fromCharCode(210) it will write actually two bytes: 0xD2 and 0x00. And since we make sure the character code passed to this function is always between 0 and 255, the second byte written will always be 0x00. However, note that all this is a very slow process. To overcome this, I've used ASM in one of my script patches though... anyways... But the most simple solution is to forget the whole SetDataPatch() function and alter the Patch() function. If you have good knowledge of what you actually are doing with all this you would have come to that conclussion already though (just to say again that copy/pasting something isn't good if you don't understand what is being involved). However, this solution has drawbacks because you would only be able to write unicode strings and not byte arrays (without even more dodgy unicode to ascii manipulations). What does Patch() do? The important stuff in that function is the use of the WriteProcessMemory API which does nothing more than writing a passed byte array to memory. A unicode string is just a array of bytes, and this is how simple it gets... So if you want to write an unicode string to memory, then all you need to do is pass the unicode string directly to the WriteProcessMemory API. The reason why the original Patch() function has some string manipulations in it is exactly because strings in JScript are always unicode. And it is very rare to patch only unicode strings so it needs this string manipulation so you can pass byte arrays in a convenient fast way. But if you do want to patch only unicode strings and nothing else, then you don't need those string manipulations at all. This is also explained (without so much words) in the original comments of that function btw... RE: RE: Hex Help by TheGuruSupremacy on 01-17-2007 at 09:35 PM
quote: ok now i have understood how you wanted say me and i'm completely agree.......so sorry if i offended you ---------------------------------------------------------------------- quote: I didn't knew that "\x45" was 0x45 0x00 i though that it was 0x45 and i was confused because i didn't know that unicode was an array of bytes....Thanks now i know it I have understand most of you said(not all cause of my bad knowing of english)tomorrow i read again attentively...However i thank you very much you have always helped me and you'll be credited in my next scripts for it....I have also tried your function and it works perfectly...Thanks again |