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 | ; ExtDLL header for MASM32 |
michael@0 | 3 | ; |
michael@0 | 4 | ; Author: Ramon |
michael@0 | 5 | ; |
michael@0 | 6 | ; Obs: This header must be included after windows.inc and kernel32.inc |
michael@0 | 7 | ; because it need the prototypes for lstrcpy, lstrcpyn, |
michael@0 | 8 | ; GlobalAlloc and GlobalFree |
michael@0 | 9 | ; |
michael@0 | 10 | ;################################################################ |
michael@0 | 11 | stack_t struct |
michael@0 | 12 | next dd ? |
michael@0 | 13 | text dd ? ; 1 DUP(?) ; this should be the length of string_size |
michael@0 | 14 | stack_t ends |
michael@0 | 15 | |
michael@0 | 16 | .const |
michael@0 | 17 | ; For page showing plug-ins |
michael@0 | 18 | WM_NOTIFY_OUTER_NEXT equ (WM_USER+0x8) |
michael@0 | 19 | WM_NOTIFY_CUSTOM_READY equ (WM_USER+0xd) |
michael@0 | 20 | NOTIFY_BYE_BYE equ 'x' |
michael@0 | 21 | |
michael@0 | 22 | INST_0 EQU 0 ; $0 |
michael@0 | 23 | INST_1 EQU 1 ; $1 |
michael@0 | 24 | INST_2 EQU 2 ; $2 |
michael@0 | 25 | INST_3 EQU 3 ; $3 |
michael@0 | 26 | INST_4 EQU 4 ; $4 |
michael@0 | 27 | INST_5 EQU 5 ; $5 |
michael@0 | 28 | INST_6 EQU 6 ; $6 |
michael@0 | 29 | INST_7 EQU 7 ; $7 |
michael@0 | 30 | INST_8 EQU 8 ; $8 |
michael@0 | 31 | INST_9 EQU 9 ; $9 |
michael@0 | 32 | INST_R0 EQU 10 ; $R0 |
michael@0 | 33 | INST_R1 EQU 11 ; $R1 |
michael@0 | 34 | INST_R2 EQU 12 ; $R2 |
michael@0 | 35 | INST_R3 EQU 13 ; $R3 |
michael@0 | 36 | INST_R4 EQU 14 ; $R4 |
michael@0 | 37 | INST_R5 EQU 15 ; $R5 |
michael@0 | 38 | INST_R6 EQU 16 ; $R6 |
michael@0 | 39 | INST_R7 EQU 17 ; $R7 |
michael@0 | 40 | INST_R8 EQU 18 ; $R8 |
michael@0 | 41 | INST_R9 EQU 19 ; $R9 |
michael@0 | 42 | INST_CMDLINE EQU 20 ; $CMDLINE |
michael@0 | 43 | INST_INSTDIR EQU 21 ; $INSTDIR |
michael@0 | 44 | INST_OUTDIR EQU 22 ; $OUTDIR |
michael@0 | 45 | INST_EXEDIR EQU 23 ; $EXEDIR |
michael@0 | 46 | INST_LANG EQU 24 ; $LANGUAGE |
michael@0 | 47 | __INST_LAST EQU 25 |
michael@0 | 48 | |
michael@0 | 49 | .data? |
michael@0 | 50 | g_stringsize dd ? |
michael@0 | 51 | g_stacktop dd ? |
michael@0 | 52 | g_variables dd ? |
michael@0 | 53 | |
michael@0 | 54 | m2m MACRO M1, M2 |
michael@0 | 55 | push M2 |
michael@0 | 56 | pop M1 |
michael@0 | 57 | ENDM |
michael@0 | 58 | |
michael@0 | 59 | EXDLL_INIT MACRO |
michael@0 | 60 | m2m g_stringsize, string_size |
michael@0 | 61 | m2m g_stacktop, stacktop |
michael@0 | 62 | m2m g_variables, variables |
michael@0 | 63 | ENDM |
michael@0 | 64 | |
michael@0 | 65 | .code |
michael@0 | 66 | |
michael@0 | 67 | ; utility functions (not required but often useful) |
michael@0 | 68 | popstring proc uses edi pStr:DWORD |
michael@0 | 69 | |
michael@0 | 70 | LOCAL th:DWORD |
michael@0 | 71 | |
michael@0 | 72 | mov edi, g_stacktop |
michael@0 | 73 | cmp edi, 0 |
michael@0 | 74 | jz STACK_ERR |
michael@0 | 75 | mov edi, [edi] |
michael@0 | 76 | cmp edi, 0 |
michael@0 | 77 | jz STACK_ERR |
michael@0 | 78 | |
michael@0 | 79 | ASSUME edi:PTR stack_t |
michael@0 | 80 | invoke lstrcpy, pStr, ADDR [edi].text |
michael@0 | 81 | mov th , edi |
michael@0 | 82 | mov edi, [edi].next |
michael@0 | 83 | mov eax, g_stacktop |
michael@0 | 84 | mov [eax], edi |
michael@0 | 85 | invoke GlobalFree, th |
michael@0 | 86 | ASSUME edi:PTR NOTHING |
michael@0 | 87 | mov eax, 0 |
michael@0 | 88 | ret |
michael@0 | 89 | |
michael@0 | 90 | STACK_ERR: |
michael@0 | 91 | mov eax, 1 |
michael@0 | 92 | ret |
michael@0 | 93 | |
michael@0 | 94 | popstring endp |
michael@0 | 95 | |
michael@0 | 96 | pushstring proc uses edi pStr:DWORD |
michael@0 | 97 | |
michael@0 | 98 | cmp g_stacktop, 0 |
michael@0 | 99 | jz STACK_ERR |
michael@0 | 100 | |
michael@0 | 101 | mov eax, sizeof stack_t |
michael@0 | 102 | add eax, g_stringsize |
michael@0 | 103 | invoke GlobalAlloc, GPTR, eax |
michael@0 | 104 | |
michael@0 | 105 | mov edi, eax |
michael@0 | 106 | assume edi:PTR stack_t |
michael@0 | 107 | |
michael@0 | 108 | invoke lstrcpyn, ADDR [edi].text, pStr, g_stringsize |
michael@0 | 109 | mov eax, g_stacktop |
michael@0 | 110 | push DWORD PTR[eax] |
michael@0 | 111 | mov [eax], edi |
michael@0 | 112 | pop eax |
michael@0 | 113 | ;lea edi, [edi].next ; Not needed [edi].next == edi |
michael@0 | 114 | mov DWORD PTR[edi], eax |
michael@0 | 115 | ASSUME edi:PTR NOTHING |
michael@0 | 116 | |
michael@0 | 117 | STACK_ERR: |
michael@0 | 118 | ret |
michael@0 | 119 | |
michael@0 | 120 | pushstring endp |
michael@0 | 121 | |
michael@0 | 122 | getuservariable proc varnum:DWORD |
michael@0 | 123 | |
michael@0 | 124 | .if varnum < 0 || varnum >= __INST_LAST |
michael@0 | 125 | xor eax, eax |
michael@0 | 126 | .else |
michael@0 | 127 | mov eax, varnum |
michael@0 | 128 | imul eax, g_stringsize |
michael@0 | 129 | add eax, g_variables |
michael@0 | 130 | .endif |
michael@0 | 131 | ret |
michael@0 | 132 | |
michael@0 | 133 | getuservariable endp |
michael@0 | 134 | |
michael@0 | 135 | setuservariable proc varnum:DWORD, var:DWORD |
michael@0 | 136 | |
michael@0 | 137 | .if (var != NULL && varnum >= 0 && varnum < __INST_LAST) |
michael@0 | 138 | mov eax, varnum |
michael@0 | 139 | imul eax, g_stringsize |
michael@0 | 140 | add eax, g_variables |
michael@0 | 141 | invoke lstrcpy, eax, var |
michael@0 | 142 | .endif |
michael@0 | 143 | ret |
michael@0 | 144 | |
michael@0 | 145 | setuservariable endp |