該庫不再在Windows 11版本24H2中使用。新的安全性增強功能使其非功能。我還沒有找到修復程序!

MemoryDll單元提供了直接從WIN64環境中的內存中加載動態鏈接庫(DLL)的高級功能。與涉及從文件系統加載DLL的傳統方法不同, MemoryDll允許您從字節數組或內存流中加載DLL?該庫非常適合需要管理DLL的Delphi/Freepascal開發人員,而無需依賴文件系統,增強性能和安全性。
MemoryDll通過使用佔位持有人DLL和基於鉤的加載啟用內存DLL加載和重定向,以繞過傳統的基於文件的DLL加載:
advapi32res.dll ),重定向調用以加載特定的DLL。該DLL充當觸發鉤截距並將重定向處理為內存dll的觸發因素。相容性 ? : MemoryDLL單元與標準DLL接口兼容,可以輕鬆地與現有應用程序集成。內存重定向方法還降低了安全風險,例如代碼注入? ,為DLL管理提供了安全的替代方案。
從內存圖像加載模塊,模仿Windows API LoadLibrary功能的行為。它解析PE格式,執行必要的重新定位,解決導入並初始化模塊。
Data: Pointer - 指向符合PE格式的內存圖像的指針。0 THandle 。要成功將MemoryDll集成到您的項目中,請按照以下步驟:
下載最新版本?
解開包裹
將MemoryDll添加到您的項目➕
uses部分。此包含將使MemoryDll單元可用於您的應用程序。確保在項目設置中正確配置了MemoryDll源文件的路徑,以避免編譯錯誤。與Windows API兼容性的無縫集成
MemoryLoadLibrary直接從內存加載DLL來輕鬆集成。加載後,可以使用標準的Windows API調用(例如FreeLibrary和GetProcAddress來管理內存dll,就好像從文件系統加載一樣。此設計確保對現有代碼的更改最小,從而保持了與Windows API約定的兼容性,同時可以有效地內存DLL處理。測試集成✅
要實例化MemoryDll ,請在單元實現部分末尾包含以下代碼。該代碼試圖將DLL作為嵌入式資源加載:
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();
該單元基於A-Normal-User的原始MemoryDll-DllRedirect項目。我們非常感謝本單元所建立的基礎工作。
該項目是根據BSD-3-CAREASE許可獲得許可的?該項目允許在有或沒有修改的情況下重新分佈和使用,並在源和二進製表格中使用。它在允許和保護貢獻者的權利之間取得了平衡。
強烈鼓勵對MemoryDll的貢獻。請隨時提交問題,建議新功能或創建拉動請求以擴大其功能和魯棒性。

用❤️在德爾菲製造