//////////////////////////////////////////////////////////////////
// //
// keygen for PCHunter_pro //
// //
// //
// //
//////////////////////////////////////////////////////////////////
#include
#include
#include
#include
using namespace std;
#include "crypto/aes.h" // 用到了cryptopp 库
#include "crypto/modes.h"
#include "crypto/filters.h"
using namespace CryptoPP;
template
string hex2str (ByteT* hex, int len, const string& delim=" ") {
if (len == 0) return "";
string s;
char x[4];
for (int i=0; i<len; i++)="" {
snprintf (x, 4, "%02X", ( (unsigned char*)hex)[i]);
s += x;
if (i != len-1) s += delim; // append delim if not the last char
}
return s;
}
string hex2str (const string& hex, const string& delim=" ") {
return hex2str (hex.c_str (), hex.length (), delim);
}
string aes_encrypt (string& plain, string& key) {
ECB_Mode< AES >::Encryption e ( (byte*)key.c_str (), key.length ());
string cipher;
StringSource ss (plain, true,
new StreamTransformationFilter ( e,
new StringSink ( cipher ),
StreamTransformationFilter::NO_PADDING) );
return cipher;
}
#pragma pack (push, 1)
struct reg {
byte unknown_1[80];
FILETIME ft_beg;
FILETIME ft_end;
byte unknown[32];
};
#pragma pack (pop)
int main () {
string key = "ShouJiErShiSiShi";
reg r;
byte* p = (byte*)&r;
for (unsigned int i=0; i<sizeof (reg); i++)="" {="" 填充="" 00="" ~="" ff
p[i] = i;
}
SYSTEMTIME st;
GetSystemTime (&st); // 得到当前时间 -> start time
SYSTEMTIME st_new = st;
st_new.wYear += 10; // 当前时间+10年 -> end time
SystemTimeToFileTime (&st, &r.ft_beg); // 转成8字节的 FILETIME,xuetr用的这个
SystemTimeToFileTime (&st_new, &r.ft_end);
string plain;
plain.assign ( (const char*)&r, sizeof (r));
cout << "raw:" << endl << hex2str (plain) << endl;
string encrypted = aes_encrypt (plain, key); // 加密
// cout << "encrypted:" << endl << hex2str (encrypted) << endl;
ofstream ofs ("c:/pchunter.ek", ios::binary); // 写到 key file
ofs << hex2str (encrypted, "");
ofs.close ();
}