char sh[] = "\x31\xc0\x31\xdb\x31\xc9\x31\xd2\x52\x68\x6e\x2f\x73\x68"
"\x68\x2f\x2f\x62\x69\x89\xe3\x52\x53\x89\xe1\xb0\x0b\xcd\x80";
Why did the programmer use hex encoding for this string? For example, why use \x31
for the first character rather than 1
?
Although sh
is an array of char
elements, it can also be considered as an array of bytes. Well, assuming char
is 8 bits wide, which it usually is.
So, if this variable contains code, it is clearer to express it as an array of bytes, rather than a text array. For example, there may be elements that are not readily expressed as printable characters. Since the content will be generated by a compiler or assembler, it will originally have been in the form of a binary block of code. And it's easiest and clearest to convert that to the hex representation that you presented.