Created
May 4, 2018 04:24
-
-
Save e2thenegpii/9b98b98f134bf7a3585033b5621056ae to your computer and use it in GitHub Desktop.
String obsfucation via MMX instructions
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 <xmmintrin.h> | |
#include <stdint.h> | |
/** | |
* Converts a string from a format where bit 7 of 8 characters form the first | |
* byte in a uint64_t, bit 6 of 8 characters form the second byte and so on | |
* in a simple attempt to obsfucate strings encoded as integers. | |
* | |
* @param data The string to destripe | |
* @param num_elem The number of uint64_t in data | |
* @param buffer The buffer where to store the destripted data | |
*/ | |
void destripe(uint64_t* data, size_t num_elem, char* buffer); | |
/* Compile this program with gcc -Os main.c then strip the binary (or don't) and run | |
* strings on it to see on the binary and notice the string "01234567" is nowhere in the binary | |
*/ | |
int main(int argc, char** argv) { | |
//A method of string obsfucation | |
uint64_t data[] = { 0x0000FFFF000F3355LL, 0x0000000000000000LL }; | |
char str[sizeof(data)] = {0}; | |
destripe(data, sizeof(data)/sizeof(*data), str); | |
printf("%s\n", str); | |
return 0; | |
} | |
void destripe(uint64_t* data, size_t num_elem, char* buffer) { | |
char* pbuf = buffer; | |
for( size_t i = 0; i < num_elem; ++i ) { | |
__m64 cur = _mm_set_pi64x(data[i]); | |
for( size_t j = 0; j < 8; ++j ) { | |
pbuf[j] = (char)_mm_movemask_pi8(cur); | |
cur = _mm_slli_si64(cur, 1); | |
} | |
pbuf += 8; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One neat thing about this method is it only uses MMX instructions that have been around since the mid 90's so virtually every x86 desktop can run it.