Default CRC input to reproduce check value - crc

I found a site where a lot of CRC values are listed, with configurations/setup. There is also a "check" value, which I believe is generated with some kind of default input (some dummy string or such).
Does anybody know what this is and/or how I can reproduce it?
Sample config: width=3 poly=0x3 init=0x7 refin=true refout=true xorout=0x0 check=0x6 name="CRC-3/ROHC"
Site: http://reveng.sourceforge.net/crc-catalogue/all.htm#crc.cat.arc
Thanks a lot.

sorry, found the solution.
HEX: 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39
String: 123456789

Related

Faster i2ccmd execution

I am facing One problem regarding system command execution ?
Actually there are 2 playback music sources like Bluetooth and other source . For that we used one specific codec (NPCA110B) in our system .
To play music on One source , Let consider BT , I have to run 20 command to play music over BT .
One Important Note is, for performing source switch between Music sources , I have to run the 20 commands in sequentially.
In My code , In one of the API , I am giving 20 system command in following way. This API is responsible for doing source switch.
void func()
{
// here 20 commands are there .
system("i2ccmd w 0x73 0x00 0x02 0xA5 0x00");
system("i2ccmd w 0x73 0x00 0x02 0xC3 0x00");
system("i2ccmd w 0x73 0x00 0x02 0xA4 0x11");
system("i2ccmd w 0x73 0x00 0x02 0x00 0x00");
....
....
....
....
system("i2ccmd w 0x73 0x00 0x02 0xA5 0x00");
}
The problem is , I able to do source switch successfully , but performance is Hampering. because i2ccmd internally perform file operation for each command . And execution time is more to execute above command sequentially.
Is there any way to write all 20 i2ccmd in single file operation ? Or any other way to make faster execution of i2ccmd ?

Aliasing memory addresses in GDB

I am looking for a way (directly or best approximation/alternative) to assign aliases to memory addresses in GDB, which would then show up with every function that prints this address (such as x, find, info proc map and so on).
Ideally, I'd also be able to set some sort of a range, which would then be used together with alias, to output offsets rather than direct addresses.
For example, using imaginary commands alias and set-offset-range
(gdb) info proc mem
0x55c10c43e000 0x55c10c44f000 0x11000 0x0 /usr/bin/htop
0x55c10c44f000 0x55c10c47d000 0x2e000 0x11000 /usr/bin/htop
0x55c10c47d000 0x55c10c48c000 0xf000 0x3f000 /usr/bin/htop
0x55c10c48d000 0x55c10c492000 0x5000 0x4e000 /usr/bin/htop
0x55c10c492000 0x55c10c493000 0x1000 0x53000 /usr/bin/htop
0x55c10c493000 0x55c10c495000 0x2000 0x0
0x55c10dee7000 0x55c10e185000 0x29e000 0x0 [heap]
...
(gdb) alias 0x55c10dee7000 'heap' <-------------------
(gdb) set-offset-range $heap 0x29e00 <-------------------
(gdb) info proc map
0x55c10c43e000 0x55c10c44f000 0x11000 0x0 /usr/bin/htop
0x55c10c44f000 0x55c10c47d000 0x2e000 0x11000 /usr/bin/htop
0x55c10c47d000 0x55c10c48c000 0xf000 0x3f000 /usr/bin/htop
0x55c10c48d000 0x55c10c492000 0x5000 0x4e000 /usr/bin/htop
0x55c10c492000 0x55c10c493000 0x1000 0x53000 /usr/bin/htop
0x55c10c493000 0x55c10c495000 0x2000 0x0
$heap ($heap+0x29e000) 0x29e000 0x0 [heap]
(gdb) x/32xb $heap
$heap: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
$heap+8: 0x91 0x02 0x00 0x00 0x00 0x00 0x00 0x00
Bonus question: if I need similar output tweaks in the future - what section of GDB manual should I be looking at to learn more about it?
After some looking around and consulting helpful people on #gdb, turns out this isn't possible - either with gdb or Python extension API.
A workaround is to use ld to generate an artifical object file and fill it with synthetic symbols using --defsym flag, then load that object file into gdb using add-symbol-file.
I won't accept the workaround as solution, so if anyone has a better idea - bring it forth please.

CRC 8 and CRC 16

CRC 16
http://www.lammertbies.nl/comm/info/crc-calculation.html
For input of hex 0x43 the CRC-16 (poly 0x8005) is 0xF141 as per above website...
How do I input this in below calculator to get same result?
https://ghsi.de/CRC/index.php?Polynom=1000000000000101&Message=43
CRC 8
http://www.codeproject.com/Articles/19059/C-CCITT-CRC-Algorithm
In above link with byte array {0xee, 0x01, 0x13, 0x00, 0x06, 0x1c, 0x00, 0x20, 0x1d, 0x00, 0x00} using CRC8 (poly 0xd5) it return 226 as a result.
How do I go about and insert the value into below website?
How about input 0x43? How do I input this using CRC8 (poly 0xd5) into the same website?
https://ghsi.de/CRC/
Sorry but I've been stucked on figuring out this... been studying CRC using below link until pg 11, and I have a rough idea on CRC calculation. But I have found difficulties in figuring how to get same result from the sources I mentioned above...
http://www.ross.net/crc/download/crc_v3.txt
For the CRC-16, use this link with the polynomial corrected to have the x16 term and the input byte reversed, and read the CRC result (828f) reversed (f141). The input and output need to be reversed since that is a reflected CRC. See the definition of that CRC here.
For the CRC-8, defining just the polynomial is not sufficient. You also need to define whether the CRC is reflected or not, what the initial value of the CRC register is, and what to exclusive-or the result with. There is one in the catalogue with that polynomial, which is not reflected and has zero for the initial value and final xor. You can use this online version for that specific CRC to get 0x37 as the CRC of 0x43. That version gives 226 decimal for your example sequence.

How to send messages as websocket client in c++ to a server?

I've a little problem in sendine my messages to the server.
It probably send them and the server recieve them, but i have no real idea how to mask them correctly.
I know this is actually the way:
https://www.rfc-editor.org/rfc/rfc6455#section-5.2
But I'm not understanding a lot of it.
It would be nice if someone could share a whole pseudocode what actually need to be done from the plain message until the writing into the buffer.
I also searched here a lot for information but mostly they advice libs or directly the link. The problem is that libs are nice, but i've actually done already all i need. Only the sending mask is missing.
Regards
Can you send the message with mask bit off?
When mask bit is set, the server expect 4 bytes mask to present, and the payload is XOR'd with
for ( size_t i=0; i<packet_len; i++ ) {
packet[i] = payload[i] ^ mask_bits[i&3];
}
EDIT: Adding more detail.
I assume you have done the Upgrade handshake, the actual bytes to send to network for communication are:
[flag][mask_bit, len][extended length][mask][payload]
Where:
flag: one byte, read the manual, note that I have not tried fragment.
mask bit, one bit located at highest bit of second byte.
len: 7 bits of second byte. If len is 126, real len is 16 bit field of extended length. if it is 127, extended length is 64-bit.
mask: present only if mask bit is set, it's 4 bytes using to XOR the payload.
payload: actual bytes to send
For example, to send "Hello" to server in binary mode, you do:
flag: 0x82, "Final packet in frame" and "Binary mode"
mask bit: 1
len: 6
mask: 0x11, 0x22, 0x33, 0x44
payload: "Hello", 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x00
The masked payload is: 0x48^0x11, 0x65^0x22, 0x6C^0x33, 0x6C^0x44, 0x6F^0x11, 0x00^0x22
=> 0x59, 0x47, 0x5F, 0x28, 0x7E, 0x22
The whole stream is: 0x82, 0x86, 0x11, 0x22, 0x33, 0x44, 0x59, 0x47, 0x5F, 0x28, 0x7E, 0x22

Sending Info Hash to Bittorrent Tracker Over UDP

So I'm writing a Bittorrent client in C++ and I can communicate with the tracker, however when I get the announce response my IP address is the only one I get in return. After looking at my traffic over wireshark and comparing it to the traffic to the same tracker in transmission I've concluded that I must be sending the info-hash of the torrent incorrectly.
So, I'm sending this as my info-hash of my test torrent (TPB AFK (totally legal to torrent!)):
99FEAE0A05C6A5DD9AF939FFCE5CA9B0D16F31B0
From reading a few other posts around the net I got the idea that I have to encode this somehow, and also that it needs to be 20 bytes (which I stupidly didn't realize it wasn't before...didn't count).
So there must be some sort of encoding that I must feed this hash into, but what is it?
Okay, so That string of 40 characters, is just 20 bytes...so the correct way to send the info_hash is:
0x99 0xFE 0xAE 0x0A 0x05 0xC6 0xA5 0xDD 0x9A 0xF9 0x39 0xFF 0xCE 0x5C 0xA9 0xB0 0xD1 0x6F 0x31 0xB0