再次经过优化的 c++ 源码
#include <iostream>
#include <stdlib.h>
#include <vector>
using namespace std;
// 模拟ASM的 PUSH, POP 操作
template<class T>
class Stack
{
public:
void push(T data)
{
vstack.push_back(data);
}
void pop(T& data)
{
if (vstack.empty())
{
data = 0;
}
else
{
data = vstack.back();
vstack.pop_back();
}
}
private:
vector<T> vstack;
};
typedef unsigned long DWORD;
Stack<DWORD> thisStack;
__int64 n402182 = 0xFEDCBA98;
std::vector<DWORD> g_stack;
void XChange(DWORD& a, DWORD& b)
{
DWORD c = 0;
c = a;
a = b;
b = c;
}
int SHR(DWORD& a)
{
int nBit = a & 0x01;
a >>= 0x01;
return nBit;
}
void XOR_HIGH_LOW(DWORD& a)
{
char value[2] = {0};
memcpy(value, &a, sizeof(short));
value[1] |= value[0];
memcpy(&a, value, sizeof(short));
}
DWORD fun(DWORD nECX)
{
DWORD nRtn = nECX;
if( nECX <= 0x80 ) // cmp ecx, 80
return nRtn; // jle short 004011F0
thisStack.push(nECX); // push ecx
DWORD nESI = nECX; // mov esi, ecx
nECX &= 0xFF; // and ecx, 0FF
DWORD nEDI = 0x549417E7; // nEAX 值 mov edi, eax ////////////////////// EAX 值
if( !(nECX <= 0x08) ) // cmp ecx, 8; jle short 004011B0
{
nEDI = 0x02F23D32; // nEBX 值 mov edi, ebx ///////////////////// EBX 值
nECX >>= 0x04; // shr ecx, 4
}
int nBit = 0;
do
{
_asm rol nEDI, 8 // rol edi, 8
nBit = SHR(nECX); // SHR ecx, 1
}
while( !nBit ); //jnz short 004011B0
nESI >>= 0x08;
nEDI &= nESI;
nEDI &= 0xFF;
thisStack.pop(nECX);
nESI = 0x80; // mov esi, 80
do
{
int nResult = (nESI & nEDI);
while( !(nResult == 0x00) ) // test esi, edi; je short 004011EC
{
nEDI ^= nESI;
thisStack.push(nEDI); // push edi
nECX &= 0xFF00; // and ecx, 0FF00
XChange(nESI, nECX); // xchg esi, ecx
XOR_HIGH_LOW(nECX); // xor ch, cl
nESI ^= nECX; // xor esi, ecx
XChange(nECX, nESI); // xchg ecx, esi
n402182++; // push ecx; inc dword ptr [402182] // n402182 地址
nECX = fun(nECX); // call 00401190
thisStack.pop(nEDI); // pop edi
nESI = 0x80; // mov esi, 80
nResult = (nESI & nEDI);
}
}while( SHR(nESI) != 1);
return nECX;
}
void main()
{
printf("0x%x\n", fun(0x0FF01));
}