放下代码 PE文件变形之初步 移动PE头

程序代码

.386

.model flat,stdcall
option casemap:none
include windows. inc
include user32. inc
include kernel32. inc
include gdi32. inc
includelib gdi32.lib
includelib user32.lib
includelib kernel32.lib
Message  proto :DWORD
movfile proto  :dword,:dword,:dword
IsPeFile proto :dword
MovPeHead proto :dword,:dword,:dword
.data
     
     szFileName db " E:\stu1\stu2\bin\Debug\main.exe ", 0
     szEorro    db " file open fail ", 0
     szCaption  db " PEêμÑé ", 0
     szsuccesful db " successful! ", 0
     szpe    db " this is a pe file ", 0
     szPeMovNo  db " Îļt2»Dèòaòƶˉ ", 0
     szNoPe     db " this is not PE file ", 0
.data?
     hFileHanld dword ?
     szbuff  dword 4096 dup (?)
     szreadnum dword ?
     szbuff1    IMAGE_DOS_HEADER <>
     dwPeRav    dword ?
     
.code
      start:
            
            invoke CreateFile,offset szFileName,GENERIC_READ or GENERIC_WRITE,NULL,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
            .IF eax==INVALID_HANDLE_VALUE
                invoke MessageBox,NULL,offset szEorro,offset szCaption,MB_OK
                invoke ExitProcess,NULL
            .endif
            
             mov hFileHanld ,eax
            invoke ReadFile,hFileHanld,offset szbuff, 0400h,offset szreadnum,NULL
            invoke IsPeFile,offset szbuff
            .if eax== 0
                invoke MessageBox,NULL,szNoPe,NULL,MB_OK
                jmp over
            .endif
             mov dwPeRav,eax
            invoke MovPeHead,offset szbuff,0ch,dwPeRav
            
            invoke SetFilePointer,hFileHanld, 0, 0,FILE_BEGIN
            invoke WriteFile,hFileHanld,offset szbuff,400h,NULL,NULL
            
            
            
          over:  
            invoke ExitProcess,NULL
           Message proc lpstring:dword
               
               invoke MessageBox,NULL,lpstring,offset szCaption,MB_OK
                ret

           Message endp
          movfile proc   dst:dword, src:dword, sizelen:dword
              
               mov edi,dst
               mov esi,src
               mov ecx,sizelen
          next:    movsb
               mov byte ptr [esi- 1], 0
              loop next
               ret

          movfile endp
          IsPeFile proc lpbuff:dword
               mov esi,lpbuff
               mov eax, 0
              assume esi : ptr IMAGE_DOS_HEADER
              .IF [esi].e_magic== " ZM "
                   mov esi,[esi].e_lfanew
                   add esi,lpbuff
                  .if word ptr [esi]== " EP "
                      invoke Message ,offset szpe
                      sub esi,lpbuff
                      mov eax,esi
                  .endif
                 
              .endif
         
              assume esi : nothing   
               ret

          IsPeFile endp
         
         MovPeHead proc lpDosHead :dword,dwPosition : DWORD,dwPeRav1 :dword
             mov eax,dwPeRav1
             .if dwPosition==eax
                 invoke MessageBox,NULL,offset szPeMovNo,NULL,MB_OK
                  ret
             .endif
               mov esi,lpDosHead
               push esi
              assume esi:ptr IMAGE_DOS_HEADER
               mov esi,[esi].e_lfanew
               add esi,lpDosHead
              assume esi:nothing
              assume esi:ptr IMAGE_NT_HEADERS
               mov  dx,[esi].FileHeader.NumberOfSections
               movzx edx,dx
               mov eax,sizeof(IMAGE_SECTION_HEADER)
               MUL edx
               add eax,sizeof(IMAGE_NT_HEADERS)
              assume esi : nothing
               mov ebx,lpDosHead
               add ebx,dwPosition
              invoke movfile,ebx,esi,eax   
               pop esi
              assume esi : ptr IMAGE_DOS_HEADER
               mov eax,dwPosition
               mov [esi].e_lfanew,eax
              assume esi:nothing
               ret
         MovPeHead endp
     end start
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值