Perpustakaan ini tidak lagi berfungsi di Windows 11 versi 24h2. Peningkatan keamanan baru membuatnya tidak berfungsi. Saya belum menemukan perbaikan!

Unit Memorydll menyediakan fungsionalitas lanjutan untuk memuat pustaka link dinamis (DLL) langsung dari memori di lingkungan Win64. Tidak seperti metode tradisional yang melibatkan memuat DLL dari sistem file, memorydll memungkinkan Anda memuat DLL dari array byte atau aliran memori ?, Retrieve Function Address, dan bongkar-semuanya dalam memori. Perpustakaan ini sangat ideal untuk pengembang Delphi/freepascal yang perlu mengelola DLL tanpa mengandalkan sistem file, meningkatkan kinerja ⚡ dan keamanan.
Memorydll memungkinkan pemuatan dan pengalihan DLL dalam memori dengan menggunakan DLL placeholder dan pemuatan berbasis kait untuk memotong pemuatan DLL berbasis file tradisional:
advapi32res.dll ). DLL ini bertindak sebagai pemicu kait untuk mencegat dan menangani pengalihan ke DLL dalam memori. Kompatibilitas? : Unit MemoryDLL kompatibel dengan antarmuka DLL standar, memungkinkan integrasi yang mudah dengan aplikasi yang ada. Metode pengalihan dalam memori juga mengurangi risiko keamanan, seperti injeksi kode ?, Menawarkan alternatif yang aman untuk manajemen DLL.
Memuat modul dari gambar memori, meniru perilaku fungsi Windows API LoadLibrary . Ini mem -parsing format PE, melakukan relokasi yang diperlukan, menyelesaikan impor, dan menginisialisasi modul.
Data: Pointer - Pointer ke gambar memori yang sesuai dengan format PE.THandle mewakili modul yang dimuat atau 0 pada kegagalan.Agar berhasil mengintegrasikan memori ke dalam proyek Anda, silakan ikuti langkah -langkah ini:
Unduh versi terbaru?
Unzip paket
Tambahkan MemoryDll ke proyek Anda ➕
uses Proyek Anda. Inklusi ini akan membuat unit MemoryDll tersedia untuk digunakan dalam aplikasi Anda. Pastikan bahwa jalur ke file sumber memoresdll dikonfigurasi dengan benar di pengaturan proyek Anda untuk menghindari kesalahan kompilasi.Integrasi tanpa batas dengan kompatibilitas Windows API
MemoryLoadLibrary untuk memuat DLL langsung dari memori. Setelah dimuat, panggilan API Windows standar seperti FreeLibrary dan GetProcAddress dapat digunakan untuk mengelola DLL dalam memori seolah-olah dimuat dari sistem file. Desain ini memastikan perubahan minimal pada kode yang ada, mempertahankan kompatibilitas dengan konvensi Windows API sambil memungkinkan penanganan DLL dalam memori yang efisien.Uji integrasi ✅
Untuk membuat instantiate memori , sertakan kode berikut di akhir bagian implementasi unit. Kode ini mencoba memuat DLL sebagai sumber daya tertanam:
uses
Windows,
MemoryDLL;
...
implementation
{
This code is an example of using MemoryDLL to load an embedded a DLL directly
from an embedded resource in memory, ensuring that no filesystem access is
required. It includes methods for loading, initializing, and unloading the
DLL. The DLL is loaded from a resource with a GUID name, providing a measure
of security by obfuscating the resource’s identity.
Variables:
- DLLHandle: THandle
- A handle to the loaded DLL. Initialized to 0, indicating the DLL has
not been loaded. It is updated with the handle returned from
LoadLibrary when the DLL is successfullyloaded from memory.
Functions:
- LoadDLL: Boolean
- Loads the DLL from an embedded resource and initializes it by
retrieving necessary exported functions. Returns True if the DLL is
loaded successfully, otherwise False.
- b6eb28fd6ebe48359ef93aef774b78d1: string
- A GUID-named helper function that returns the resource name for the DLL.
This GUID-like name helps avoid easy detection of the resource.
- UnloadDLL: procedure
- Unloads the DLL by freeing the library associated with DLLHandle. Resets
DLLHandle to 0 to indicate the DLL is unloaded.
Initialization:
- The LoadDLL function is called during initialization, and the program will
terminate with code 1 if the DLL fails to load.
Finalization:
- The UnloadDLL procedure is called upon finalization, ensuring the DLL is
unloaded before program termination.
}
var
DLLHandle: THandle = 0 ; // Global handle to the loaded DLL, 0 when not loaded.
{
LoadDLL
--------
Attempts to load a DLL directly from a resource embedded within the executable
file. This DLL is expected to be stored as an RCDATA resource under a specific
GUID-like name.
Returns:
Boolean - True if the DLL is successfully loaded, False otherwise.
}
function LoadDLL (): Boolean;
var
LResStream: TResourceStream; // Stream to access the DLL data stored in the
resource.
{
b6eb28fd6ebe48359ef93aef774b78d1
---------------------------------
Returns the name of the embedded DLL resource. Uses a GUID-like name for
obfuscation.
Returns:
string - The name of the resource containing the DLL data.
}
function b6eb28fd6ebe48359ef93aef774b78d1 (): string;
const
// GUID-like resource name for the embedded DLL.
CValue = ' b87deef5bbfd43c3a07379e26f4dec9b ' ;
begin
Result := CValue;
end ;
begin
Result := False;
// Check if the DLL is already loaded.
if DLLHandle <> 0 then Exit;
// Ensure the DLL resource exists.
if not Boolean((FindResource(HInstance,
PChar(b6eb28fd6ebe48359ef93aef774b78d1()), RT_RCDATA) <> 0 )) then Exit;
// Create a stream for the DLL resource data.
LResStream := TResourceStream.Create(HInstance,
b6eb28fd6ebe48359ef93aef774b78d1(), RT_RCDATA);
try
// Attempt to load the DLL from the resource stream.
DLLHandle := MemoryLoadLibrary(LResStream.Memory);
if DLLHandle = 0 then Exit; // Loading failed.
// Retrieve and initialize any necessary function exports from the DLL.
GetExports(DLLHandle);
Result := True; // Successful load and initialization.
finally
LResStream.Free(); // Release the resource stream.
end ;
end ;
{
UnloadDLL
---------
Frees the loaded DLL, releasing any resources associated with DLLHandle,
and resets DLLHandle to 0.
}
procedure UnloadDLL ();
begin
if DLLHandle <> 0 then
begin
FreeLibrary(DLLHandle); // Unload the DLL.
DLLHandle := 0 ; // Reset DLLHandle to indicate the DLL is no longer loaded.
end ;
end ;
initialization
// Attempt to load the DLL upon program startup. Halt execution with error
// code 1 if it fails.
if not LoadDLL() then
begin
Halt( 1 );
end ;
finalization
// Ensure the DLL is unloaded upon program termination.
UnloadDLL();
Unit ini didasarkan pada Proyek Memorydll-Dllredirect asli oleh A-Normal-User. Kami berterima kasih atas pekerjaan dasar yang dibangun oleh unit ini.
Proyek ini dilisensikan di bawah lisensi BSD-3-Clause ?, Yang memungkinkan redistribusi dan penggunaan dalam bentuk sumber dan biner, dengan atau tanpa modifikasi, asalkan kondisi tertentu dipenuhi. Ini mencapai keseimbangan antara permisif dan melindungi hak -hak kontributor.
Kontribusi untuk memorydll sangat dianjurkan. Jangan ragu untuk mengirimkan masalah, menyarankan fitur baru, atau membuat permintaan tarik untuk memperluas kemampuan dan ketahanannya.

Dibuat dengan ❤️ di Delphi