Last active
November 16, 2016 14:00
-
-
Save OsandaMalith/ae5cfbbddbcd7a062d2fbfe5ddd2a62f to your computer and use it in GitHub Desktop.
Simple experiment of packing and unpacking a DWORD and a short inside a DWORD64 variable and making a string value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <windows.h> | |
/* | |
* Author : @OsandaMalith | |
* Website: https://osandamalith.com | |
* Description: Simple experiment of packing and unpacking a DWORD and a short inside a DWORD64 variable and making a string value. | |
*/ | |
int main() { | |
DWORD a = 1633971809; // a < 2 ^ 32 | |
short b = 29519; // b < 2 ^ 16; | |
DWORD64 pack = 0, temp = 0; | |
printf("Value of a = %d\n",a); | |
printf("Value of b = %d\n\n",b); | |
puts("\t-=[Packing]=-\n"); | |
pack = a; | |
pack <<= 0x10; // shift 2 bytes left | |
pack |= b; | |
printf("Packed data: 0x%I64X\n\n",pack); | |
printf("As a string: %s\n\n",&pack); | |
// clear the variables | |
a ^= a; | |
b ^= b; | |
puts("\t-=[Unpacking]=-\n"); | |
temp = pack; | |
pack &= 0xffff; // Extract the lowest 16 bits | |
b = pack; | |
temp >>= 0x10; // Extract the highest 32 bits | |
a = temp; | |
printf("Value of a = %d\n",a); | |
printf("Value of b = %d\n\n",b); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment