Delphi 形式函数原型:
function FixResFromStream(AStream: TMemoryStream; ErrMsg: PChar): Boolean;
参数说明:
AStream 为 PE 映象的内存流,其他说明同 <1> 。
此函数对写注册机的朋友特别适用,当你将 dump 出来的 PE 内存映象保存到硬盘之前,你可以先
进行资源修复,通过对内存流的操作,可以减少代码工作量。注意:该函数仅适用于 Delphi 语言。
第二类:导出重建后的资源节功能。由于不同的加壳程序对原始 PE 文件的结构改变的千差万别,
导致对脱壳文件的 PE 结构优化方案也是千差万别的,因此很难在一个程序里完成对所有
脱壳类型的 PE 结构优化,引擎将机会留给用户自己。作为使用者,你可能知道如何脱某
种类型的壳以及如何优化脱壳后的 PE 结构,那么你也就可能需要将修复后的资源节加载
在你认为更合适的 RVA 地址起始处。该功能接口能满足你的这个定制需要,由于该功能的
相对复杂性,要求使用者对 PE 结构必须十分属性,因此本功能仅适合高级用户使用。
此函数对写注册机的朋友特别适用,当你将 dump 出来的 PE 内存映象保存到硬盘之前,你可能需
要进行 PE 结构的优化,在优化之前很可能需要导出重建的资源节。通过对内存流的操作,可以减
少代码工作量。注意:该函数仅适用于 Delphi 语言。
特别提示:引擎只在正确 PE 格式的基础上修复、重建 PE 资源,因此应用以上五个函数之前请保
证被操作文件或者内存流均具有正确的 PE 格式,否则可能造成不可预期的错误。
调用范例(Delphi 语言):
procedure FixResDemo;
type
TFixPERes = function(const AFileName: PChar; ErrBuff: PChar): Boolean; stdcall;
var
ErrBuff: array[1..80] of Char;
Handle: THandle;
FixPERes: TFixPERes;
begin
Handle := LoadLibrary('DT_FixRes.dll');
if Handle <> 0 then
begin
@FixPERes := GetProcAddress(Handle, 'FixResFromFile');
if @FixPERes <> nil then
if not FixPERes(PChar('ur PE file'), @ErrBuff) then
ShowMessage(ErrBuff);
FreeLibrary(Handle);
end;
end;
It is a common problem in packed PE files that after unpacking, their resources cannot be viewed or modified by some resource explorers. The main reason for this is that many packers/protectors move the uncompressable resources(eg. Icon,Version information) into the appended section, while most of the resource explorers cannot recognize correctly the resources distributed in two separate sections(except PE explorer, by the way). DT_FixRes is a professional resource rebuilding engine for PE files, capable of recollecting the resources in different sections into a single one, optimizing structures and removing junks if any. Comparable to resource compilers, DT_FixRes restores the resource structures on an almost perfect basis. PE files, when fixed by DT_FixRes, expose the resources to all the resource explorers for free view or modification.
The functions of DT_FixRes are accessible to programmers and especially to software localizers through specific intefaces.
Disclaimers:
1.DT_FixRes is free for use, subject to the inclusion of copyrights for support to the author.
2.DT_FixRes is presumbly safe to use, but the author holds no responsibility for any damages possibly caused by the engine.
Instructions:
The engine of DT_FixRes is implemented as a dll, exporting five functions in all, sorted into two types.
1st Type: Restoration of PE resources. When done, the engine will unconditionally append a resource section to the PE file, resulting in an increase in size. These functions apply to simple restoration of unpacked PE files.
<1> Export Function Name: FixResFromFile
-Prototype for C
BOOL __stdcall FixResFromFile(const char* PEFile, char* ErrBuff);
-Prototype for Delphi
function FixResFromFile(const AFileName: PChar; ErrMsg: PChar): Boolean; stdcall;
Arguments Specifications:
PEFile --- Pointer to the path of the PE file whose resource is to be fixed;
ErrBuff --- Pointer to buffer with the size of at least 80 bytes, for the reception for error messages.
This function is compatible with all Win32 platforms.
<2> Export Function Name: FixResFromStream
-Prototype for Delphi
function FixResFromStream(AStream: TMemoryStream; ErrMsg: PChar): Boolean;
Arguments Specifications:
AStream represents the memory stream of the PE image. Refer to (1) for the others.
This function is especially applicable to keygen makers. You may fix the resources by operating the memory stream for a reduction on customized code before dumping the PE image onto your harddisk. Note that it is exclusively compatible with Delphi.
2nd Type: Export of restored resource section. There are various schemes of optimization for dumped PE files due to diversified modifications made to the original PE files by different packers/protectors. The engine provides an oppurtunity to the programmers that they can make customed optimization to the dumped PE files. As the caller, you may be quite acquainted with the best optimization scheme for the specific packer/protector as well as the best starting RVA to load the resource section into. So this function is prepared for the customed requirement. Note that the user should be familiar with PE stuctures on account of the relative complexity of this function. Advanced users only.
<1> Export Function Name: DumpResFromFile
-Prototype for C
BOOL __stdcall DumpResFromFile(const char* PEFile, char* ResFile,
DWORD NewRVA, DWord FileAlign, char* ErrBuff);
-Prototype for Delphi
function DumpResFromFile(const PEFile: PChar; const ResFile: PChar;
NewRVA: DWord; FileAlign: DWord; ErrMsg: PChar): Boolean; stdcall;
Arguments Specifications:
PEFile --- Pointer to the path of the PE file whose resource is to be fixed;
ResFile --- Pointer to the path of the exported resource section;
NewRVA --- RVA for the PE file to load resource section into, or the virtual address of resource data directory;
FileAlign --- File alignment of the resource section, 0x200 or 0x1000 exclusively;
ErrBuff --- Pointer to buffer with the size of at least 80 bytes, for the reception for error messages.
This function is compatible with all Win32 platforms.
<2> Export Function Name: DumpResFromStream
-Prototype for Delphi
function DumpResFromStream(PEStream: TMemoryStream; const ResFile: string;
NewRVA: DWord; FileAlign: DWord; ErrMsg: PChar): Boolean;
Arguments Specifications:
AStream represents the memory stream of the PE image. Refer to (1) for the others.
<3> Export Function Name: DumpResFromStreamEx
-Prototype for Delphi
function DumpResFromStreamEx(PEStream: TMemoryStream; ResStream: TMemoryStream;
NewRVA: DWord; FileAlign: DWord; ErrMsg: PChar): Boolean;
This function is especially applicable to keygen makers. You may fix the resources by operating the memory stream for a reduction on customized code before dumping the PE image onto your harddisk. Note that it is exclusively compatible with Delphi.
Special tips:
The engine restores only the resource of a correctly structured PE file so that please make sure of the validity of the target PE file before calling any of the above five functions. Otherwise, it may result in unexpectable errors.
Demo for Delphi:
procedure FixResDemo;
type
TFixPERes = function(const AFileName: PChar; ErrBuff: PChar): Boolean; stdcall;
var
ErrBuff: array[1..80] of Char;
Handle: THandle;
FixPERes: TFixPERes;
begin
Handle := LoadLibrary('DT_FixRes.dll');
if Handle <> 0 then
begin
@FixPERes := GetProcAddress(Handle, 'FixResFromFile');
if @FixPERes <> nil then
if not FixPERes(PChar('ur PE file'), @ErrBuff) then
ShowMessage(ErrBuff);
FreeLibrary(Handle);
end;
end;
Others:
I wrote a demo to test the engine, which located in the same directory as the dll did. Please feel free to inform me of the bugs if any.