VOID XmlMenuParseChild(CDUIMenuBuilder* pThis, CDUIXml& xml, CRefPtr<IDUIControl> pParentControl) { IDUIApp* pDUIApp = DUIGetAppInstance(); if(pDUIApp == NULL) return; IDUIControlFactory* pControlFactory = pDUIApp->GetControlFactory(); if(pControlFactory == NULL) return; CDUIString strControlName, strAttriName, strAttriValue; CRefPtr<IDUIControl> pControl; INT nIndex(0); while(xml.FindChildElem()) { xml.IntoElem(); strControlName = xml.GetTagName(); pControl = pControlFactory->NewControl(strControlName); if(pControl.IsNull() && pThis->GetCallBack() != NULL) { pControl = pThis->GetCallBack()->OnBuilderNewControl(strControlName); } DUI_ASSERT(!pControl.IsNull()); if(!pControl.IsNull()) { DUI_ASSERT(pControl->GetInterface(IMenu) != NULL || pControl->GetInterface(IMenuItem) != NULL); nIndex = 0; do { strAttriName = xml.GetAttribName(nIndex++); if(strAttriName.size() <= 0) break; strAttriValue = xml.GetAttrib(strAttriName); pControl->SetAttribute(strAttriName, strAttriValue); } while(TRUE); if(pThis->GetCallBack() != NULL) { pThis->GetCallBack()->OnAddChildControl(pParentControl, pControl); } else { DefAddChildControl(pParentControl, pControl); } XmlMenuParseChild(pThis, xml, pControl); } xml.OutOfElem(); } }
//++ // Details: Get escaped string from *this string. // Type: Method. // Args: None. // Return: CMIUtilString - The escaped version of the initial string. // Throws: None. //-- CMIUtilString CMIUtilString::Escape(bool vbEscapeQuotes /* = false */) const { const size_t nLen(length()); CMIUtilString strNew; strNew.reserve(nLen); for (size_t nIndex(0); nIndex < nLen; ++nIndex) { const char cUnescapedChar((*this)[nIndex]); if (cUnescapedChar == '"' && vbEscapeQuotes) strNew.append("\\\""); else strNew.append(ConvertToPrintableASCII((char)cUnescapedChar)); } return strNew; }
void FetchProcessHandle::OnQuerySucess( const int Pid, ULONG NumberOfHandle, SYSTEM_HANDLE_INFORMATION* pResult, std::function<bool(FetchProcessHandleResult&)> cbFetchResult ) { bool bLoop = true; for(std::size_t nIndex(0); nIndex<NumberOfHandle&&bLoop; nIndex++) { if ( pResult[nIndex].ProcessId!=Pid ) continue; char szName[MAX_PATH] = {0}; char szType[128] = {0}; DWORD dwFlags = 0; // 把远端句柄拷贝到本地进程 HANDLE hObject = NULL; HANDLE hRemoteProcess = OpenProcess( PROCESS_DUP_HANDLE, FALSE, Pid ); FetchProcessHandleResult FetchResult; NTSTATUS NtStatus = m_pZwDuplicateObject( hRemoteProcess, (HANDLE)(pResult[nIndex].Handle), GetCurrentProcess(), &hObject, 0, 0, 0 ); NtStatus = m_pZWQueryObject( hObject, ObjectNameInformation, (POBJECT_NAME_INFORMATION)szName, MAX_PATH, &dwFlags ); NtStatus = m_pZWQueryObject( hObject, ObjectTypeInformation, (POBJECT_NAME_INFORMATION)szType, 128, &dwFlags ); POBJECT_NAME_INFORMATION pObjName = ((POBJECT_NAME_INFORMATION)szName); POBJECT_NAME_INFORMATION pObjType = ((POBJECT_NAME_INFORMATION)szType); FetchResult.ProcessId = pResult[nIndex].ProcessId; FetchResult.GrantedAccess = pResult[nIndex].GrantedAccess; FetchResult.Handle = (HANDLE)pResult[nIndex].Handle; FetchResult.Object = pResult[nIndex].Object; assert( sizeof(FetchResult.ObjectName)>pObjName->Name.Length ); assert( sizeof(FetchResult.ObjType)>pObjType->Name.Length ); int i(0); for( ; i<pObjName->Name.Length; ++i ) { FetchResult.ObjectName[i] = (UCHAR)pObjName->Name.Buffer[i]; } for( i=0;i<pObjType->Name.Length; ++i ) { FetchResult.ObjType[i] = (UCHAR)pObjType->Name.Buffer[i]; } if( !cbFetchResult( FetchResult ) ) { bLoop = false; } CloseHandle( hRemoteProcess ); } }
CRefPtr<IDUIMenu> XmlControlParse(CDUIMenuBuilder* pThis, CDUIXml& xml) { IDUIApp* pDUIApp = DUIGetAppInstance(); if(pDUIApp == NULL) return NULL; IDUIControlFactory* pControlFactory = pDUIApp->GetControlFactory(); if(pControlFactory == NULL) return NULL; if(!xml.FindElem(_T("menu"))) { DUI_ASSERT(FALSE); return NULL; } CRefPtr<IDUIControl> pRootControl = pControlFactory->NewControl(_T("menu")); DUI_ASSERT(!pRootControl.IsNull()); if(pRootControl.IsNull()) return NULL; //parse menu attribute CDUIString strAttriName, strAttriValue; INT nIndex(0); do { strAttriName = xml.GetAttribName(nIndex++); if(strAttriName.size() <= 0) break; strAttriValue = xml.GetAttrib(strAttriName); pRootControl->SetAttribute(strAttriName, strAttriValue); } while(TRUE); XmlMenuParseChild(pThis, xml, pRootControl); if(pThis->GetCallBack() != NULL) { pThis->GetCallBack()->OnBuilderControlCreated(pRootControl); } IDUIMenu* pMenuRet = (IDUIMenu*)pRootControl->GetInterface(IMenu); DUI_ASSERT(pMenuRet != NULL); return pMenuRet; }
CRefPtr<IDUIControl> XmlControlParse(CDUIControlBuilder* pThis, CDUIXml& xml) { IDUIApp* pDUIApp = DUIGetAppInstance(); if(pDUIApp == NULL) return NULL; IDUIControlFactory* pControlFactory = pDUIApp->GetControlFactory(); if(pControlFactory == NULL) return NULL; if(!xml.FindElem(_T("window"))) { DUI_ASSERT(FALSE); return NULL; } //parse window attribute CDUIString strAttriName, strAttriValue; INT nIndex(0); do { strAttriName = xml.GetAttribName(nIndex++); if(strAttriName.size() <= 0) break; strAttriValue = xml.GetAttrib(strAttriName); if(pThis->GetCallBack() != NULL) { pThis->GetCallBack()->OnBuilderWindowAttribute(strAttriName, strAttriValue); } } while(TRUE); //parse child control CDUIString strControlName; CRefPtr<IDUIControl> pRootControl; if(xml.FindChildElem(NULL)) { xml.IntoElem(); strControlName = xml.GetTagName(); pRootControl = pControlFactory->NewControl(strControlName); if(pRootControl.IsNull() && pThis->GetCallBack() != NULL) { pRootControl = pThis->GetCallBack()->OnBuilderNewControl(strControlName); } DUI_ASSERT(!pRootControl.IsNull()); if(!pRootControl.IsNull()) { nIndex = 0; do { strAttriName = xml.GetAttribName(nIndex++); if(strAttriName.size() <= 0) break; strAttriValue = xml.GetAttrib(strAttriName); pRootControl->SetAttribute(strAttriName, strAttriValue); } while(TRUE); XmlControlParseChild(pThis, xml, pRootControl); if(pThis->GetCallBack() != NULL) { pThis->GetCallBack()->OnBuilderControlCreated(pRootControl); } } xml.OutOfElem(); } return pRootControl; }