473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Need help with hex and winsock

Xion
5
Hey, I'm working on program that connects to a server and I need to get the user ID and display it in a textbox but I'm having trouble getting it from the packet recived.
Here is part of the packet


Expand|Select|Wrap|Line Numbers
  1. 00 01 08 00 FF FF FC 19 xx xx xx xx FF FF FC 19
Where the xx xx xx xx is the server generates a user ID.
Does any 1 know how I could get this ID in a textbox using
Expand|Select|Wrap|Line Numbers
  1. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Thanks.
Jan 20 '07 #1
13 2161
Killer42
8,435 Expert 8TB
Does your code need to find the ID first, or is it at a known position?
Jan 21 '07 #2
Xion
5
This ID is in a known position
Expand|Select|Wrap|Line Numbers
  1. 00 01 08 00 FF FF FC 19 xx xx xx xx FF FF FC 19
is the beginning of the packet. I thought I might have to do something like:
Expand|Select|Wrap|Line Numbers
  1. If InStr(buffer, Chr(0) & Chr(1) & Chr(8) & Chr(0))
To find the packet with the ID, and then something else to get the user ID from it's position, but I'm not sure.
Jan 21 '07 #3
Killer42
8,435 Expert 8TB
This ID is in a known position
Expand|Select|Wrap|Line Numbers
  1. 00 01 08 00 FF FF FC 19 xx xx xx xx FF FF FC 19
is the beginning of the packet. I thought I might have to do something like:
Expand|Select|Wrap|Line Numbers
  1. If InStr(buffer, Chr(0) & Chr(1) & Chr(8) & Chr(0))
To find the packet with the ID, and then something else to get the user ID from it's position, but I'm not sure.
Sorry, I also meant to ask, is the ID a known length, or do you have to determine where it finishes?

And is the packet received as pairs of hex digits separated by spaces as shown here? Or is it a simple string of byte values, which you have represented as hex pairs here for readability? In other words, would the above sample be received as 16 bytes, or 47?

Hm... actually, the bit about the Instr() probably answers that. I'm busy at work now, but should be able to help with this at lunch time (in a couple of hours), if someone doesn't beat me to it (my bet would be on willakawill).
Jan 21 '07 #4
Xion
5
The ID length is four pairs of hex digits represented by the x's.
Expand|Select|Wrap|Line Numbers
  1. 00 01 08 00 FF FF FC 19 xx xx xx xx FF FF FC 19
The ID remains in the same place each time you connect.
Jan 21 '07 #5
Killer42
8,435 Expert 8TB
The ID length is four pairs of hex digits represented by the x's.
Expand|Select|Wrap|Line Numbers
  1. 00 01 08 00 FF FF FC 19 xx xx xx xx FF FF FC 19
The ID remains in the same place each time you connect.
Ah. So it's actually received in the same format you showed it here?

What I'm getting at is whether we need to do a conversion from a string of spaces and two-digit hex values to simple byte values, or whether it's just been rendered this way for display purposes, by a hex editor or something.

Or, to put it another way, does this sample data actually start with the ASCII string "00" (character 48, or &h30, repeated twice) or with a null byte? Sorry to harp on this, but I feel it's very important to ensure we're talking about the same thing.
Jan 22 '07 #6
Xion
5
It starts with 00 and there is a space between each pair of hex digits.
Jan 22 '07 #7
Killer42
8,435 Expert 8TB
It starts with 00 and there is a space between each pair of hex digits.
Ok, now we're cooking with gas.

That means your suggestion of
Expand|Select|Wrap|Line Numbers
  1. If InStr(buffer, Chr(0) & Chr(1) & Chr(8) & Chr(0))
would have to be modified, something like
Expand|Select|Wrap|Line Numbers
  1. If InStr(buffer, "00 01 08 00")
  2.   or possibly
  3. If Left(buffer, 11) = "00 01 08 00"
Note also, if you need to know the location within the packet, the Instr( ) function above will tell you where it is - just add 12 to what it returns.

I'm sure we can come up with a pretty simple routine to pull out the ID. I've just started work, again, so if someone doesn't beat me to it, I should be able to get back to it in a few hours, at lunch time.

Feel free to have a go at it yourself. It shouldn't be particularly difficult. Off the top of my head, I'd suggest you just isloate the pairs of characters with something like Mid( ), concatenate it with the string "&H" to make a recognisable hex value, use Val( ) to convert to a number, then use Chr( ) function to convert the number to an ASCII character. Then concatenate these characters them into a string.

Have fun... :)
Jan 22 '07 #8
Killer42
8,435 Expert 8TB
I'm really busy, so I might leave you to play with this for a day or two. It'll be good practice, anyway.
Jan 23 '07 #9
kZero
23
Hey, I'm working on program that connects to a server and I need to get the user ID and display it in a textbox but I'm having trouble getting it from the packet recived.
Here is part of the packet


Expand|Select|Wrap|Line Numbers
  1. 00 01 08 00 FF FF FC 19 xx xx xx xx FF FF FC 19
Where the xx xx xx xx is the server generates a user ID.
Does any 1 know how I could get this ID in a textbox using
Expand|Select|Wrap|Line Numbers
  1. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Thanks.
u said that the packet is for example
Expand|Select|Wrap|Line Numbers
  1. 00 01 08 00 FF FF FC 19 xx xx xx xx FF FF FC 19
if u sure that "00 01 08 00 FF FF FC 19" and "FF FF FC 19" always the same and never change so its so easy u can use this small code to get the "xx xx xx xx"
Expand|Select|Wrap|Line Numbers
  1.  dim x as string ' x = the recieved packet
  2. x = replace("00 01 08 00 FF FF FC 19 xx xx xx xx FF FF FC 19","00 01 08 00 FF FF FC 19","")
  3. x = replace ( x , "FF FF FC 19","")
  4. msgbox "Username : " & x
  5.  
i hope it help u
Jan 23 '07 #10
Killer42
8,435 Expert 8TB
...
Expand|Select|Wrap|Line Numbers
  1. dim x as string ' x = the recieved packet (really?)
  2. x = replace(<packet>,"00 01 08 00 FF FF FC 19","")
  3. x = replace ( x , "FF FF FC 19","")
  4. msgbox "Username : " & x
This seems like a nice, compact way to extract the user ID from the string (making certain assumptions about the initial string, of course). But you still need to convert the hex pairs to bytes, and put them together into either a byte array or a string.
Jan 23 '07 #11
Xion
5
I managed to do it like this:
Expand|Select|Wrap|Line Numbers
  1. If InStr(buffer, Chr(0) & Chr(1) & Chr(8) & Chr(0) & "ÿÿü") Then
  2.  
  3. aaa = Split(buffer, "ÿÿü")
  4.  
  5. For c = 1 To Len(aaa(1))
  6. bbb = Mid(aaa(1), c, 1)
  7.  
  8. bbb = Hex(Asc(bbb))
  9.  
  10. If Len(bbb) = "1" Then
  11. bbb = "0" & bbb
  12. End If
  13.  
  14. rdata = rdata & bbb & " "
  15. Next
  16.  
  17. ccc = Left(rdata, Len(rdata) - 1)
  18.  
  19.  
  20. Text3 = ccc
Jan 23 '07 #12
Killer42
8,435 Expert 8TB
I managed to do it like this:...
Given the extracted ID from kZero's post, I'd probably do it something like this...
Expand|Select|Wrap|Line Numbers
  1. Dim strHex As String, strID As String, I As Long
  2. ' Set up some hex values to represent the input...
  3. strHex = "41 42 43 44"
  4.  
  5. ' Convert to a simple string...
  6. For I = 1 To 10 step 3
  7.   strID = strID & Chr(Val("&H" & Mid(strHex, I, 2)))
  8. Next
I haven't tested this (just typed it here), but I think it should work, leaving the user ID in strID.
Jan 23 '07 #13
Nobody help this loser newbie.

He needs help to create a program to hack digichat (www.digichat.com) chat rooms across the internet.

What a loser.
Feb 1 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ophir | last post by:
Hello all ! I wrote a simple ActiveX DLL to wrap winsock functionality so I can use it in an ASP page. I call it MyWinSock In the Class module I use this declaration: Dim ctlSocket as...
1
by: Yu Chai | last post by:
Hi guys, I created a ASP page that 1. users can run when WinSock proxy are using (ie's one is unchecked) 2. users can't run when WinSock proxy are using (ie's one is checked) 3. users can't run...
1
by: Glen Conway | last post by:
Hi, I'm trying to use the gethostbyname function from wsock32.dll and failing dismally Has anyone got a successful implementation of this in VB.NET? My ulitimate goal is to resolve NetBIOS names...
5
by: kc | last post by:
Hi Just upgrading a app from VB6 to VB.Net. All is going well apart from the Winsock control. The first thing we notice is that there does not appear to be a .Net version (please correct me if...
1
by: kpaxoid | last post by:
An odd problem. Application runs fine in the VB6 IDE, but when compiled, as soon as the application attempts to execute Winsock.Listen 'Winsock is created by Winsock = New Winsock the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.