#include<iostream>
#include<Windows.h>
#include<tchar.h>
using namespace std;
#if _MSC_VER < 1600
void __cpuidex(INT32 CPUInfo[4], INT32 InfoType, INT32 ECXValue)
{
if (NULL == CPUInfo) return;
_asm {
// load. 读取参数到寄存器
mov edi, CPUInfo; // 准备用edi寻址CPUInfo
mov eax, InfoType;
mov ecx, ECXValue;
// CPUID
cpuid;
// save. 将寄存器保存到CPUInfo
mov[edi], eax;
mov[edi + 4], ebx;
mov[edi + 8], ecx;
mov[edi + 12], edx;
}
}
#endif
void _strcat(char* str, int num)//字符串拼接算法
{
int temp = 0;
int i = 0;
while (*str != NULL)
{
str++;
}
*str = 0x2D;
for (i = 4; i > 0; i--)
{
temp = num % 0xA;
str[i] = temp + '0';
num = num / 0xA;
}
}
void _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int cx = 0;
int ax = 0;
int dx = 0;
char name[0x2D] = { 0 };//用户名
char key[26] = { 0 };//生成的key
int i = 0;
int temp = 0;
int temp1 = 0;
char* pstr = NULL;//处理寄存器高低位 游走指针
//memcpy(name, "CTFHUB", sizeof("CTFHUB"));
memset(key, 0, 20);
scanf_s("%s", name, 0x2D);
temp = strlen(name);
dx = name[0] * name[temp - 1];
cx = 2;
temp = temp / cx;
cx = name[temp];
dx = dx * cx;
memcpy(key, "HNT", sizeof("HNT"));
_strcat(key, dx);
TCHAR ComputerName[0x1E] = { 0 };
DWORD Size = 0x1E;
GetComputerName((LPTSTR)ComputerName, &Size);
pstr = (char*)&ComputerName;
temp = 0;
while (*pstr != 0)
{
temp += *pstr;
pstr++;
}
cx = strlen(name);
temp = cx;
name[cx + 1] = '\0';//还原字符串后面的'\0'
for (i = cx; i > 0; i--)
{
name[i] = name[i - 1];
}
name[0] = 0xdc;
dx = 0;
while (cx != 0)
{
pstr = (char*)&dx;//dl=name[cx]
*pstr = name[cx];
dx = dx * cx;
temp += dx;
cx--;
}
INT32 dwBuf[4] = { 0 };
__cpuidex(dwBuf, 0, 1);
char szTmp[60] = { NULL };
sprintf_s(szTmp, "%08X %08X %08X %08X", dwBuf[0], dwBuf[1], dwBuf[2], dwBuf[3]);
temp = temp & dwBuf[1];
_strcat(key, temp);
pstr = name;
pstr++;
do
{
ax = *pstr;
pstr++;
temp += ax;
} while (ax != 0);
temp = temp ^ dwBuf[3];
temp = temp | dwBuf[2];
temp1 = temp;
pstr = name;
pstr++;
temp1 = *pstr++;
temp1 = temp1 * (*pstr);
temp1 *= temp;
_strcat(key, temp1);
pstr = name;
temp = 0;
pstr++;
do
{
ax = *pstr;
pstr++;
temp += ax;
} while (ax != 0);
dx = temp % 0x1A;
ax = 0x41 + dx;
cx = strlen(name) - 1;
temp = cx;
while (cx != 0)
{
pstr = (char*)&dx;//dl=name[cx]
*pstr = name[cx];
dx = dx * cx;
temp += dx;
cx--;
}
dx = (temp % 0x1A) + 0x41;
cx = strlen(name) - 1;
pstr = key;
while (*pstr != NULL)
{
pstr++;
}
*(pstr) = 0x2D;
char* v1;
v1 = (char*)&ax;
*(pstr + 1) = *v1;//*(pstr+1)=al
v1 = (char*)&dx;
*(pstr + 2) = *v1;//*(pstr+2)=dl
*(pstr + 3) = '\0';//字符串末尾
printf("%s", key);
}
|