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 | // Unicode support by Jim Park -- 08/23/2007 |
michael@0 | 2 | |
michael@0 | 3 | #include <windows.h> |
michael@0 | 4 | #include "exdllutil.h" |
michael@0 | 5 | |
michael@0 | 6 | // utility functions (not required but often useful) |
michael@0 | 7 | static int __stdcall popstring(TCHAR *str) |
michael@0 | 8 | { |
michael@0 | 9 | stack_t *th; |
michael@0 | 10 | if (!g_stacktop || !*g_stacktop) return 1; |
michael@0 | 11 | th=(*g_stacktop); |
michael@0 | 12 | lstrcpy(str,th->text); |
michael@0 | 13 | *g_stacktop = th->next; |
michael@0 | 14 | GlobalFree((HGLOBAL)th); |
michael@0 | 15 | return 0; |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | static void __stdcall pushstring(const TCHAR *str) |
michael@0 | 19 | { |
michael@0 | 20 | stack_t *th; |
michael@0 | 21 | if (!g_stacktop) return; |
michael@0 | 22 | th=(stack_t*)GlobalAlloc(GPTR,(sizeof(stack_t)+(g_stringsize)*sizeof(TCHAR))); |
michael@0 | 23 | lstrcpyn(th->text,str,g_stringsize); |
michael@0 | 24 | th->next=*g_stacktop; |
michael@0 | 25 | *g_stacktop=th; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | static TCHAR * __stdcall getuservariable(const int varnum) |
michael@0 | 29 | { |
michael@0 | 30 | if (varnum < 0 || varnum >= __INST_LAST) return NULL; |
michael@0 | 31 | return g_variables+varnum*g_stringsize; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | static void __stdcall setuservariable(const int varnum, const TCHAR *var) |
michael@0 | 35 | { |
michael@0 | 36 | if (var != NULL && varnum >= 0 && varnum < __INST_LAST) |
michael@0 | 37 | lstrcpy(g_variables + varnum*g_stringsize, var); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | #ifdef _UNICODE |
michael@0 | 41 | static int __stdcall PopStringA(char* ansiStr) |
michael@0 | 42 | { |
michael@0 | 43 | wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t)); |
michael@0 | 44 | int rval = popstring(wideStr); |
michael@0 | 45 | WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); |
michael@0 | 46 | GlobalFree((HGLOBAL)wideStr); |
michael@0 | 47 | return rval; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | static void __stdcall PushStringA(const char* ansiStr) |
michael@0 | 51 | { |
michael@0 | 52 | wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t)); |
michael@0 | 53 | MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); |
michael@0 | 54 | pushtring(wideStr); |
michael@0 | 55 | GlobalFree((HGLOBAL)wideStr); |
michael@0 | 56 | return; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr) |
michael@0 | 60 | { |
michael@0 | 61 | lstrcpyW(wideStr, getuservariable(varnum)); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | static void __stdcall GetUserVariableA(const int varnum, char* ansiStr) |
michael@0 | 65 | { |
michael@0 | 66 | wchar_t* wideStr = getuservariable(varnum); |
michael@0 | 67 | WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | static void __stdcall SetUserVariableA(const int varnum, const char* ansiStr) |
michael@0 | 71 | { |
michael@0 | 72 | if (ansiStr != NULL && varnum >= 0 && varnum < __INST_LAST) |
michael@0 | 73 | { |
michael@0 | 74 | wchar_t* wideStr = g_variables + varnum * g_stringsize; |
michael@0 | 75 | MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); |
michael@0 | 76 | } |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | #else |
michael@0 | 80 | // ANSI defs |
michael@0 | 81 | static int __stdcall PopStringW(wchar_t* wideStr) |
michael@0 | 82 | { |
michael@0 | 83 | char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize); |
michael@0 | 84 | int rval = popstring(ansiStr); |
michael@0 | 85 | MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); |
michael@0 | 86 | GlobalFree((HGLOBAL)ansiStr); |
michael@0 | 87 | return rval; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | static void __stdcall PushStringW(wchar_t* wideStr) |
michael@0 | 91 | { |
michael@0 | 92 | char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize); |
michael@0 | 93 | WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); |
michael@0 | 94 | pushstring(ansiStr); |
michael@0 | 95 | GlobalFree((HGLOBAL)ansiStr); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr) |
michael@0 | 99 | { |
michael@0 | 100 | char* ansiStr = getuservariable(varnum); |
michael@0 | 101 | MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | static void __stdcall GetUserVariableA(const int varnum, char* ansiStr) |
michael@0 | 105 | { |
michael@0 | 106 | lstrcpyA(ansiStr, getuservariable(varnum)); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | static void __stdcall SetUserVariableW(const int varnum, const wchar_t* wideStr) |
michael@0 | 110 | { |
michael@0 | 111 | if (wideStr != NULL && varnum >= 0 && varnum < __INST_LAST) |
michael@0 | 112 | { |
michael@0 | 113 | char* ansiStr = g_variables + varnum * g_stringsize; |
michael@0 | 114 | WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); |
michael@0 | 115 | } |
michael@0 | 116 | } |
michael@0 | 117 | #endif |
michael@0 | 118 | |
michael@0 | 119 | static BOOL __stdcall IsUnicode(void) |
michael@0 | 120 | { |
michael@0 | 121 | #ifdef _UNICODE |
michael@0 | 122 | return TRUE; |
michael@0 | 123 | #else |
michael@0 | 124 | return FALSE; |
michael@0 | 125 | #endif |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | static TCHAR* __stdcall AllocString() |
michael@0 | 129 | { |
michael@0 | 130 | return (TCHAR*) GlobalAlloc(GPTR, g_stringsize*sizeof(TCHAR)); |
michael@0 | 131 | } |