Skip to content

Instantly share code, notes, and snippets.

@dscp46
Created June 13, 2023 08:10
Show Gist options
  • Select an option

  • Save dscp46/baf743a451415d12b362428a57c8560d to your computer and use it in GitHub Desktop.

Select an option

Save dscp46/baf743a451415d12b362428a57c8560d to your computer and use it in GitHub Desktop.
Decode Type 7 string
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TYPE7_LUT_SZ 53
const unsigned char type7_lut[] = "dsfd;kfoA,.iyewrkldJKDHSUBsgvca69834ncxv9873254k;fg87";
void deobfuscate( const char* in, char* out)
{
int in_sz = strlen( in)/2;
unsigned char val;
char offset_str[3] = { 0, 0, 0};
// Read LUT offset (stored in decimal form in 2 first bytes)
memcpy( offset_str, in, 2);
int offset = atoi( offset_str);
for( int i=1; i<in_sz; ++i)
{
sscanf( in+(i*2), "%2hhx", &val); // Read and decode hex byte
out[i-1] = val ^ type7_lut[offset]; // XOR read byte and LUT byte
if( ++offset >= TYPE7_LUT_SZ) // Increment LUT offset
offset = 0;
}
}
int main( int argc, char** argv)
{
if( argc != 2 )
{
printf( "Usage: %s type7_secret\n", argv[0] );
return 1;
}
// Allocate result string
int clear_len = strlen( argv[1]) / 2;
char *result = (char*) malloc( clear_len);
memset( result, clear_len, 0);
deobfuscate( argv[1], result);
printf( "Decoded password: %s\n", result);
free(result);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment