Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@OsandaMalith
Last active November 16, 2016 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OsandaMalith/ae5cfbbddbcd7a062d2fbfe5ddd2a62f to your computer and use it in GitHub Desktop.
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.
#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