这段时间给公司做了一套软件,要发布的时候,被公司告知要写加密程序,因为对这个领域不数太了解,我就用序列号验证的方法在程序中做了简单的验证,其中的加了一点花指令(初级的)。下面的代码是在程序启动时做的验证方法,我帖出来,大家帮吗看看这样做可不可以,还有没更好的方法,因为都是初级的,大家多指教:
char
*
msg
=
NULL;
__asm ... {
lea eax, DWORD PTR [errormsgok]
mov [msg],eax
}
// 函数调用,返回代码直接写入eax
TestKey();
__asm ... {
push eax
cmp eax, 0x0
// 注册跳转
jz normal
// 未注册跳转
lea eax, DWORD PTR [errormsgerr]
mov [msg],eax
jnz abnormal
// 以下防止一般的反汇编,写入花指令
_emit 0Ebh
// 以下防止一般的反汇编程序查找字符串引用
errormsgok: // 字符串: "OK!"
_emit 0x4f
_emit 0x4b
_emit 0x21
_emit 0x00
errormsgerr: // 字符串:"未注册用户!"
_emit 0xCE
_emit 0xB4
_emit 0xD7
_emit 0xA2
_emit 0xB2
_emit 0xE1
_emit 0xD3
_emit 0xC3
_emit 0xBB
_emit 0xA7
_emit 0xA3
_emit 0xA1
_emit 0x00
}
abnormal:
// 平衡堆栈
__asm ... {
pop eax
}
AfxMessageBox(msg);
return FALSE;
normal:
// 平衡堆栈
__asm ... {
pop eax
}
AfxMessageBox(msg);
__asm ... {
lea eax, DWORD PTR [errormsgok]
mov [msg],eax
}
// 函数调用,返回代码直接写入eax
TestKey();
__asm ... {
push eax
cmp eax, 0x0
// 注册跳转
jz normal
// 未注册跳转
lea eax, DWORD PTR [errormsgerr]
mov [msg],eax
jnz abnormal
// 以下防止一般的反汇编,写入花指令
_emit 0Ebh
// 以下防止一般的反汇编程序查找字符串引用
errormsgok: // 字符串: "OK!"
_emit 0x4f
_emit 0x4b
_emit 0x21
_emit 0x00
errormsgerr: // 字符串:"未注册用户!"
_emit 0xCE
_emit 0xB4
_emit 0xD7
_emit 0xA2
_emit 0xB2
_emit 0xE1
_emit 0xD3
_emit 0xC3
_emit 0xBB
_emit 0xA7
_emit 0xA3
_emit 0xA1
_emit 0x00
}
abnormal:
// 平衡堆栈
__asm ... {
pop eax
}
AfxMessageBox(msg);
return FALSE;
normal:
// 平衡堆栈
__asm ... {
pop eax
}
AfxMessageBox(msg);
弹出对话框引用的字符串是直接写在程序的代码段的。