|
1 // w32crack.cpp |
|
2 // |
|
3 // Copyright (c) 2008 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include <fshell/common.mmh> |
|
14 #include <fshell/ltkutils.h> |
|
15 #include <e32base.h> |
|
16 #include <fshell/iocli.h> |
|
17 #include <w32std.h> |
|
18 #include <fshell/ioutils.h> |
|
19 #include <fshell/memoryaccess.h> |
|
20 |
|
21 // |
|
22 // LtkUtils::W32CrackL |
|
23 // loads the autometric logging engine, dlogev.dll, into wserv |
|
24 // enabling Autometric to monitor events from within wserv - key/pointer events, text drawn to screen etc |
|
25 // |
|
26 EXPORT_C void LtkUtils::W32CrackL() |
|
27 { |
|
28 #ifndef FSHELL_WSERV_SUPPORT |
|
29 User::Leave(KErrNotSupported); |
|
30 #else |
|
31 |
|
32 // Check if P&S says it's already enabled, if so no need to do anything |
|
33 if (W32CrackIsEnabled()) return; |
|
34 |
|
35 _LIT(KWsIniFile, "z:\\system\\data\\wsini.ini"); |
|
36 _LIT(KCWsIniFile,"c:\\system\\data\\wsini.ini"); |
|
37 _LIT(KLogEv, "LOG EV\r\n"); |
|
38 |
|
39 // Open z file |
|
40 RFs fs; |
|
41 User::LeaveIfError(fs.Connect()); |
|
42 CleanupClosePushL(fs); |
|
43 |
|
44 RFile file; |
|
45 User::LeaveIfError(file.Open(fs, KWsIniFile, EFileRead)); |
|
46 CleanupClosePushL(file); |
|
47 |
|
48 TInt size; |
|
49 User::LeaveIfError(file.Size(size)); |
|
50 |
|
51 RBuf8 buf; |
|
52 buf.CreateL(size + KLogEv().Size()); |
|
53 CleanupClosePushL(buf); |
|
54 User::LeaveIfError(file.Read(buf)); |
|
55 TPtrC16 wptr((TUint16*)buf.Ptr(), buf.Size()/2); |
|
56 buf.Insert(2, TPtrC8((TUint8*)KLogEv().Ptr(), KLogEv().Size())); // +2 to get past the BOM |
|
57 TInt err = KErrNone; |
|
58 err = fs.MkDirAll(KCWsIniFile); // mkdir c:\system\data\ in case it is not exist |
|
59 if((err != KErrNone) && (err != KErrAlreadyExists)) |
|
60 { |
|
61 User::Leave(err); |
|
62 } |
|
63 User::LeaveIfError(file.Replace(fs, KCWsIniFile, EFileWrite)); |
|
64 User::LeaveIfError(file.Write(buf)); |
|
65 CleanupStack::PopAndDestroy(2, &file); // file, buf |
|
66 |
|
67 err = RMemoryAccess::LoadDriver(); |
|
68 if ((err != KErrNone) && (err != KErrAlreadyExists)) |
|
69 { |
|
70 User::Leave(err); |
|
71 } |
|
72 |
|
73 RMemoryAccess memAccess; |
|
74 User::LeaveIfError(memAccess.Open()); |
|
75 CleanupClosePushL(memAccess); |
|
76 |
|
77 RWsSession ws; |
|
78 User::LeaveIfError(ws.Connect(fs)); |
|
79 CleanupClosePushL(ws); |
|
80 |
|
81 #ifdef __WINS__ |
|
82 // On wins the binary isn't renamed |
|
83 _LIT(KWservMatch, "wserv*.exe*"); |
|
84 #else |
|
85 _LIT(KWservMatch, "EwSrv.exe*"); |
|
86 #endif |
|
87 TFindProcess find(KWservMatch); |
|
88 TFullName name; |
|
89 User::LeaveIfError(find.Next(name)); |
|
90 |
|
91 RProcess wservProc; |
|
92 User::LeaveIfError(wservProc.Open(find)); |
|
93 if (wservProc.ExitType() != EExitPending) |
|
94 { |
|
95 // in case wserv kicks off the preferred implementation in a new process then kills itself |
|
96 // (is one retry enough or should we be looping here?) |
|
97 wservProc.Close(); |
|
98 User::LeaveIfError(find.Next(name)); |
|
99 User::LeaveIfError(wservProc.Open(find)); |
|
100 } |
|
101 CleanupClosePushL(wservProc); |
|
102 name = wservProc.FileName(); |
|
103 name[0] = 'c'; |
|
104 TPtrC8 narrowName = name.Collapse(); |
|
105 User::LeaveIfError(memAccess.InPlaceSetProcessFileName(wservProc, narrowName)); |
|
106 |
|
107 // Now tell wserv to reload its wsini.ini and enable logging |
|
108 ws.LogCommand(RWsSession::ELoggingEnable); |
|
109 ws.Flush(); |
|
110 |
|
111 // cleanup |
|
112 CleanupStack::PopAndDestroy(4, &fs); |
|
113 |
|
114 #endif // FSHELL_WSERV_SUPPORT |
|
115 } |
|
116 |
|
117 EXPORT_C TBool LtkUtils::W32CrackIsEnabled() |
|
118 { |
|
119 TInt enabled = EFalse; |
|
120 TInt err = RProperty::Get(KW32CrackCategory, KW32CrackKey, enabled); |
|
121 return (err == KErrNone && enabled); |
|
122 } |