Update contrib.
1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Implementation of the FontInjector DLL, only for the emulator. This DLL has
15 // writeable static data and should use the EPOCALLOWDLLDATA keyword in the MMP
16 // file, but it does not because by default the EKA2 emulator allows global data
17 // as long as the constructors do not make executive calls and, in some test
18 // cases, there is more than one instance of the test server with this DLL loaded,
19 // although it should be in active use by only one process at a time. For more
20 // information see the Symbian Developer Library > Symbian OS Guide > Essential
21 // idioms > Static data.
24 #include "fontinjector.h"
28 template<class C> EXPORT_C XVtableInjector<C>::XVtableInjector()
30 ASSERT(gObjects.Count() == 0);
32 ASSERT(!gOriginalVtable);
35 template<class C> EXPORT_C XVtableInjector<C>::~XVtableInjector()
37 for (TInt i = 0; i < gObjects.Count(); ++i)
39 *reinterpret_cast<TAny**>(gObjects[i]) = gOriginalVtable;
43 gOriginalVtable = NULL;
46 template<class C> EXPORT_C TInt XVtableInjector<C>::InjectShellcode(C* aObject, MShellcode* aShellcode)
48 if (gShellcode && gShellcode != aShellcode)
53 if (gObjects.FindInAddressOrder(aObject) == KErrNotFound)
55 if (gOriginalVtable && gOriginalVtable != *reinterpret_cast<TAny**>(aObject))
59 err = gObjects.InsertInAddressOrder(aObject);
62 gShellcode = aShellcode;
63 gOriginalVtable = *reinterpret_cast<TAny**>(aObject);
64 *reinterpret_cast<TAny**>(aObject) = *reinterpret_cast<TAny**>(this);
70 template<> EXPORT_C void XVtableInjector<CFont>::GetVirtualFunctionName(TInt aIndex, TDes& aName)
75 aName.Copy(_S("CFont::~CFont()"));
78 aName.Copy(_S("CFont::Extension_(TUint, TAny*&, TAny*)"));
81 aName.Copy(_S("CFont::DoTypeUid()"));
84 aName.Copy(_S("CFont::DoHeightInPixels()"));
87 aName.Copy(_S("CFont::DoAscentInPixels()"));
90 aName.Copy(_S("CFont::DoDescentInPixels()"));
93 aName.Copy(_S("CFont::DoCharWidthInPixels(TChar)"));
96 aName.Copy(_S("CFont::DoTextWidthInPixels(const TDesC&)"));
99 aName.Copy(_S("CFont::DoBaselineOffsetInPixels()"));
102 aName.Copy(_S("CFont::DoTextCount(const TDesC&, TInt)"));
105 aName.Copy(_S("CFont::DoTextCount(const TDesC&, TInt, TInt&)"));
108 aName.Copy(_S("CFont::DoMaxCharWidthInPixels()"));
111 aName.Copy(_S("CFont::DoMaxNormalCharWidthInPixels()"));
114 aName.Copy(_S("CFont::DoFontSpecInTwips()"));
117 aName.Copy(_S("CFont::DoGetCharacterData(TUint, TOpenFontCharMetrics&, const TUint8*&, TSize&)"));
120 aName.Copy(_S("CFont::DoGetCharacterPosition(CFont::TPositionParam&)"));
123 aName.Copy(_S("CFont::DoExtendedFunction(TUid, TAny*)"));
126 aName.Copy(_S("CFont::<Unknown Virtual Function>"));
130 template<> EXPORT_C void XVtableInjector<COpenFont>::GetVirtualFunctionName(TInt aIndex, TDes& aName)
135 aName.Copy(_S("COpenFont::~COpenFont()"));
138 aName.Copy(_S("COpenFont::Extension_(TUint, TAny*&, TAny*)"));
141 aName.Copy(_S("COpenFont::RasterizeL(TInt, TOpenFontGlyphData*)"));
144 aName.Copy(_S("COpenFont::ExtendedInterface(TUid, TAny*&)"));
147 aName.Format(_L("COpenFont::<Extended Virtual Function %03d>"), aIndex - 3);
151 template<class C> void XVtableInjector<C>::ObjectDestroyed(TAny* aObject)
153 gObjects.Remove(gObjects.FindInAddressOrder(aObject));
156 template<class C> void __declspec(naked) XVtableInjector<C>::Function000()
159 /* cdecl calling convention */
161 asm { call ObjectDestroyed }
163 /* thiscall calling convention */
164 asm { mov ecx, gShellcode }
166 asm { mov eax, [ecx] }
168 /* continue to original function */
170 asm { mov eax, gOriginalVtable }
174 #define DISPATCH_NTH_VIRTUAL_FUNCTION(n) \
176 /* thiscall calling convention */ \
177 asm { mov ecx, gShellcode } \
179 asm { mov eax, [ecx] } \
181 /* continue to original function */ \
183 asm { mov eax, gOriginalVtable } \
184 asm { jmp [eax + (n * 4)] }
186 template<class C> void __declspec(naked) XVtableInjector<C>::Function001()
188 DISPATCH_NTH_VIRTUAL_FUNCTION(1)
191 template<class C> void __declspec(naked) XVtableInjector<C>::Function002()
193 DISPATCH_NTH_VIRTUAL_FUNCTION(2)
196 template<class C> void __declspec(naked) XVtableInjector<C>::Function003()
198 DISPATCH_NTH_VIRTUAL_FUNCTION(3)
201 template<class C> void __declspec(naked) XVtableInjector<C>::Function004()
203 DISPATCH_NTH_VIRTUAL_FUNCTION(4)
206 template<class C> void __declspec(naked) XVtableInjector<C>::Function005()
208 DISPATCH_NTH_VIRTUAL_FUNCTION(5)
211 template<class C> void __declspec(naked) XVtableInjector<C>::Function006()
213 DISPATCH_NTH_VIRTUAL_FUNCTION(6)
216 template<class C> void __declspec(naked) XVtableInjector<C>::Function007()
218 DISPATCH_NTH_VIRTUAL_FUNCTION(7)
221 template<class C> void __declspec(naked) XVtableInjector<C>::Function008()
223 DISPATCH_NTH_VIRTUAL_FUNCTION(8)
226 template<class C> void __declspec(naked) XVtableInjector<C>::Function009()
228 DISPATCH_NTH_VIRTUAL_FUNCTION(9)
231 template<class C> void __declspec(naked) XVtableInjector<C>::Function010()
233 DISPATCH_NTH_VIRTUAL_FUNCTION(10)
236 template<class C> void __declspec(naked) XVtableInjector<C>::Function011()
238 DISPATCH_NTH_VIRTUAL_FUNCTION(11)
241 template<class C> void __declspec(naked) XVtableInjector<C>::Function012()
243 DISPATCH_NTH_VIRTUAL_FUNCTION(12)
246 template<class C> void __declspec(naked) XVtableInjector<C>::Function013()
248 DISPATCH_NTH_VIRTUAL_FUNCTION(13)
251 template<class C> void __declspec(naked) XVtableInjector<C>::Function014()
253 DISPATCH_NTH_VIRTUAL_FUNCTION(14)
256 template<class C> void __declspec(naked) XVtableInjector<C>::Function015()
258 DISPATCH_NTH_VIRTUAL_FUNCTION(15)
261 template<class C> void __declspec(naked) XVtableInjector<C>::Function016()
263 DISPATCH_NTH_VIRTUAL_FUNCTION(16)
266 template<class C> void __declspec(naked) XVtableInjector<C>::Function017()
268 DISPATCH_NTH_VIRTUAL_FUNCTION(17)
271 template<class C> void __declspec(naked) XVtableInjector<C>::Function018()
273 DISPATCH_NTH_VIRTUAL_FUNCTION(18)
276 template<class C> void __declspec(naked) XVtableInjector<C>::Function019()
278 DISPATCH_NTH_VIRTUAL_FUNCTION(19)
281 template<class C> void __declspec(naked) XVtableInjector<C>::Function020()
283 DISPATCH_NTH_VIRTUAL_FUNCTION(20)
286 template<class C> void __declspec(naked) XVtableInjector<C>::Function021()
288 DISPATCH_NTH_VIRTUAL_FUNCTION(21)
291 template<class C> void __declspec(naked) XVtableInjector<C>::Function022()
293 DISPATCH_NTH_VIRTUAL_FUNCTION(22)
296 template<class C> void __declspec(naked) XVtableInjector<C>::Function023()
298 DISPATCH_NTH_VIRTUAL_FUNCTION(23)
301 template<class C> void __declspec(naked) XVtableInjector<C>::Function024()
303 DISPATCH_NTH_VIRTUAL_FUNCTION(24)
306 template<class C> void __declspec(naked) XVtableInjector<C>::Function025()
308 DISPATCH_NTH_VIRTUAL_FUNCTION(25)
311 template<class C> void __declspec(naked) XVtableInjector<C>::Function026()
313 DISPATCH_NTH_VIRTUAL_FUNCTION(26)
316 template<class C> void __declspec(naked) XVtableInjector<C>::Function027()
318 DISPATCH_NTH_VIRTUAL_FUNCTION(27)
321 template<class C> void __declspec(naked) XVtableInjector<C>::Function028()
323 DISPATCH_NTH_VIRTUAL_FUNCTION(28)
326 template<class C> void __declspec(naked) XVtableInjector<C>::Function029()
328 DISPATCH_NTH_VIRTUAL_FUNCTION(29)
331 template<class C> void __declspec(naked) XVtableInjector<C>::Function030()
333 DISPATCH_NTH_VIRTUAL_FUNCTION(30)
336 template<class C> void __declspec(naked) XVtableInjector<C>::Function031()
338 DISPATCH_NTH_VIRTUAL_FUNCTION(31)
341 template<class C> RPointerArray<TAny> XVtableInjector<C>::gObjects;
342 template<class C> MShellcode* XVtableInjector<C>::gShellcode = NULL;
343 template<class C> TAny* XVtableInjector<C>::gOriginalVtable = NULL;
345 // Explicit instantiation of the injector classes.
346 template class XVtableInjector<CFont>;
347 template class XVtableInjector<COpenFont>;