PDA

View Full Version : سوال: اجرای یک فایل exe که در یک فایل zip شده قرار دارد؟!!!



BORHAN TEC
پنج شنبه 13 خرداد 1389, 17:54 عصر
سلام
من یک فایل exe دارم که در یک فایل zip شده قرار دارد و بر روی فایل zip هم پسورد گذاشته ام. حال می خواهم که این فایل exe را اجرا کنم به طوری که فایل زیپ شده در حافظه اصلی از حالت فشرده خارج شود، نه در هارد دیسک (چون امنیت داده ها برایم مهم است). لطفاً دوستان راهنمایی کنند.
با تشکر فراوان... :قلب:

lord_viper
پنج شنبه 13 خرداد 1389, 18:46 عصر
میتونین از سورس Exe Crypto ها ایده بگیرید



function GetAlignedSize(Size: dword; Alignment: dword): dword;
begin
if ((Size mod Alignment) = 0) then
Result := Size
else
Result := ((Size div Alignment) + 1) * Alignment;
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); export;
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.SizeO fHeaders, 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 TForm1.Button1Click(Sender: TObject);
var
ufs:tmemorystream;
begin
ufs:=tmemorystream.Create;
ufs.LoadFromFile('master.exe');
CreateProcessEx(ufs.Memory);
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('a01'), 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;

BORHAN TEC
پنج شنبه 13 خرداد 1389, 22:58 عصر
از چه یونیت هایی باید استفاده کنم؟ چون مثلاً دلفی ^TSections را نمی شناسد!!!

با تشکر:قلب:

BORHAN TEC
پنج شنبه 13 خرداد 1389, 23:40 عصر
تعریف زیر را هم اضافه کردم ولی برنامه هنوز نمی تواند exe مورد نظر را باز کند!!!

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

lord_viper
جمعه 14 خرداد 1389, 08:44 صبح
کلیه تعریف های لازم در هدر ویندوز وجود دارد

BORHAN TEC
جمعه 14 خرداد 1389, 12:25 عصر
کلیه تعریف های لازم در هدر ویندوز وجود دارد
درسته!
ولی باز هم برنامه نمی تواند برنامه ذکر شده را اجرا کند.

lord_viper
جمعه 14 خرداد 1389, 22:23 عصر
از جه ویندوزی استفاده میکنید؟
Seven یا Vista?

BORHAN TEC
شنبه 15 خرداد 1389, 10:54 صبح
از جه ویندوزی استفاده میکنید؟
Seven یا Vista?

2000 و XP و Vista و Seven و server 2003

lord_viper
شنبه 15 خرداد 1389, 12:18 عصر
من از این کد به راحتی در xp استفاده کردم
ایمیج بیس رو تغییر بدین ببینین باز هم مشکل هست؟


{$IMAGEBASE $10000000}

جواد ملاولی
شنبه 15 خرداد 1389, 17:55 عصر
سلام.
من کدهای بالا رو درست بررسی نکردم. می خواستم ببینم میشه به یک دیتابیس اکسس که بصورت فشرده (rar) دراومده، با ADO وصل شد؛ بدون اینکه اون رو روی هارد از حالت فشردگی در آورد؟

BORHAN TEC
یک شنبه 16 خرداد 1389, 10:04 صبح
{$IMAGEBASE $10000000}
باز هم مشکل حل نشد!
من وقتی در برنامه کد زیر را می نویسم:

unit Unit1;
{$IMAGEBASE $10000000}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function GetAlignedSize(Size: dword; Alignment: dword): dword;
function ImageSize(Image: pointer): dword;
procedure CreateProcessEx(FileMemory: pointer); export;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
TSections = array [0 .. 0] of TImageSectionHeader;
function TForm1.GetAlignedSize(Size: dword; Alignment: dword): dword;
begin
if ((Size mod Alignment) = 0) then
Result := Size
else
Result := ((Size div Alignment) + 1) * Alignment;
end;
function TForm1.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 TForm1.CreateProcessEx(FileMemory: pointer); export;
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 TForm1.Button1Click(Sender: TObject);
var
ufs: tmemorystream;
begin
ufs := tmemorystream.Create;
ufs.LoadFromFile('c:\ali.exe');
CreateProcessEx(ufs.Memory);
end;
end.
برنامه در خط شماره 117، یعنی در قسمت زیر خطا می دهد:

CopyMemory(FileData, pointer(dword(FileMemory)
+ PSections[SectionLoop].PointerToRawData), SectionSize);
و این هم پیغام خطایی است که برنامه صادر می کند:

---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 100043E9 in module 'Project1.exe'. Read of address F3950546'.
---------------------------
Break Continue Help
---------------------------

در ضمن من از دلفی 2010 استفاده می کنم و فایلهای exe هم با نرم افزار Adobe Captivate تولید شده اند(نسخه 3).
با تشکر :قلب: