//========================================================================= // Internal function: // // Will try to allocate the trampoline structure within 2 gigabytes of // the target function. //========================================================================= static MHOOKS_TRAMPOLINE* TrampolineAlloc(PBYTE pSystemFunction, S64 nLimitUp, S64 nLimitDown) { MHOOKS_TRAMPOLINE* pTrampoline = NULL; // do we have room to store this guy? if (g_nHooksInUse < MHOOKS_MAX_SUPPORTED_HOOKS) { // determine lower and upper bounds for the allocation locations. // in the basic scenario this is +/- 2GB but IP-relative instructions // found in the original code may require a smaller window. PBYTE pLower = pSystemFunction + nLimitUp; pLower = pLower < (PBYTE)(DWORD_PTR)0x0000000080000000 ? (PBYTE)(0x1) : (PBYTE)(pLower - (PBYTE)0x7fff0000); PBYTE pUpper = pSystemFunction + nLimitDown; pUpper = pUpper < (PBYTE)(DWORD_PTR)0xffffffff80000000 ? (PBYTE)(pUpper + (DWORD_PTR)0x7ff80000) : (PBYTE)(DWORD_PTR)0xfffffffffff80000; ODPRINTF((L"mhooks: TrampolineAlloc: Allocating for %p between %p and %p", pSystemFunction, pLower, pUpper)); SYSTEM_INFO sSysInfo = {0}; ::GetSystemInfo(&sSysInfo); // go through the available memory blocks and try to allocate a chunk for us for (PBYTE pbAlloc = pLower; pbAlloc < pUpper;) { // determine current state MEMORY_BASIC_INFORMATION mbi; ODPRINTF((L"mhooks: TrampolineAlloc: Looking at address %p", pbAlloc)); if (!VirtualQuery(pbAlloc, &mbi, sizeof(mbi))) break; // free & large enough? if (mbi.State == MEM_FREE && mbi.RegionSize >= sizeof(MHOOKS_TRAMPOLINE) && mbi.RegionSize >= sSysInfo.dwAllocationGranularity) { // yes, align the pointer to the 64K boundary first pbAlloc = (PBYTE)(ULONG_PTR((ULONG_PTR(pbAlloc) + (sSysInfo.dwAllocationGranularity-1)) / sSysInfo.dwAllocationGranularity) * sSysInfo.dwAllocationGranularity); // and then try to allocate it pTrampoline = (MHOOKS_TRAMPOLINE*)VirtualAlloc(pbAlloc, sizeof(MHOOKS_TRAMPOLINE), MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READ); if (pTrampoline) { ODPRINTF((L"mhooks: TrampolineAlloc: Allocated block at %p as the trampoline", pTrampoline)); break; } } // continue the search pbAlloc = (PBYTE)mbi.BaseAddress + mbi.RegionSize; } // found and allocated a trampoline? if (pTrampoline) { // put it into our list so we know we'll have to free it for (DWORD i=0; i<MHOOKS_MAX_SUPPORTED_HOOKS; i++) { if (g_pHooks[i] == NULL) { g_pHooks[i] = pTrampoline; g_nHooksInUse++; break; } } } } return pTrampoline; }
bool WMFVideoMFTManager::InitInternal(bool aForceD3D9) { mUseHwAccel = false; // default value; changed if D3D setup succeeds. bool useDxva = InitializeDXVA(aForceD3D9); RefPtr<MFTDecoder> decoder(new MFTDecoder()); HRESULT hr = decoder->Create(GetMFTGUID()); NS_ENSURE_TRUE(SUCCEEDED(hr), false); RefPtr<IMFAttributes> attr(decoder->GetAttributes()); UINT32 aware = 0; if (attr) { attr->GetUINT32(MF_SA_D3D_AWARE, &aware); attr->SetUINT32(CODECAPI_AVDecNumWorkerThreads, WMFDecoderModule::GetNumDecoderThreads()); if (WMFDecoderModule::LowLatencyMFTEnabled()) { hr = attr->SetUINT32(CODECAPI_AVLowLatencyMode, TRUE); if (SUCCEEDED(hr)) { LOG("Enabling Low Latency Mode"); } else { LOG("Couldn't enable Low Latency Mode"); } } } if (useDxva) { if (aware) { // TODO: Test if I need this anywhere... Maybe on Vista? //hr = attr->SetUINT32(CODECAPI_AVDecVideoAcceleration_H264, TRUE); //NS_ENSURE_TRUE(SUCCEEDED(hr), hr); MOZ_ASSERT(mDXVA2Manager); ULONG_PTR manager = ULONG_PTR(mDXVA2Manager->GetDXVADeviceManager()); hr = decoder->SendMFTMessage(MFT_MESSAGE_SET_D3D_MANAGER, manager); if (SUCCEEDED(hr)) { mUseHwAccel = true; } else { mDXVA2Manager = nullptr; mDXVAFailureReason = nsPrintfCString("MFT_MESSAGE_SET_D3D_MANAGER failed with code %X", hr); } } else { mDXVAFailureReason.AssignLiteral("Decoder returned false for MF_SA_D3D_AWARE"); } } if (!mUseHwAccel) { Telemetry::Accumulate(Telemetry::MEDIA_DECODER_BACKEND_USED, uint32_t(media::MediaDecoderBackend::WMFSoftware)); } mDecoder = decoder; hr = SetDecoderMediaTypes(); NS_ENSURE_TRUE(SUCCEEDED(hr), false); LOG("Video Decoder initialized, Using DXVA: %s", (mUseHwAccel ? "Yes" : "No")); return true; }
template < typename _T_REG_UNION > __forceinline void writeRegisterNoFence ( _T_REG_UNION RegUnion ) const throw () { C_ASSERT(sizeof(UINT32) == sizeof(ULONG)); ULONG* const regPtr = reinterpret_cast<ULONG*>( ULONG_PTR(this->basePtr) + ULONG(RegUnion.OFFSET)); ::WRITE_REGISTER_NOFENCE_ULONG(regPtr, RegUnion.AsUint32); } // writeRegisterNoFence<...> ( _T_REG_UNION )
template < typename _T_REG_UNION > __forceinline void readRegisterNoFence ( _Out_ _T_REG_UNION* RegUnionPtr ) const throw () { C_ASSERT(sizeof(UINT32) == sizeof(ULONG)); ULONG* const regPtr = reinterpret_cast<ULONG*>( ULONG_PTR(this->basePtr) + ULONG(RegUnionPtr->OFFSET)); RegUnionPtr->AsUint32 = ::READ_REGISTER_NOFENCE_ULONG(regPtr); } // readRegisterNoFence<...> ( _T_REG_UNION* )
nsresult WMFVideoDecoder::Init(mozilla::layers::LayersBackend aLayersBackend, mozilla::layers::ImageContainer* aImageContainer) { NS_ENSURE_ARG_POINTER(aImageContainer); bool useDxva= InitializeDXVA(aLayersBackend); mDecoder = new MFTDecoder(); HRESULT hr = mDecoder->Create(CLSID_CMSH264DecoderMFT); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); if (useDxva) { RefPtr<IMFAttributes> attr(mDecoder->GetAttributes()); UINT32 aware = 0; if (attr) { attr->GetUINT32(MF_SA_D3D_AWARE, &aware); } if (aware) { // TODO: Test if I need this anywhere... Maybe on Vista? //hr = attr->SetUINT32(CODECAPI_AVDecVideoAcceleration_H264, TRUE); //NS_ENSURE_TRUE(SUCCEEDED(hr), hr); MOZ_ASSERT(mDXVA2Manager); ULONG_PTR manager = ULONG_PTR(mDXVA2Manager->GetDXVADeviceManager()); hr = mDecoder->SendMFTMessage(MFT_MESSAGE_SET_D3D_MANAGER, manager); if (SUCCEEDED(hr)) { mUseHwAccel = true; } } } // Setup the input/output media types. RefPtr<IMFMediaType> type; hr = wmf::MFCreateMediaType(byRef(type)); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); hr = type->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); hr = type->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); hr = type->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_MixedInterlaceOrProgressive); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); GUID outputType = mUseHwAccel ? MFVideoFormat_NV12 : MFVideoFormat_YV12; hr = mDecoder->SetMediaTypes(type, outputType); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); mImageContainer = aImageContainer; LOG("Video Decoder initialized, Using DXVA: %s", (mUseHwAccel ? "Yes" : "No")); return NS_OK; }
HRESULT WMFReader::CreateSourceReader() { HRESULT hr; RefPtr<IMFAttributes> attr; hr = wmf::MFCreateAttributes(byRef(attr), 1); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); hr = attr->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, mSourceReaderCallback); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); if (mUseHwAccel) { hr = attr->SetUnknown(MF_SOURCE_READER_D3D_MANAGER, mDXVA2Manager->GetDXVADeviceManager()); if (FAILED(hr)) { DECODER_LOG("Failed to set DXVA2 D3D Device manager on source reader attributes"); mUseHwAccel = false; } } hr = wmf::MFCreateSourceReaderFromByteStream(mByteStream, attr, byRef(mSourceReader)); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); hr = ConfigureVideoDecoder(); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); hr = ConfigureAudioDecoder(); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); if (mUseHwAccel && mInfo.HasVideo()) { RefPtr<IMFTransform> videoDecoder; hr = mSourceReader->GetServiceForStream(MF_SOURCE_READER_FIRST_VIDEO_STREAM, GUID_NULL, IID_IMFTransform, (void**)(IMFTransform**)(byRef(videoDecoder))); if (SUCCEEDED(hr)) { ULONG_PTR manager = ULONG_PTR(mDXVA2Manager->GetDXVADeviceManager()); hr = videoDecoder->ProcessMessage(MFT_MESSAGE_SET_D3D_MANAGER, manager); if (hr == MF_E_TRANSFORM_TYPE_NOT_SET) { // Ignore MF_E_TRANSFORM_TYPE_NOT_SET. Vista returns this here // on some, perhaps all, video cards. This may be because activating // DXVA changes the available output types. It seems to be safe to // ignore this error. hr = S_OK; } } if (FAILED(hr)) { DECODER_LOG("Failed to set DXVA2 D3D Device manager on decoder hr=0x%x", hr); mUseHwAccel = false; } } return hr; }
void Monitor::AddMemorBlock(ULONG_PTR addr, ULONG_PTR size, bool monitorWrite) { ULONG_PTR firstPage = ULONG_PTR(addr) & (MAXULONG_PTR << PAGE_SHIFT); ULONG_PTR lastPage = (ULONG_PTR(addr) + size - 1) & (MAXULONG_PTR << PAGE_SHIFT); ULONG_PTR page = firstPage; BreakPoint::BreakPointType type; if (monitorWrite) type = BreakPoint::Write; else type = BreakPoint::Access; do { ULONG bp = g_dbgEng->SetBreakPoint((PVOID )page, type, PAGE_SIZE, false, false, false); _pageMgr->InsertPage(page, bp); page += PAGE_SIZE; } while (page <= lastPage); }
TemporaryRef<MFTDecoder> WMFVideoOutputSource::Init() { bool useDxva = InitializeDXVA(); RefPtr<MFTDecoder> decoder(new MFTDecoder()); HRESULT hr = decoder->Create(CLSID_CMSH264DecoderMFT); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); if (useDxva) { RefPtr<IMFAttributes> attr(decoder->GetAttributes()); UINT32 aware = 0; if (attr) { attr->GetUINT32(MF_SA_D3D_AWARE, &aware); } if (aware) { // TODO: Test if I need this anywhere... Maybe on Vista? //hr = attr->SetUINT32(CODECAPI_AVDecVideoAcceleration_H264, TRUE); //NS_ENSURE_TRUE(SUCCEEDED(hr), hr); MOZ_ASSERT(mDXVA2Manager); ULONG_PTR manager = ULONG_PTR(mDXVA2Manager->GetDXVADeviceManager()); hr = decoder->SendMFTMessage(MFT_MESSAGE_SET_D3D_MANAGER, manager); if (SUCCEEDED(hr)) { mUseHwAccel = true; } } } // Setup the input/output media types. RefPtr<IMFMediaType> type; hr = wmf::MFCreateMediaType(byRef(type)); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); hr = type->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); hr = type->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); hr = type->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_MixedInterlaceOrProgressive); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); GUID outputType = mUseHwAccel ? MFVideoFormat_NV12 : MFVideoFormat_YV12; hr = decoder->SetMediaTypes(type, outputType); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); mDecoder = decoder; LOG("Video Decoder initialized, Using DXVA: %s", (mUseHwAccel ? "Yes" : "No")); return decoder.forget(); }
int _RosLogBugcheck ( ULONG Level ) { volatile void* returnAddress = _ReturnAddress(); #pragma prefast(suppress:__WARNING_USE_OTHER_FUNCTION, "We really-really want to bugcheck here...)") KeBugCheckEx( BUGCODE_ID_DRIVER, ULONG_PTR(returnAddress), Level, 0, 0); //return 1; } // _RosLogBugcheck (...)
void Multitouch::Touch(unsigned int id, int x, int y) { // TODO scale x and y to server screen coordinates TOUCHINPUT input; input.x = x; input.y = y; input.hSource = 0; // Don't know what to do if the input doesn't have a corresponding device... hopefully 0 works input.dwID = id; input.dwFlags = TOUCHEVENTF_DOWN; input.dwMask = 0; // Could potentially send touch area input.dwTimeinput.dwExtraInfo = ULONG_PTR(NULL); input.cxContact = 0; input.cyContact = 0; SendMessage }
bool WMFVideoMFTManager::InitInternal(bool aForceD3D9) { mUseHwAccel = false; // default value; changed if D3D setup succeeds. bool useDxva = InitializeDXVA(aForceD3D9); RefPtr<MFTDecoder> decoder(new MFTDecoder()); HRESULT hr = decoder->Create(GetMFTGUID()); NS_ENSURE_TRUE(SUCCEEDED(hr), false); RefPtr<IMFAttributes> attr(decoder->GetAttributes()); UINT32 aware = 0; if (attr) { attr->GetUINT32(MF_SA_D3D_AWARE, &aware); attr->SetUINT32(CODECAPI_AVDecNumWorkerThreads, WMFDecoderModule::GetNumDecoderThreads()); hr = attr->SetUINT32(CODECAPI_AVLowLatencyMode, TRUE); if (SUCCEEDED(hr)) { LOG("Enabling Low Latency Mode"); } else { LOG("Couldn't enable Low Latency Mode"); } } if (useDxva) { if (aware) { // TODO: Test if I need this anywhere... Maybe on Vista? //hr = attr->SetUINT32(CODECAPI_AVDecVideoAcceleration_H264, TRUE); //NS_ENSURE_TRUE(SUCCEEDED(hr), hr); MOZ_ASSERT(mDXVA2Manager); ULONG_PTR manager = ULONG_PTR(mDXVA2Manager->GetDXVADeviceManager()); hr = decoder->SendMFTMessage(MFT_MESSAGE_SET_D3D_MANAGER, manager); if (SUCCEEDED(hr)) { mUseHwAccel = true; } else { mDXVA2Manager = nullptr; mDXVAFailureReason = nsPrintfCString("MFT_MESSAGE_SET_D3D_MANAGER failed with code %X", hr); } } else { mDXVAFailureReason.AssignLiteral("Decoder returned false for MF_SA_D3D_AWARE"); } } mDecoder = decoder; hr = SetDecoderMediaTypes(); NS_ENSURE_TRUE(SUCCEEDED(hr), false); LOG("Video Decoder initialized, Using DXVA: %s", (mUseHwAccel ? "Yes" : "No")); // Just in case ConfigureVideoFrameGeometry() does not set these mVideoInfo = VideoInfo(); mVideoStride = 0; mVideoWidth = 0; mVideoHeight = 0; mPictureRegion.SetEmpty(); return true; }
// EventHResult Monitor::OnException(DWORD tid, EXCEPTION_DEBUG_INFO& info) EventHResult Monitor::OnBreakPoint(DWORD tid, BreakPoint& bp, EXCEPTION_DEBUG_INFO& info) { EXCEPTION_RECORD& excepRec = info.ExceptionRecord; bool wrtten; /* if (excepRec.ExceptionCode == STATUS_ACCESS_VIOLATION && g_dbgEng->IsBreakPoint(info)) */ { ULONG_PTR pageBound; ULONG_PTR addr; ULONG_PTR code_addr = (ULONG_PTR )excepRec.ExceptionAddress; if (excepRec.ExceptionInformation[1] != NULL) { addr = excepRec.ExceptionInformation[1]; pageBound = ULONG_PTR(addr) & (MAXULONG_PTR << PAGE_SHIFT); if (excepRec.ExceptionInformation[0] != 0) { // 写数据, 需要更新 if (pageBound == _selected) { _updateDataFlag = true; } wrtten = true; } else wrtten = false; } else { addr = (ULONG_PTR )excepRec.ExceptionAddress; pageBound = ULONG_PTR(addr) & (MAXULONG_PTR << PAGE_SHIFT); } if (_hitonce) { if (_hits.find(addr) == _hits.end()) { _hits.insert(addr); g_dbgEng->Log(L_INFO, "[%d]hit: %p, addr: %p, prog: %p", Monitor::instance().GetHitNum(), pageBound, addr, code_addr); } } else { g_dbgEng->Log(L_INFO, "[%d]hit: %p, addr: %p, prog: %p", Monitor::instance().GetHitNum(), pageBound, addr, code_addr); } _leftView->QueuePageUpdate(pageBound, wrtten); } /* else { if (excepRec.ExceptionCode != STATUS_BREAKPOINT && excepRec.ExceptionCode != STATUS_SINGLE_STEP) { ExcepHandleMap::iterator it; it = _excepHandles.find(excepRec.ExceptionCode); if (it == _excepHandles.end()) { TCHAR buf[1024]; wsprintf(buf, _T("Unknown exception: %#08x, addr:%p, continue?"), excepRec.ExceptionCode, excepRec.ExceptionAddress); if (AfxMessageBox(buf, MB_YESNO) == IDYES) { _excepHandles[excepRec.ExceptionCode] = DbgContinue; return DbgContinue; } else _excepHandles[excepRec.ExceptionCode] = DbgNext; } } // return DbgContinue; } */ return DbgNext; }
already_AddRefed<MFTDecoder> WMFVideoMFTManager::InitInternal(bool aForceD3D9) { mUseHwAccel = false; // default value; changed if D3D setup succeeds. bool useDxva = InitializeDXVA(aForceD3D9); RefPtr<MFTDecoder> decoder(new MFTDecoder()); HRESULT hr = decoder->Create(GetMFTGUID()); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); RefPtr<IMFAttributes> attr(decoder->GetAttributes()); UINT32 aware = 0; if (attr) { attr->GetUINT32(MF_SA_D3D_AWARE, &aware); attr->SetUINT32(CODECAPI_AVDecNumWorkerThreads, WMFDecoderModule::GetNumDecoderThreads()); } if (useDxva) { if (aware) { // TODO: Test if I need this anywhere... Maybe on Vista? //hr = attr->SetUINT32(CODECAPI_AVDecVideoAcceleration_H264, TRUE); //NS_ENSURE_TRUE(SUCCEEDED(hr), hr); MOZ_ASSERT(mDXVA2Manager); ULONG_PTR manager = ULONG_PTR(mDXVA2Manager->GetDXVADeviceManager()); hr = decoder->SendMFTMessage(MFT_MESSAGE_SET_D3D_MANAGER, manager); if (SUCCEEDED(hr)) { mUseHwAccel = true; } } } // Setup the input/output media types. RefPtr<IMFMediaType> inputType; hr = wmf::MFCreateMediaType(byRef(inputType)); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); hr = inputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); hr = inputType->SetGUID(MF_MT_SUBTYPE, GetMediaSubtypeGUID()); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); hr = inputType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_MixedInterlaceOrProgressive); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); RefPtr<IMFMediaType> outputType; hr = wmf::MFCreateMediaType(byRef(outputType)); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); hr = outputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); GUID outputSubType = mUseHwAccel ? MFVideoFormat_NV12 : MFVideoFormat_YV12; hr = outputType->SetGUID(MF_MT_SUBTYPE, outputSubType); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); hr = decoder->SetMediaTypes(inputType, outputType); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); mDecoder = decoder; LOG("Video Decoder initialized, Using DXVA: %s", (mUseHwAccel ? "Yes" : "No")); // Just in case ConfigureVideoFrameGeometry() does not set these mVideoInfo = VideoInfo(); mVideoStride = 0; mVideoWidth = 0; mVideoHeight = 0; mPictureRegion.SetEmpty(); return decoder.forget(); }
DWORD CShortcut::GetData(BYTE* _pData) const { BYTE* pData=_pData; *((WORD*)pData)=0xFFED; // Start mark pData+=sizeof(WORD); // Flags *((WORD*)pData)=m_dwFlags; // Virtual key *(pData+2)=m_bVirtualKey; // Modfiers *(pData+3)=m_bModifiers; // Class if (m_pClass==LPSTR(-1)) *((DWORD*)(pData+4))=DWORD(-1); else *((DWORD*)(pData+4))=(DWORD)min(ULONG_PTR(m_pClass),MAXDWORD); // Title *((DWORD*)(pData+8))=(DWORD)min(ULONG_PTR(m_pTitle),MAXDWORD); // Delay *((DWORD*)(pData+12))=m_nDelay; // Array *((DWORD*)(pData+24))=m_apActions.GetSize(); pData+=28 /*sizeof(CShortcut)*/; if ((m_dwFlags&sfKeyTypeMask)!=sfLocal) { if (m_pClass!=NULL && m_pClass!=LPSTR(-1)) { int iUsed=istrlen(m_pClass)+1; CopyMemory(pData,m_pClass,iUsed); pData+=iUsed; } if (m_pTitle!=NULL) { int iUsed=istrlen(m_pTitle)+1; CopyMemory(pData,m_pTitle,iUsed); pData+=iUsed; } } for (int i=0;i<m_apActions.GetSize();i++) { pData+=m_apActions[i]->GetData(pData); } return DWORD(pData-_pData); }
void fillbasicinfo(Capstone* cp, BASIC_INSTRUCTION_INFO* basicinfo) { //zero basicinfo memset(basicinfo, 0, sizeof(BASIC_INSTRUCTION_INFO)); //copy instruction text strcpy_s(basicinfo->instruction, cp->InstructionText().c_str()); //instruction size basicinfo->size = cp->Size(); //branch/call info if(cp->InGroup(CS_GRP_CALL)) { basicinfo->branch = true; basicinfo->call = true; } else if(cp->InGroup(CS_GRP_JUMP) || cp->IsLoop()) { basicinfo->branch = true; } //handle operands for(int i = 0; i < cp->x86().op_count; i++) { const cs_x86_op & op = cp->x86().operands[i]; switch(op.type) { case X86_OP_IMM: { if(basicinfo->branch) { basicinfo->type |= TYPE_ADDR; basicinfo->addr = duint(op.imm); basicinfo->value.value = duint(op.imm); } else { basicinfo->type |= TYPE_VALUE; basicinfo->value.size = VALUE_SIZE(op.size); basicinfo->value.value = duint(op.imm); } } break; case X86_OP_MEM: { const x86_op_mem & mem = op.mem; strcpy_s(basicinfo->memory.mnemonic, cp->OperandText(i).c_str()); basicinfo->memory.size = MEMORY_SIZE(op.size); if(op.mem.base == X86_REG_RIP) //rip-relative { basicinfo->memory.value = ULONG_PTR(cp->GetInstr()->address + op.mem.disp + basicinfo->size); basicinfo->type |= TYPE_MEMORY; } else if(mem.disp) { basicinfo->type |= TYPE_MEMORY; basicinfo->memory.value = ULONG_PTR(mem.disp); } } break; } } }
nsresult WMFReader::ReadMetadata(MediaInfo* aInfo, MetadataTags** aTags) { NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread."); LOG("WMFReader::ReadMetadata()"); HRESULT hr; RefPtr<IMFAttributes> attr; hr = wmf::MFCreateAttributes(byRef(attr), 1); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); hr = attr->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, mSourceReaderCallback); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); if (mUseHwAccel) { hr = attr->SetUnknown(MF_SOURCE_READER_D3D_MANAGER, mDXVA2Manager->GetDXVADeviceManager()); if (FAILED(hr)) { LOG("Failed to set DXVA2 D3D Device manager on source reader attributes"); mUseHwAccel = false; } } hr = wmf::MFCreateSourceReaderFromByteStream(mByteStream, attr, byRef(mSourceReader)); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); hr = ConfigureVideoDecoder(); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); hr = ConfigureAudioDecoder(); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); if (mUseHwAccel && mInfo.mVideo.mHasVideo) { RefPtr<IMFTransform> videoDecoder; hr = mSourceReader->GetServiceForStream(MF_SOURCE_READER_FIRST_VIDEO_STREAM, GUID_NULL, IID_IMFTransform, (void**)(IMFTransform**)(byRef(videoDecoder))); if (SUCCEEDED(hr)) { ULONG_PTR manager = ULONG_PTR(mDXVA2Manager->GetDXVADeviceManager()); hr = videoDecoder->ProcessMessage(MFT_MESSAGE_SET_D3D_MANAGER, manager); if (hr == MF_E_TRANSFORM_TYPE_NOT_SET) { // Ignore MF_E_TRANSFORM_TYPE_NOT_SET. Vista returns this here // on some, perhaps all, video cards. This may be because activating // DXVA changes the available output types. It seems to be safe to // ignore this error. hr = S_OK; } } if (FAILED(hr)) { LOG("Failed to set DXVA2 D3D Device manager on decoder hr=0x%x", hr); mUseHwAccel = false; // Re-run the configuration process, so that the output video format // is set correctly to reflect that hardware acceleration is disabled. // Without this, we'd be running with !mUseHwAccel and the output format // set to NV12, which is the format we expect when using hardware // acceleration. This would cause us to misinterpret the frame contents. hr = ConfigureVideoDecoder(); } } if (mInfo.HasVideo()) { LOG("Using DXVA: %s", (mUseHwAccel ? "Yes" : "No")); } // Abort if both video and audio failed to initialize. NS_ENSURE_TRUE(mInfo.HasValidMedia(), NS_ERROR_FAILURE); // Get the duration, and report it to the decoder if we have it. int64_t duration = 0; hr = GetSourceReaderDuration(mSourceReader, duration); if (SUCCEEDED(hr)) { ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); mDecoder->SetMediaDuration(duration); } // We can seek if we get a duration *and* the reader reports that it's // seekable. bool canSeek = false; if (FAILED(hr) || FAILED(GetSourceReaderCanSeek(mSourceReader, canSeek)) || !canSeek) { mDecoder->SetMediaSeekable(false); } *aInfo = mInfo; *aTags = nullptr; // aTags can be retrieved using techniques like used here: // http://blogs.msdn.com/b/mf/archive/2010/01/12/mfmediapropdump.aspx return NS_OK; }
nsresult WMFReader::ReadMetadata(VideoInfo* aInfo, MetadataTags** aTags) { NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread."); LOG("WMFReader::ReadMetadata()"); HRESULT hr; RefPtr<IMFAttributes> attr; hr = wmf::MFCreateAttributes(byRef(attr), 1); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); hr = attr->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, mSourceReaderCallback); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); if (mUseHwAccel) { hr = attr->SetUnknown(MF_SOURCE_READER_D3D_MANAGER, mDXVA2Manager->GetDXVADeviceManager()); if (FAILED(hr)) { LOG("Failed to set DXVA2 D3D Device manager on source reader attributes"); mUseHwAccel = false; } } hr = wmf::MFCreateSourceReaderFromByteStream(mByteStream, attr, byRef(mSourceReader)); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); hr = ConfigureVideoDecoder(); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); hr = ConfigureAudioDecoder(); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); if (mUseHwAccel && mInfo.mHasVideo) { RefPtr<IMFTransform> videoDecoder; hr = mSourceReader->GetServiceForStream(MF_SOURCE_READER_FIRST_VIDEO_STREAM, GUID_NULL, IID_IMFTransform, (void**)(IMFTransform**)(byRef(videoDecoder))); if (SUCCEEDED(hr)) { ULONG_PTR manager = ULONG_PTR(mDXVA2Manager->GetDXVADeviceManager()); hr = videoDecoder->ProcessMessage(MFT_MESSAGE_SET_D3D_MANAGER, manager); } if (FAILED(hr)) { LOG("Failed to set DXVA2 D3D Device manager on decoder"); mUseHwAccel = false; } } if (mInfo.mHasVideo) { LOG("Using DXVA: %s", (mUseHwAccel ? "Yes" : "No")); } // Abort if both video and audio failed to initialize. NS_ENSURE_TRUE(mInfo.mHasAudio || mInfo.mHasVideo, NS_ERROR_FAILURE); int64_t duration = 0; if (SUCCEEDED(GetSourceReaderDuration(mSourceReader, duration))) { ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); mDecoder->SetMediaDuration(duration); } hr = GetSourceReaderCanSeek(mSourceReader, mCanSeek); NS_ASSERTION(SUCCEEDED(hr), "Can't determine if resource is seekable"); *aInfo = mInfo; *aTags = nullptr; // aTags can be retrieved using techniques like used here: // http://blogs.msdn.com/b/mf/archive/2010/01/12/mfmediapropdump.aspx return NS_OK; }