Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

363 lines
7.7 KiB

  1. //
  2. // Application Verifier UI
  3. // Copyright (c) Microsoft Corporation, 2001
  4. //
  5. //
  6. //
  7. // module: ChooseExe.cpp
  8. // author: CLupu
  9. // created: 04/13/2001
  10. //
  11. // Description:
  12. //
  13. // "Launch the application to be verified" wizard page class.
  14. //
  15. #include "stdafx.h"
  16. #include "appverif.h"
  17. #include "StartApp.h"
  18. #include "AVUtil.h"
  19. #include "AVGlobal.h"
  20. #include "Log.h"
  21. #include "Debugger.h"
  22. #include "ChooseExe.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. HWND g_hWndOutput;
  29. BOOL g_bDebuggeeExited = TRUE;
  30. //
  31. // Help IDs
  32. //
  33. static DWORD MyHelpIds[] =
  34. {
  35. 0, 0
  36. };
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CStartAppPage property page
  39. IMPLEMENT_DYNCREATE(CStartAppPage, CAppverifPage)
  40. CStartAppPage::CStartAppPage() : CAppverifPage(CStartAppPage::IDD)
  41. {
  42. //{{AFX_DATA_INIT(CStartAppPage)
  43. // NOTE: the ClassWizard will add member initialization here
  44. //}}AFX_DATA_INIT
  45. m_nIssues = 0;
  46. m_bAppRun = FALSE;
  47. }
  48. CStartAppPage::~CStartAppPage()
  49. {
  50. }
  51. void CStartAppPage::DoDataExchange(CDataExchange* pDX)
  52. {
  53. CAppverifPage::DoDataExchange(pDX);
  54. //{{AFX_DATA_MAP(CStartAppPage)
  55. DDX_Control(pDX, IDC_EXE_NAME, m_ExeName);
  56. DDX_Control(pDX, IDC_RUNAPP_NEXTDESCR_STATIC, m_NextDescription);
  57. //}}AFX_DATA_MAP
  58. }
  59. BEGIN_MESSAGE_MAP(CStartAppPage, CAppverifPage)
  60. //{{AFX_MSG_MAP(CStartAppPage)
  61. ON_MESSAGE( WM_HELP, OnHelp )
  62. ON_WM_CONTEXTMENU()
  63. ON_BN_CLICKED(IDC_RUNAPP, OnRunApp)
  64. //}}AFX_MSG_MAP
  65. END_MESSAGE_MAP()
  66. /////////////////////////////////////////////////////////////////////////////
  67. ULONG CStartAppPage::GetDialogId() const
  68. {
  69. return IDD_STARTAPP_PAGE;
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. int g_nMessages = 0;
  73. TCHAR g_szMsg[1024];
  74. void _cdecl LogMessage( MSGLEVEL mlevel, LPTSTR pszFmt, ... )
  75. {
  76. va_list arglist;
  77. int off = 0;
  78. switch ( mlevel )
  79. {
  80. case LOG_ERROR:
  81. lstrcpy( g_szMsg, _T("ERR: ") );
  82. off = sizeof( _T("ERR: ") ) / sizeof( TCHAR ) - 1;
  83. break;
  84. case LOG_WARNING:
  85. lstrcpy( g_szMsg, _T("WRN: ") );
  86. off = sizeof( _T("ERR: ") ) / sizeof( TCHAR ) - 1;
  87. break;
  88. case LOG_INFO:
  89. break;
  90. }
  91. va_start( arglist, pszFmt );
  92. _vsntprintf( g_szMsg + off, 1023 - off, pszFmt, arglist );
  93. g_szMsg[1023] = 0; // ensure null termination
  94. va_end( arglist );
  95. TCHAR* psz = g_szMsg + lstrlen(g_szMsg) - 1;
  96. while ( *psz == _T('\n') || *psz == _T('\r') )
  97. {
  98. *psz = 0;
  99. psz--;
  100. }
  101. if ( g_hWndOutput != NULL )
  102. {
  103. SendMessage(g_hWndOutput, LB_ADDSTRING, 0, (LPARAM)g_szMsg);
  104. SendMessage(g_hWndOutput, LB_SETCURSEL, g_nMessages, 0);
  105. SendMessage(g_hWndOutput, LB_SETTOPINDEX, g_nMessages++, 0);
  106. }
  107. lstrcat( g_szMsg, _T("\r\n") );
  108. OutputDebugString( g_szMsg );
  109. }
  110. BOOL GetShortName( LPCTSTR lpszCmd, LPTSTR lpszShortName )
  111. {
  112. LPCTSTR psz = lpszCmd;
  113. LPCTSTR pszStart = lpszCmd;
  114. LPCTSTR pszEnd;
  115. BOOL bBraket = FALSE;
  116. //
  117. // Skip over spaces...
  118. //
  119. while ( *psz == _T(' ') || *psz == _T('\t') )
  120. {
  121. psz++;
  122. }
  123. if ( *psz == _T('\"') )
  124. {
  125. bBraket = TRUE;
  126. psz++;
  127. pszStart = psz;
  128. }
  129. while ( *psz != 0 )
  130. {
  131. if ( *psz == _T('\"') )
  132. {
  133. pszEnd = psz;
  134. break;
  135. }
  136. else if ( *psz == _T('\\') )
  137. {
  138. pszStart = psz + 1;
  139. }
  140. else if ( *psz == _T(' ') && !bBraket )
  141. {
  142. pszEnd = psz;
  143. break;
  144. }
  145. psz++;
  146. }
  147. if ( *psz == 0 )
  148. {
  149. pszEnd = psz;
  150. }
  151. RtlCopyMemory( lpszShortName, pszStart, (pszEnd - pszStart) * sizeof(TCHAR) );
  152. lpszShortName[pszEnd - pszStart] = 0;
  153. return TRUE;
  154. }
  155. BOOL CStartAppPage::RunProgram()
  156. {
  157. HANDLE hThread;
  158. DWORD dwThreadId;
  159. LPARAM lParam;
  160. SetEnvironmentVariable( _T("VERIFIER_FILE_LOG"), VERIFIER_FILE_LOG_NAME );
  161. if ( g_dwRegFlags & RTL_VRF_FLG_APPCOMPAT_CHECKS )
  162. {
  163. SetEnvironmentVariable( _T("__COMPAT_LAYER"), APPVERIFIER_LAYER_NAME );
  164. #if DBG
  165. SetEnvironmentVariable( _T("SHIM_FILE_LOG"), _T("dbg_av.txt") );
  166. SetEnvironmentVariable( _T("SHIM_DEBUG_LEVEL"), _T("2") );
  167. #endif // DBG
  168. }
  169. //
  170. // Get the short name.
  171. //
  172. GetShortName( g_szAppFullPath, g_szAppShortName );
  173. if ( g_szAppShortName[0] == 0 )
  174. {
  175. LogMessage( LOG_ERROR, _T("[RunProgram] No app is selected to run.") );
  176. return FALSE;
  177. }
  178. InitFileLogSupport( VERIFIER_FILE_LOG_NAME );
  179. //
  180. // Create the debugger thread.
  181. //
  182. lParam = (LPARAM)g_dwRegFlags;
  183. hThread = CreateThread( NULL, 0, ExecuteAppThread, (LPVOID)lParam, 0, &dwThreadId );
  184. if ( hThread == NULL )
  185. {
  186. LogMessage( LOG_ERROR, _T("[RunProgram] Failed to create the debugger thread.") );
  187. return FALSE;
  188. }
  189. while ( 1 )
  190. {
  191. MSG msg;
  192. DWORD dwRes;
  193. dwRes = MsgWaitForMultipleObjects( 1, &hThread, FALSE, INFINITE, QS_ALLINPUT );
  194. if ( dwRes == WAIT_OBJECT_0 )
  195. {
  196. break;
  197. }
  198. else if ( dwRes == WAIT_OBJECT_0 + 1 )
  199. {
  200. //
  201. // There are some messages in message queue.
  202. //
  203. while ( PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE) )
  204. {
  205. DispatchMessageA(&msg);
  206. }
  207. }
  208. else
  209. {
  210. break;
  211. }
  212. }
  213. CloseHandle( hThread );
  214. m_bAppRun = TRUE;
  215. SetEnvironmentVariable( _T("__COMPAT_LAYER"), NULL );
  216. return TRUE;
  217. }
  218. /////////////////////////////////////////////////////////////////////////////
  219. // CStartAppPage message handlers
  220. /////////////////////////////////////////////////////////////
  221. LONG CStartAppPage::OnHelp( WPARAM wParam, LPARAM lParam )
  222. {
  223. LONG lResult = 0;
  224. LPHELPINFO lpHelpInfo = (LPHELPINFO)lParam;
  225. ::WinHelp(
  226. (HWND) lpHelpInfo->hItemHandle,
  227. g_szAVHelpFile,
  228. HELP_WM_HELP,
  229. (DWORD_PTR) MyHelpIds );
  230. return lResult;
  231. }
  232. /////////////////////////////////////////////////////////////////////////////
  233. void CStartAppPage::OnContextMenu(CWnd* pWnd, CPoint point)
  234. {
  235. ::WinHelp(
  236. pWnd->m_hWnd,
  237. g_szAVHelpFile,
  238. HELP_CONTEXTMENU,
  239. (DWORD_PTR) MyHelpIds );
  240. }
  241. void CStartAppPage::OnRunApp()
  242. {
  243. m_pParentSheet->EnableWindow(FALSE);
  244. RunProgram();
  245. m_pParentSheet->EnableWindow(TRUE);
  246. m_pParentSheet->SetWizardButtons( PSWIZB_BACK | PSWIZB_NEXT );
  247. }
  248. /////////////////////////////////////////////////////////////////////////////
  249. LRESULT CStartAppPage::OnWizardNext()
  250. {
  251. GoingToNextPageNotify( IDD_VIEWLOG_PAGE );
  252. return IDD_VIEWLOG_PAGE;
  253. }
  254. /////////////////////////////////////////////////////////////////////////////
  255. BOOL CStartAppPage::OnSetActive()
  256. {
  257. ASSERT_VALID( m_pParentSheet );
  258. if ( m_bAppRun )
  259. {
  260. m_pParentSheet->SetWizardButtons( PSWIZB_BACK | PSWIZB_NEXT );
  261. }
  262. else
  263. {
  264. m_pParentSheet->SetWizardButtons( PSWIZB_BACK );
  265. }
  266. m_ExeName.SetWindowText(g_szAppFullPath);
  267. return CAppverifPage::OnSetActive();
  268. }
  269. /////////////////////////////////////////////////////////////////////////////
  270. BOOL CStartAppPage::OnInitDialog()
  271. {
  272. CAppverifPage::OnInitDialog();
  273. g_hWndOutput = GetDlgItem(IDC_OUTPUT)->m_hWnd;
  274. AVSetWindowText( m_NextDescription, IDS_RUNAPP_NEXTDESCR_STATIC );
  275. return TRUE; // return TRUE unless you set the focus to a control
  276. // EXCEPTION: OCX Property Pages should return FALSE
  277. }
  278. /////////////////////////////////////////////////////////////////////////////
  279. // CStartAppPage message handlers