├── BTMemoryModule
├── BTMemoryModule.pas
└── license.txt
├── DelphiDemo
├── DemoApp
│ ├── basic
│ │ ├── DemoApp.dpr
│ │ ├── Main.dfm
│ │ └── Main.pas
│ └── loadfromresource
│ │ ├── DemoAppRes.dpr
│ │ ├── DemoDLL.RES
│ │ ├── Main.dfm
│ │ ├── Main.pas
│ │ └── compile_res
│ │ ├── DemoDLL.dll
│ │ ├── DemoDLL.rc
│ │ └── compileRcScript.bat
└── DemoDll
│ └── DemoDLL.dpr
├── LazarusDemo
├── DemoApp
│ ├── BTMemoryModule.ppu
│ ├── DemoApp.compiled
│ ├── DemoApp.ico
│ ├── DemoApp.lpi
│ ├── DemoApp.lpr
│ ├── DemoApp.lrs
│ ├── DemoApp.manifest
│ ├── DemoApp.rc
│ ├── DemoApp.res
│ ├── demodll.dll
│ ├── fpc-res.or
│ ├── fpc-res.res
│ ├── main.lfm
│ ├── main.lrs
│ ├── main.pas
│ └── main.ppu
└── DemoDll
│ ├── demodll.compiled
│ ├── demodll.ico
│ ├── demodll.lpi
│ ├── demodll.lpr
│ ├── demodll.manifest
│ ├── demodll.rc
│ ├── demodll.res
│ ├── fpc-res.or
│ └── fpc-res.res
├── changes.txt
└── license.txt
/BTMemoryModule/BTMemoryModule.pas:
--------------------------------------------------------------------------------
1 | unit BTMemoryModule;
2 |
3 | { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4 | * Memory DLL loading code (32bit) *
5 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
6 | * Delphi BTMemoryModule 0.0.4.2 *
7 | * Copyright (c) 2005-2015 by Martin Offenwanger / coder@dsplayer.com *
8 | * http://www.dsplayer.com *
9 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
10 | * BTMemoryModule originally is a plain pascal port from c code *
11 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
12 | * Original C Code Copyright (c) 2004- 2005 by Joachim Bauch *
13 | * mail@joachim-bauch.de *
14 | * http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/ *
15 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
16 | * Thanks to Markus_13 (Markus_13@ymail.com) for the SectionFinalization *
17 | * flags contribution. *
18 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
19 | * Mozilla Public License Version 1.1: *
20 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
21 | * The contents of this file are used with permission, subject to the *
22 | * Mozilla Public License Version 1.1 (the "License"); you may *
23 | * not use this file except in compliance with the License. You may *
24 | * obtain a copy of the License at *
25 | * http://www.mozilla.org/MPL/MPL-1.1.html *
26 | * *
27 | * Software distributed under the License is distributed on an *
28 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or *
29 | * implied. See the License for the specific language governing *
30 | * rights and limitations under the License. *
31 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
32 | {
33 | @author(Martin Offenwanger: coder@dsplayer.com)
34 | @created(Mar 20, 2005)
35 | @lastmod(Apr 14, 2015)
36 | @supported operationg systems(Windows 98 up to Windows 8)
37 | ==============================================================================
38 | => this versino should work for all Delphi versions from 7 up to 2010 <=
39 | => including on most of Lazaru Free Pascal 32bit releases <=
40 | ==============================================================================
41 | @tested Delphi compilers(Delphi 7, Delphi 2007 , Delphi 2010, Delphi XE2)
42 | @tested Free Pascal compilers(Lazarus 0.9.28.2 & Free Pascal 2.2.4 ,
43 | Lazarus 1.2.6 & Free Pascal 2.6.4)
44 | }
45 |
46 | {$IFDEF FPC}
47 | {$WARNINGS OFF}
48 | {$HINTS OFF}
49 | {$ELSE FPC}
50 | {$WARN UNSAFE_CODE OFF}
51 | {$WARN UNSAFE_TYPE OFF}
52 | {$WARN UNSAFE_CAST OFF}
53 | {$ENDIF FPC}
54 |
55 | interface
56 |
57 | uses
58 | Windows;
59 |
60 | { ++++++++++++++++++++++++++++++++++++++
61 | *** MemoryModule Type Definition ***
62 | -------------------------------------- }
63 | type
64 | PBTMemoryModule = ^TBTMemoryModule;
65 |
66 | _BT_MEMORY_MODULE = packed record
67 | headers: PImageNtHeaders;
68 | codeBase: Pointer;
69 | modules: Pointer;
70 | numModules: Integer;
71 | initialized: boolean;
72 | end;
73 | {$EXTERNALSYM _BT_MEMORY_MODULE}
74 |
75 | TBTMemoryModule = _BT_MEMORY_MODULE;
76 | BT_MEMORY_MODULE = _BT_MEMORY_MODULE;
77 | {$EXTERNALSYM BT_MEMORY_MODULE}
78 | PUInt64 = ^UInt64;
79 |
80 | { +++++++++++++++++++++++++++++++++++
81 | *** SectionFinalization Flags ***
82 | ----------------------------------- }
83 | TSFFlag = Byte;
84 | const
85 | SF_NOFIN = $0; // no SectionFinalization
86 | {$EXTERNALSYM SF_NOFIN}
87 | SF_PROTECT = $1; // SectionFinalization with VirtualProtect
88 | {$EXTERNALSYM SF_PROTECT}
89 | SF_DISCARD = $10; // SectionFinalization with Discard
90 | {$EXTERNALSYM SF_DISCARD}
91 | SF_BOTH = $11; // FIN_PROTECT + FIN_DISCARD
92 | {$EXTERNALSYM SF_BOTH}
93 |
94 |
95 | { ++++++++++++++++++++++++++++++++++++++++++++++++++
96 | *** Memory DLL loading functions Declaration ***
97 | -------------------------------------------------- }
98 |
99 | // return value is nil if function fails
100 | function BTMemoryLoadLibary(fp_data: Pointer; const f_size: int64;
101 | f_SectionFinalization: TSFFlag = SF_BOTH;
102 | f_DllProcessAttach: Boolean = True): PBTMemoryModule;
103 |
104 | // return value is nil if function fails
105 | function BTMemoryGetProcAddress(fp_module: PBTMemoryModule;
106 | const fp_name: PChar): Pointer;
107 | // free module
108 | procedure BTMemoryFreeLibrary(fp_module: PBTMemoryModule);
109 | // returns last error
110 | function BTMemoryGetLastError: string;
111 |
112 | implementation
113 |
114 | uses
115 | SysUtils;
116 |
117 | { +++++++++++++++++++++++++++++++++++
118 | *** Dll EntryPoint Definition ***
119 | ----------------------------------- }
120 | type
121 | TDllEntryProc = function(hinstdll: THandle; fdwReason: DWORD;
122 | lpReserved: Pointer): BOOL; stdcall;
123 | PDllEntryProc = ^TDllEntryProc;
124 |
125 | { ++++++++++++++++++++++++++++++++++++++++
126 | *** Missing Windows API Definitions ***
127 | ---------------------------------------- }
128 |
129 | const
130 | IMAGE_SIZEOF_SHORT_NAME = 8;
131 |
132 | type
133 |
134 | PImageExportDirectory = ^TImageExportDirectory;
135 |
136 | _IMAGE_EXPORT_DIRECTORY = packed record
137 | Characteristics: DWORD;
138 | TimeDateStamp: DWORD;
139 | MajorVersion: Word;
140 | MinorVersion: Word;
141 | Name: DWORD;
142 | Base: DWORD;
143 | NumberOfFunctions: DWORD;
144 | NumberOfNames: DWORD;
145 | AddressOfFunctions: ^PDWORD;
146 | AddressOfNames: ^PDWORD;
147 | ADDressOfNameOrdinals: ^PWord;
148 | end;
149 | {$EXTERNALSYM _IMAGE_EXPORT_DIRECTORY}
150 |
151 | TImageExportDirectory = _IMAGE_EXPORT_DIRECTORY;
152 | IMAGE_EXPORT_DIRECTORY = _IMAGE_EXPORT_DIRECTORY;
153 | {$EXTERNALSYM IMAGE_EXPORT_DIRECTORY}
154 | PImageDosHeader = ^TImageDosHeader;
155 |
156 | _IMAGE_DOS_HEADER = packed record
157 | e_magic: Word;
158 | e_cblp: Word;
159 | e_cp: Word;
160 | e_crlc: Word;
161 | e_cparhdr: Word;
162 | e_minalloc: Word;
163 | e_maxalloc: Word;
164 | e_ss: Word;
165 | e_sp: Word;
166 | e_csum: Word;
167 | e_ip: Word;
168 | e_cs: Word;
169 | e_lfarlc: Word;
170 | e_ovno: Word;
171 | e_res: array [0 .. 3] of Word;
172 | e_oemid: Word;
173 | e_oeninfo: Word;
174 | e_res2: array [0 .. 9] of Word;
175 | _lfanew: LongInt;
176 | end;
177 | {$EXTERNALSYM _IMAGE_DOS_HEADER}
178 |
179 | TImageDosHeader = _IMAGE_DOS_HEADER;
180 | IMAGE_DOS_HEADER = _IMAGE_DOS_HEADER;
181 | {$EXTERNALSYM IMAGE_DOS_HEADER}
182 |
183 | TISHMisc = packed record
184 | case Integer of
185 | 0:
186 | (PhysicalAddress: DWORD);
187 | 1:
188 | (VirtualSize: DWORD);
189 | end;
190 |
191 | PImageSectionHeader = ^TImageSectionHeader;
192 |
193 | _IMAGE_SECTION_HEADER = packed record
194 | Name: packed array [0 .. IMAGE_SIZEOF_SHORT_NAME - 1] of Byte;
195 | Misc: TISHMisc;
196 | VirtualAddress: DWORD;
197 | SizeOfRawData: DWORD;
198 | PointerToRawData: DWORD;
199 | PointerToRelocations: DWORD;
200 | PointerToLinenumbers: DWORD;
201 | NumberOfRelocations: Word;
202 | NuberOfLinenumbers: Word;
203 | Characteristics: DWORD;
204 | end;
205 | {$EXTERNALSYM _IMAGE_SECTION_HEADER}
206 |
207 | TImageSectionHeader = _IMAGE_SECTION_HEADER;
208 | IMAGE_SECTION_HEADER = _IMAGE_SECTION_HEADER;
209 | {$EXTERNALSYM IMAGE_SECTION_HEADER}
210 | PImageBaseRelocation = ^TImageBaseRelocation;
211 |
212 | _IMAGE_BASE_RELOCATION = packed record
213 | VirtualAddress: DWORD;
214 | SizeOfBlock: DWORD;
215 | end;
216 | {$EXTERNALSYM _IMAGE_BASE_RELOCATION}
217 |
218 | TImageBaseRelocation = _IMAGE_BASE_RELOCATION;
219 | IMAGE_BASE_RELOCATION = _IMAGE_BASE_RELOCATION;
220 | {$EXTERNALSYM IMAGE_BASE_RELOCATION}
221 | PImageImportDescriptor = ^TImageImportDescriptor;
222 |
223 | _IMAGE_IMPORT_DESCRIPTOR = packed record
224 | OriginalFirstThunk: DWORD;
225 | TimeDateStamp: DWORD;
226 | ForwarderChain: DWORD;
227 | Name: DWORD;
228 | FirstThunk: DWORD;
229 | end;
230 | {$EXTERNALSYM _IMAGE_IMPORT_DESCRIPTOR}
231 |
232 | TImageImportDescriptor = _IMAGE_IMPORT_DESCRIPTOR;
233 | IMAGE_IMPORT_DESCRIPTOR = _IMAGE_IMPORT_DESCRIPTOR;
234 | {$EXTERNALSYM IMAGE_IMPORT_DESCRIPTOR}
235 | PImageImportByName = ^TImageImportByName;
236 |
237 | _IMAGE_IMPORT_BY_NAME = packed record
238 | Hint: Word;
239 | Name: array [0 .. 255] of Byte; // original: "Name: array [0..0] of Byte;"
240 | end;
241 | {$EXTERNALSYM _IMAGE_IMPORT_BY_NAME}
242 |
243 | TImageImportByName = _IMAGE_IMPORT_BY_NAME;
244 | IMAGE_IMPORT_BY_NAME = _IMAGE_IMPORT_BY_NAME;
245 | {$EXTERNALSYM IMAGE_IMPORT_BY_NAME}
246 |
247 | TPRawChar = array[0..2047] of WideChar;
248 |
249 | TSectionInfo = packed record
250 | Addr:Pointer;
251 | Size:DWORD;
252 | end;
253 | TSectionList = array of TSectionInfo;
254 |
255 | const
256 | IMAGE_SIZEOF_BASE_RELOCATION = 8;
257 | {$EXTERNALSYM IMAGE_SIZEOF_BASE_RELOCATION}
258 | IMAGE_REL_BASED_HIGHLOW = 3;
259 | {$EXTERNALSYM IMAGE_REL_BASED_HIGHLOW}
260 | IMAGE_ORDINAL_FLAG32 = DWORD($80000000);
261 | {$EXTERNALSYM IMAGE_ORDINAL_FLAG32}
262 | IMAGE_DIRECTORY_ENTRY_IMPORT = 1;
263 | {$EXTERNALSYM IMAGE_DIRECTORY_ENTRY_IMPORT}
264 | IMAGE_DIRECTORY_ENTRY_BASERELOC = 5;
265 | {$EXTERNALSYM IMAGE_DIRECTORY_ENTRY_BASERELOC}
266 | IMAGE_SCN_LNK_NRELOC_CVFL = $01000000;
267 | {$EXTERNALSYM IMAGE_SCN_LNK_NRELOC_CVFL}
268 | IMAGE_SCN_MEM_DISCARDABLE = $02000000;
269 | {$EXTERNALSYM IMAGE_SCN_MEM_DISCARDABLE}
270 | IMAGE_SCN_MEM_NOT_CACHED = $04000000;
271 | {$EXTERNALSYM IMAGE_SCN_MEM_NOT_CACHED}
272 | IMAGE_SCN_MEM_NOT_PAGED = $08000000;
273 | {$EXTERNALSYM IMAGE_SCN_MEM_NOT_PAGED}
274 | IMAGE_SCN_MEM_NOT_SHARED = $10000000;
275 | {$EXTERNALSYM IMAGE_SCN_MEM_NOT_SHARED}
276 | IMAGE_SCN_MEM_EXECUTE = $20000000;
277 | {$EXTERNALSYM IMAGE_SCN_MEM_EXECUTE}
278 | IMAGE_SCN_MEM_READ = $40000000;
279 | {$EXTERNALSYM IMAGE_SCN_MEM_READ}
280 | IMAGE_SCN_MEM_WRITE = DWORD($80000000);
281 | {$EXTERNALSYM IMAGE_SCN_MEM_WRITE}
282 | IMAGE_SCN_CNT_INITIALIZED_DATA = $00000040;
283 | {$EXTERNALSYM IMAGE_SCN_CNT_INITIALIZED_DATA}
284 | IMAGE_SCN_CNT_UNINITIALIZED_DATA = $00000080;
285 | {$EXTERNALSYM IMAGE_SCN_CNT_UNINITIALIZED_DATA}
286 | IMAGE_DIRECTORY_ENTRY_EXPORT = 0;
287 | {$EXTERNALSYM IMAGE_DIRECTORY_ENTRY_EXPORT}
288 |
289 |
290 |
291 | var
292 | lastErrStr: string;
293 | SectionList:TSectionList;
294 | { +++++++++++++++++++++++++++++++++++++++++++++++++++++
295 | *** Memory DLL loading functions Implementation ***
296 | ----------------------------------------------------- }
297 |
298 | function BTMemoryGetLastError: string;
299 | begin
300 | Result := lastErrStr;
301 | end;
302 |
303 | procedure IncP(var f_X; f_N: UInt64);
304 | begin
305 | Pointer(f_X) := Pointer(UInt64(f_X) + f_N);
306 | end;
307 |
308 | procedure DecP(var f_X; f_N: UInt64);
309 | begin
310 | Pointer(f_X) := Pointer(UInt64(f_X) - f_N);
311 | end;
312 |
313 | function IncF(f_X: Pointer; f_N: UInt64): Pointer; overload;
314 | begin
315 | try
316 | Result := Pointer(UInt64(f_X) + f_N);
317 | except
318 | Result := nil;
319 | end;
320 | end;
321 |
322 | function IncF(f_X: Pointer; f_N: Pointer): Pointer; overload;
323 | begin
324 | try
325 | Result := Pointer(UInt64(f_X) + UInt64(f_N));
326 | except
327 | Result := nil;
328 | end;
329 | end;
330 |
331 | function DecF(f_X: Pointer; f_N: UInt64): Pointer;
332 | begin
333 | try
334 | Result := Pointer(UInt64(f_X) - f_N);
335 | except
336 | Result := nil;
337 | end;
338 | end;
339 |
340 | //function PAnsiCharToPChar(f_X: Pointer): PChar;
341 | //begin
342 | //{$IFDEF UNICODE}
343 | // Result := StringToOleStr(PAnsiChar(f_X));
344 | //{$ELSE}
345 | // Result := PAnsiChar(f_X);
346 | //{$ENDIF}
347 | //end;
348 |
349 | procedure PAnsiCharToPChar(f_X: Pointer;Var f_Y:TPRawChar);
350 | const
351 | {$IFDEF UNICODE}
352 | Size:Integer = 2;
353 | {$ELSE}
354 | Size:Integer = 1;
355 | {$ENDIF}
356 | var
357 | I:Integer;
358 | begin
359 | FillChar(f_Y,sizeof(f_Y),#0);
360 | for I := Low(f_Y) to High(f_Y) do
361 | begin
362 | PByte(PByte(@f_Y[0])+ I*Size)^ := PByte(PByte(f_X) + I)^;
363 | if PByte(PByte(f_X) + I)^ = 0 then Exit;
364 | end;
365 | end;
366 |
367 | function GetFieldOffset(const Struc; const Field): Cardinal;
368 | begin
369 | Result := UInt64(@Field) - UInt64(@Struc);
370 | end;
371 |
372 | function GetImageFirstSection(NtHeader: PImageNtHeaders): PImageSectionHeader;
373 | stdcall;
374 | begin
375 | Result := PImageSectionHeader(UInt64(NtHeader) + GetFieldOffset(NtHeader^,
376 | NtHeader^.OptionalHeader) + NtHeader^.FileHeader.SizeOfOptionalHeader);
377 | end;
378 |
379 | function GetHeaderDictionary(f_module: PBTMemoryModule;
380 | f_idx: Integer): PImageDataDirectory;
381 | begin
382 | Result := PImageDataDirectory
383 | (@(f_module^.headers^.OptionalHeader.DataDirectory[f_idx]));
384 | end;
385 |
386 | function GetImageOrdinal(Ordinal: DWORD): Word;
387 | begin
388 | Result := Ordinal and $FFFF;
389 | end;
390 |
391 | function GetImageSnapByOrdinal(Ordinal: DWORD): boolean;
392 | begin
393 | Result := ((Ordinal and IMAGE_ORDINAL_FLAG32) <> 0);
394 | end;
395 |
396 | procedure CopySections(fp_data: Pointer; f_old_headers: TImageNtHeaders;
397 | fp_module: PBTMemoryModule);
398 | var
399 | lp_dest: Pointer;
400 | l_size, l_i: Integer;
401 | lp_section: PImageSectionHeader;
402 | begin
403 | lp_section := GetImageFirstSection(fp_module^.headers);
404 | SetLength(SectionList,fp_module^.headers^.FileHeader.NumberOfSections);
405 | for l_i := 0 to fp_module^.headers^.FileHeader.NumberOfSections - 1 do
406 | begin
407 | // section doesn't contain data in the dll itself, but may define
408 | // uninitialized data
409 | if (lp_section^.SizeOfRawData = 0) then
410 | begin
411 | l_size := f_old_headers.OptionalHeader.SectionAlignment;
412 | if l_size > 0 then
413 | begin
414 | lp_dest := VirtualAlloc(IncF(fp_module^.codeBase,
415 | lp_section^.VirtualAddress), l_size, MEM_COMMIT,
416 | PAGE_EXECUTE_READWRITE);
417 | SectionList[l_i].Addr:=lp_dest;
418 | SectionList[l_i].Size:=l_size;
419 | lp_section^.Misc.PhysicalAddress := UInt64(lp_dest);
420 | ZeroMemory(lp_dest, l_size);
421 | end;
422 | IncP(lp_section, SizeOf(TImageSectionHeader));
423 | end
424 | else
425 | begin
426 | // commit memory block and copy data from dll
427 | lp_dest := VirtualAlloc(IncF(fp_module^.codeBase,
428 | lp_section^.VirtualAddress), lp_section^.SizeOfRawData,
429 | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
430 | SectionList[l_i].Addr:=lp_dest;
431 | SectionList[l_i].Size:=lp_section^.SizeOfRawData;
432 | CopyMemory(lp_dest, IncF(fp_data, lp_section^.PointerToRawData),
433 | lp_section^.SizeOfRawData);
434 | lp_section^.Misc.PhysicalAddress := UInt64(lp_dest);
435 | IncP(lp_section, SizeOf(TImageSectionHeader));
436 | end;
437 | end;
438 | end;
439 |
440 | // xy this procedure still contains 32 bit code..
441 | procedure PerformBaseRelocation(f_module: PBTMemoryModule; f_delta: Cardinal);
442 | stdcall;
443 | var
444 | l_i: Cardinal;
445 | lp_directory: PImageDataDirectory;
446 | lp_relocation: PImageBaseRelocation;
447 | lp_dest: Pointer;
448 | lp_relInfo: PWord;
449 | l_type, l_offset: Integer;
450 | begin
451 | lp_directory := GetHeaderDictionary(f_module,
452 | IMAGE_DIRECTORY_ENTRY_BASERELOC);
453 | if lp_directory^.Size > 0 then
454 | begin
455 | lp_relocation := IncF(f_module^.codeBase, lp_directory^.VirtualAddress);
456 | while lp_relocation^.VirtualAddress > 0 do
457 | begin
458 | lp_dest := IncF(f_module^.codeBase, lp_relocation^.VirtualAddress);
459 | lp_relInfo := IncF(lp_relocation, IMAGE_SIZEOF_BASE_RELOCATION);
460 | for l_i := 0 to (trunc(((lp_relocation^.SizeOfBlock -
461 | IMAGE_SIZEOF_BASE_RELOCATION) / 2)) - 1) do
462 | begin
463 | // the upper 4 bits define the type of relocation
464 | l_type := (lp_relInfo^ shr 12);
465 | // the lower 12 bits define the offset
466 | l_offset := lp_relInfo^ and $FFF;
467 | if l_type = IMAGE_REL_BASED_HIGHLOW then
468 | begin
469 | // change complete 32 bit address
470 | IncP(PUInt64(IncF(lp_dest, l_offset))^, f_delta);
471 | end;
472 | Inc(lp_relInfo);
473 | end;
474 | IncP(lp_relocation, lp_relocation^.SizeOfBlock);
475 | end;
476 | end;
477 | end;
478 |
479 | function BuildImportTable(fp_module: PBTMemoryModule): boolean; stdcall;
480 | var
481 | lp_directory: PImageDataDirectory;
482 | lp_importDesc: PImageImportDescriptor;
483 | lp_thunkRef, lp_funcRef: PCardinal;
484 | l_handle: HMODULE;
485 | l_temp: Integer;
486 | l_thunkData: TImageImportByName;
487 | s_temp:TPRawChar;
488 | begin
489 | Result := true;
490 | lp_directory := GetHeaderDictionary(fp_module, IMAGE_DIRECTORY_ENTRY_IMPORT);
491 | if (lp_directory^.Size > 0) then
492 | begin
493 | lp_importDesc := IncF(fp_module^.codeBase, lp_directory^.VirtualAddress);
494 | while (not IsBadReadPtr(lp_importDesc, SizeOf(TImageImportDescriptor))) and
495 | (lp_importDesc^.Name <> 0) do
496 | begin
497 | PAnsiCharToPChar(IncF(fp_module^.codeBase,lp_importDesc^.Name),s_temp);
498 | l_handle := LoadLibrary(
499 | PChar(@s_temp[0])
500 | );
501 | if (l_handle = INVALID_HANDLE_VALUE) then
502 | begin
503 | PAnsiCharToPChar((IncF(fp_module^.codeBase, lp_importDesc^.Name)),s_temp);
504 | lastErrStr :=
505 | (
506 | 'BuildImportTable: can''t load library: ' +
507 | PChar(@s_temp[0])
508 | );
509 | Result := false;
510 | exit;
511 | end;
512 | // ReallocMemory crashes if "f_module.modules = nil"
513 | if fp_module^.modules = nil then
514 | fp_module^.modules := AllocMem(1);
515 | fp_module^.modules := ReallocMemory(fp_module^.modules,
516 | ((fp_module^.numModules + 1) * (SizeOf(UInt64))));
517 | if fp_module^.modules = nil then
518 | begin
519 | lastErrStr := 'BuildImportTable: ReallocMemory failed';
520 | Result := false;
521 | exit;
522 | end;
523 | // module->modules[module->numModules++] = handle;
524 | l_temp := (SizeOf(UInt64) * (fp_module^.numModules));
525 | IncP(fp_module^.modules, l_temp);
526 | UInt64(fp_module^.modules^) := l_handle;
527 | DecP(fp_module^.modules, l_temp);
528 | fp_module^.numModules := fp_module^.numModules + 1;
529 | if lp_importDesc^.OriginalFirstThunk <> 0 then
530 | lp_thunkRef := IncF(fp_module^.codeBase,
531 | lp_importDesc^.OriginalFirstThunk)
532 | else
533 | lp_thunkRef := IncF(fp_module^.codeBase, lp_importDesc^.FirstThunk);
534 | lp_funcRef := IncF(fp_module^.codeBase, lp_importDesc^.FirstThunk);
535 | while lp_thunkRef^ <> 0 do
536 | begin
537 | if GetImageSnapByOrdinal(lp_thunkRef^) then
538 | lp_funcRef^ := UInt64(GetProcAddress(l_handle,
539 | PAnsiChar(GetImageOrdinal(lp_thunkRef^))))
540 | else
541 | begin
542 | CopyMemory(@l_thunkData, IncF(fp_module^.codeBase, lp_thunkRef^),
543 | SizeOf(TImageImportByName));
544 | lp_funcRef^ := UInt64(GetProcAddress(l_handle,
545 | PAnsiChar(@(l_thunkData.Name))));
546 | end;
547 | if lp_funcRef^ = 0 then
548 | begin
549 | lastErrStr := 'BuildImportTable: GetProcAddress failed';
550 | Result := false;
551 | break;
552 | end;
553 | Inc(lp_funcRef);
554 | Inc(lp_thunkRef);
555 | end;
556 | IncP(lp_importDesc, SizeOf(TImageImportDescriptor));
557 | end;
558 | end;
559 | end;
560 |
561 | function GetSectionProtection(f_SC: Cardinal): Cardinal; stdcall;
562 | // SC ?ImageSectionHeader.Characteristics
563 | begin
564 | Result := 0;
565 | if (f_SC and IMAGE_SCN_MEM_NOT_CACHED) <> 0 then
566 | Result := Result or PAGE_NOCACHE;
567 | // E - Execute, R ?Read , W ?Write
568 | if (f_SC and IMAGE_SCN_MEM_EXECUTE) <> 0 // E ?
569 | then
570 | if (f_SC and IMAGE_SCN_MEM_READ) <> 0 // ER ?
571 | then
572 | if (f_SC and IMAGE_SCN_MEM_WRITE) <> 0 // ERW ?
573 | then
574 | Result := Result or PAGE_EXECUTE_READWRITE
575 | else
576 | Result := Result or PAGE_EXECUTE_READ
577 | else if (f_SC and IMAGE_SCN_MEM_WRITE) <> 0 // EW?
578 | then
579 | Result := Result or PAGE_EXECUTE_WRITECOPY
580 | else
581 | Result := Result or PAGE_EXECUTE
582 | else if (f_SC and IMAGE_SCN_MEM_READ) <> 0 // R?
583 | then
584 | if (f_SC and IMAGE_SCN_MEM_WRITE) <> 0 // RW?
585 | then
586 | Result := Result or PAGE_READWRITE
587 | else
588 | Result := Result or PAGE_READONLY
589 | else if (f_SC and IMAGE_SCN_MEM_WRITE) <> 0 // W?
590 | then
591 | Result := Result or PAGE_WRITECOPY
592 | else
593 | Result := Result or PAGE_NOACCESS;
594 | end;
595 |
596 | procedure FinalizeSections(fp_module: PBTMemoryModule;
597 | f_SectionFinalization: TSFFlag); stdcall;
598 | var
599 | l_i: Integer;
600 | lp_section: PImageSectionHeader;
601 | l_protect, l_oldProtect, l_size: Cardinal;
602 | begin
603 | lp_section := GetImageFirstSection(fp_module^.headers);
604 |
605 | for l_i := 0 to fp_module^.headers^.FileHeader.NumberOfSections - 1 do
606 | begin
607 |
608 | if ((f_SectionFinalization and SF_DISCARD) <> 0) and
609 | ((lp_section^.Characteristics and IMAGE_SCN_MEM_DISCARDABLE) <> 0) then
610 | begin
611 | // section is not needed any more and can safely be freed
612 | VirtualFree(Pointer(lp_section^.Misc.PhysicalAddress),
613 | lp_section^.SizeOfRawData, MEM_DECOMMIT);
614 | IncP(lp_section, SizeOf(TImageSectionHeader));
615 | Continue;
616 | end;
617 |
618 | if ((f_SectionFinalization and SF_PROTECT) <> 0) and
619 | ((lp_section^.Characteristics and IMAGE_SCN_MEM_DISCARDABLE)=0) then
620 | begin
621 | l_protect := GetSectionProtection(lp_section^.Characteristics);
622 | if (lp_section^.Characteristics and IMAGE_SCN_MEM_NOT_CACHED) <> 0 then
623 | l_protect := (l_protect or PAGE_NOCACHE);
624 | // determine size of region
625 | l_size := lp_section^.SizeOfRawData;
626 | if l_size = 0 then
627 | begin
628 | if (lp_section^.Characteristics and IMAGE_SCN_CNT_INITIALIZED_DATA)
629 | <> 0 then
630 | begin
631 | l_size := fp_module^.headers^.OptionalHeader.SizeOfInitializedData;
632 | end else begin
633 | if (lp_section^.Characteristics and IMAGE_SCN_CNT_UNINITIALIZED_DATA)
634 | <> 0 then
635 | l_size := fp_module^.headers^.OptionalHeader.SizeOfUninitializedData;
636 | end;
637 | if l_size > 0 then
638 | begin
639 | if not VirtualProtect(Pointer(lp_section^.Misc.PhysicalAddress),
640 | lp_section^.SizeOfRawData, l_protect, @l_oldProtect) then
641 | begin
642 | lastErrStr := 'FinalizeSections: VirtualProtect failed';
643 | exit;
644 | end;
645 | end;
646 | end;
647 | end;
648 |
649 | IncP(lp_section, SizeOf(TImageSectionHeader));
650 | end;
651 | end;
652 |
653 | function BTMemoryLoadLibary(fp_data: Pointer; const f_size: int64;
654 | f_SectionFinalization: TSFFlag = SF_BOTH;
655 | f_DllProcessAttach: Boolean = True): PBTMemoryModule;
656 | var
657 | lp_result: PBTMemoryModule;
658 | l_dos_header: TImageDosHeader;
659 | l_old_header: TImageNtHeaders;
660 | l_code, l_headers: Pointer;
661 | l_locationdelta: Cardinal;
662 | lp_DllEntry: PDllEntryProc;
663 | l_successfull: boolean;
664 | begin
665 | lp_result := nil;
666 | Result := nil;
667 | try
668 | CopyMemory(@l_dos_header, fp_data, SizeOf(_IMAGE_DOS_HEADER));
669 | if (l_dos_header.e_magic <> IMAGE_DOS_SIGNATURE) then
670 | begin
671 | lastErrStr := 'BTMemoryLoadLibary: dll dos header is not valid';
672 | exit;
673 | end;
674 | CopyMemory(@l_old_header, IncF(fp_data, l_dos_header._lfanew),
675 | SizeOf(_IMAGE_NT_HEADERS));
676 | if l_old_header.Signature <> IMAGE_NT_SIGNATURE then
677 | begin
678 | lastErrStr := 'BTMemoryLoadLibary: IMAGE_NT_SIGNATURE is not valid';
679 | exit;
680 | end;
681 | // reserve memory for image of library
682 | l_code := VirtualAlloc(Pointer(l_old_header.OptionalHeader.ImageBase),
683 | l_old_header.OptionalHeader.SizeOfImage, MEM_RESERVE,
684 | PAGE_EXECUTE_READWRITE);
685 | if l_code = nil then
686 | // try to allocate memory at arbitrary position
687 | l_code := VirtualAlloc(nil, l_old_header.OptionalHeader.SizeOfImage,
688 | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
689 | if l_code = nil then
690 | begin
691 | lastErrStr := 'BTMemoryLoadLibary: VirtualAlloc failed';
692 | exit;
693 | end;
694 | // alloc space for the result record
695 | lp_result := PBTMemoryModule(HeapAlloc(GetProcessHeap(), 0,
696 | SizeOf(TBTMemoryModule)));
697 | lp_result^.codeBase := l_code;
698 | lp_result^.numModules := 0;
699 | lp_result^.modules := nil;
700 | lp_result^.initialized := false;
701 | // xy: is it correct to commit the complete memory region at once?
702 | // calling DllEntry raises an exception if we don't...
703 | VirtualAlloc(l_code, l_old_header.OptionalHeader.SizeOfImage, MEM_COMMIT,
704 | PAGE_EXECUTE_READWRITE);
705 | // commit memory for headers
706 | l_headers := VirtualAlloc(l_code,
707 | l_old_header.OptionalHeader.SizeOfHeaders, MEM_COMMIT,
708 | PAGE_EXECUTE_READWRITE);
709 | // copy PE header to code
710 | CopyMemory(l_headers, fp_data,
711 | (UInt64(l_dos_header._lfanew)
712 | + l_old_header.OptionalHeader.SizeOfHeaders));
713 | lp_result^.headers := PImageNtHeaders
714 | (UInt64(l_headers) + l_dos_header._lfanew);
715 | // update position
716 | lp_result^.headers^.OptionalHeader.ImageBase := UInt64(l_code);
717 | // copy sections from DLL file block to new memory location
718 | CopySections(fp_data, l_old_header, lp_result);
719 | // adjust base address of imported data
720 | l_locationdelta := Cardinal
721 | (UInt64(l_code) - l_old_header.OptionalHeader.ImageBase);
722 | if l_locationdelta <> 0 then
723 | PerformBaseRelocation(lp_result, l_locationdelta);
724 | // load required dlls and adjust function table of imports
725 | if not BuildImportTable(lp_result) then
726 | begin
727 | lastErrStr := lastErrStr + ' BTMemoryLoadLibary: BuildImportTable failed';
728 | Abort;
729 | end;
730 | // mark memory pages depending on section headers and release
731 | // sections that are marked as "discardable"
732 | FinalizeSections(lp_result, f_SectionFinalization);
733 | // get entry point of loaded library
734 | if (lp_result^.headers^.OptionalHeader.AddressOfEntryPoint) <> 0 then
735 | begin
736 | lp_DllEntry := Pointer
737 | (UInt64(l_code)
738 | + lp_result^.headers^.OptionalHeader.AddressOfEntryPoint);
739 | if lp_DllEntry = nil then
740 | begin
741 | lastErrStr := 'BTMemoryLoadLibary: Get DLLEntyPoint failed';
742 | Abort;
743 | end;
744 | if f_DllProcessAttach then begin
745 | l_successfull := TDllEntryProc(lp_DllEntry)(UInt64(l_code),
746 | DLL_PROCESS_ATTACH, nil);
747 | if not l_successfull then
748 | begin
749 | lastErrStr := 'BTMemoryLoadLibary: Can''t attach library';
750 | Abort;
751 | end;
752 | end;
753 | lp_result^.initialized := true;
754 | end;
755 | except
756 | BTMemoryFreeLibrary(lp_result);
757 | exit;
758 | end;
759 | Result := lp_result;
760 | end;
761 |
762 | function BTMemoryGetProcAddress(fp_module: PBTMemoryModule;
763 | const fp_name: PChar): Pointer;
764 | var
765 | l_idx: Integer;
766 | l_i: DWORD;
767 | l_nameRef: PDWORD;
768 | l_ordinal: PWord;
769 | l_exports: PImageExportDirectory;
770 | l_directory: PImageDataDirectory;
771 | s_temp:TPRawChar;
772 | begin
773 | Result := nil;
774 | l_idx := -1;
775 | l_directory := GetHeaderDictionary(fp_module, IMAGE_DIRECTORY_ENTRY_EXPORT);
776 | if l_directory^.Size = 0 then
777 | begin
778 | lastErrStr := 'BTMemoryGetProcAddress: no export table found';
779 | exit;
780 | end;
781 | l_exports := IncF(fp_module^.codeBase, l_directory^.VirtualAddress);
782 | if ((l_exports^.NumberOfNames = 0) or (l_exports^.NumberOfFunctions = 0)) then
783 | begin
784 | lastErrStr := 'BTMemoryGetProcAddress: DLL doesn''t export anything';
785 | exit;
786 | end;
787 | // search function name in list of exported names
788 | l_nameRef := IncF(fp_module^.codeBase, l_exports^.AddressOfNames);
789 | l_ordinal := IncF(fp_module^.codeBase, l_exports^.ADDressOfNameOrdinals);
790 | for l_i := 0 to l_exports^.NumberOfNames - 1 do
791 | begin
792 | PAnsiCharToPChar((IncF(fp_module^.codeBase, l_nameRef^)),s_temp);
793 | if StrComp(
794 | fp_name,
795 | PChar(@s_temp[0])
796 | ) = 0 then
797 | begin
798 | l_idx := l_ordinal^;
799 | break;
800 | end;
801 | Inc(l_nameRef);
802 | Inc(l_ordinal);
803 | end;
804 | if (l_idx = -1) then
805 | begin
806 | lastErrStr := 'BTMemoryGetProcAddress: exported symbol not found';
807 | exit;
808 | end;
809 | if (UInt64(l_idx) > l_exports^.NumberOfFunctions - 1) then
810 | begin
811 | lastErrStr :=
812 | 'BTMemoryGetProcAddress: name <-> ordinal number don''t match';
813 | exit;
814 | end;
815 | // AddressOfFunctions contains the RVAs to the "real" functions
816 | Result := IncF(fp_module^.codeBase,
817 | PUInt64(IncF(fp_module^.codeBase, IncF(l_exports^.AddressOfFunctions,
818 | l_idx * 4)))^);
819 | end;
820 |
821 | procedure BTMemoryFreeLibrary(fp_module: PBTMemoryModule);
822 | var
823 | lp_module: PBTMemoryModule;
824 | l_i: Integer;
825 | l_temp: Integer;
826 | lp_DllEntry: PDllEntryProc;
827 | begin
828 | lp_module := fp_module;
829 | if lp_module <> nil then
830 | begin
831 | if lp_module^.initialized then
832 | begin
833 | lp_DllEntry := IncF(lp_module^.codeBase,
834 | lp_module^.headers^.OptionalHeader.AddressOfEntryPoint);
835 | TDllEntryProc(lp_DllEntry)(UInt64(lp_module^.codeBase),
836 | DLL_PROCESS_DETACH, nil);
837 | lp_module^.initialized := false;
838 | // free previously opened libraries
839 | for l_i := 0 to lp_module^.numModules - 1 do
840 | begin
841 | l_temp := (SizeOf(UInt64) * (l_i));
842 | IncP(lp_module^.modules, l_temp);
843 | if UInt64(fp_module^.modules^) <> INVALID_HANDLE_VALUE then
844 | FreeLibrary(UInt64(fp_module^.modules^));
845 | DecP(lp_module^.modules, l_temp);
846 | end;
847 | FreeMemory(lp_module^.modules);
848 | if lp_module^.codeBase <> nil then
849 | // release memory of library
850 | VirtualFree(lp_module^.codeBase, 0, MEM_RELEASE);
851 | HeapFree(GetProcessHeap(), 0, fp_module);
852 | Pointer(fp_module) := nil;
853 | end;
854 | for l_i := Low(SectionList) to High(SectionList) do
855 | begin
856 | if SectionList[l_i].Addr <> nil then
857 | begin
858 | VirtualFree(SectionList[l_i].Addr,SectionList[l_i].Size,MEM_RELEASE);
859 | end;
860 | end;
861 |
862 | end;
863 | end;
864 |
865 | end.
--------------------------------------------------------------------------------
/BTMemoryModule/license.txt:
--------------------------------------------------------------------------------
1 |
2 | { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3 | * Memory DLL loading code (32bit) *
4 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
5 | * Delphi BTMemoryModule 0.0.4.2 *
6 | * Copyright (c) 2005-2015 by Martin Offenwanger / coder@dsplayer.com *
7 | * http://www.dsplayer.com *
8 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
9 | * BTMemoryModule originally is a plain pascal port from c code *
10 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
11 | * Original C Code Copyright (c) 2004- 2005 by Joachim Bauch *
12 | * mail@joachim-bauch.de *
13 | * http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/ *
14 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
15 | * Thanks to Markus_13 (Markus_13@ymail.com) for the SectionFinalization *
16 | * flags contribution. *
17 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
18 | * Mozilla Public License Version 1.1: *
19 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
20 | * The contents of this file are used with permission, subject to the *
21 | * Mozilla Public License Version 1.1 (the "License"); you may *
22 | * not use this file except in compliance with the License. You may *
23 | * obtain a copy of the License at *
24 | * http://www.mozilla.org/MPL/MPL-1.1.html *
25 | * *
26 | * Software distributed under the License is distributed on an *
27 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or *
28 | * implied. See the License for the specific language governing *
29 | * rights and limitations under the License. *
30 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
31 | {
32 | @author(Martin Offenwanger: coder@dsplayer.com)
33 | @created(Mar 20, 2005)
34 | @lastmod(Apr 14, 2015)
35 | @supported operationg systems(Windows 98 up to Windows 8)
36 | ==============================================================================
37 | => this versino should work for all Delphi versions from 7 up to 2010 <=
38 | => including on most of Lazaru Free Pascal 32bit releases <=
39 | ==============================================================================
40 | @tested Delphi compilers(Delphi 7, Delphi 2007 , Delphi 2010, Delphi XE2)
41 | @tested Free Pascal compilers(Lazarus 0.9.28.2 & Free Pascal 2.2.4 ,
42 | Lazarus 1.2.6 & Free Pascal 2.6.4)
43 | }
44 |
45 |
46 | Mozilla Public License Version 1.1
47 | 1. Definitions.
48 | 1.0.1. "Commercial Use"
49 | means distribution or otherwise making the Covered Code available to a third party.
50 | 1.1. "Contributor"
51 | means each entity that creates or contributes to the creation of Modifications.
52 | 1.2. "Contributor Version"
53 | means the combination of the Original Code, prior Modifications used by a Contributor, and the Modifications made by that particular Contributor.
54 | 1.3. "Covered Code"
55 | means the Original Code or Modifications or the combination of the Original Code and Modifications, in each case including portions thereof.
56 | 1.4. "Electronic Distribution Mechanism"
57 | means a mechanism generally accepted in the software development community for the electronic transfer of data.
58 | 1.5. "Executable"
59 | means Covered Code in any form other than Source Code.
60 | 1.6. "Initial Developer"
61 | means the individual or entity identified as the Initial Developer in the Source Code notice required by Exhibit A.
62 | 1.7. "Larger Work"
63 | means a work which combines Covered Code or portions thereof with code not governed by the terms of this License.
64 | 1.8. "License"
65 | means this document.
66 | 1.8.1. "Licensable"
67 | means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein.
68 | 1.9. "Modifications"
69 | means any addition to or deletion from the substance or structure of either the Original Code or any previous Modifications. When Covered Code is released as a series of files, a Modification is:
70 |
71 | a.Any addition to or deletion from the contents of a file containing Original Code or previous Modifications.
72 | b.Any new file that contains any part of the Original Code or previous Modifications.
73 | 1.10. "Original Code"
74 | means Source Code of computer software code which is described in the Source Code notice required by Exhibit A as Original Code, and which, at the time of its release under this License is not already Covered Code governed by this License.
75 | 1.10.1. "Patent Claims"
76 | means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor.
77 | 1.11. "Source Code"
78 | means the preferred form of the Covered Code for making modifications to it, including all modules it contains, plus any associated interface definition files, scripts used to control compilation and installation of an Executable, or source code differential comparisons against either the Original Code or another well known, available Covered Code of the Contributor's choice. The Source Code can be in a compressed or archival form, provided the appropriate decompression or de-archiving software is widely available for no charge.
79 | 1.12. "You" (or "Your")
80 | means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License or a future version of this License issued under Section 6.1. For legal entities, "You" includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
81 | 2. Source Code License.
82 | 2.1. The Initial Developer Grant.
83 | The Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license, subject to third party intellectual property claims:
84 |
85 | a.under intellectual property rights (other than patent or trademark) Licensable by Initial Developer to use, reproduce, modify, display, perform, sublicense and distribute the Original Code (or portions thereof) with or without Modifications, and/or as part of a Larger Work; and
86 | b.under Patents Claims infringed by the making, using or selling of Original Code, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Code (or portions thereof).
87 | c.the licenses granted in this Section 2.1 (a) and (b) are effective on the date Initial Developer first distributes Original Code under the terms of this License.
88 | d.Notwithstanding Section 2.1 (b) above, no patent license is granted: 1) for code that You delete from the Original Code; 2) separate from the Original Code; or 3) for infringements caused by: i) the modification of the Original Code or ii) the combination of the Original Code with other software or devices.
89 | 2.2. Contributor Grant.
90 | Subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license
91 |
92 | a.under intellectual property rights (other than patent or trademark) Licensable by Contributor, to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof) either on an unmodified basis, with other Modifications, as Covered Code and/or as part of a Larger Work; and
93 | b.under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: 1) Modifications made by that Contributor (or portions thereof); and 2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination).
94 | c.the licenses granted in Sections 2.2 (a) and 2.2 (b) are effective on the date Contributor first makes Commercial Use of the Covered Code.
95 | d.Notwithstanding Section 2.2 (b) above, no patent license is granted: 1) for any code that Contributor has deleted from the Contributor Version; 2) separate from the Contributor Version; 3) for infringements caused by: i) third party modifications of Contributor Version or ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or 4) under Patent Claims infringed by Covered Code in the absence of Modifications made by that Contributor.
96 | 3. Distribution Obligations.
97 | 3.1. Application of License.
98 | The Modifications which You create or to which You contribute are governed by the terms of this License, including without limitation Section 2.2. The Source Code version of Covered Code may be distributed only under the terms of this License or a future version of this License released under Section 6.1, and You must include a copy of this License with every copy of the Source Code You distribute. You may not offer or impose any terms on any Source Code version that alters or restricts the applicable version of this License or the recipients' rights hereunder. However, You may include an additional document offering the additional rights described in Section 3.5.
99 |
100 | 3.2. Availability of Source Code.
101 | Any Modification which You create or to which You contribute must be made available in Source Code form under the terms of this License either on the same media as an Executable version or via an accepted Electronic Distribution Mechanism to anyone to whom you made an Executable version available; and if made available via Electronic Distribution Mechanism, must remain available for at least twelve (12) months after the date it initially became available, or at least six (6) months after a subsequent version of that particular Modification has been made available to such recipients. You are responsible for ensuring that the Source Code version remains available even if the Electronic Distribution Mechanism is maintained by a third party.
102 |
103 | 3.3. Description of Modifications.
104 | You must cause all Covered Code to which You contribute to contain a file documenting the changes You made to create that Covered Code and the date of any change. You must include a prominent statement that the Modification is derived, directly or indirectly, from Original Code provided by the Initial Developer and including the name of the Initial Developer in (a) the Source Code, and (b) in any notice in an Executable version or related documentation in which You describe the origin or ownership of the Covered Code.
105 |
106 | 3.4. Intellectual Property Matters
107 | (a) Third Party Claims
108 | If Contributor has knowledge that a license under a third party's intellectual property rights is required to exercise the rights granted by such Contributor under Sections 2.1 or 2.2, Contributor must include a text file with the Source Code distribution titled "LEGAL" which describes the claim and the party making the claim in sufficient detail that a recipient will know whom to contact. If Contributor obtains such knowledge after the Modification is made available as described in Section 3.2, Contributor shall promptly modify the LEGAL file in all copies Contributor makes available thereafter and shall take other steps (such as notifying appropriate mailing lists or newsgroups) reasonably calculated to inform those who received the Covered Code that new knowledge has been obtained.
109 |
110 | (b) Contributor APIs
111 | If Contributor's Modifications include an application programming interface and Contributor has knowledge of patent licenses which are reasonably necessary to implement that API, Contributor must also include this information in the legal file.
112 |
113 | (c) Representations.
114 | Contributor represents that, except as disclosed pursuant to Section 3.4 (a) above, Contributor believes that Contributor's Modifications are Contributor's original creation(s) and/or Contributor has sufficient rights to grant the rights conveyed by this License.
115 |
116 | 3.5. Required Notices.
117 | You must duplicate the notice in Exhibit A in each file of the Source Code. If it is not possible to put such notice in a particular Source Code file due to its structure, then You must include such notice in a location (such as a relevant directory) where a user would be likely to look for such a notice. If You created one or more Modification(s) You may add your name as a Contributor to the notice described in Exhibit A. You must also duplicate this License in any documentation for the Source Code where You describe recipients' rights or ownership rights relating to Covered Code. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Code. However, You may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear than any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer.
118 |
119 | 3.6. Distribution of Executable Versions.
120 | You may distribute Covered Code in Executable form only if the requirements of Sections 3.1, 3.2, 3.3, 3.4 and 3.5 have been met for that Covered Code, and if You include a notice stating that the Source Code version of the Covered Code is available under the terms of this License, including a description of how and where You have fulfilled the obligations of Section 3.2. The notice must be conspicuously included in any notice in an Executable version, related documentation or collateral in which You describe recipients' rights relating to the Covered Code. You may distribute the Executable version of Covered Code or ownership rights under a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable version does not attempt to limit or alter the recipient's rights in the Source Code version from the rights set forth in this License. If You distribute the Executable version under a different license You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or any Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer.
121 |
122 | 3.7. Larger Works.
123 | You may create a Larger Work by combining Covered Code with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Code.
124 |
125 | 4. Inability to Comply Due to Statute or Regulation.
126 | If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Code due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be included in the legal file described in Section 3.4 and must be included with all distributions of the Source Code. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it.
127 |
128 | 5. Application of this License.
129 | This License applies to code to which the Initial Developer has attached the notice in Exhibit A and to related Covered Code.
130 |
131 | 6. Versions of the License.
132 | 6.1. New Versions
133 | Netscape Communications Corporation ("Netscape") may publish revised and/or new versions of the License from time to time. Each version will be given a distinguishing version number.
134 |
135 | 6.2. Effect of New Versions
136 | Once Covered Code has been published under a particular version of the License, You may always continue to use it under the terms of that version. You may also choose to use such Covered Code under the terms of any subsequent version of the License published by Netscape. No one other than Netscape has the right to modify the terms applicable to Covered Code created under this License.
137 |
138 | 6.3. Derivative Works
139 | If You create or use a modified version of this License (which you may only do in order to apply it to code which is not already Covered Code governed by this License), You must (a) rename Your license so that the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", "MPL", "NPL" or any confusingly similar phrase do not appear in your license (except to note that your license differs from this License) and (b) otherwise make it clear that Your version of the license contains terms which differ from the Mozilla Public License and Netscape Public License. (Filling in the name of the Initial Developer, Original Code or Contributor in the notice described in Exhibit A shall not of themselves be deemed to be modifications of this License.)
140 |
141 | 7. Disclaimer of warranty
142 | Covered code is provided under this license on an "as is" basis, without warranty of any kind, either expressed or implied, including, without limitation, warranties that the covered code is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire risk as to the quality and performance of the covered code is with you. Should any covered code prove defective in any respect, you (not the initial developer or any other contributor) assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty constitutes an essential part of this license. No use of any covered code is authorized hereunder except under this disclaimer.
143 |
144 | 8. Termination
145 | 8.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. All sublicenses to the Covered Code which are properly granted shall survive any termination of this License. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive.
146 |
147 | 8.2. If You initiate litigation by asserting a patent infringement claim (excluding declatory judgment actions) against Initial Developer or a Contributor (the Initial Developer or Contributor against whom You file such action is referred to as "Participant") alleging that:
148 |
149 | a.such Participant's Contributor Version directly or indirectly infringes any patent, then any and all rights granted by such Participant to You under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively, unless if within 60 days after receipt of notice You either: (i) agree in writing to pay Participant a mutually agreeable reasonable royalty for Your past and future use of Modifications made by such Participant, or (ii) withdraw Your litigation claim with respect to the Contributor Version against such Participant. If within 60 days of notice, a reasonable royalty and payment arrangement are not mutually agreed upon in writing by the parties or the litigation claim is not withdrawn, the rights granted by Participant to You under Sections 2.1 and/or 2.2 automatically terminate at the expiration of the 60 day notice period specified above.
150 | b.any software, hardware, or device, other than such Participant's Contributor Version, directly or indirectly infringes any patent, then any rights granted to You by such Participant under Sections 2.1(b) and 2.2(b) are revoked effective as of the date You first made, used, sold, distributed, or had made, Modifications made by that Participant.
151 | 8.3. If You assert a patent infringement claim against Participant alleging that such Participant's Contributor Version directly or indirectly infringes any patent where such claim is resolved (such as by license or settlement) prior to the initiation of patent infringement litigation, then the reasonable value of the licenses granted by such Participant under Sections 2.1 or 2.2 shall be taken into account in determining the amount or value of any payment or license.
152 |
153 | 8.4. In the event of termination under Sections 8.1 or 8.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or any distributor hereunder prior to termination shall survive termination.
154 |
155 | 9. Limitation of liability
156 | Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, shall you, the initial developer, any other contributor, or any distributor of covered code, or any supplier of any of such parties, be liable to any person for any indirect, special, incidental, or consequential damages of any character including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if such party shall have been informed of the possibility of such damages. This limitation of liability shall not apply to liability for death or personal injury resulting from such party's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to you.
157 |
158 | 10. U.S. government end users
159 | The Covered Code is a "commercial item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" and "commercial computer software documentation," as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Code with only those rights set forth herein.
160 |
161 | 11. Miscellaneous
162 | This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by California law provisions (except to the extent applicable law, if any, provides otherwise), excluding its conflict-of-law provisions. With respect to disputes in which at least one party is a citizen of, or an entity chartered or registered to do business in the United States of America, any litigation relating to this License shall be subject to the jurisdiction of the Federal Courts of the Northern District of California, with venue lying in Santa Clara County, California, with the losing party responsible for costs, including without limitation, court costs and reasonable attorneys' fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License.
163 |
164 | 12. Responsibility for claims
165 | As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability.
166 |
167 | 13. Multiple-licensed code
168 | Initial Developer may designate portions of the Covered Code as "Multiple-Licensed". "Multiple-Licensed" means that the Initial Developer permits you to utilize portions of the Covered Code under Your choice of the MPL or the alternative licenses, if any, specified by the Initial Developer in the file described in Exhibit A.
169 |
170 | Exhibit A - Mozilla Public License.
171 | "The contents of this file are subject to the Mozilla Public License
172 | Version 1.1 (the "License"); you may not use this file except in
173 | compliance with the License. You may obtain a copy of the License at
174 | http://www.mozilla.org/MPL/
175 |
176 | Software distributed under the License is distributed on an "AS IS"
177 | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
178 | License for the specific language governing rights and limitations
179 | under the License.
180 |
181 | The Original Code is ______________________________________.
182 |
183 | The Initial Developer of the Original Code is ________________________.
184 | Portions created by ______________________ are Copyright (C) ______
185 | _______________________. All Rights Reserved.
186 |
187 | Contributor(s): ______________________________________.
188 |
189 | Alternatively, the contents of this file may be used under the terms
190 | of the _____ license (the "[___] License"), in which case the
191 | provisions of [______] License are applicable instead of those
192 | above. If you wish to allow use of your version of this file only
193 | under the terms of the [____] License and not to allow others to use
194 | your version of this file under the MPL, indicate your decision by
195 | deleting the provisions above and replace them with the notice and
196 | other provisions required by the [___] License. If you do not delete
197 | the provisions above, a recipient may use your version of this file
198 | under either the MPL or the [___] License."NOTE: The text of this Exhibit A may differ slightly from the text of the notices in the Source Code files of the Original Code. You should use the text of this Exhibit A rather than the text found in the Original Code Source Code for Your Modifications.
199 |
--------------------------------------------------------------------------------
/DelphiDemo/DemoApp/basic/DemoApp.dpr:
--------------------------------------------------------------------------------
1 | program DemoApp;
2 |
3 | { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4 | * Memory DLL loading code Demo Application *
5 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
6 | * Copyright (c) 2005-2010 by Martin Offenwanger / coder@dsplayer.de *
7 | * http://www.dsplayer.de *
8 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
9 | * Mozilla Public License Version 1.1: *
10 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
11 | * The contents of this file are used with permission, subject to the *
12 | * Mozilla Public License Version 1.1 (the "License"); you may *
13 | * not use this file except in compliance with the License. You may *
14 | * obtain a copy of the License at *
15 | * http://www.mozilla.org/MPL/MPL-1.1.html *
16 | * +
17 | * Software distributed under the License is distributed on an *
18 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or *
19 | * implied. See the License for the specific language governing *
20 | * rights and limitations under the License. *
21 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
22 | {
23 | @author(Martin Offenwanger: coder@dsplayer.de)
24 | @created(Mar 20, 2005)
25 | @lastmod(Jul 16, 2010)
26 | @supported operationg systems(Windows 98 up to Windows 7)
27 | @tested Delphi compilers(Delphi 7, Delphi 2007 , Delphi 2010)
28 | }
29 |
30 | uses
31 | Forms,
32 | Main in 'Main.pas' {Form1},
33 | BTMemoryModule in '..\..\..\BTMemoryModule\BTMemoryModule.pas';
34 |
35 | {$R *.res}
36 |
37 | begin
38 | Application.Initialize;
39 | Application.CreateForm(TForm1, Form1);
40 | Application.Run;
41 | end.
42 |
--------------------------------------------------------------------------------
/DelphiDemo/DemoApp/basic/Main.dfm:
--------------------------------------------------------------------------------
1 | object Form1: TForm1
2 | Left = 373
3 | Top = 231
4 | Caption = 'MemoryModule Demo Application'
5 | ClientHeight = 53
6 | ClientWidth = 314
7 | Color = clBtnFace
8 | Font.Charset = DEFAULT_CHARSET
9 | Font.Color = clWindowText
10 | Font.Height = -11
11 | Font.Name = 'MS Sans Serif'
12 | Font.Style = []
13 | OldCreateOrder = False
14 | OnCreate = FormCreate
15 | OnDestroy = FormDestroy
16 | PixelsPerInch = 96
17 | TextHeight = 13
18 | object BtnFileCAll: TButton
19 | Left = 24
20 | Top = 16
21 | Width = 121
22 | Height = 25
23 | Caption = 'file call'
24 | TabOrder = 0
25 | OnClick = BtnFileCAllClick
26 | end
27 | object BtnMemCall: TButton
28 | Left = 168
29 | Top = 16
30 | Width = 129
31 | Height = 25
32 | Caption = 'memory call'
33 | TabOrder = 1
34 | OnClick = BtnMemCallClick
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/DelphiDemo/DemoApp/basic/Main.pas:
--------------------------------------------------------------------------------
1 | unit Main;
2 |
3 | { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4 | * Memory DLL loading code Demo Application *
5 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
6 | * Copyright (c) 2005-2010 by Martin Offenwanger / coder@dsplayer.de *
7 | * http://www.dsplayer.de *
8 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
9 | * Mozilla Public License Version 1.1: *
10 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
11 | * The contents of this file are used with permission, subject to the *
12 | * Mozilla Public License Version 1.1 (the "License"); you may *
13 | * not use this file except in compliance with the License. You may *
14 | * obtain a copy of the License at *
15 | * http://www.mozilla.org/MPL/MPL-1.1.html *
16 | * +
17 | * Software distributed under the License is distributed on an *
18 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or *
19 | * implied. See the License for the specific language governing *
20 | * rights and limitations under the License. *
21 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
22 | {
23 | @author(Martin Offenwanger: coder@dsplayer.de)
24 | @created(Mar 20, 2005)
25 | @lastmod(Jul 16, 2010)
26 | @supported operationg systems(Windows 98 up to Windows 7)
27 | @tested Delphi compilers(Delphi 7, Delphi 2007 , Delphi 2010)
28 | }
29 |
30 | interface
31 |
32 | uses
33 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
34 | Dialogs, BTMemoryModule, StdCtrls, xpman;
35 |
36 | type
37 | TTestCallstdA = procedure(f_Text: PAnsiChar); stdcall;
38 | TTestCallstdW = procedure(f_Text: PWideChar); stdcall;
39 | TTestCallcdelA = procedure(f_Text: PAnsiChar); cdecl;
40 | TTestCallcdelW = procedure(f_Text: PWideChar); cdecl;
41 |
42 | TForm1 = class(TForm)
43 | BtnFileCAll: TButton;
44 | BtnMemCall: TButton;
45 | procedure FormCreate(Sender: TObject);
46 | procedure FormDestroy(Sender: TObject);
47 | procedure BtnFileCAllClick(Sender: TObject);
48 | procedure BtnMemCallClick(Sender: TObject);
49 | private
50 | m_TestCallstdA: TTestCallstdA;
51 | m_TestCallstdW: TTestCallstdW;
52 | m_TestCallcdelA: TTestCallcdelA;
53 | m_TestCallcdelW: TTestCallcdelW;
54 | mp_DllData: Pointer;
55 | m_DllDataSize: Integer;
56 | mp_MemoryModule: PBTMemoryModule;
57 | m_DllHandle: Cardinal;
58 | public
59 | { Public declarations }
60 | end;
61 |
62 | var
63 | Form1: TForm1;
64 |
65 |
66 | implementation
67 |
68 | {$R *.dfm}
69 |
70 | procedure TForm1.FormCreate(Sender: TObject);
71 | var
72 | MemoryStream: TMemoryStream;
73 | begin
74 | Position := poScreenCenter;
75 | MemoryStream := TMemoryStream.Create;
76 | MemoryStream.LoadFromFile('DemoDLL.dll');
77 | MemoryStream.Position := 0;
78 | m_DllDataSize := MemoryStream.Size;
79 | mp_DllData := GetMemory(m_DllDataSize);
80 | MemoryStream.Read(mp_DllData^, m_DllDataSize);
81 | MemoryStream.Free;
82 | end;
83 |
84 | procedure TForm1.FormDestroy(Sender: TObject);
85 | begin
86 | FreeMemory(mp_DllData);
87 | end;
88 |
89 | procedure TForm1.BtnFileCAllClick(Sender: TObject);
90 | begin
91 | m_DllHandle := LoadLibrary('DemoDLL.dll');
92 | try
93 | if m_DllHandle = 0 then
94 | Abort;
95 | @m_TestCallstdA := GetProcAddress(m_DllHandle, 'TestCallstdA');
96 | if @m_TestCallstdA = nil then
97 | Abort;
98 | @m_TestCallstdW := GetProcAddress(m_DllHandle, 'TestCallstdW');
99 | if @m_TestCallstdW = nil then
100 | Abort;
101 | @m_TestCallcdelA := GetProcAddress(m_DllHandle, 'TestCallcdelA');
102 | if @m_TestCallcdelA = nil then
103 | Abort;
104 | @m_TestCallcdelW := GetProcAddress(m_DllHandle, 'TestCallcdelW');
105 | if @m_TestCallcdelW = nil then
106 | Abort;
107 | m_TestCallstdA('This is a Dll File call!');
108 | m_TestCallstdW('This is a Dll File call!');
109 | m_TestCallcdelA('This is a Dll File call!');
110 | m_TestCallcdelW('This is a Dll File call!');
111 | except
112 | Showmessage('An error occoured while loading the dll');
113 | end;
114 | if m_DllHandle <> 0 then
115 | FreeLibrary(m_DllHandle)
116 | end;
117 |
118 | procedure TForm1.BtnMemCallClick(Sender: TObject);
119 | begin
120 | mp_MemoryModule := BTMemoryLoadLibary(mp_DllData, m_DllDataSize);
121 | try
122 | if mp_MemoryModule = nil then
123 | Abort;
124 | @m_TestCallstdA := BTMemoryGetProcAddress(mp_MemoryModule, 'TestCallstdA');
125 | if @m_TestCallstdA = nil then
126 | Abort;
127 | @m_TestCallstdW := BTMemoryGetProcAddress(mp_MemoryModule, 'TestCallstdW');
128 | if @m_TestCallstdW = nil then
129 | Abort;
130 | @m_TestCallcdelA := BTMemoryGetProcAddress(mp_MemoryModule, 'TestCallcdelA');
131 | if @m_TestCallcdelA = nil then
132 | Abort;
133 | @m_TestCallcdelW := BTMemoryGetProcAddress(mp_MemoryModule, 'TestCallcdelW');
134 | if @m_TestCallcdelW = nil then
135 | Abort;
136 | m_TestCallstdA('This is a Dll Memory call!');
137 | m_TestCallstdW('This is a Dll Memory call!');
138 | m_TestCallcdelA('This is a Dll Memory call!');
139 | m_TestCallcdelW('This is a Dll Memory call!');
140 | except
141 | Showmessage('An error occoured while loading the dll: ' +
142 | BTMemoryGetLastError);
143 | end;
144 | if mp_MemoryModule <> nil then
145 | BTMemoryFreeLibrary(mp_MemoryModule);
146 | end;
147 |
148 |
149 | end.
150 |
151 |
--------------------------------------------------------------------------------
/DelphiDemo/DemoApp/loadfromresource/DemoAppRes.dpr:
--------------------------------------------------------------------------------
1 | program DemoAppRes;
2 |
3 | { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4 | * Memory DLL loading code Demo Application *
5 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
6 | * Copyright (c) 2005-2010 by Martin Offenwanger / coder@dsplayer.de *
7 | * http://www.dsplayer.de *
8 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
9 | * Mozilla Public License Version 1.1: *
10 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
11 | * The contents of this file are used with permission, subject to the *
12 | * Mozilla Public License Version 1.1 (the "License"); you may *
13 | * not use this file except in compliance with the License. You may *
14 | * obtain a copy of the License at *
15 | * http://www.mozilla.org/MPL/MPL-1.1.html *
16 | * +
17 | * Software distributed under the License is distributed on an *
18 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or *
19 | * implied. See the License for the specific language governing *
20 | * rights and limitations under the License. *
21 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
22 | {
23 | @author(Martin Offenwanger: coder@dsplayer.de)
24 | @created(Mar 20, 2005)
25 | @lastmod(Jul 16, 2010)
26 | @supported operationg systems(Windows 98 up to Windows 7)
27 | @tested Delphi compilers(Delphi 7, Delphi 2007 , Delphi 2010)
28 | }
29 |
30 | uses
31 | Forms,
32 | Main in 'Main.pas' {Form1},
33 | BTMemoryModule in '..\..\..\BTMemoryModule\BTMemoryModule.pas';
34 |
35 | {$R *.res}
36 |
37 | begin
38 | Application.Initialize;
39 | Application.CreateForm(TForm1, Form1);
40 | Application.Run;
41 | end.
42 |
--------------------------------------------------------------------------------
/DelphiDemo/DemoApp/loadfromresource/DemoDLL.RES:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DSPlayer/memorymodule/511c5175b168a56f926e7a12e2301d9f7067eda2/DelphiDemo/DemoApp/loadfromresource/DemoDLL.RES
--------------------------------------------------------------------------------
/DelphiDemo/DemoApp/loadfromresource/Main.dfm:
--------------------------------------------------------------------------------
1 | object Form1: TForm1
2 | Left = 978
3 | Top = 246
4 | Width = 330
5 | Height = 91
6 | Caption = 'MemoryModule Demo Application'
7 | Color = clBtnFace
8 | Font.Charset = DEFAULT_CHARSET
9 | Font.Color = clWindowText
10 | Font.Height = -11
11 | Font.Name = 'MS Sans Serif'
12 | Font.Style = []
13 | OldCreateOrder = False
14 | OnCreate = FormCreate
15 | OnDestroy = FormDestroy
16 | PixelsPerInch = 96
17 | TextHeight = 13
18 | object BtnMemCall: TButton
19 | Left = 80
20 | Top = 16
21 | Width = 153
22 | Height = 25
23 | Caption = 'resource memory call'
24 | TabOrder = 0
25 | OnClick = BtnMemCallClick
26 | end
27 | end
28 |
--------------------------------------------------------------------------------
/DelphiDemo/DemoApp/loadfromresource/Main.pas:
--------------------------------------------------------------------------------
1 | unit Main;
2 |
3 | { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4 | * Memory DLL loading code Demo Application *
5 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
6 | * Copyright (c) 2005-2010 by Martin Offenwanger / coder@dsplayer.de *
7 | * http://www.dsplayer.de *
8 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
9 | * Mozilla Public License Version 1.1: *
10 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
11 | * The contents of this file are used with permission, subject to the *
12 | * Mozilla Public License Version 1.1 (the "License"); you may *
13 | * not use this file except in compliance with the License. You may *
14 | * obtain a copy of the License at *
15 | * http://www.mozilla.org/MPL/MPL-1.1.html *
16 | * +
17 | * Software distributed under the License is distributed on an *
18 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or *
19 | * implied. See the License for the specific language governing *
20 | * rights and limitations under the License. *
21 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
22 | {
23 | @author(Martin Offenwanger: coder@dsplayer.de)
24 | @created(Mar 20, 2005)
25 | @lastmod(Jul 16, 2010)
26 | @supported operationg systems(Windows 98 up to Windows 7)
27 | @tested Delphi compilers(Delphi 7, Delphi 2007 , Delphi 2010)
28 | }
29 |
30 | interface
31 |
32 | uses
33 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
34 | Dialogs, BTMemoryModule, StdCtrls, xpman;
35 |
36 | type
37 | TTestCallstdA = procedure(f_Text: PAnsiChar); stdcall;
38 | TTestCallstdW = procedure(f_Text: PWideChar); stdcall;
39 | TTestCallcdelA = procedure(f_Text: PAnsiChar); cdecl;
40 | TTestCallcdelW = procedure(f_Text: PWideChar); cdecl;
41 |
42 | TForm1 = class(TForm)
43 | BtnMemCall: TButton;
44 | procedure FormCreate(Sender: TObject);
45 | procedure FormDestroy(Sender: TObject);
46 | procedure BtnMemCallClick(Sender: TObject);
47 | private
48 | m_TestCallstdA: TTestCallstdA;
49 | m_TestCallstdW: TTestCallstdW;
50 | m_TestCallcdelA: TTestCallcdelA;
51 | m_TestCallcdelW: TTestCallcdelW;
52 | mp_DllData: Pointer;
53 | m_DllDataSize: Integer;
54 | mp_MemoryModule: PBTMemoryModule;
55 | public
56 | { Public declarations }
57 | end;
58 |
59 | var
60 | Form1: TForm1;
61 |
62 |
63 | implementation
64 |
65 | {$R *.dfm}
66 | {$R DemoDLL.RES}
67 |
68 | procedure TForm1.FormCreate(Sender: TObject);
69 | var
70 | ResStream: TResourceStream;
71 | begin
72 | Position := poScreenCenter;
73 | ResStream := TResourceStream.Create(HInstance, 'DemoDLL', RT_RCDATA);
74 | ResStream.Position := 0;
75 | m_DllDataSize := ResStream.Size;
76 | mp_DllData := GetMemory(m_DllDataSize);
77 | ResStream.Read(mp_DllData^, m_DllDataSize);
78 | ResStream.Free;
79 | end;
80 |
81 | procedure TForm1.FormDestroy(Sender: TObject);
82 | begin
83 | FreeMemory(mp_DllData);
84 | end;
85 |
86 | procedure TForm1.BtnMemCallClick(Sender: TObject);
87 | begin
88 | mp_MemoryModule := BTMemoryLoadLibary(mp_DllData, m_DllDataSize);
89 | try
90 | if mp_MemoryModule = nil then
91 | Abort;
92 | @m_TestCallstdA := BTMemoryGetProcAddress(mp_MemoryModule, 'TestCallstdA');
93 | if @m_TestCallstdA = nil then
94 | Abort;
95 | @m_TestCallstdW := BTMemoryGetProcAddress(mp_MemoryModule, 'TestCallstdW');
96 | if @m_TestCallstdW = nil then
97 | Abort;
98 | @m_TestCallcdelA := BTMemoryGetProcAddress(mp_MemoryModule, 'TestCallcdelA');
99 | if @m_TestCallcdelA = nil then
100 | Abort;
101 | @m_TestCallcdelW := BTMemoryGetProcAddress(mp_MemoryModule, 'TestCallcdelW');
102 | if @m_TestCallcdelW = nil then
103 | Abort;
104 | m_TestCallstdA('This is a Dll Memory call loaded from resource!');
105 | m_TestCallstdW('This is a Dll Memory call loaded from resource!');
106 | m_TestCallcdelA('This is a Dll Memory call loaded from resource!');
107 | m_TestCallcdelW('This is a Dll Memory call loaded from resource!');
108 | except
109 | Showmessage('An error occoured while loading the dll: ' +
110 | BTMemoryGetLastError);
111 | end;
112 | if mp_MemoryModule <> nil then
113 | BTMemoryFreeLibrary(mp_MemoryModule);
114 | end;
115 |
116 |
117 | end.
118 |
119 |
--------------------------------------------------------------------------------
/DelphiDemo/DemoApp/loadfromresource/compile_res/DemoDLL.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DSPlayer/memorymodule/511c5175b168a56f926e7a12e2301d9f7067eda2/DelphiDemo/DemoApp/loadfromresource/compile_res/DemoDLL.dll
--------------------------------------------------------------------------------
/DelphiDemo/DemoApp/loadfromresource/compile_res/DemoDLL.rc:
--------------------------------------------------------------------------------
1 | DemoDLL RCDATA DemoDLL.dll
2 |
3 |
--------------------------------------------------------------------------------
/DelphiDemo/DemoApp/loadfromresource/compile_res/compileRcScript.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | brcc32.exe DemoDLL.rc
3 | pause
--------------------------------------------------------------------------------
/DelphiDemo/DemoDll/DemoDLL.dpr:
--------------------------------------------------------------------------------
1 | library DemoDLL;
2 |
3 | { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4 | * Memory DLL loading code Demo Dll *
5 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
6 | * Copyright (c) 2005-2010 by Martin Offenwanger / coder@dsplayer.de *
7 | * http://www.dsplayer.de *
8 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
9 | * Mozilla Public License Version 1.1: *
10 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
11 | * The contents of this file are used with permission, subject to the *
12 | * Mozilla Public License Version 1.1 (the "License"); you may *
13 | * not use this file except in compliance with the License. You may *
14 | * obtain a copy of the License at *
15 | * http://www.mozilla.org/MPL/MPL-1.1.html *
16 | * +
17 | * Software distributed under the License is distributed on an *
18 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or *
19 | * implied. See the License for the specific language governing *
20 | * rights and limitations under the License. *
21 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
22 | {
23 | @author(Martin Offenwanger: coder@dsplayer.de)
24 | @created(Mar 20, 2005)
25 | @lastmod(Jul 16, 2010)
26 | @supported operationg systems(Windows 98 up to Windows 7)
27 | @tested Delphi compilers(Delphi 7, Delphi 2007 , Delphi 2010)
28 | }
29 |
30 | uses
31 | windows;
32 |
33 | procedure TestCallstdA(f_Text: PAnsiChar); stdcall;
34 | begin
35 | MessageBoxA(0, f_Text, 'Dll Dialog Ansi (stdcall)', 0);
36 | end;
37 |
38 | procedure TestCallstdW(f_Text: PWideChar); stdcall;
39 | begin
40 | MessageBoxW(0, f_Text, 'Dll Dialog Unicode (stdcall)', 0);
41 | end;
42 |
43 | procedure TestCallcdelA(f_Text: PAnsiChar); cdecl;
44 | begin
45 | MessageBoxA(0, f_Text, 'Dll Dialog Ansi (cdecl)', 0);
46 | end;
47 |
48 | procedure TestCallcdelW(f_Text: PWideChar); cdecl;
49 | begin
50 | MessageBoxW(0, f_Text, 'Dll Dialog Unicode (cdecl)', 0);
51 | end;
52 |
53 |
54 | exports
55 | TestCallstdA,
56 | TestCallstdW,
57 | TestCallcdelA,
58 | TestCallcdelW;
59 |
60 | begin
61 | end.
62 |
63 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/BTMemoryModule.ppu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DSPlayer/memorymodule/511c5175b168a56f926e7a12e2301d9f7067eda2/LazarusDemo/DemoApp/BTMemoryModule.ppu
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/DemoApp.compiled:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/DemoApp.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DSPlayer/memorymodule/511c5175b168a56f926e7a12e2301d9f7067eda2/LazarusDemo/DemoApp/DemoApp.ico
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/DemoApp.lpi:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/DemoApp.lpr:
--------------------------------------------------------------------------------
1 | program DemoApp;
2 |
3 | { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4 | * Memory DLL loading code Demo Dll *
5 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
6 | * Copyright (c) 2005-2010 by Martin Offenwanger / coder@dsplayer.de *
7 | * http://www.dsplayer.de *
8 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
9 | * Mozilla Public License Version 1.1: *
10 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
11 | * The contents of this file are used with permission, subject to the *
12 | * Mozilla Public License Version 1.1 (the "License"); you may *
13 | * not use this file except in compliance with the License. You may *
14 | * obtain a copy of the License at *
15 | * http://www.mozilla.org/MPL/MPL-1.1.html *
16 | * +
17 | * Software distributed under the License is distributed on an *
18 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or *
19 | * implied. See the License for the specific language governing *
20 | * rights and limitations under the License. *
21 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
22 | {
23 | @author(Martin Offenwanger: coder@dsplayer.de)
24 | @created(Mar 20, 2005)
25 | @lastmod(Jul 16, 2010)
26 | @supported operationg systems(Windows 98 up to Windows 7)
27 | @tested Delphi compilers(Delphi 7, Delphi 2007 , Delphi 2010)
28 | }
29 |
30 | {$mode objfpc}{$H+}
31 |
32 | uses
33 | {$IFDEF UNIX}{$IFDEF UseCThreads}
34 | cthreads,
35 | {$ENDIF}{$ENDIF}
36 | Interfaces, // this includes the LCL widgetset
37 | Forms, Main, BTMemoryModule, LResources;
38 |
39 | {$IFDEF WINDOWS}{$R DemoApp.rc}{$ENDIF}
40 |
41 | begin
42 | {$I DemoApp.lrs}
43 | Application.Initialize;
44 | Application.CreateForm(TFrmMain, FrmMain);
45 | Application.Run;
46 | end.
47 |
48 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/DemoApp.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Your application description here.
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/DemoApp.rc:
--------------------------------------------------------------------------------
1 | #define RT_MANIFEST 24
2 | #define CREATEPROCESS_MANIFEST_RESOURCE_ID 1
3 | #define ISOLATIONAWARE_MANIFEST_RESOURCE_ID 2
4 | #define ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID 3
5 |
6 | CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "DemoApp.manifest"
7 | MAINICON ICON "DemoApp.ico"
8 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/DemoApp.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DSPlayer/memorymodule/511c5175b168a56f926e7a12e2301d9f7067eda2/LazarusDemo/DemoApp/DemoApp.res
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/demodll.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DSPlayer/memorymodule/511c5175b168a56f926e7a12e2301d9f7067eda2/LazarusDemo/DemoApp/demodll.dll
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/fpc-res.or:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DSPlayer/memorymodule/511c5175b168a56f926e7a12e2301d9f7067eda2/LazarusDemo/DemoApp/fpc-res.or
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/fpc-res.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DSPlayer/memorymodule/511c5175b168a56f926e7a12e2301d9f7067eda2/LazarusDemo/DemoApp/fpc-res.res
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/main.lfm:
--------------------------------------------------------------------------------
1 | object FrmMain: TFrmMain
2 | Left = 644
3 | Height = 82
4 | Top = 211
5 | Width = 393
6 | Caption = 'BTMemoryModule Demo Application'
7 | ClientHeight = 82
8 | ClientWidth = 393
9 | OnCreate = FormCreate
10 | OnDestroy = FormDestroy
11 | LCLVersion = '0.9.28.2'
12 | object BtnFileCall: TButton
13 | Left = 40
14 | Height = 25
15 | Top = 32
16 | Width = 131
17 | Caption = 'file call'
18 | OnClick = BtnFileCallClick
19 | TabOrder = 0
20 | end
21 | object BtnMemCall: TButton
22 | Left = 224
23 | Height = 25
24 | Top = 32
25 | Width = 131
26 | Caption = 'memory call'
27 | OnClick = BtnMemCallClick
28 | TabOrder = 1
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/main.lrs:
--------------------------------------------------------------------------------
1 | { Das ist eine automatisch erzeugte Lazarus-Ressourcendatei }
2 |
3 | LazarusResources.Add('TFrmMain','FORMDATA',[
4 | 'TPF0'#8'TFrmMain'#7'FrmMain'#4'Left'#3#132#2#6'Height'#2'R'#3'Top'#3#211#0#5
5 | +'Width'#3#137#1#7'Caption'#6#31'BTMemoryModule Demo Application'#12'ClientHe'
6 | +'ight'#2'R'#11'ClientWidth'#3#137#1#8'OnCreate'#7#10'FormCreate'#9'OnDestroy'
7 | +#7#11'FormDestroy'#10'LCLVersion'#6#8'0.9.28.2'#0#7'TButton'#11'BtnFileCall'
8 | +#4'Left'#2'('#6'Height'#2#25#3'Top'#2' '#5'Width'#3#131#0#7'Caption'#6#9'fil'
9 | +'e call'#7'OnClick'#7#16'BtnFileCallClick'#8'TabOrder'#2#0#0#0#7'TButton'#10
10 | +'BtnMemCall'#4'Left'#3#224#0#6'Height'#2#25#3'Top'#2' '#5'Width'#3#131#0#7'C'
11 | +'aption'#6#11'memory call'#7'OnClick'#7#15'BtnMemCallClick'#8'TabOrder'#2#1#0
12 | +#0#0
13 | ]);
14 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/main.pas:
--------------------------------------------------------------------------------
1 | unit Main;
2 |
3 | { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4 | * Memory DLL loading code Demo Dll *
5 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
6 | * Copyright (c) 2005-2010 by Martin Offenwanger / coder@dsplayer.de *
7 | * http://www.dsplayer.de *
8 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
9 | * Mozilla Public License Version 1.1: *
10 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
11 | * The contents of this file are used with permission, subject to the *
12 | * Mozilla Public License Version 1.1 (the "License"); you may *
13 | * not use this file except in compliance with the License. You may *
14 | * obtain a copy of the License at *
15 | * http://www.mozilla.org/MPL/MPL-1.1.html *
16 | * +
17 | * Software distributed under the License is distributed on an *
18 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or *
19 | * implied. See the License for the specific language governing *
20 | * rights and limitations under the License. *
21 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
22 | {
23 | @author(Martin Offenwanger: coder@dsplayer.de)
24 | @created(Mar 20, 2005)
25 | @lastmod(Jul 16, 2010)
26 | @supported operationg systems(Windows 98 up to Windows 7)
27 | @tested Delphi compilers(Delphi 7, Delphi 2007 , Delphi 2010)
28 | }
29 |
30 | {$mode objfpc}{$H+}
31 |
32 | {$WARN UNSAFE_CODE OFF}
33 | {$WARN UNSAFE_TYPE OFF}
34 | {$WARN UNSAFE_CAST OFF}
35 |
36 | interface
37 |
38 | uses
39 | Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
40 | StdCtrls, Windows, BTMemoryModule;
41 |
42 | type
43 |
44 | TTestCallstdA = procedure(f_Text: PAnsiChar); stdcall;
45 | PTestCallstdA = ^TTestCallstdA;
46 | TTestCallstdW = procedure(f_Text: PWideChar); stdcall;
47 | PTestCallstdW = ^TTestCallstdW;
48 | TTestCallcdelA = procedure(f_Text: PAnsiChar); cdecl;
49 | PTestCallcdelA = ^TTestCallcdelA;
50 | TTestCallcdelW = procedure(f_Text: PWideChar); cdecl;
51 | PTestCallcdelW = ^TTestCallcdelW;
52 |
53 | { TFrmMain }
54 |
55 | TFrmMain = class(TForm)
56 | BtnFileCall: TButton;
57 | BtnMemCall: TButton;
58 | procedure BtnFileCallClick(Sender: TObject);
59 | procedure BtnMemCallClick(Sender: TObject);
60 | procedure FormCreate(Sender: TObject);
61 | procedure FormDestroy(Sender: TObject);
62 | private
63 | mp_TestCallstdA: PTestCallstdA;
64 | mp_TestCallstdW: PTestCallstdW;
65 | mp_TestCallcdelA: PTestCallcdelA;
66 | mp_TestCallcdelW: PTestCallcdelW;
67 | mp_DllData: Pointer;
68 | m_DllDataSize: integer;
69 | mp_MemoryModule: PBTMemoryModule;
70 | m_DllHandle: cardinal;
71 | end;
72 |
73 | var
74 | FrmMain: TFrmMain;
75 |
76 | implementation
77 |
78 | { TFrmMain }
79 |
80 | procedure TFrmMain.FormCreate(Sender: TObject);
81 | var
82 | MemoryStream: TMemoryStream;
83 | begin
84 | Position := poScreenCenter;
85 | MemoryStream := TMemoryStream.Create;
86 | MemoryStream.LoadFromFile('DemoDLL.dll');
87 | MemoryStream.Position := 0;
88 | m_DllDataSize := MemoryStream.Size;
89 | mp_DllData := GetMemory(m_DllDataSize);
90 | MemoryStream.Read(mp_DllData^, m_DllDataSize);
91 | MemoryStream.Free;
92 | end;
93 |
94 | procedure TFrmMain.BtnFileCallClick(Sender: TObject);
95 | begin
96 | BtnFileCall.Enabled := False;
97 | BtnMemCall.Enabled := False;
98 | m_DllHandle := LoadLibrary('DemoDLL.dll');
99 | try
100 | if m_DllHandle = 0 then
101 | Abort;
102 | mp_TestCallstdA := GetProcAddress(m_DllHandle, 'TestCallstdA');
103 | if mp_TestCallstdA = nil then
104 | Abort;
105 | mp_TestCallstdW := GetProcAddress(m_DllHandle, 'TestCallstdW');
106 | if mp_TestCallstdW = nil then
107 | Abort;
108 | mp_TestCallcdelA := GetProcAddress(m_DllHandle, 'TestCallcdelA');
109 | if mp_TestCallcdelA = nil then
110 | Abort;
111 | mp_TestCallcdelW := GetProcAddress(m_DllHandle, 'TestCallcdelW');
112 | if mp_TestCallcdelW = nil then
113 | Abort;
114 | TTestCallstdA(mp_TestCallstdA)('This is a Dll File call!');
115 | TTestCallstdW(mp_TestCallstdW)('This is a Dll File call!');
116 | TTestCallcdelA(mp_TestCallcdelA)('This is a Dll File call!');
117 | TTestCallcdelW(mp_TestCallcdelW)('This is a Dll File call!');
118 | except
119 | ShowMessage('An error occoured while loading the dll');
120 | end;
121 | if m_DllHandle <> 0 then
122 | FreeLibrary(m_DllHandle);
123 | BtnFileCall.Enabled := True;
124 | BtnMemCall.Enabled := True;
125 | end;
126 |
127 | procedure TFrmMain.BtnMemCallClick(Sender: TObject);
128 | begin
129 | BtnFileCall.Enabled := False;
130 | BtnMemCall.Enabled := False;
131 | mp_MemoryModule := BTMemoryLoadLibary(mp_DllData, m_DllDataSize);
132 | try
133 | if mp_MemoryModule = nil then
134 | Abort;
135 | mp_TestCallstdA := BTMemoryGetProcAddress(mp_MemoryModule, 'TestCallstdA');
136 | if mp_TestCallstdA = nil then
137 | Abort;
138 | mp_TestCallstdW := BTMemoryGetProcAddress(mp_MemoryModule, 'TestCallstdW');
139 | if mp_TestCallstdW = nil then
140 | Abort;
141 | mp_TestCallcdelA := BTMemoryGetProcAddress(mp_MemoryModule, 'TestCallcdelA');
142 | if mp_TestCallcdelA = nil then
143 | Abort;
144 | mp_TestCallcdelW := BTMemoryGetProcAddress(mp_MemoryModule, 'TestCallcdelW');
145 | if mp_TestCallcdelW = nil then
146 | Abort;
147 | TTestCallstdA(mp_TestCallstdA)('This is a dll memory call!');
148 | TTestCallstdW(mp_TestCallstdW)('This is a dll memory call!');
149 | TTestCallcdelA(mp_TestCallcdelA)('This is a dll memory call!');
150 | TTestCallcdelW(mp_TestCallcdelW)('This is a dll memory call!');
151 | except
152 | ShowMessage('An error occoured while loading the dll: ' + BTMemoryGetLastError);
153 | end;
154 | if mp_MemoryModule <> nil then
155 | BTMemoryFreeLibrary(mp_MemoryModule);
156 | BtnFileCall.Enabled := True;
157 | BtnMemCall.Enabled := True;
158 | end;
159 |
160 |
161 | procedure TFrmMain.FormDestroy(Sender: TObject);
162 | begin
163 | FreeMemory(mp_DllData);
164 | end;
165 |
166 | initialization
167 | {$I main.lrs}
168 |
169 | end.
170 |
171 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoApp/main.ppu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DSPlayer/memorymodule/511c5175b168a56f926e7a12e2301d9f7067eda2/LazarusDemo/DemoApp/main.ppu
--------------------------------------------------------------------------------
/LazarusDemo/DemoDll/demodll.compiled:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoDll/demodll.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DSPlayer/memorymodule/511c5175b168a56f926e7a12e2301d9f7067eda2/LazarusDemo/DemoDll/demodll.ico
--------------------------------------------------------------------------------
/LazarusDemo/DemoDll/demodll.lpi:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoDll/demodll.lpr:
--------------------------------------------------------------------------------
1 | library demodll;
2 |
3 | { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4 | * Memory DLL loading code Demo Dll *
5 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
6 | * Copyright (c) 2005-2010 by Martin Offenwanger / coder@dsplayer.de *
7 | * http://www.dsplayer.de *
8 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
9 | * Mozilla Public License Version 1.1: *
10 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
11 | * The contents of this file are used with permission, subject to the *
12 | * Mozilla Public License Version 1.1 (the "License"); you may *
13 | * not use this file except in compliance with the License. You may *
14 | * obtain a copy of the License at *
15 | * http://www.mozilla.org/MPL/MPL-1.1.html *
16 | * +
17 | * Software distributed under the License is distributed on an *
18 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or *
19 | * implied. See the License for the specific language governing *
20 | * rights and limitations under the License. *
21 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
22 | {
23 | @author(Martin Offenwanger: coder@dsplayer.de)
24 | @created(Mar 20, 2005)
25 | @lastmod(Jul 16, 2010)
26 | @supported operationg systems(Windows 98 up to Windows 7)
27 | @tested Delphi compilers(Delphi 7, Delphi 2007 , Delphi 2010)
28 | }
29 |
30 | {$mode objfpc}{$H+}
31 |
32 | uses
33 | Windows
34 | { you can add units after this };
35 |
36 | procedure TestCallstdA(f_Text: PAnsiChar); stdcall;
37 | begin
38 | MessageBoxA(0, f_Text, 'Dll Dialog Ansi (stdcall)', 0);
39 | end;
40 |
41 | procedure TestCallstdW(f_Text: PWideChar); stdcall;
42 | begin
43 | MessageBoxW(0, f_Text, 'Dll Dialog Unicode (stdcall)', 0);
44 | end;
45 |
46 | procedure TestCallcdelA(f_Text: PAnsiChar); cdecl;
47 | begin
48 | MessageBoxA(0, f_Text, 'Dll Dialog Ansi (cdecl)', 0);
49 | end;
50 |
51 | procedure TestCallcdelW(f_Text: PWideChar); cdecl;
52 | begin
53 | MessageBoxW(0, f_Text, 'Dll Dialog Unicode (cdecl)', 0);
54 | end;
55 |
56 |
57 | {$IFDEF WINDOWS}{$R demodll.rc}{$ENDIF}
58 |
59 | exports
60 | TestCallstdA,
61 | TestCallstdW,
62 | TestCallcdelA,
63 | TestCallcdelW;
64 |
65 | begin
66 | end.
67 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoDll/demodll.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Your application description here.
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoDll/demodll.rc:
--------------------------------------------------------------------------------
1 | #define RT_MANIFEST 24
2 | #define CREATEPROCESS_MANIFEST_RESOURCE_ID 1
3 | #define ISOLATIONAWARE_MANIFEST_RESOURCE_ID 2
4 | #define ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID 3
5 |
6 | CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "demodll.manifest"
7 | MAINICON ICON "demodll.ico"
8 |
--------------------------------------------------------------------------------
/LazarusDemo/DemoDll/demodll.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DSPlayer/memorymodule/511c5175b168a56f926e7a12e2301d9f7067eda2/LazarusDemo/DemoDll/demodll.res
--------------------------------------------------------------------------------
/LazarusDemo/DemoDll/fpc-res.or:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DSPlayer/memorymodule/511c5175b168a56f926e7a12e2301d9f7067eda2/LazarusDemo/DemoDll/fpc-res.or
--------------------------------------------------------------------------------
/LazarusDemo/DemoDll/fpc-res.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DSPlayer/memorymodule/511c5175b168a56f926e7a12e2301d9f7067eda2/LazarusDemo/DemoDll/fpc-res.res
--------------------------------------------------------------------------------
/changes.txt:
--------------------------------------------------------------------------------
1 | BTMemoryModule changes:
2 |
3 | ============================
4 | new in 0.0.42:
5 | ============================
6 | - added unicode support
7 | - added optional SectionProtection Flags
8 | - Fixed DecP isuue in Sectionheader Loop
9 | - Module runs now on Systems with DEP (Data Execution Prevention)
10 |
11 | ============================
12 | new in 0.0.4:
13 | ============================
14 | - new helpers added
15 | - a major code clean up has been done
16 | - added lazarus free pascal 32bit support
17 |
18 | ============================
19 | new in 0.0.3:
20 | ============================
21 | - added delphi unicode support
22 | - added unicode example calls
23 | - removed lazarus version
24 |
25 | ============================
26 | new in 0.0.2:
27 | ============================
28 | - added Lazarus version
29 | - minor fixes
30 |
31 | ============================
32 | new in 0.0.1:
33 | ============================
34 | - initial release
35 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 |
2 | { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3 | * Memory DLL loading code (32bit) *
4 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
5 | * Delphi BTMemoryModule 0.0.4.2 *
6 | * Copyright (c) 2005-2015 by Martin Offenwanger / coder@dsplayer.com *
7 | * http://www.dsplayer.com *
8 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
9 | * BTMemoryModule originally is a plain pascal port from c code *
10 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
11 | * Original C Code Copyright (c) 2004- 2005 by Joachim Bauch *
12 | * mail@joachim-bauch.de *
13 | * http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/ *
14 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
15 | * Thanks to Markus_13 (Markus_13@ymail.com) for the SectionFinalization *
16 | * flags contribution. *
17 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
18 | * Mozilla Public License Version 1.1: *
19 | *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
20 | * The contents of this file are used with permission, subject to the *
21 | * Mozilla Public License Version 1.1 (the "License"); you may *
22 | * not use this file except in compliance with the License. You may *
23 | * obtain a copy of the License at *
24 | * http://www.mozilla.org/MPL/MPL-1.1.html *
25 | * *
26 | * Software distributed under the License is distributed on an *
27 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or *
28 | * implied. See the License for the specific language governing *
29 | * rights and limitations under the License. *
30 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
31 | {
32 | @author(Martin Offenwanger: coder@dsplayer.com)
33 | @created(Mar 20, 2005)
34 | @lastmod(Apr 14, 2015)
35 | @supported operationg systems(Windows 98 up to Windows 8)
36 | ==============================================================================
37 | => this versino should work for all Delphi versions from 7 up to 2010 <=
38 | => including on most of Lazaru Free Pascal 32bit releases <=
39 | ==============================================================================
40 | @tested Delphi compilers(Delphi 7, Delphi 2007 , Delphi 2010, Delphi XE2)
41 | @tested Free Pascal compilers(Lazarus 0.9.28.2 & Free Pascal 2.2.4 ,
42 | Lazarus 1.2.6 & Free Pascal 2.6.4)
43 | }
44 |
45 |
46 | Mozilla Public License Version 1.1
47 | 1. Definitions.
48 | 1.0.1. "Commercial Use"
49 | means distribution or otherwise making the Covered Code available to a third party.
50 | 1.1. "Contributor"
51 | means each entity that creates or contributes to the creation of Modifications.
52 | 1.2. "Contributor Version"
53 | means the combination of the Original Code, prior Modifications used by a Contributor, and the Modifications made by that particular Contributor.
54 | 1.3. "Covered Code"
55 | means the Original Code or Modifications or the combination of the Original Code and Modifications, in each case including portions thereof.
56 | 1.4. "Electronic Distribution Mechanism"
57 | means a mechanism generally accepted in the software development community for the electronic transfer of data.
58 | 1.5. "Executable"
59 | means Covered Code in any form other than Source Code.
60 | 1.6. "Initial Developer"
61 | means the individual or entity identified as the Initial Developer in the Source Code notice required by Exhibit A.
62 | 1.7. "Larger Work"
63 | means a work which combines Covered Code or portions thereof with code not governed by the terms of this License.
64 | 1.8. "License"
65 | means this document.
66 | 1.8.1. "Licensable"
67 | means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein.
68 | 1.9. "Modifications"
69 | means any addition to or deletion from the substance or structure of either the Original Code or any previous Modifications. When Covered Code is released as a series of files, a Modification is:
70 |
71 | a.Any addition to or deletion from the contents of a file containing Original Code or previous Modifications.
72 | b.Any new file that contains any part of the Original Code or previous Modifications.
73 | 1.10. "Original Code"
74 | means Source Code of computer software code which is described in the Source Code notice required by Exhibit A as Original Code, and which, at the time of its release under this License is not already Covered Code governed by this License.
75 | 1.10.1. "Patent Claims"
76 | means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor.
77 | 1.11. "Source Code"
78 | means the preferred form of the Covered Code for making modifications to it, including all modules it contains, plus any associated interface definition files, scripts used to control compilation and installation of an Executable, or source code differential comparisons against either the Original Code or another well known, available Covered Code of the Contributor's choice. The Source Code can be in a compressed or archival form, provided the appropriate decompression or de-archiving software is widely available for no charge.
79 | 1.12. "You" (or "Your")
80 | means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License or a future version of this License issued under Section 6.1. For legal entities, "You" includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
81 | 2. Source Code License.
82 | 2.1. The Initial Developer Grant.
83 | The Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license, subject to third party intellectual property claims:
84 |
85 | a.under intellectual property rights (other than patent or trademark) Licensable by Initial Developer to use, reproduce, modify, display, perform, sublicense and distribute the Original Code (or portions thereof) with or without Modifications, and/or as part of a Larger Work; and
86 | b.under Patents Claims infringed by the making, using or selling of Original Code, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Code (or portions thereof).
87 | c.the licenses granted in this Section 2.1 (a) and (b) are effective on the date Initial Developer first distributes Original Code under the terms of this License.
88 | d.Notwithstanding Section 2.1 (b) above, no patent license is granted: 1) for code that You delete from the Original Code; 2) separate from the Original Code; or 3) for infringements caused by: i) the modification of the Original Code or ii) the combination of the Original Code with other software or devices.
89 | 2.2. Contributor Grant.
90 | Subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license
91 |
92 | a.under intellectual property rights (other than patent or trademark) Licensable by Contributor, to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof) either on an unmodified basis, with other Modifications, as Covered Code and/or as part of a Larger Work; and
93 | b.under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: 1) Modifications made by that Contributor (or portions thereof); and 2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination).
94 | c.the licenses granted in Sections 2.2 (a) and 2.2 (b) are effective on the date Contributor first makes Commercial Use of the Covered Code.
95 | d.Notwithstanding Section 2.2 (b) above, no patent license is granted: 1) for any code that Contributor has deleted from the Contributor Version; 2) separate from the Contributor Version; 3) for infringements caused by: i) third party modifications of Contributor Version or ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or 4) under Patent Claims infringed by Covered Code in the absence of Modifications made by that Contributor.
96 | 3. Distribution Obligations.
97 | 3.1. Application of License.
98 | The Modifications which You create or to which You contribute are governed by the terms of this License, including without limitation Section 2.2. The Source Code version of Covered Code may be distributed only under the terms of this License or a future version of this License released under Section 6.1, and You must include a copy of this License with every copy of the Source Code You distribute. You may not offer or impose any terms on any Source Code version that alters or restricts the applicable version of this License or the recipients' rights hereunder. However, You may include an additional document offering the additional rights described in Section 3.5.
99 |
100 | 3.2. Availability of Source Code.
101 | Any Modification which You create or to which You contribute must be made available in Source Code form under the terms of this License either on the same media as an Executable version or via an accepted Electronic Distribution Mechanism to anyone to whom you made an Executable version available; and if made available via Electronic Distribution Mechanism, must remain available for at least twelve (12) months after the date it initially became available, or at least six (6) months after a subsequent version of that particular Modification has been made available to such recipients. You are responsible for ensuring that the Source Code version remains available even if the Electronic Distribution Mechanism is maintained by a third party.
102 |
103 | 3.3. Description of Modifications.
104 | You must cause all Covered Code to which You contribute to contain a file documenting the changes You made to create that Covered Code and the date of any change. You must include a prominent statement that the Modification is derived, directly or indirectly, from Original Code provided by the Initial Developer and including the name of the Initial Developer in (a) the Source Code, and (b) in any notice in an Executable version or related documentation in which You describe the origin or ownership of the Covered Code.
105 |
106 | 3.4. Intellectual Property Matters
107 | (a) Third Party Claims
108 | If Contributor has knowledge that a license under a third party's intellectual property rights is required to exercise the rights granted by such Contributor under Sections 2.1 or 2.2, Contributor must include a text file with the Source Code distribution titled "LEGAL" which describes the claim and the party making the claim in sufficient detail that a recipient will know whom to contact. If Contributor obtains such knowledge after the Modification is made available as described in Section 3.2, Contributor shall promptly modify the LEGAL file in all copies Contributor makes available thereafter and shall take other steps (such as notifying appropriate mailing lists or newsgroups) reasonably calculated to inform those who received the Covered Code that new knowledge has been obtained.
109 |
110 | (b) Contributor APIs
111 | If Contributor's Modifications include an application programming interface and Contributor has knowledge of patent licenses which are reasonably necessary to implement that API, Contributor must also include this information in the legal file.
112 |
113 | (c) Representations.
114 | Contributor represents that, except as disclosed pursuant to Section 3.4 (a) above, Contributor believes that Contributor's Modifications are Contributor's original creation(s) and/or Contributor has sufficient rights to grant the rights conveyed by this License.
115 |
116 | 3.5. Required Notices.
117 | You must duplicate the notice in Exhibit A in each file of the Source Code. If it is not possible to put such notice in a particular Source Code file due to its structure, then You must include such notice in a location (such as a relevant directory) where a user would be likely to look for such a notice. If You created one or more Modification(s) You may add your name as a Contributor to the notice described in Exhibit A. You must also duplicate this License in any documentation for the Source Code where You describe recipients' rights or ownership rights relating to Covered Code. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Code. However, You may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear than any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer.
118 |
119 | 3.6. Distribution of Executable Versions.
120 | You may distribute Covered Code in Executable form only if the requirements of Sections 3.1, 3.2, 3.3, 3.4 and 3.5 have been met for that Covered Code, and if You include a notice stating that the Source Code version of the Covered Code is available under the terms of this License, including a description of how and where You have fulfilled the obligations of Section 3.2. The notice must be conspicuously included in any notice in an Executable version, related documentation or collateral in which You describe recipients' rights relating to the Covered Code. You may distribute the Executable version of Covered Code or ownership rights under a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable version does not attempt to limit or alter the recipient's rights in the Source Code version from the rights set forth in this License. If You distribute the Executable version under a different license You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or any Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer.
121 |
122 | 3.7. Larger Works.
123 | You may create a Larger Work by combining Covered Code with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Code.
124 |
125 | 4. Inability to Comply Due to Statute or Regulation.
126 | If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Code due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be included in the legal file described in Section 3.4 and must be included with all distributions of the Source Code. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it.
127 |
128 | 5. Application of this License.
129 | This License applies to code to which the Initial Developer has attached the notice in Exhibit A and to related Covered Code.
130 |
131 | 6. Versions of the License.
132 | 6.1. New Versions
133 | Netscape Communications Corporation ("Netscape") may publish revised and/or new versions of the License from time to time. Each version will be given a distinguishing version number.
134 |
135 | 6.2. Effect of New Versions
136 | Once Covered Code has been published under a particular version of the License, You may always continue to use it under the terms of that version. You may also choose to use such Covered Code under the terms of any subsequent version of the License published by Netscape. No one other than Netscape has the right to modify the terms applicable to Covered Code created under this License.
137 |
138 | 6.3. Derivative Works
139 | If You create or use a modified version of this License (which you may only do in order to apply it to code which is not already Covered Code governed by this License), You must (a) rename Your license so that the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", "MPL", "NPL" or any confusingly similar phrase do not appear in your license (except to note that your license differs from this License) and (b) otherwise make it clear that Your version of the license contains terms which differ from the Mozilla Public License and Netscape Public License. (Filling in the name of the Initial Developer, Original Code or Contributor in the notice described in Exhibit A shall not of themselves be deemed to be modifications of this License.)
140 |
141 | 7. Disclaimer of warranty
142 | Covered code is provided under this license on an "as is" basis, without warranty of any kind, either expressed or implied, including, without limitation, warranties that the covered code is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire risk as to the quality and performance of the covered code is with you. Should any covered code prove defective in any respect, you (not the initial developer or any other contributor) assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty constitutes an essential part of this license. No use of any covered code is authorized hereunder except under this disclaimer.
143 |
144 | 8. Termination
145 | 8.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. All sublicenses to the Covered Code which are properly granted shall survive any termination of this License. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive.
146 |
147 | 8.2. If You initiate litigation by asserting a patent infringement claim (excluding declatory judgment actions) against Initial Developer or a Contributor (the Initial Developer or Contributor against whom You file such action is referred to as "Participant") alleging that:
148 |
149 | a.such Participant's Contributor Version directly or indirectly infringes any patent, then any and all rights granted by such Participant to You under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively, unless if within 60 days after receipt of notice You either: (i) agree in writing to pay Participant a mutually agreeable reasonable royalty for Your past and future use of Modifications made by such Participant, or (ii) withdraw Your litigation claim with respect to the Contributor Version against such Participant. If within 60 days of notice, a reasonable royalty and payment arrangement are not mutually agreed upon in writing by the parties or the litigation claim is not withdrawn, the rights granted by Participant to You under Sections 2.1 and/or 2.2 automatically terminate at the expiration of the 60 day notice period specified above.
150 | b.any software, hardware, or device, other than such Participant's Contributor Version, directly or indirectly infringes any patent, then any rights granted to You by such Participant under Sections 2.1(b) and 2.2(b) are revoked effective as of the date You first made, used, sold, distributed, or had made, Modifications made by that Participant.
151 | 8.3. If You assert a patent infringement claim against Participant alleging that such Participant's Contributor Version directly or indirectly infringes any patent where such claim is resolved (such as by license or settlement) prior to the initiation of patent infringement litigation, then the reasonable value of the licenses granted by such Participant under Sections 2.1 or 2.2 shall be taken into account in determining the amount or value of any payment or license.
152 |
153 | 8.4. In the event of termination under Sections 8.1 or 8.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or any distributor hereunder prior to termination shall survive termination.
154 |
155 | 9. Limitation of liability
156 | Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, shall you, the initial developer, any other contributor, or any distributor of covered code, or any supplier of any of such parties, be liable to any person for any indirect, special, incidental, or consequential damages of any character including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if such party shall have been informed of the possibility of such damages. This limitation of liability shall not apply to liability for death or personal injury resulting from such party's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to you.
157 |
158 | 10. U.S. government end users
159 | The Covered Code is a "commercial item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" and "commercial computer software documentation," as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Code with only those rights set forth herein.
160 |
161 | 11. Miscellaneous
162 | This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by California law provisions (except to the extent applicable law, if any, provides otherwise), excluding its conflict-of-law provisions. With respect to disputes in which at least one party is a citizen of, or an entity chartered or registered to do business in the United States of America, any litigation relating to this License shall be subject to the jurisdiction of the Federal Courts of the Northern District of California, with venue lying in Santa Clara County, California, with the losing party responsible for costs, including without limitation, court costs and reasonable attorneys' fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License.
163 |
164 | 12. Responsibility for claims
165 | As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability.
166 |
167 | 13. Multiple-licensed code
168 | Initial Developer may designate portions of the Covered Code as "Multiple-Licensed". "Multiple-Licensed" means that the Initial Developer permits you to utilize portions of the Covered Code under Your choice of the MPL or the alternative licenses, if any, specified by the Initial Developer in the file described in Exhibit A.
169 |
170 | Exhibit A - Mozilla Public License.
171 | "The contents of this file are subject to the Mozilla Public License
172 | Version 1.1 (the "License"); you may not use this file except in
173 | compliance with the License. You may obtain a copy of the License at
174 | http://www.mozilla.org/MPL/
175 |
176 | Software distributed under the License is distributed on an "AS IS"
177 | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
178 | License for the specific language governing rights and limitations
179 | under the License.
180 |
181 | The Original Code is ______________________________________.
182 |
183 | The Initial Developer of the Original Code is ________________________.
184 | Portions created by ______________________ are Copyright (C) ______
185 | _______________________. All Rights Reserved.
186 |
187 | Contributor(s): ______________________________________.
188 |
189 | Alternatively, the contents of this file may be used under the terms
190 | of the _____ license (the "[___] License"), in which case the
191 | provisions of [______] License are applicable instead of those
192 | above. If you wish to allow use of your version of this file only
193 | under the terms of the [____] License and not to allow others to use
194 | your version of this file under the MPL, indicate your decision by
195 | deleting the provisions above and replace them with the notice and
196 | other provisions required by the [___] License. If you do not delete
197 | the provisions above, a recipient may use your version of this file
198 | under either the MPL or the [___] License."NOTE: The text of this Exhibit A may differ slightly from the text of the notices in the Source Code files of the Original Code. You should use the text of this Exhibit A rather than the text found in the Original Code Source Code for Your Modifications.
199 |
--------------------------------------------------------------------------------