The shellcode array, consists of 1666 characters (shellcode[0]=f to shellcode[1665]=7 plus a null terminator shellcode[1666]=nullTerminator ).
The strlen(shellcode)=1666 and the sizeof(shellcode)=16667 , because it calculates the null terminator.
Below we calculate the proper size of memory we need to allocate:
The number of characters which are going to be converted to the shellcode bytes, are 1666 characters (in this example) and these are shellcode[0] to shellcode[1665])
The null terminator is not part of the shellcode, so we have :
x=(sizeof(shellcode) - 1) . or x= strlen(shellcode)/2
2. These 1666 characters in pair, are going to create a byte. Every 2 chacracters are going to represent one byte. For example fc (which is actually \xfc) will be converted to 1 byte:
So the tottal number of bytes in the final shellcode are bytes=x/2 , or bytes = (sizeof(shellcode) - 1)/2 or bytes = strlen(shellcode)/2.
This equals to 833 bytes of pure shellcode bytes, which do not contain the null terminator.
*/
unsigned intmemory_allocation=strlen(shellcode) / 2; //memory we are going to allocate for shellcode
printf("%s\n\n", &logo);
/*
convert to shellcode:
Iterations is equal to strlen(shellcode) which is the total number of characters (in the above example 1666 shellcode[0] to shellcode[1665]).
We convert in pairs, so for i=0 we are going to read shellcode[0] and shellcode[1] in order to create one byte from those 2 chars.
The last byte will be created for i=1664 which will convert the characters shellcode[1664] and shellcode[1665]. So the last time we are going to enter the loop
will be for i = 1664, meaning i<16665 which is i < 1666-1 or i < iterations-1