@@ -4,6 +4,7 @@ interface
44
55uses
66 System.Classes,
7+ System.SysUtils,
78
89 PE.Common,
910 PE.Imports.Func;
@@ -15,6 +16,8 @@ TPEImportLibrary = class
1516 FBound: Boolean;
1617 FFunctions: TPEImportFunctions;
1718 FTimeDateStamp: uint32;
19+ FOriginal: boolean;
20+ procedure CheckAddingToOriginalLib ;
1821 public
1922 // Relative address of IAT region for this library.
2023 // It is address of first word in array of words (4/8 bytes) corresponding
@@ -29,7 +32,7 @@ TPEImportLibrary = class
2932 // when import directory is rebuilt.
3033 IatRva: TRVA;
3134
32- constructor Create(const AName: String; Bound: Boolean = False);
35+ constructor Create(const AName: String; Bound: Boolean = False; Original: Boolean = False );
3336 destructor Destroy; override;
3437
3538 function NewFunction (const Name : string): TPEImportFunction; overload;
@@ -43,18 +46,24 @@ TPEImportLibrary = class
4346
4447 property Bound: Boolean read FBound;
4548 property TimeDateStamp: uint32 read FTimeDateStamp write FTimeDateStamp;
49+
50+ // True if it is library parsed from executable.
51+ // You can't add new functions to this library, because IAT must stay untouched.
52+ // Add new library instead.
53+ property Original: boolean read FOriginal;
4654 end ;
4755
4856implementation
4957
5058{ TImportLibrary }
5159
52- constructor TPEImportLibrary.Create(const AName: String; Bound: Boolean);
60+ constructor TPEImportLibrary.Create(const AName: String; Bound: Boolean; Original: Boolean );
5361begin
5462 inherited Create;
5563 FFunctions := TPEImportFunctions.Create;
5664 FName := AName;
5765 FBound := Bound;
66+ FOriginal := Original;
5867end ;
5968
6069destructor TPEImportLibrary.Destroy;
@@ -63,14 +72,22 @@ destructor TPEImportLibrary.Destroy;
6372 inherited ;
6473end ;
6574
75+ procedure TPEImportLibrary.CheckAddingToOriginalLib ();
76+ begin
77+ if (Original) then
78+ raise Exception.Create(' You can'' t add new function to original library.' );
79+ end ;
80+
6681function TPEImportLibrary.NewFunction (const Name : string): TPEImportFunction;
6782begin
83+ CheckAddingToOriginalLib();
6884 Result := TPEImportFunction.Create(Name );
6985 FFunctions.Add(Result);
7086end ;
7187
7288function TPEImportLibrary.NewFunction (Ordinal: uint16): TPEImportFunction;
7389begin
90+ CheckAddingToOriginalLib();
7491 Result := TPEImportFunction.Create(' ' , Ordinal);
7592 FFunctions.Add(Result);
7693end ;
0 commit comments