Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | { |
michael@0 | 2 | NSIS ExDLL example |
michael@0 | 3 | (C) 2001 - Peter Windridge |
michael@0 | 4 | |
michael@0 | 5 | Fixed and formatted by Brett Dever |
michael@0 | 6 | http://editor.nfscheats.com/ |
michael@0 | 7 | |
michael@0 | 8 | Tested in Delphi 7.0 |
michael@0 | 9 | } |
michael@0 | 10 | |
michael@0 | 11 | library exdll; |
michael@0 | 12 | |
michael@0 | 13 | uses Windows; |
michael@0 | 14 | |
michael@0 | 15 | type |
michael@0 | 16 | VarConstants = ( |
michael@0 | 17 | INST_0, |
michael@0 | 18 | INST_1, // $1 |
michael@0 | 19 | INST_2, // $2 |
michael@0 | 20 | INST_3, // $3 |
michael@0 | 21 | INST_4, // $4 |
michael@0 | 22 | INST_5, // $5 |
michael@0 | 23 | INST_6, // $6 |
michael@0 | 24 | INST_7, // $7 |
michael@0 | 25 | INST_8, // $8 |
michael@0 | 26 | INST_9, // $9 |
michael@0 | 27 | INST_R0, // $R0 |
michael@0 | 28 | INST_R1, // $R1 |
michael@0 | 29 | INST_R2, // $R2 |
michael@0 | 30 | INST_R3, // $R3 |
michael@0 | 31 | INST_R4, // $R4 |
michael@0 | 32 | INST_R5, // $R5 |
michael@0 | 33 | INST_R6, // $R6 |
michael@0 | 34 | INST_R7, // $R7 |
michael@0 | 35 | INST_R8, // $R8 |
michael@0 | 36 | INST_R9, // $R9 |
michael@0 | 37 | INST_CMDLINE, // $CMDLINE |
michael@0 | 38 | INST_INSTDIR, // $INSTDIR |
michael@0 | 39 | INST_OUTDIR, // $OUTDIR |
michael@0 | 40 | INST_EXEDIR, // $EXEDIR |
michael@0 | 41 | INST_LANG, // $LANGUAGE |
michael@0 | 42 | __INST_LAST |
michael@0 | 43 | ); |
michael@0 | 44 | TVariableList = INST_0..__INST_LAST; |
michael@0 | 45 | pstack_t = ^stack_t; |
michael@0 | 46 | stack_t = record |
michael@0 | 47 | next: pstack_t; |
michael@0 | 48 | text: PChar; |
michael@0 | 49 | end; |
michael@0 | 50 | |
michael@0 | 51 | var |
michael@0 | 52 | g_stringsize: integer; |
michael@0 | 53 | g_stacktop: ^pstack_t; |
michael@0 | 54 | g_variables: PChar; |
michael@0 | 55 | g_hwndParent: HWND; |
michael@0 | 56 | |
michael@0 | 57 | function PopString(): string; |
michael@0 | 58 | var |
michael@0 | 59 | th: pstack_t; |
michael@0 | 60 | begin |
michael@0 | 61 | if integer(g_stacktop^) <> 0 then begin |
michael@0 | 62 | th := g_stacktop^; |
michael@0 | 63 | Result := PChar(@th.text); |
michael@0 | 64 | g_stacktop^ := th.next; |
michael@0 | 65 | GlobalFree(HGLOBAL(th)); |
michael@0 | 66 | end; |
michael@0 | 67 | end; |
michael@0 | 68 | |
michael@0 | 69 | procedure PushString(const str: string=''); |
michael@0 | 70 | var |
michael@0 | 71 | th: pstack_t; |
michael@0 | 72 | begin |
michael@0 | 73 | if integer(g_stacktop) <> 0 then begin |
michael@0 | 74 | th := pstack_t(GlobalAlloc(GPTR, SizeOf(stack_t) + g_stringsize)); |
michael@0 | 75 | lstrcpyn(@th.text, PChar(str), g_stringsize); |
michael@0 | 76 | th.next := g_stacktop^; |
michael@0 | 77 | g_stacktop^ := th; |
michael@0 | 78 | end; |
michael@0 | 79 | end; |
michael@0 | 80 | |
michael@0 | 81 | function GetUserVariable(const varnum: TVariableList): string; |
michael@0 | 82 | begin |
michael@0 | 83 | if (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then |
michael@0 | 84 | Result := g_variables + integer(varnum) * g_stringsize |
michael@0 | 85 | else |
michael@0 | 86 | Result := ''; |
michael@0 | 87 | end; |
michael@0 | 88 | |
michael@0 | 89 | procedure SetUserVariable(const varnum: TVariableList; const value: string); |
michael@0 | 90 | begin |
michael@0 | 91 | if (value <> '') and (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then |
michael@0 | 92 | lstrcpy(g_variables + integer(varnum) * g_stringsize, PChar(value)) |
michael@0 | 93 | end; |
michael@0 | 94 | |
michael@0 | 95 | procedure NSISDialog(const text, caption: string; const buttons: integer); |
michael@0 | 96 | begin |
michael@0 | 97 | MessageBox(g_hwndParent, PChar(text), PChar(caption), buttons); |
michael@0 | 98 | end; |
michael@0 | 99 | |
michael@0 | 100 | procedure ex_dll(const hwndParent: HWND; const string_size: integer; const variables: PChar; const stacktop: pointer); cdecl; |
michael@0 | 101 | begin |
michael@0 | 102 | // setup global variables |
michael@0 | 103 | g_stringsize := string_size; |
michael@0 | 104 | g_hwndParent := hwndParent; |
michael@0 | 105 | g_stacktop := stacktop; |
michael@0 | 106 | g_variables := variables; |
michael@0 | 107 | // end global variable setup |
michael@0 | 108 | |
michael@0 | 109 | NSISDialog(GetUserVariable(INST_0), 'The value of $0', MB_OK); |
michael@0 | 110 | NSISDialog(PopString, 'pop', MB_OK); |
michael@0 | 111 | PushString('Hello, this is a push'); |
michael@0 | 112 | SetUserVariable(INST_0, 'This is user var $0'); |
michael@0 | 113 | end; |
michael@0 | 114 | |
michael@0 | 115 | exports ex_dll; |
michael@0 | 116 | |
michael@0 | 117 | begin |
michael@0 | 118 | end. |