⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 code.asm

📁 此为本书的配套光盘.本书结合实例
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;函数名:SearchCryptFlag
;功能:搜索加密标记
;入口参数:SearchAddrBegain : DWORD,SearchSize:DWORD,SearchWhat:DWORD
;出口参数:此函数仅仅改变eax值和edx,如果发现 eax就返回发现的地址,否则eax=0,edx返回搜索了多少个字节
SearchCryptFlag PROC uses edi esi ecx ebx SearchAddrBegain : DWORD,SearchSize:DWORD,SearchWhat:DWORD
mov esi,SearchAddrBegain ;esi搜索开始地址

xor eax,eax									;清空eax
xor edx,edx					;搜索计数器
pushf
FirstSearch:
cmp BYTE ptr [esi],0ebh  ;先搜索第一个配备的
jz SecondSearch	;第一个配备
inc edx						;计数器+1
inc esi						;下一个地址
cmp edx,SearchSize			;比较是否搜索到头了
ja find_exit				;退出比较,eax=0
jmp FirstSearch	;继续比较
SecondSearch:
cld							;方向标记df=0
mov edi,SearchWhat			;edi是标记码的地址
mov ecx,0ah					;比较10个
mov ebx,esi					;保存esi
REPE cmps BYTE ptr [esi],BYTE ptr [edi];串比较
jz Find
mov esi,ebx
inc esi						;下一个地址
inc edx						;计数器+1
jmp FirstSearch	;继续比较
Find:
mov eax,ebx					;eax=找到的地址
find_exit:
popf
ret
SearchCryptFlag ENDP


;函数名:For_Crypt_Sdk_Data
;功能:加密数据
;入口参数:CryptAddrBegain : DWORD,CryptSize:DWORD
;出口参数:无
For_Crypt_Sdk_Data PROC uses edi esi edx ecx ebx eax CryptAddrBegain : DWORD,CryptSize:DWORD
mov esi,CryptAddrBegain
mov ecx,CryptSize
Crypt_Next_Data:
not BYTE ptr [esi]
inc esi
loop Crypt_Next_Data
ret
For_Crypt_Sdk_Data ENDP

;函数名:Find_Export_Function_My_Sdk
;功能:寻找给定的字符串
;入口参数:SearchAddrBegain : DWORD,SearchSize:DWORD,SearchWhat:DWORD
;出口参数:eax,eax=1发现,否则eax=0
Find_Export_Function_My_Sdk proc PROC uses edi esi edx ecx ebx SearchAddrBegain : DWORD,SearchSize:DWORD,SearchWhat:DWORD
mov esi,SearchAddrBegain
xor eax,eax									;清空eax
xor edx,edx					;搜索计数器
pushf
FirstSearchChar:
cmp BYTE ptr [esi],'G'  ;先搜索第一个配备的
jz SecondSearchString	;第一个配备
inc edx						;计数器+1
inc esi						;下一个地址
cmp edx,SearchSize			;比较是否搜索到头了
ja Nofind_exit				;退出比较,eax=0
jmp FirstSearchChar	;继续比较
SecondSearchString:
cld							;方向标记df=0
mov edi,SearchWhat			;edi是标记码的地址
mov ecx,14h					;比较20个
mov ebx,esi					;保存esi
REPE cmps BYTE ptr [esi],BYTE ptr [edi];串比较
jz FindString
mov esi,ebx
inc esi						;下一个地址
inc edx						;计数器+1
jmp FirstSearchChar	;继续比较
FindString:
inc eax					;找到eax=1
Nofind_exit:
popf
ret
Find_Export_Function_My_Sdk ENDP

;函数名:RVAToFileMap
;功能:转化RVA到offset
;入口参数:pFileMap:DWORD,RVA:DWORD 
;出口参数:eax=offset of RVAToFileMap
RVAToFileMap PROC uses edi esi edx ecx pFileMap:DWORD,RVA:DWORD 
mov esi,pFileMap 
assume esi:ptr IMAGE_DOS_HEADER 
add esi,[esi].e_lfanew 
assume esi:ptr IMAGE_NT_HEADERS 
mov edi,RVA ; edi == RVA 
mov edx,esi 
add edx,sizeof IMAGE_NT_HEADERS 
mov cx,[esi].FileHeader.NumberOfSections 
movzx ecx,cx 
assume edx:ptr IMAGE_SECTION_HEADER 
.while ecx>0
   .if edi>=[edx].VirtualAddress 
     mov eax,[edx].VirtualAddress 
     add eax,[edx].SizeOfRawData 
     .if edi<eax
       mov eax,[edx].VirtualAddress 
       sub edi,eax
       mov eax,[edx].PointerToRawData 
       add eax,edi
       add eax,pFileMap 
       ret 
     .endif 
   .endif 
   add edx,sizeof IMAGE_SECTION_HEADER 
   dec ecx 
.endw 
assume edx:nothing 
assume esi:nothing 
mov eax,edi 
ret 
RVAToFileMap endp 


CryptFile PROC szFname : LPSTR, hDlg : HWND,dwProtFlags : DWORD
	assume fs : nothing
invoke CreateFileA,szFname,GENERIC_READ or GENERIC_WRITE, \
                   FILE_SHARE_READ or FILE_SHARE_WRITE, \
                   NULL,OPEN_EXISTING, \
	           FILE_ATTRIBUTE_NORMAL,NULL
				  cmp eax,INVALID_HANDLE_VALUE
	jz preadfail
mov hFile, eax ;文件句柄

invoke GetFileSize,hFile,NULL	;得到文件大小
mov dwFsize,eax
invoke GlobalAlloc,GMEM_FIXED,eax;分配内存
mov pMem,eax
invoke SetFilePointer,hFile,0,0,FILE_BEGIN;定位到文件头
invoke ReadFile,hFile,pMem,dwFsize,addr byte_read,0;读文件
push dwFsize
pop Search_Size ;搜索的大小为文件大小
push pMem
pop Search_Addr;从文件头开始搜索

;以下是搜索加密标记的代码
Begain_find:
mov eax,offset My_Shell_CRYPT_BEGIN
push eax				;搜索的是加密开始标记
push Search_Size		;搜索的大小
push Search_Addr			;搜索开始地址
call SearchCryptFlag;开始搜索
cmp eax,0				;是否发现
jz  End_find			;没有发现结束加密
mov Begain_Flag_Addr,eax;保存发现的地址
mov eax,offset My_Shell_CRYPT_END;搜索加密结束的标记
push eax

mov eax,Search_Size
sub eax,edx
mov Search_Size,eax
push Search_Size				;搜索的大小是总大小-已经搜索过的大小

push Begain_Flag_Addr;从搜索到的加密开始标记处开始搜索
call SearchCryptFlag
cmp eax,0				;是否发现
jz End_find				;没有就结束加密
mov End_Flag_Addr,eax;保存发现的地址

mov eax,End_Flag_Addr
sub eax,Begain_Flag_Addr
sub eax,0ah				;得到加密需要加密代码的大小
push eax					;传递参数1

mov ebx,Begain_Flag_Addr;
add ebx,2
mov DWORD ptr [ebx],eax;在10字节加密开始标记的里面保存这次加密代码的大小

mov ebx,End_Flag_Addr;
add ebx,2
mov DWORD ptr [ebx],eax;在10字节加密结束标记的里面保存这次加密代码的大小

mov eax,Begain_Flag_Addr
add eax,0ah				;需加密开始地址
push eax					;传递参数2
call For_Crypt_Sdk_Data;开始加密



mov eax,Search_Size		;搜索的大小是总大小-已经搜索过的大小
sub eax,edx
mov Search_Size,eax	;
push End_Flag_Addr
pop Search_Addr		;下一次搜索地址的开始是结束地址
jmp Begain_find		;继续搜索
End_find:


mov edi,pMem
xor eax,eax
assume edi:ptr IMAGE_DOS_HEADER 
 .if [edi].e_magic==IMAGE_DOS_SIGNATURE 
           add edi, [edi].e_lfanew 
           assume edi:ptr IMAGE_NT_HEADERS 
           .if [edi].Signature==IMAGE_NT_SIGNATURE 
             mov eax, TRUE 
           .else 
             jmp pnope
           .endif 
         .else 
           jmp pnope
         .endif 

			assume edi:ptr IMAGE_NT_HEADERS 
mov edi, [edi].OptionalHeader.DataDirectory.VirtualAddress 
.if edi==0 
invoke MessageBox,hDlg,offset MExportTableErr,offset mtitle,64
jmp NoExportTable
.endif 
invoke RVAToFileMap,pMem,edi
mov edi,eax 
assume edi:ptr IMAGE_EXPORT_DIRECTORY
push [edi].NumberOfNames
pop NumberOfNames
push [edi].nBase 
pop myBase
invoke RVAToFileMap,pMem,[edi].AddressOfNames
mov esi,eax
invoke RVAToFileMap,pMem,[edi].AddressOfNameOrdinals 
mov ebx,eax
invoke RVAToFileMap,pMem,[edi].AddressOfFunctions 
mov edi,eax
assume edi:ptr nothing
.while NumberOfNames>0 
   invoke RVAToFileMap,pMem,dword ptr [esi] 
   mov dx,[ebx] 
   movzx edx,dx 
   mov ecx,edx 
   shl edx,2 
   add edx,edi 
   add ecx,myBase
	mov NameFuncaddr,eax
	
	push dword ptr [edx]
	pop FunctionAddrRva			
	invoke Find_Export_Function_My_Sdk,NameFuncaddr,20h,offset MyEnCryptFunctionName
   .if eax==1
		push FunctionAddrRva			;保存函数的rva用于壳中调用
		pop EnFunctionRva
	.else
	invoke Find_Export_Function_My_Sdk,NameFuncaddr,20h,offset MyDeCryptFunctionName
	.if eax==1
	push FunctionAddrRva				;保存函数的rva用于壳中的调用
	pop DeFunctionRva
	.endif
	.endif
   dec NumberOfNames 
   add esi,4 
   add ebx,2 
.endw

mov edi,pMem
xor eax,eax
assume edi:ptr IMAGE_DOS_HEADER 
add edi, [edi].e_lfanew 
assume edi:ptr IMAGE_NT_HEADERS 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -