Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   Communications (http://www.xtremevbtalk.com/communications/)
-   -   Byte conversion? (http://www.xtremevbtalk.com/communications/327901-byte-conversion.html)

Jmann84 11-01-2015 03:47 AM

Byte conversion?
 
Ok I'm not really sure if I am even approaching this issue correctly as I am not 100% sure what I am dealing with in my project but I will do my best to explain.

I am working on an RTMP client project. There is one packet that I send to the server containing a unique ID. There are multiple unique ID's and the returned packet has what appears to be the unique ID put into a byte array.

Here is the outgoing packet I am sending:

Send: Return Code: 0x00000000
00000000 83 00 0B 5C 02 00 07 61 63 63 6F 75 6E 74 00 00 ...\...account..
00000010 00 00 00 00 00 00 00 05 02 00 05 34 38 32 37 32 ...........48272

and here is the incoming packet I receive back from the server:

Receive: Return Code: 0x00000000
00000000 C3 02 00 07 61 63 63 6F 75 6E 74 00 00 00 00 00 ....account.....
00000010 00 00 00 00 05 03 00 07 61 63 63 6F 75 6E 74 02 ........account.
00000020 00 09 6B 75 73 68 69 73 66 69 67 00 02 69 64 00 ..kushisfig..id.
00000030 40 E7 92 00 00 00 00 00 00 00 09 @..........

Now "kushisfig" is the account that corresponds to the unique ID "48272" that I have sent in the first packet.

What I need to do is read the "id" at the end of the packet to know what ID that account belongs to, but I am not really that familiar with byte arrays in VB6.

Any help would be greatly appreciated as I've been wracking my brain over here for hours.

dilettante 11-01-2015 05:06 AM

You can use the MidB$() function on the array to extract a substring, then convert that to Unicode. To do this the offset will be a 1-based value, so keep that in mind.

You can also use InStrB() if necessary to search for the ending NUL to get the length to extract.


The real question is why are you using VB6 if you don't know VB6? It is not legally available for free and expensive to acquire legitimately now so newcomers have no excuse for tampering with it.

Jmann84 11-01-2015 07:21 AM

Quote:

Originally Posted by dilettante (Post 1409124)
You can use the MidB$() function on the array to extract a substring, then convert that to Unicode. To do this the offset will be a 1-based value, so keep that in mind.

You can also use InStrB() if necessary to search for the ending NUL to get the length to extract.


The real question is why are you using VB6 if you don't know VB6? It is not legally available for free and expensive to acquire legitimately now so newcomers have no excuse for tampering with it.

I have been developing in VB since 5.0, I have just not really ever had to read byte arrays from a protocol stream. Thanks for the answer tho, I will try this out and let you know how it goes.

passel 11-02-2015 02:24 PM

RTMP uses doubles for identifying a number of things (e.g. audioCodec, videoCodec, videoFunction etc...).
I don't know anything about RTMP, really, but looking at the sequence of bytes after id
40 E7 92 00 00 00 00 00 00 00
looked like a Big Endian Double format (a lot of Doubles holding integer values will start with exponent 40 xx ...).
Sure enough, if you byte swap the eight bytes into a double and display it in VB, the value is 48272, which is the number you passed to the server.

Since you gave the server the number that it is passing back to you, I don't see that you're getting a lot of additional information at this point, just in a different format (ASCII in, Big Endian Double out).
A quick, hardcoded, conversion as proof
Code:

Option Explicit
  Private Type dblBytesType
    b(7) As Byte
  End Type
 
  Private Type dblType
    d As Double
  End Type
 
Private Sub Command1_Click()
  Dim b As dblBytesType
  Dim d As dblType
 
  With b
    .b(7) = &H40 'reversing the bytes, going from BigEndian to LittleEndian order
    .b(6) = &HE7
    .b(5) = &H92
  End With
  LSet d = b      'Copy the eight bytes from the byte array into a Double
  Debug.Print d.d  'Print the double value out in the "debug" window.
End Sub



All times are GMT -6. The time now is 02:58 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.