other-licenses/nsis/Contrib/ExDLL/exdll.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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 // Unicode support added by Jim Park -- 07/27/2007
michael@0 2 // Unicode support requires that all plugins take TCHARs instead as well. This
michael@0 3 // means existing plugins will not work for the Unicode version of NSIS unless
michael@0 4 // recompiled. You have been warned.
michael@0 5
michael@0 6 #ifndef _EXDLL_H_
michael@0 7 #define _EXDLL_H_
michael@0 8
michael@0 9 #include <windows.h>
michael@0 10 #include "tchar.h"
michael@0 11
michael@0 12 #if defined(__GNUC__)
michael@0 13 #define UNUSED __attribute__((unused))
michael@0 14 #else
michael@0 15 #define UNUSED
michael@0 16 #endif
michael@0 17
michael@0 18 // only include this file from one place in your DLL.
michael@0 19 // (it is all static, if you use it in two places it will fail)
michael@0 20
michael@0 21 #define EXDLL_INIT() { \
michael@0 22 g_stringsize=string_size; \
michael@0 23 g_stacktop=stacktop; \
michael@0 24 g_variables=variables; }
michael@0 25
michael@0 26 // For page showing plug-ins
michael@0 27 #define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8)
michael@0 28 #define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd)
michael@0 29
michael@0 30 /* Jim Park: This char is compared as an int value and therefore
michael@0 31 it's fine as an ASCII. Do not need to change to wchar_t since
michael@0 32 it will get the same integer value. */
michael@0 33 #define NOTIFY_BYE_BYE _T('x')
michael@0 34
michael@0 35 typedef struct _stack_t {
michael@0 36 struct _stack_t *next;
michael@0 37 TCHAR text[1]; // this should be the length of string_size
michael@0 38 } stack_t;
michael@0 39
michael@0 40
michael@0 41 static unsigned int g_stringsize;
michael@0 42 static stack_t **g_stacktop;
michael@0 43 static TCHAR *g_variables;
michael@0 44
michael@0 45 static int __stdcall popstring(TCHAR *str) UNUSED; // 0 on success, 1 on empty stack
michael@0 46 static void __stdcall pushstring(const TCHAR *str) UNUSED;
michael@0 47 static TCHAR * __stdcall getuservariable(const int varnum) UNUSED;
michael@0 48 static void __stdcall setuservariable(const int varnum, const TCHAR *var) UNUSED;
michael@0 49
michael@0 50 enum
michael@0 51 {
michael@0 52 INST_0, // $0
michael@0 53 INST_1, // $1
michael@0 54 INST_2, // $2
michael@0 55 INST_3, // $3
michael@0 56 INST_4, // $4
michael@0 57 INST_5, // $5
michael@0 58 INST_6, // $6
michael@0 59 INST_7, // $7
michael@0 60 INST_8, // $8
michael@0 61 INST_9, // $9
michael@0 62 INST_R0, // $R0
michael@0 63 INST_R1, // $R1
michael@0 64 INST_R2, // $R2
michael@0 65 INST_R3, // $R3
michael@0 66 INST_R4, // $R4
michael@0 67 INST_R5, // $R5
michael@0 68 INST_R6, // $R6
michael@0 69 INST_R7, // $R7
michael@0 70 INST_R8, // $R8
michael@0 71 INST_R9, // $R9
michael@0 72 INST_CMDLINE, // $CMDLINE
michael@0 73 INST_INSTDIR, // $INSTDIR
michael@0 74 INST_OUTDIR, // $OUTDIR
michael@0 75 INST_EXEDIR, // $EXEDIR
michael@0 76 INST_LANG, // $LANGUAGE
michael@0 77 __INST_LAST
michael@0 78 };
michael@0 79
michael@0 80 typedef struct {
michael@0 81 int autoclose;
michael@0 82 int all_user_var;
michael@0 83 int exec_error;
michael@0 84 int abort;
michael@0 85 int exec_reboot;
michael@0 86 int reboot_called;
michael@0 87 int XXX_cur_insttype; // deprecated
michael@0 88 int XXX_insttype_changed; // deprecated
michael@0 89 int silent;
michael@0 90 int instdir_error;
michael@0 91 int rtl;
michael@0 92 int errlvl;
michael@0 93 int alter_reg_view;
michael@0 94 int status_update;
michael@0 95 } exec_flags_type;
michael@0 96
michael@0 97 typedef struct {
michael@0 98 exec_flags_type *exec_flags;
michael@0 99 int (__stdcall *ExecuteCodeSegment)(int, HWND);
michael@0 100 void (__stdcall *validate_filename)(TCHAR *);
michael@0 101 } extra_parameters;
michael@0 102
michael@0 103 // utility functions (not required but often useful)
michael@0 104 static int __stdcall popstring(TCHAR *str)
michael@0 105 {
michael@0 106 stack_t *th;
michael@0 107 if (!g_stacktop || !*g_stacktop) return 1;
michael@0 108 th=(*g_stacktop);
michael@0 109 lstrcpy(str,th->text);
michael@0 110 *g_stacktop = th->next;
michael@0 111 GlobalFree((HGLOBAL)th);
michael@0 112 return 0;
michael@0 113 }
michael@0 114
michael@0 115 static void __stdcall pushstring(const TCHAR *str)
michael@0 116 {
michael@0 117 stack_t *th;
michael@0 118 if (!g_stacktop) return;
michael@0 119 th=(stack_t*)GlobalAlloc(GPTR,(sizeof(stack_t)+(g_stringsize)*sizeof(TCHAR)));
michael@0 120 lstrcpyn(th->text,str,g_stringsize);
michael@0 121 th->next=*g_stacktop;
michael@0 122 *g_stacktop=th;
michael@0 123 }
michael@0 124
michael@0 125 static TCHAR * __stdcall getuservariable(const int varnum)
michael@0 126 {
michael@0 127 if (varnum < 0 || varnum >= __INST_LAST) return NULL;
michael@0 128 return g_variables+varnum*g_stringsize;
michael@0 129 }
michael@0 130
michael@0 131 static void __stdcall setuservariable(const int varnum, const TCHAR *var)
michael@0 132 {
michael@0 133 if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
michael@0 134 lstrcpy(g_variables + varnum*g_stringsize, var);
michael@0 135 }
michael@0 136
michael@0 137 #ifdef _UNICODE
michael@0 138 #define PopStringW(x) popstring(x)
michael@0 139 #define PushStringW(x) pushstring(x)
michael@0 140 #define SetUserVariableW(x,y) setuservariable(x,y)
michael@0 141
michael@0 142 static int __stdcall PopStringA(char* ansiStr)
michael@0 143 {
michael@0 144 wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t));
michael@0 145 int rval = popstring(wideStr);
michael@0 146 WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL);
michael@0 147 GlobalFree((HGLOBAL)wideStr);
michael@0 148 return rval;
michael@0 149 }
michael@0 150
michael@0 151 static void __stdcall PushStringA(const char* ansiStr)
michael@0 152 {
michael@0 153 wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t));
michael@0 154 MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize);
michael@0 155 pushstring(wideStr);
michael@0 156 GlobalFree((HGLOBAL)wideStr);
michael@0 157 return;
michael@0 158 }
michael@0 159
michael@0 160 static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr)
michael@0 161 {
michael@0 162 lstrcpyW(wideStr, getuservariable(varnum));
michael@0 163 }
michael@0 164
michael@0 165 static void __stdcall GetUserVariableA(const int varnum, char* ansiStr)
michael@0 166 {
michael@0 167 wchar_t* wideStr = getuservariable(varnum);
michael@0 168 WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL);
michael@0 169 }
michael@0 170
michael@0 171 static void __stdcall SetUserVariableA(const int varnum, const char* ansiStr)
michael@0 172 {
michael@0 173 if (ansiStr != NULL && varnum >= 0 && varnum < __INST_LAST)
michael@0 174 {
michael@0 175 wchar_t* wideStr = g_variables + varnum * g_stringsize;
michael@0 176 MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize);
michael@0 177 }
michael@0 178 }
michael@0 179
michael@0 180 #else
michael@0 181 // ANSI defs
michael@0 182
michael@0 183 #define PopStringA(x) popstring(x)
michael@0 184 #define PushStringA(x) pushstring(x)
michael@0 185 #define SetUserVariableA(x,y) setuservariable(x,y)
michael@0 186
michael@0 187 static int __stdcall PopStringW(wchar_t* wideStr)
michael@0 188 {
michael@0 189 char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize);
michael@0 190 int rval = popstring(ansiStr);
michael@0 191 MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize);
michael@0 192 GlobalFree((HGLOBAL)ansiStr);
michael@0 193 return rval;
michael@0 194 }
michael@0 195
michael@0 196 static void __stdcall PushStringW(wchar_t* wideStr)
michael@0 197 {
michael@0 198 char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize);
michael@0 199 WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL);
michael@0 200 pushstring(ansiStr);
michael@0 201 GlobalFree((HGLOBAL)ansiStr);
michael@0 202 }
michael@0 203
michael@0 204 static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr)
michael@0 205 {
michael@0 206 char* ansiStr = getuservariable(varnum);
michael@0 207 MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize);
michael@0 208 }
michael@0 209
michael@0 210 static void __stdcall GetUserVariableA(const int varnum, char* ansiStr)
michael@0 211 {
michael@0 212 lstrcpyA(ansiStr, getuservariable(varnum));
michael@0 213 }
michael@0 214
michael@0 215 static void __stdcall SetUserVariableW(const int varnum, const wchar_t* wideStr)
michael@0 216 {
michael@0 217 if (wideStr != NULL && varnum >= 0 && varnum < __INST_LAST)
michael@0 218 {
michael@0 219 char* ansiStr = g_variables + varnum * g_stringsize;
michael@0 220 WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL);
michael@0 221 }
michael@0 222 }
michael@0 223 #endif
michael@0 224
michael@0 225 static BOOL __stdcall IsUnicode(void)
michael@0 226 {
michael@0 227 #ifdef _UNICODE
michael@0 228 return TRUE;
michael@0 229 #else
michael@0 230 return FALSE;
michael@0 231 #endif
michael@0 232 }
michael@0 233
michael@0 234 #endif//_EXDLL_H_

mercurial