Skip to content

Instantly share code, notes, and snippets.

@OsandaMalith
Last active June 15, 2016 20:51
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/e16886809d366bf37fd1b7423b7f67d4 to your computer and use it in GitHub Desktop.
Save OsandaMalith/e16886809d366bf37fd1b7423b7f67d4 to your computer and use it in GitHub Desktop.
Solution for my birthday crackme part 1 ;)
#include "stdafx.h"
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
unsigned int checksum(unsigned char string[]) {
unsigned int var;
unsigned int eax;
unsigned int ecx;
unsigned int esi;
unsigned char value1;
unsigned char value2;
unsigned char value3;
unsigned int * pointer1;
unsigned int * pointer2;
unsigned int * pointer3;
int a;
/* pointer1 should point to the second byte of var */
pointer1 = &var;
a = (int)pointer1;
a = a + 1;
pointer1 = (unsigned int *)a;
/* pointer2 should point to the first byte of eax */
pointer2 = &eax;
/* pointer3 should point to the second byte of eax */
pointer3 = &eax;
a = (int)pointer3;
a = a + 1;
pointer3 = (unsigned int *)a;
esi = 0;
eax = 0;
var = 0;
ecx = 4;
while (ecx != 0)
{
/* xor byte ptr [var+1], ah */
value1 = eax >> 8;
value2 = var >> 8;
value3 = value1 ^ value2;
*pointer1 = value3;
/* lodsw */
* pointer2 = string[esi];
*pointer3 = string[esi + 1];
esi = esi + 2;
/* dec ecx */
ecx--;
/* add [var], eax */
var = var + eax;
}
return var;
}
int _tmain(int argc, _TCHAR* argv[])
{
string line;
ifstream myfile("my1.txt");
if (myfile.is_open())
{
while (getline(myfile, line)) {
unsigned int var = checksum((unsigned char *) line.c_str());
if (var == 0x39a)
cout << line.c_str() << endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment