sl@0
|
1 |
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Implementation of the FontInjector DLL, only for the emulator. This DLL has
|
sl@0
|
15 |
// writeable static data and should use the EPOCALLOWDLLDATA keyword in the MMP
|
sl@0
|
16 |
// file, but it does not because by default the EKA2 emulator allows global data
|
sl@0
|
17 |
// as long as the constructors do not make executive calls and, in some test
|
sl@0
|
18 |
// cases, there is more than one instance of the test server with this DLL loaded,
|
sl@0
|
19 |
// although it should be in active use by only one process at a time. For more
|
sl@0
|
20 |
// information see the Symbian Developer Library > Symbian OS Guide > Essential
|
sl@0
|
21 |
// idioms > Static data.
|
sl@0
|
22 |
//
|
sl@0
|
23 |
|
sl@0
|
24 |
#include "fontinjector.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
#ifdef __WINS__
|
sl@0
|
27 |
|
sl@0
|
28 |
template<class C> EXPORT_C XVtableInjector<C>::XVtableInjector()
|
sl@0
|
29 |
{
|
sl@0
|
30 |
ASSERT(gObjects.Count() == 0);
|
sl@0
|
31 |
ASSERT(!gShellcode);
|
sl@0
|
32 |
ASSERT(!gOriginalVtable);
|
sl@0
|
33 |
}
|
sl@0
|
34 |
|
sl@0
|
35 |
template<class C> EXPORT_C XVtableInjector<C>::~XVtableInjector()
|
sl@0
|
36 |
{
|
sl@0
|
37 |
for (TInt i = 0; i < gObjects.Count(); ++i)
|
sl@0
|
38 |
{
|
sl@0
|
39 |
*reinterpret_cast<TAny**>(gObjects[i]) = gOriginalVtable;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
gObjects.Close();
|
sl@0
|
42 |
gShellcode = NULL;
|
sl@0
|
43 |
gOriginalVtable = NULL;
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
template<class C> EXPORT_C TInt XVtableInjector<C>::InjectShellcode(C* aObject, MShellcode* aShellcode)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
if (gShellcode && gShellcode != aShellcode)
|
sl@0
|
49 |
{
|
sl@0
|
50 |
return KErrArgument;
|
sl@0
|
51 |
}
|
sl@0
|
52 |
TInt err = KErrNone;
|
sl@0
|
53 |
if (gObjects.FindInAddressOrder(aObject) == KErrNotFound)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
if (gOriginalVtable && gOriginalVtable != *reinterpret_cast<TAny**>(aObject))
|
sl@0
|
56 |
{
|
sl@0
|
57 |
return KErrArgument;
|
sl@0
|
58 |
}
|
sl@0
|
59 |
err = gObjects.InsertInAddressOrder(aObject);
|
sl@0
|
60 |
if (err == KErrNone)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
gShellcode = aShellcode;
|
sl@0
|
63 |
gOriginalVtable = *reinterpret_cast<TAny**>(aObject);
|
sl@0
|
64 |
*reinterpret_cast<TAny**>(aObject) = *reinterpret_cast<TAny**>(this);
|
sl@0
|
65 |
}
|
sl@0
|
66 |
}
|
sl@0
|
67 |
return err;
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
template<> EXPORT_C void XVtableInjector<CFont>::GetVirtualFunctionName(TInt aIndex, TDes& aName)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
switch (aIndex)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
case 0:
|
sl@0
|
75 |
aName.Copy(_S("CFont::~CFont()"));
|
sl@0
|
76 |
break;
|
sl@0
|
77 |
case 1:
|
sl@0
|
78 |
aName.Copy(_S("CFont::Extension_(TUint, TAny*&, TAny*)"));
|
sl@0
|
79 |
break;
|
sl@0
|
80 |
case 2:
|
sl@0
|
81 |
aName.Copy(_S("CFont::DoTypeUid()"));
|
sl@0
|
82 |
break;
|
sl@0
|
83 |
case 3:
|
sl@0
|
84 |
aName.Copy(_S("CFont::DoHeightInPixels()"));
|
sl@0
|
85 |
break;
|
sl@0
|
86 |
case 4:
|
sl@0
|
87 |
aName.Copy(_S("CFont::DoAscentInPixels()"));
|
sl@0
|
88 |
break;
|
sl@0
|
89 |
case 5:
|
sl@0
|
90 |
aName.Copy(_S("CFont::DoDescentInPixels()"));
|
sl@0
|
91 |
break;
|
sl@0
|
92 |
case 6:
|
sl@0
|
93 |
aName.Copy(_S("CFont::DoCharWidthInPixels(TChar)"));
|
sl@0
|
94 |
break;
|
sl@0
|
95 |
case 7:
|
sl@0
|
96 |
aName.Copy(_S("CFont::DoTextWidthInPixels(const TDesC&)"));
|
sl@0
|
97 |
break;
|
sl@0
|
98 |
case 8:
|
sl@0
|
99 |
aName.Copy(_S("CFont::DoBaselineOffsetInPixels()"));
|
sl@0
|
100 |
break;
|
sl@0
|
101 |
case 9:
|
sl@0
|
102 |
aName.Copy(_S("CFont::DoTextCount(const TDesC&, TInt)"));
|
sl@0
|
103 |
break;
|
sl@0
|
104 |
case 10:
|
sl@0
|
105 |
aName.Copy(_S("CFont::DoTextCount(const TDesC&, TInt, TInt&)"));
|
sl@0
|
106 |
break;
|
sl@0
|
107 |
case 11:
|
sl@0
|
108 |
aName.Copy(_S("CFont::DoMaxCharWidthInPixels()"));
|
sl@0
|
109 |
break;
|
sl@0
|
110 |
case 12:
|
sl@0
|
111 |
aName.Copy(_S("CFont::DoMaxNormalCharWidthInPixels()"));
|
sl@0
|
112 |
break;
|
sl@0
|
113 |
case 13:
|
sl@0
|
114 |
aName.Copy(_S("CFont::DoFontSpecInTwips()"));
|
sl@0
|
115 |
break;
|
sl@0
|
116 |
case 14:
|
sl@0
|
117 |
aName.Copy(_S("CFont::DoGetCharacterData(TUint, TOpenFontCharMetrics&, const TUint8*&, TSize&)"));
|
sl@0
|
118 |
break;
|
sl@0
|
119 |
case 15:
|
sl@0
|
120 |
aName.Copy(_S("CFont::DoGetCharacterPosition(CFont::TPositionParam&)"));
|
sl@0
|
121 |
break;
|
sl@0
|
122 |
case 16:
|
sl@0
|
123 |
aName.Copy(_S("CFont::DoExtendedFunction(TUid, TAny*)"));
|
sl@0
|
124 |
break;
|
sl@0
|
125 |
default:
|
sl@0
|
126 |
aName.Copy(_S("CFont::<Unknown Virtual Function>"));
|
sl@0
|
127 |
}
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
template<> EXPORT_C void XVtableInjector<COpenFont>::GetVirtualFunctionName(TInt aIndex, TDes& aName)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
switch (aIndex)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
case 0:
|
sl@0
|
135 |
aName.Copy(_S("COpenFont::~COpenFont()"));
|
sl@0
|
136 |
break;
|
sl@0
|
137 |
case 1:
|
sl@0
|
138 |
aName.Copy(_S("COpenFont::Extension_(TUint, TAny*&, TAny*)"));
|
sl@0
|
139 |
break;
|
sl@0
|
140 |
case 2:
|
sl@0
|
141 |
aName.Copy(_S("COpenFont::RasterizeL(TInt, TOpenFontGlyphData*)"));
|
sl@0
|
142 |
break;
|
sl@0
|
143 |
case 3:
|
sl@0
|
144 |
aName.Copy(_S("COpenFont::ExtendedInterface(TUid, TAny*&)"));
|
sl@0
|
145 |
break;
|
sl@0
|
146 |
default:
|
sl@0
|
147 |
aName.Format(_L("COpenFont::<Extended Virtual Function %03d>"), aIndex - 3);
|
sl@0
|
148 |
}
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
template<class C> void XVtableInjector<C>::ObjectDestroyed(TAny* aObject)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
gObjects.Remove(gObjects.FindInAddressOrder(aObject));
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function000()
|
sl@0
|
157 |
{
|
sl@0
|
158 |
asm { push ecx }
|
sl@0
|
159 |
/* cdecl calling convention */
|
sl@0
|
160 |
asm { push ecx }
|
sl@0
|
161 |
asm { call ObjectDestroyed }
|
sl@0
|
162 |
asm { add esp, 4 }
|
sl@0
|
163 |
/* thiscall calling convention */
|
sl@0
|
164 |
asm { mov ecx, gShellcode }
|
sl@0
|
165 |
asm { push 0 }
|
sl@0
|
166 |
asm { mov eax, [ecx] }
|
sl@0
|
167 |
asm { call [eax] }
|
sl@0
|
168 |
/* continue to original function */
|
sl@0
|
169 |
asm { pop ecx }
|
sl@0
|
170 |
asm { mov eax, gOriginalVtable }
|
sl@0
|
171 |
asm { jmp [eax] }
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
#define DISPATCH_NTH_VIRTUAL_FUNCTION(n) \
|
sl@0
|
175 |
asm { push ecx } \
|
sl@0
|
176 |
/* thiscall calling convention */ \
|
sl@0
|
177 |
asm { mov ecx, gShellcode } \
|
sl@0
|
178 |
asm { push n } \
|
sl@0
|
179 |
asm { mov eax, [ecx] } \
|
sl@0
|
180 |
asm { call [eax] } \
|
sl@0
|
181 |
/* continue to original function */ \
|
sl@0
|
182 |
asm { pop ecx } \
|
sl@0
|
183 |
asm { mov eax, gOriginalVtable } \
|
sl@0
|
184 |
asm { jmp [eax + (n * 4)] }
|
sl@0
|
185 |
|
sl@0
|
186 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function001()
|
sl@0
|
187 |
{
|
sl@0
|
188 |
DISPATCH_NTH_VIRTUAL_FUNCTION(1)
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function002()
|
sl@0
|
192 |
{
|
sl@0
|
193 |
DISPATCH_NTH_VIRTUAL_FUNCTION(2)
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function003()
|
sl@0
|
197 |
{
|
sl@0
|
198 |
DISPATCH_NTH_VIRTUAL_FUNCTION(3)
|
sl@0
|
199 |
}
|
sl@0
|
200 |
|
sl@0
|
201 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function004()
|
sl@0
|
202 |
{
|
sl@0
|
203 |
DISPATCH_NTH_VIRTUAL_FUNCTION(4)
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function005()
|
sl@0
|
207 |
{
|
sl@0
|
208 |
DISPATCH_NTH_VIRTUAL_FUNCTION(5)
|
sl@0
|
209 |
}
|
sl@0
|
210 |
|
sl@0
|
211 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function006()
|
sl@0
|
212 |
{
|
sl@0
|
213 |
DISPATCH_NTH_VIRTUAL_FUNCTION(6)
|
sl@0
|
214 |
}
|
sl@0
|
215 |
|
sl@0
|
216 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function007()
|
sl@0
|
217 |
{
|
sl@0
|
218 |
DISPATCH_NTH_VIRTUAL_FUNCTION(7)
|
sl@0
|
219 |
}
|
sl@0
|
220 |
|
sl@0
|
221 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function008()
|
sl@0
|
222 |
{
|
sl@0
|
223 |
DISPATCH_NTH_VIRTUAL_FUNCTION(8)
|
sl@0
|
224 |
}
|
sl@0
|
225 |
|
sl@0
|
226 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function009()
|
sl@0
|
227 |
{
|
sl@0
|
228 |
DISPATCH_NTH_VIRTUAL_FUNCTION(9)
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function010()
|
sl@0
|
232 |
{
|
sl@0
|
233 |
DISPATCH_NTH_VIRTUAL_FUNCTION(10)
|
sl@0
|
234 |
}
|
sl@0
|
235 |
|
sl@0
|
236 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function011()
|
sl@0
|
237 |
{
|
sl@0
|
238 |
DISPATCH_NTH_VIRTUAL_FUNCTION(11)
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function012()
|
sl@0
|
242 |
{
|
sl@0
|
243 |
DISPATCH_NTH_VIRTUAL_FUNCTION(12)
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function013()
|
sl@0
|
247 |
{
|
sl@0
|
248 |
DISPATCH_NTH_VIRTUAL_FUNCTION(13)
|
sl@0
|
249 |
}
|
sl@0
|
250 |
|
sl@0
|
251 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function014()
|
sl@0
|
252 |
{
|
sl@0
|
253 |
DISPATCH_NTH_VIRTUAL_FUNCTION(14)
|
sl@0
|
254 |
}
|
sl@0
|
255 |
|
sl@0
|
256 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function015()
|
sl@0
|
257 |
{
|
sl@0
|
258 |
DISPATCH_NTH_VIRTUAL_FUNCTION(15)
|
sl@0
|
259 |
}
|
sl@0
|
260 |
|
sl@0
|
261 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function016()
|
sl@0
|
262 |
{
|
sl@0
|
263 |
DISPATCH_NTH_VIRTUAL_FUNCTION(16)
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function017()
|
sl@0
|
267 |
{
|
sl@0
|
268 |
DISPATCH_NTH_VIRTUAL_FUNCTION(17)
|
sl@0
|
269 |
}
|
sl@0
|
270 |
|
sl@0
|
271 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function018()
|
sl@0
|
272 |
{
|
sl@0
|
273 |
DISPATCH_NTH_VIRTUAL_FUNCTION(18)
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function019()
|
sl@0
|
277 |
{
|
sl@0
|
278 |
DISPATCH_NTH_VIRTUAL_FUNCTION(19)
|
sl@0
|
279 |
}
|
sl@0
|
280 |
|
sl@0
|
281 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function020()
|
sl@0
|
282 |
{
|
sl@0
|
283 |
DISPATCH_NTH_VIRTUAL_FUNCTION(20)
|
sl@0
|
284 |
}
|
sl@0
|
285 |
|
sl@0
|
286 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function021()
|
sl@0
|
287 |
{
|
sl@0
|
288 |
DISPATCH_NTH_VIRTUAL_FUNCTION(21)
|
sl@0
|
289 |
}
|
sl@0
|
290 |
|
sl@0
|
291 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function022()
|
sl@0
|
292 |
{
|
sl@0
|
293 |
DISPATCH_NTH_VIRTUAL_FUNCTION(22)
|
sl@0
|
294 |
}
|
sl@0
|
295 |
|
sl@0
|
296 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function023()
|
sl@0
|
297 |
{
|
sl@0
|
298 |
DISPATCH_NTH_VIRTUAL_FUNCTION(23)
|
sl@0
|
299 |
}
|
sl@0
|
300 |
|
sl@0
|
301 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function024()
|
sl@0
|
302 |
{
|
sl@0
|
303 |
DISPATCH_NTH_VIRTUAL_FUNCTION(24)
|
sl@0
|
304 |
}
|
sl@0
|
305 |
|
sl@0
|
306 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function025()
|
sl@0
|
307 |
{
|
sl@0
|
308 |
DISPATCH_NTH_VIRTUAL_FUNCTION(25)
|
sl@0
|
309 |
}
|
sl@0
|
310 |
|
sl@0
|
311 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function026()
|
sl@0
|
312 |
{
|
sl@0
|
313 |
DISPATCH_NTH_VIRTUAL_FUNCTION(26)
|
sl@0
|
314 |
}
|
sl@0
|
315 |
|
sl@0
|
316 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function027()
|
sl@0
|
317 |
{
|
sl@0
|
318 |
DISPATCH_NTH_VIRTUAL_FUNCTION(27)
|
sl@0
|
319 |
}
|
sl@0
|
320 |
|
sl@0
|
321 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function028()
|
sl@0
|
322 |
{
|
sl@0
|
323 |
DISPATCH_NTH_VIRTUAL_FUNCTION(28)
|
sl@0
|
324 |
}
|
sl@0
|
325 |
|
sl@0
|
326 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function029()
|
sl@0
|
327 |
{
|
sl@0
|
328 |
DISPATCH_NTH_VIRTUAL_FUNCTION(29)
|
sl@0
|
329 |
}
|
sl@0
|
330 |
|
sl@0
|
331 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function030()
|
sl@0
|
332 |
{
|
sl@0
|
333 |
DISPATCH_NTH_VIRTUAL_FUNCTION(30)
|
sl@0
|
334 |
}
|
sl@0
|
335 |
|
sl@0
|
336 |
template<class C> void __declspec(naked) XVtableInjector<C>::Function031()
|
sl@0
|
337 |
{
|
sl@0
|
338 |
DISPATCH_NTH_VIRTUAL_FUNCTION(31)
|
sl@0
|
339 |
}
|
sl@0
|
340 |
|
sl@0
|
341 |
template<class C> RPointerArray<TAny> XVtableInjector<C>::gObjects;
|
sl@0
|
342 |
template<class C> MShellcode* XVtableInjector<C>::gShellcode = NULL;
|
sl@0
|
343 |
template<class C> TAny* XVtableInjector<C>::gOriginalVtable = NULL;
|
sl@0
|
344 |
|
sl@0
|
345 |
// Explicit instantiation of the injector classes.
|
sl@0
|
346 |
template class XVtableInjector<CFont>;
|
sl@0
|
347 |
template class XVtableInjector<COpenFont>;
|
sl@0
|
348 |
|
sl@0
|
349 |
#endif // __WINS__
|