Sign in to follow this  
Followers 0
huyit

Porblem with converter hex and number

5 posts in this topic

I have the packet received from the server through win.httprequest .

I use charles to view the message .

The response code when i view with hex code in charles

Hex code : 75 69 64 00 41 07 47 90

Text code : uid A G

The response code when i view with AMF RPC or AMF in charles

Name Type

Uid Number 190706

Posted Image

How can i convert from hex code to the number .

one more question . How can i convert the responseBody to the Object like this enclose image .

Share this post


Link to post
Share on other sites



Hi huyit,

It's not clear to me what you want to achieve, but you might want to try the folowing two functions:

Dec() => Converts a hex to decimal

BinaryToString() => Converts a binary variant to a string.


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

Try this:

#include <String.au3>
$hex_code = "7569640041074790"
$hex2string = _HexToString($hex_code)
MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$hex2string' & @lf & @lf & 'Return:' & @lf & $hex2string) ;### Debug MSGBOX
$bin2string = BinaryToString("0x" & $hex_code)
MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$bin2string' & @lf & @lf & 'Return:' & @lf & $bin2string) ;### Debug MSGBOX

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Try this:

#include <String.au3>
$hex_code = "7569640041074790"
$hex2string = _HexToString($hex_code)
MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$hex2string' & @lf & @lf & 'Return:' & @lf & $hex2string) ;### Debug MSGBOX
$bin2string = BinaryToString("0x" & $hex_code)
MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$bin2string' & @lf & @lf & 'Return:' & @lf & $bin2string) ;### Debug MSGBOX

Br,

UEZ

Thanks for help .

But this code does not work . It just show "uid" and not display the number i need .

Share this post


Link to post
Share on other sites

Hi huyit,

It's not clear to me what you want to achieve, but you might want to try the folowing two functions:

Dec() => Converts a hex to decimal

BinaryToString() => Converts a binary variant to a string.

Thanks , i have tried . But the result is not match .

My program send the the request to server from client . I use win.httprequest

I have sended successfully . And the result is string binary , it content many character null , etx , soh ... etc

I want to extract the data for my purpose . But i have some problem with the convert .

I have tried many way to convert . But the result i convert , it not match with the result in charles .

THis is my code

#include<string.au3>

#include <file.au3>

Global $zauth , $response

dim $NULL=0x00 , $SOH=0x01,$ETX=0x03,$STX=0x02,$DLE=0x10,$CAN=0x18,$BS=0x10

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")

Func login($u,$p)

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")

$url="https://loginme.zing.vn/login/act"

$oHTTP.Open('POST',$url,True)

initHeader($oHTTP)

$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

$data="u=" & $u & "&pp=" & $p

$oHTTP.Send($data)

$response = $oHTTP.responseBody

$k=$oHTTP.getallresponseheaders

$zauth=getZauth($k)

;~ ConsoleWrite($k)

EndFunc

Func getZauth($str)

$start = StringInStr($str, 'Set-Cookie: ZAUTH=',1,2) + StringLen("Set-Cookie: ZAUTH=")

$end = StringInStr($str, ';', 0, 1, $start)

$size = StringMid($str, $start, $end - $start)

return $size

EndFunc

Func initHeader($oHTTP)

$oHTTP.SetRequestHeader("Acept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")

$oHTTP.SetRequestHeader("Acept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")

$oHTTP.SetRequestHeader("Accept-Language", "en-us,en;q=0.5")

$oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10")

$oHTTP.SetRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")

$oHTTP.SetRequestHeader("Keep-Alive", "115")

EndFunc

Func getFriendList()

$id="28272366"

$oHTTP.Open('GET','http://me.zing.vn/apps/ntvv2')

initHeader($oHTTP)

$oHTTP.Send()

$response = $oHTTP.Responsetext

;~ $data=Chr($NULL)&Chr($ETX)&Chr($NULL)&Chr($NULL)&Chr($NULL)&Chr($SOH)&Chr($NULL)&Chr($DLE)&'Service.proccess'&Chr($NULL)&Chr($STX)&'/1'&Chr($NULL)&Chr($NULL)&Chr($NULL)&'Q'&@CRLF&Chr($NULL)&Chr($NULL)&Chr($NULL)&Chr($ETX)&Chr($STX)&'#[{"fT":2,"method":"getFriendList"}]'&Chr($STX)&Chr($NULL)&Chr($CAN)&$zauth&Chr($STX)&Chr($NULL)&Chr($BS)&$id

$data="0003000000010010536572766963652e70726f636365737300022f31000000510a000000030200235b7b226654223a322c226d6574686f64223a22676574467269656e644c697374227d5d020018"&_StringToHex($zauth)&"020008"&_StringToHex($id)

$test=_HexToString($data)

$oHTTP.Open('POST',"http://friends-ntvv2.apps.zing.vn/3in1/amf/gateway")

initHeader($oHTTP)

$oHTTP.SetRequestHeader("Content-Type", "application/x-amf")

$oHTTP.Send(StringToBinary($test))

$response = $oHTTP.responseBody

EndFunc

Func writeFile($filename,$data)

$filew=FileOpen($filename,1)

if $filew = -1 then

ConsoleWrite("open file fail")

Return

EndIf

FileWrite($filew,$data)

FileClose($filew)

Return

EndFunc

Func _HexToDecimal($hx_hex)

If StringLeft($hx_hex, 2) = "0x" Then $hx_hex = StringMid($hx_hex, 3)

If StringIsXDigit($hx_hex) = 0 Then

SetError(1)

MsgBox(0,"Error","Wrong input, try again ...")

Return ""

EndIf

Local $ret="", $hx_count=0, $hx_array = StringSplit($hx_hex, ""), $Ii, $hx_tmp

For $Ii = $hx_array[0] To 1 Step -1

$hx_tmp = StringInStr($HX_REF, $hx_array[$Ii]) - 1

$ret += $hx_tmp * 16 ^ $hx_count

$hx_count += 1

Next

Return $ret

EndFunc

Func BinToDec($binary)

Local $len = 1, $dec = 0, $decimal = 0

While $len < StringLen($binary)+1

$dec = StringMid($binary, $len, 1)

For $i = 1 To (StringLen($binary)-$len)

$dec *= 2

Next

$decimal += $dec

$len += 1

WEnd

Return $decimal

EndFunc

;~ main program

login("quanthatno1","12121988");~ can use for test

getFriendList()

writeFile("D:/huy/study/autoit/data",$response);~ i write the data to file , you can create the file name for test

ConsoleWrite($response)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0