该库不再在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的贡献。请随时提交问题,建议新功能或创建拉动请求以扩大其功能和鲁棒性。

用❤️在德尔菲制造