能力值:
( LV2,RANK:10 )
5 楼
invoke CreateFile,addr szFileName,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
.if eax == INVALID_HANDLE_VALUE
invoke MessageBox,mbp.hwndOwner,addr szFileOpenError,addr szDialogCaption,MB_OK or MB_ICONHAND
invoke GetDlgItem,mbp.hwndOwner,ID_TEXT_FILE_NAME
invoke SetFocus,eax
invoke SendMessage,eax,EM_SETSEL,0,-1
.endif
mov hFile,eax
invoke ReadFile,hFile,addr img_dos_hdr,sizeof img_dos_hdr,esp,0
.if img_dos_hdr.e_magic != IMAGE_DOS_SIGNATURE
invoke MessageBox,mbp.hwndOwner,addr szFilePEError,addr szDialogCaption,MB_OK or MB_ICONERROR
.endif
invoke SetFilePointer,hFile,img_dos_hdr.e_lfanew,0,FILE_BEGIN
invoke ReadFile,hFile,addr img_nt_hdr,size img_nt_hdr,esp,0
.if img_nt_hdr.Signature != IMAGE_NT_SIGNATURE
invoke MessageBox,mbp.hwndOwner,addr szFilePEError,addr szDialogCaption,MB_OK or MB_ICONERROR
.endif
xor eax,eax
xor edx,edx
movzx ecx,img_nt_hdr.FileHeader.NumberOfSections
@@s000:
push ecx
push eax
push edx
invoke ReadFile,hFile,addr img_sect_hdr,sizeof img_sect_hdr,esp,0
invoke MessageBox,mbp.hwndOwner,addr [img_sect_hdr.Name1],addr szDialogCaption,MB_OK
;edx记录的是文件中的偏移地址
;eax记录的是相对RVA偏移地址
pop edx
mov eax,img_sect_hdr.PointerToRawData
add eax,img_sect_hdr.SizeOfRawData
cmp eax,edx
jbe @@s001
mov edx,eax
@@s001:
pop eax
mov ecx,[img_sect_hdr.VirtualAddress]
add ecx,[img_sect_hdr.Misc.VirtualSize]
cmp eax,ecx
jae @@s002
mov eax,ecx
@@s002:
pop ecx
loopd @@s000
;增加新节
mov dword ptr [img_sect_hdr.Name1+00h],"caj."
mov dword ptr [img_sect_hdr.Name1+04h],0
mov [img_sect_hdr.Misc.VirtualSize],Attach_Size
mov [img_sect_hdr.VirtualAddress],eax
mov [img_sect_hdr.PointerToRawData],edx
mov [img_sect_hdr.SizeOfRawData],Attach_Size
mov [img_sect_hdr.PointerToRelocations],ecx
mov [img_sect_hdr.PointerToLinenumbers],ecx
mov dword ptr [img_sect_hdr.NumberOfRelocations],ecx
;把VirtualAddress按照1000h对齐
mov edx,00000FFFh
test [img_sect_hdr.VirtualAddress],edx
.if !ZERO?
and edx,[img_sect_hdr.VirtualAddress]
sub edx,1000h
neg edx
add [img_sect_hdr.VirtualAddress],edx
.endif
;PointerToRawData按照200h对齐
xor edx,edx
mov eax,[img_sect_hdr.PointerToRawData]
mov ecx,[img_nt_hdr.OptionalHeader.FileAlignment]
div ecx
test edx,edx
.if !ZERO?
sub edx,[img_nt_hdr.OptionalHeader.FileAlignment]
neg edx
add [img_sect_hdr.PointerToRawData],edx
.endif
mov [img_sect_hdr.Characteristics],0E00000E0h
invoke WriteFile,[hFile],addr img_sect_hdr,sizeof img_sect_hdr,esp,0
invoke SetFilePointer,hFile,[img_sect_hdr.PointerToRawData],0,FILE_BEGIN
push esi
push edi
mov esi,Attach_Start
mov edi,offset szNewBuffer
;mov ecx,Attach_Size
mov ecx,Attach_Size shr 2
rep movsd
mov ecx,Attach_Size
and ecx,3
rep movsb
mov esi,offset szNewBuffer
mov ecx,Attach_Size
@@copy:
mov eax,[esi]
and eax,NOT 00000FFFh
cmp eax,Attach_Data_Start
.if ZERO?
mov eax,[esi]
sub eax,Attach_Start
add eax,[img_nt_hdr.OptionalHeader.ImageBase]
add eax,[img_sect_hdr.VirtualAddress]
mov [esi],eax
.endif
inc esi
loopd @@copy
mov eax,[img_nt_hdr.OptionalHeader.AddressOfEntryPoint]
add eax,[img_nt_hdr.OptionalHeader.ImageBase]
mov dword ptr [szNewBuffer + @@oep],eax
invoke WriteFile,[hFile],addr szNewBuffer,Attach_Size,esp,0
invoke SetFilePointer,[hFile],[img_dos_hdr.e_lfanew],0,FILE_BEGIN
mov eax,[img_sect_hdr.VirtualAddress]
add eax,Attach_Code_Start - Attach_Start
inc [img_nt_hdr.FileHeader.NumberOfSections]
mov [img_nt_hdr.OptionalHeader.AddressOfEntryPoint],eax
mov eax,[img_sect_hdr.VirtualAddress]
add eax,[img_sect_hdr.Misc.VirtualSize]
mov [img_nt_hdr.OptionalHeader.SizeOfImage],eax
invoke WriteFile, [hFile], addr img_nt_hdr, sizeof img_nt_hdr, esp, 0
invoke CloseHandle,[hFile]
能力值:
( LV2,RANK:10 )
6 楼
这段代码就是壳了,我是参考别的一些程序写的,还只是新手,正在学习中
_call MACRO procedure, parameters:VARARG
LOCAL param, reversed
reversed TEXTEQU <>
% for param, <parameters>
reversed CATSTR <param>, <!,>, reversed
endm
% for param, <reversed>
push param
endm
call procedure
ENDM
Attachment proto
_GetKernelBase proto :dword
_GetApi proto :dword,:dword
.code
;下面是要用到的一大堆变量定义:
;以“_”开头,并以 API 函数名相接的,是用来储存通过 GetProcAddress 得到的 API 线形地址:
Attach_Start equ $
Attach_Data_Start equ $
hLibUser32 dd ?
_GetProcAddress dd 0
_LoadLibrary dd 0
_FreeLibrary dd 0
_ExitProcess dd 0
_MessageBox dd 0
szLibUser32 db "user32", 0
szGetProcAddress db "GetProcAddress",0
szProcLoadLibrary db "LoadLibraryA", 0
szProcFreeLibrary db "FreeLibrary", 0
szProcExitProcess db "ExitProcess", 0
szProcMessageBox db "MessageBoxA", 0
szWarning db "要继续运行该程序吗",0
szCaption db "程序提示",0
;*********************************************************
;真正的代码开始
;*********************************************************
Attach_Code_Start equ $
;*********************************************************
;附加段的子程序处理模块
;*********************************************************
Attachment proc
;以下是经典的查找 kernel32.dll 的基地址的代码:
call @F
@@:
pop ebx
sub ebx,offset @B
invoke _GetKernelBase,[esp];获取kernel32的基址
push ebp
push ebx
push esi
push edi
mov ebp,eax;kernel32的基址
invoke _GetApi,eax,addr szGetProcAddress;获得GetProcAddress的地址
mov [_GetProcAddress],eax
;下面的是通过 GetProcAddress 获得一大堆 API 的线形地址,并储存起来,供后面使用:
_call [_GetProcAddress], ebp, offset szProcFreeLibrary
mov [_FreeLibrary], eax
_call [_GetProcAddress], ebp, offset szProcExitProcess
mov [_ExitProcess], eax
_call [_GetProcAddress], ebp, offset szProcLoadLibrary
mov [_LoadLibrary], eax
;载入 user32.dll ,并储存它的句柄:
_call eax, offset szLibUser32
mov [hLibUser32], eax
_call [_GetProcAddress], [hLibUser32], offset szProcMessageBox
mov [_MessageBox], eax
pop edi
pop esi
pop ebx
pop ebp
_call [_MessageBox],NULL,offset szWarning,offset szCaption,MB_YESNO
.if eax==IDYES
@@oep equ $ - Attach_Start + 1
mov eax, 00000000h
jmp eax
.else
_call [_FreeLibrary],[hLibUser32]
_call [_ExitProcess],0
.endif
Attachment endp
_GetKernelBase proc _dwKernelRet
LOCAL @dwReturn
pushad
mov @dwReturn,0
;relocation
call @F
@@:
pop ebx
sub ebx,@B
mov edi,_dwKernelRet
and edi,0ffff0000h
.while TRUE
.if word ptr [edi] == IMAGE_DOS_SIGNATURE
mov esi,edi
add esi,[esi + 003ch]
.if word ptr [esi] == IMAGE_NT_SIGNATURE
mov @dwReturn,edi
.break
.endif
.endif
_PageError:
sub edi,1000h
.break .if edi < 070000000h
.endw
popad
mov eax,@dwReturn
ret
_GetKernelBase endp
_GetApi proc _hModule,_lpszApi
LOCAL @dwReturn,@dwLength
pushad
mov @dwReturn,0
;relocation
call @F
@@:
pop ebx
sub ebx,offset @B
;Compute the API string length
mov edi,_lpszApi
mov ecx,-1
xor al,al
cld
repnz scasb
mov ecx,edi
sub ecx,_lpszApi
mov @dwLength,ecx
;Get the Api entre address from
mov esi,_hModule
add esi,[esi+3ch]
mov esi,[esi][IMAGE_NT_HEADERS.OptionalHeader.DataDirectory.VirtualAddress]
add esi,_hModule
;Search the Api name
mov ebx,[esi][IMAGE_EXPORT_DIRECTORY.AddressOfNames]
add ebx,_hModule
xor edx,edx
.repeat
push esi
mov edi,[ebx]
add edi,_hModule
mov esi,_lpszApi
mov ecx,@dwLength
repz cmpsb
.if ZERO?
pop esi
jmp @F
.endif
pop esi
add ebx,4
inc edx
.until edx > [esi][IMAGE_EXPORT_DIRECTORY.NumberOfNames]
jmp _Error
@@:
;Api's name index --> Api's Num index --> Api's address index
sub ebx,[esi][IMAGE_EXPORT_DIRECTORY.AddressOfNames]
sub ebx,_hModule
shr ebx,1 ;maybe because AddressOfNameOrdinals is a word array,not a dword array
add ebx,[esi][IMAGE_EXPORT_DIRECTORY.AddressOfNameOrdinals]
add ebx,_hModule
movzx eax,word ptr [ebx]
shl eax,2;?
add eax,[esi][IMAGE_EXPORT_DIRECTORY.AddressOfFunctions]
add eax,_hModule
;Get Api's address from function address table
mov eax,[eax]
add eax,_hModule
mov @dwReturn,eax
_Error:
popad
mov eax,@dwReturn
ret
_GetApi endp
;收工!
Attach_Size equ $ - offset Attach_Start