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.