有矛就有盾。
所以我们要讨论加密技术。
我们知道,所有的编译型语 言,例如VC、BCB、Delphi和Win32ASM……最终都会把源代码编译成机器能识别的0和1——因此也能够反过来把这些0和1反编译成汇编代 码。反编译有什么用呢?试想想,你辛辛苦苦写了一个perfect的软件出来,正准备把它卖上100万份,忽然!在市面上出现了很多仿制你的东 西……hoho,不知道你会怎么想呢?反正我是会欲哭无泪的。还有另外一种情况,你的软件是用注册码的形式来授权的,每份license要卖30个美刀。 呵呵,正当你在考虑着一年后是去加利福尼亚还是夏威夷度假的时候,你的软件被Crack了——也就是说,你一分钱都不会得到……(啊!我想跳楼啦!!)
所以我们要讨论如何给自己的程序加密。这次就先说说最简单的花指令。
在解释这个“花指令”之前,不妨先做几个小小的实验。
我们先来写一个程序,命名为hua.asm,内容如下:
;*************************************************************** ;花指令实验1 ;作者:罗聪 ;日期:2002-8-21 ;*************************************************************** .386 .model flat, stdcall option casemap:none include "masm32"include"windows.inc include "masm32"include"kernel32.inc include "masm32"include"user32.inc includelib "masm32"lib"kernel32.lib includelib "masm32"lib"user32.lib .data szText db "嘿嘿,这是一个花指令程序……", 0 szCaption db "花指令演示 by LC 2002-8-21", 0 .code main: jmp Do_It Do_It: invoke MessageBox, NULL, addr szText, addr szCaption, MB_OK invoke ExitProcess, 0 end main |
+++++++++++++++++++ ASSEMBLY CODE LISTING ++++++++++++++++++ //********************** Start of Code in Object .text ************** Program Entry Point = 00401000 (hua.exe File Offset:00001600) //******************** Program Entry Point ******** :00401000 EB00 jmp 00401002 * Referenced by a (U)nconditional or ?onditional Jump at Address: |:00401000(U) | :00401002 6A00 push 00000000 * Possible StringData Ref from Data Obj ->"花指令演示 by LC 2002-8-21" | :00401004 681F304000 push 0040301F * Possible StringData Ref from Data Obj ->"嘿嘿,这是一个花指令程序……" | :00401009 6800304000 push 00403000 :0040100E 6A00 push 00000000 * Reference To: USER32.MessageBoxA, Ord:01BBh | :00401010 E80D000000 Call 00401022 :00401015 6A00 push 00000000 * Reference To: KERNEL32.ExitProcess, Ord:0075h | :00401017 E800000000 Call 0040101C |
"嘿嘿,这个是一个花指令程序……" "花指令演示 by LC 2002-8-21" |
;*************************************************************** ;花指令实验2 ;作者:罗聪 ;日期:2002-8-21 ;*************************************************************** .386 .model flat, stdcall option casemap:none include "masm32"include"windows.inc include "masm32"include"kernel32.inc include "masm32"include"user32.inc includelib "masm32"lib"kernel32.lib includelib "masm32"lib"user32.lib .data szText db "嘿嘿,这是一个花指令程序……", 0 szCaption db "花指令演示 by LC 2002-8-21", 0 .code main: jz Do_It ;注意这里和第一个实验中的源程序的区别 jnz Do_It ;注意这里和第一个实验中的源程序的区别 Do_It: invoke MessageBox, NULL, addr szText, addr szCaption, MB_OK end main |
+++++++++++++++++++ ASSEMBLY CODE LISTING ++++++++++++++++++ //********************** Start of Code in Object .text ************** Program Entry Point = 00401000 (hua.exe File Offset:00001600) //******************** Program Entry Point ******** :00401000 7402 je 00401004 :00401002 7500 jne 00401004 * Referenced by a (U)nconditional or ?onditional Jump at Addresses: |:00401000?, :00401002? | :00401004 6A00 push 00000000 * Possible StringData Ref from Data Obj ->"花指令演示 by LC 2002-8-21" | :00401006 681F304000 push 0040301F * Possible StringData Ref from Data Obj ->"嘿嘿,这是一个花指令程序……" | :0040100B 6800304000 push 00403000 :00401010 6A00 push 00000000 * Reference To: USER32.MessageBoxA, Ord:01BBh | :00401012 E801000000 Call 00401018 |
;*************************************************************** ;花指令实验3 ;作者:罗聪 ;日期:2002-8-21 ;*************************************************************** .386 .model flat, stdcall option casemap:none include "masm32"include"windows.inc include "masm32"include"kernel32.inc include "masm32"include"user32.inc includelib "masm32"lib"kernel32.lib includelib "masm32"lib"user32.lib .data szText db "嘿嘿,这是一个花指令程序……", 0 szCaption db "花指令演示 by LC 2002-8-21", 0 .code main: jz Do_It ;注意这里和第一个实验中的源程序的区别 jnz Do_It ;注意这里和第一个实验中的源程序的区别 db 0E8h ;注意这里和第二个实验中的源程序的区别 Do_It: invoke MessageBox, NULL, addr szText, addr szCaption, MB_OK invoke ExitProcess, 0 end main |
+++++++++++++++++++ ASSEMBLY CODE LISTING ++++++++++++++++++ //********************** Start of Code in Object .text ************** Program Entry Point = 00401000 (hua.exe File Offset:00001600) //******************** Program Entry Point ******** :00401000 7403 je 00401005 :00401002 7501 jne 00401005 :00401004 E86A00681D call 1DA81073 :00401009 304000 xor byte ptr [eax+00], al * Possible StringData Ref from Data Obj ->"嘿嘿,这是一个花指令程序……" | :0040100C 6800304000 push 00403000 :00401011 6A00 push 00000000 * Reference To: USER32.MessageBoxA, Ord:01BBh | :00401013 E80E000000 Call 00401026 :00401018 6A00 push 00000000 * Reference To: KERNEL32.ExitProcess, Ord:0075h | :0040101A E801000000 Call 00401020 |
"嘿嘿,这是一个花指令程序……" |
;*************************************************************** ;花指令实验4 ;作者:罗聪 ;日期:2002-8-21 ;*************************************************************** .386 .model flat, stdcall option casemap:none include "masm32"include"windows.inc include "masm32"include"kernel32.inc include "masm32"include"user32.inc includelib "masm32"lib"kernel32.lib includelib "masm32"lib"user32.lib .data szText db "嘿嘿,这是一个花指令程序……", 0 szCaption db "花指令演示 by LC 2002-8-21", 0 .code main: jz Do_It ;注意这里和第一个实验中的源程序的区别 jnz Do_It ;注意这里和第一个实验中的源程序的区别 db 0E8h ;注意这里和第二个实验中的源程序的区别 Do_It: lea eax, szText ;注意这里和第三个实验中的源程序的区别 lea ebx, szCaption ;注意这里和第三个实验中的源程序的区别 invoke MessageBox, NULL, eax, ebx, MB_OK ;注意这里和第三个实验中的源程序的区别 invoke ExitProcess, 0 end main |
+++++++++++++++++++ ASSEMBLY CODE LISTING ++++++++++++++++++ //********************** Start of Code in Object .text ************** Program Entry Point = 00401000 (hua.exe File Offset:00001600) //******************** Program Entry Point ******** :00401000 7403 je 00401005 :00401002 7501 jne 00401005 :00401004 E88D050030 call 30401596 :00401009 40 inc eax :0040100A 008D1D1D3040 add byte ptr [ebp+40301D1D], cl :00401010 006A00 add byte ptr [edx+00], ch :00401013 53 push ebx :00401014 50 push eax :00401015 6A00 push 00000000 * Reference To: USER32.MessageBoxA, Ord:01BBh | :00401017 E80E000000 Call 0040102A :0040101C 6A00 push 00000000 * Reference To: KERNEL32.ExitProcess, Ord:0075h | :0040101E E801000000 Call 00401024 |