-2

Below is the data i've got from wireshark and not able to crack it.

char peer0_13[] = {
0x02, 0xb6, 0x8d, 0x7c, 0x7a, 0x56, 0x2f, 0x06, 
0xde, 0x6c, 0xd9, 0x55, 0x78, 0xd3, 0x12, 0xf9, 
0xe5, 0x4a, 0x57, 0x02, 0xdc, 0xb7, 0x1c, 0x75, 
0x5b, 0x9c, 0x51, 0x51, 0x3e, 0x2a, 0x3a, 0x9a, 
0xca, 0x50, 0xeb, 0x40, 0x28, 0x05, 0x00, 0xa0, 
0x14, 0x02, 0x80, 0x50, 0x0a, 0x01, 0x40, 0x28, 
0x05, 0x00, 0xa0, 0x14, 0x02, 0x80, 0x50, 0x0a, 
0x01, 0x40, 0x28, 0x05, 0x00, 0xa0, 0x14, 0x02, 
0x80, 0x50, 0x0a, 0x01, 0x40, 0x28, 0x05, 0x00, 
0xa0, 0x14, 0x02, 0x80, 0x50, 0x0a, 0x01, 0x40, 
0x28, 0x05, 0x00, 0xa0, 0x14, 0x02, 0x80, 0x50, 
0x0a, 0x01, 0x40, 0x28, 0x05, 0x00, 0xa0, 0x14, 
0x02, 0x80, 0x50, 0x0a, 0x01, 0x40, 0x28, 0x05, 
0x00, 0xa0, 0x14, 0x02, 0x80, 0x50, 0x0a, 0x01, 
0x40, 0x28, 0x05, 0x00, 0xa0, 0x14, 0x02, 0x80, 
0x50, 0x0a, 0x01, 0x40, 0x28, 0x05, 0x00, 0xa0, 
0x14, 0x02, 0x80, 0x50, 0x0a, 0x01, 0x40, 0x28, 
0x05, 0x00, 0xa0, 0x14, 0x02, 0x80, 0x50, 0x0a, 
0x01, 0x40, 0x28, 0x05, 0x00, 0xa0, 0x14, 0x02, 
0x80, 0x50, 0x0a, 0x01, 0x40, 0x28, 0x05, 0x00, 
0xa0, 0x3f, 0xff, 0xd9 };

I am not getting that how to convert this data into plain text / string so that it is easy to read.

Here are some manual tricks i've applied to get in plain text. (First solution is not working properly, as it gives me garbage values).

#1.
    for (int i = 0; i <= sizeof (peer0_13); i++)
    {
        printf ("%c",peer0_13[i]);
    }

#2.
    cout << peer0_13 << endl ;

#3.
    printf ("%s\n", peer0_13);

Please help to convert this data into normal string. Any help would be grateful. :)

darthVader
  • 197
  • 4
  • 17
  • you don't have a char array containing hex values. You just have entered the char values as hex. – wimh Aug 30 '15 at 12:11
  • Do you mean you literally want your string to contain `"0x02, 0xB6, 0x8D, ..."`? – cbr Aug 30 '15 at 12:11
  • @Wimmel yes, but is there any way to convert this value into string? plain text? – darthVader Aug 30 '15 at 12:13
  • Google how to print one number in HEX representation, then do some magic to print two hundred of them. Is it that hard? – LogicStuff Aug 30 '15 at 12:14
  • @unnat1993 and what should the plain text contain? like the example cubrr gave? – wimh Aug 30 '15 at 12:15
  • @cubrr i m not getting you, but as much i do, i do not want that my string contain 0x02, 0xB6, i want to convert 0x02 into plain string. is it possible to do so? – darthVader Aug 30 '15 at 12:16
  • possible duplicate of [c++ cout hex values?](http://stackoverflow.com/questions/479373/c-cout-hex-values) – LogicStuff Aug 30 '15 at 12:17
  • So is this the output you expect `2, 182, 141, 124, 122, 86, 47, 6, 222, 108, 217, 85, 120, 211, 18, 249, 229, 74, 87, 2, 220, 183, 28, 117, 91, 156, 81, 81, 62, 42, 58, 154, 202, 80, 235, 64, 40, 5, 0, [...], 40, 5, 0, 160, 20, 2, 128, 80, 10, 1, 64, 40, 5, 0, 160, 20, 2, 128, 80, 10, 1, 64, 40, 5, 0, 160, 20, 2, 128, 80, 10, 1, 64, 40, 5, 0, 160, 63, 255, 217`? Or something else? You have to ask a clear and complete question to get good answers. – jwpfox Aug 30 '15 at 12:19
  • the hex numbers in char array are a single byte and equivalent to a char you don’t need to convert it, since C understands the hex numbers, 0x10 is a character equal to 32 decimal which is a space and if you write your char array with a %s it will print something but will stop when it reaches to 0x00 – Iman Nia Aug 30 '15 at 12:20
  • @LogicStuff i've done that too, but it leads me to failure only, that is why i post it here. – darthVader Aug 30 '15 at 12:21
  • @jwpfox , i would like my ans in string form. like if above array's equivalent string is "Hello this is programmer", than i want it to print on my terminal. – darthVader Aug 30 '15 at 12:24
  • 1
    The data you have provided is not ascii char codes that are representable as a string.... http://www.asciitable.com/ converting to string gives something like: ��|zV/�l�Ux���JWܷu[�QQ>*:��P�@( perhaps you need to identify where this data is coming from. – William Jones Aug 30 '15 at 12:25
  • Append a null to your array and simply: std::string* out = new std::string(peer0_13); – William Jones Aug 30 '15 at 12:27
  • My list of numbers is in 'string form'. I assume you mean you want it in alphabetical character form? To do that we need to know what encoding was used. And a C string with zeros in the middle is not going to do what you seem to think you expect to get as output. Lots of unknowns here. – jwpfox Aug 30 '15 at 12:34
  • @WilliamJones yes, this data is from a tool name "WIRESHARK". – darthVader Aug 30 '15 at 12:35
  • I believe you are not capturing a "string" here. This is some sort of data packet (perhaps encrypted? compressed?) and you would need to decrypt/decode/decompress it to see a "string"... – William Jones Aug 30 '15 at 12:40
  • So the zeros are the end of strings? so you have a stream of data made up of multiple strings? So the first step is to break the stream down into strings instead of trying to treat it as one big string? or something else? – jwpfox Aug 30 '15 at 12:40
  • @WilliamJones exactly, is it any way to do it? – darthVader Aug 30 '15 at 12:42
  • 1
    If you got the data via Wireshark why aren't you using Wireshark to analyse it? Why this bizarre attempt to do what you seem to be trying to do? Have you typed Wireshark into google and read up a bit about the tool or are you just rushing about trying to do a task you don't understand because someone asked you to do something? – jwpfox Aug 30 '15 at 12:42
  • Without knowledge of the transmitter I would try standard encoding methods for the traffic you are sniffing: https://en.wikipedia.org/wiki/Character_encoding – William Jones Aug 30 '15 at 12:43
  • 2
    re-write your question and tell everyone that these are wireshark data, and explain why are you doing this, you have received two down vote and they may re consider their votes if you change your question into a better way. – Iman Nia Aug 30 '15 at 12:43
  • @jwpfox i've tried to analyze it by TCP stream, but some how i m getting dots (.) only. is there any other way to read packats? – darthVader Aug 30 '15 at 12:44
  • I strongly support `Iman`'s suggestion. Stop now. Rewrite your question giving the information slowly dragged out in these comments into the actual question and start again. Your question is actually something like 'How can I read the following data stream collected using Wireshark'. As it is I don't think you will ever get a useful answer from the mess you now have. – jwpfox Aug 30 '15 at 12:48
  • @jwpfox i m sorry for what i have made of, but is it correct, my question? – darthVader Aug 30 '15 at 12:51
  • 1
    No. As pointed out by almost everyone who has responded to you this is not a C array in the way most would understand it and 'normal form' means nothing unless you can explain what you think 'normal' is. Take a break. Have a glass of water. Think slowly and carefully about what it is you have and what you want to end up with. Write that out carefully and get some help from someone who reads through it and see if it makes sense to someone not inside your head. Give examples of what output you expect. Explain why you aren't just using Wireshark to look at the the data. Then try again. – jwpfox Aug 30 '15 at 12:56

1 Answers1

1

You can not convert the above char vector into String since I see 0x00 at the end of the line before the last. char[] is a String but if you need to copy its data into a normal string then you have to copy all of the chars to an empty string one by one using a loop, but the 0x00 value will truncate the string.

Note that in your first loop you need to change the condition to i < sizeof (peer0_13) and eleminate the equal sign which raises an index out of bound error.

If you meant to read the char array as a String that a human could understand and you need to just print it out, You have to exclude the null characters (0x00) while copying it into a String or erase null character from your array and simply use %s with a printf.

Iman Nia
  • 2,255
  • 2
  • 15
  • 35
  • i just got a job to convert this type of data into plain string, that's why it wont hurt the idea of my program, as such i have bigger array then this one, this is the smallest one :D and thank for reply :D – darthVader Aug 30 '15 at 12:21
  • Ok just filter the null characters and printf it with %s, simply! :D – Iman Nia Aug 30 '15 at 12:24
  • @lman the array also contains characters lower then 0x20 and larger then 0x7f. You need to handle that too – wimh Aug 30 '15 at 12:25
  • @Wimmel, They will print somthing! 0x07 is a beep and will make the speaker of your computer to beep! instead of writing a char on the screen, Actually I don’t know what does our friend about to do. It will produce a strange result for sure, and Yes if I was him I would filter all of the chars below 0x20 – Iman Nia Aug 30 '15 at 12:28
  • @Iman i m trying to convert this data ( which is from wireshark , got by my colleague ) into normal form. !! – darthVader Aug 30 '15 at 12:34
  • So theses are network packet data!, you have to consider that most of these data are encrypted and you need to understand the packets and their formats well enough so you may succeed to filter binary data, if you are about to create a meaningfull result from such a low level data, you need to know much more about cryptography, MIME types but if you just print them all, you will find some human readable string. sometimes very interesting and personal data, I had such an experiance with WINPCAP, So filter all of the characters with codes lower than 0x20. – Iman Nia Aug 30 '15 at 12:41
  • @Iman thanks for the help, and as you said, i've rewirte the question. and i m filtering data less than 0x20. (y) will let you know that what the result of it. and thank you again (y) – darthVader Aug 30 '15 at 12:49