nsresult nsDeviceContextSpecOS2::SetPrintSettingsFromDevMode(nsIPrintSettings* aPrintSettings, ULONG printer) { if (aPrintSettings == nsnull) return NS_ERROR_FAILURE; int bufferSize = 3 * sizeof(DJP_ITEM); PBYTE pDJP_Buffer = new BYTE[bufferSize]; memset(pDJP_Buffer, 0, bufferSize); PDJP_ITEM pDJP = (PDJP_ITEM) pDJP_Buffer; HDC hdc = nsDeviceContextSpecOS2::PrnDlg.GetDCHandle(printer); //Get Number of Copies from Job Properties pDJP->lType = DJP_CURRENT; pDJP->cb = sizeof(DJP_ITEM); pDJP->ulNumReturned = 1; pDJP->ulProperty = DJP_SJ_COPIES; pDJP->ulValue = 1; pDJP++; //Get Orientation from Job Properties pDJP->lType = DJP_CURRENT; pDJP->cb = sizeof(DJP_ITEM); pDJP->ulNumReturned = 1; pDJP->ulProperty = DJP_SJ_ORIENTATION; pDJP->ulValue = 1; pDJP++; pDJP->lType = DJP_NONE; pDJP->cb = sizeof(DJP_ITEM); pDJP->ulNumReturned = 1; pDJP->ulProperty = 0; pDJP->ulValue = 0; LONG driverSize = nsDeviceContextSpecOS2::PrnDlg.GetPrintDriverSize(printer); LONG rc = GreEscape(hdc, DEVESC_QUERYJOBPROPERTIES, bufferSize, pDJP_Buffer, &driverSize, PBYTE(nsDeviceContextSpecOS2::PrnDlg.GetPrintDriver(printer))); pDJP = (PDJP_ITEM) pDJP_Buffer; if ((rc == DEV_OK) || (rc == DEV_WARNING)) { while (pDJP->lType != DJP_NONE) { if ((pDJP->ulProperty == DJP_SJ_ORIENTATION) && (pDJP->lType > 0)){ if ((pDJP->ulValue == DJP_ORI_PORTRAIT) || (pDJP->ulValue == DJP_ORI_REV_PORTRAIT)) aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation); else aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation); } if ((pDJP->ulProperty == DJP_SJ_COPIES) && (pDJP->lType > 0)){ aPrintSettings->SetNumCopies(PRInt32(pDJP->ulValue)); } pDJP = DJP_NEXT_STRUCTP(pDJP); } } delete [] pDJP_Buffer; DevCloseDC(hdc); return NS_OK; }
/***************************************************************************** * LookupClassId() ***************************************************************************** */ GUID LookupClassId ( IN LPTSTR SymbolicLink ) { GUID ClassId; HKEY EmuPublicKey = NULL; DWORD w32Error = RegCreateKeyEx(HKEY_LOCAL_MACHINE, EMU_PUBLIC_KEY, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &EmuPublicKey, NULL); if (ERROR_SUCCESS == w32Error) { HKEY ClassKey = NULL; w32Error = RegCreateKeyEx(EmuPublicKey, "{EB5A82E1-B4E7-47e8-97B0-F0751F97C2D1}", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &ClassKey, NULL); if (ERROR_SUCCESS == w32Error) { TCHAR ValueName[MAX_PATH]; _tcscpy(ValueName, SymbolicLink); TCHAR * token = _tcschr(ValueName, '\\'); while (token) { *token = '#'; token = _tcschr(token+1, '\\'); } ULONG Type = 0; ULONG Size = sizeof(ClassId); w32Error = RegQueryValueEx(ClassKey, ValueName, 0, &Type, PBYTE(&ClassId), &Size); if (ERROR_SUCCESS != w32Error) { CoCreateGuid(&ClassId); RegSetValueEx(ClassKey, ValueName, 0, REG_BINARY, (BYTE*)&ClassId, sizeof(ClassId)); w32Error = ERROR_SUCCESS; } RegCloseKey(ClassKey); } RegCloseKey(EmuPublicKey); } if (ERROR_SUCCESS != w32Error) { CoCreateGuid(&ClassId); } return ClassId; }
MHANDLE ClaimHandle( ADDR Address ) { // Need to scan along the list of handles to find an unused one if (HandlesInUse == (ElementsInHandleTable-1)) { // we have run out of handles TRACEUSER( "Rik", wxT("ClaimHandle - No more handles available. Trying to get some more\n") ); // First off we had better try to extend our allocation of memory to the table // If it fails, return saying there are no more handles left! if (!HandlesMemory.Grow(HandleTableTotalSize, HandleTableTotalSize+HandleTableByteSize, (LPVOID*)&HandlesTable )) { TRACE( wxT("ClaimHandle - Failed to get more handles!!!! P A N I C\n") ); return BAD_MHANDLE; } // grew handle table OK, Set all the new bits of mem to defaults for (INT32 i=0; i<HandleTableSize; i++) HandlesTable[ElementsInHandleTable+i].Address = PBYTE(BAD_MHANDLE); // increase the counters HandleTableTotalSize += HandleTableByteSize; ElementsInHandleTable += HandleTableSize; } // Ok, we must have some handles by now, so lets try and find one UINT32 Handle = ElementsInHandleTable - 1; while (Handle>0) { if (HandlesTable[Handle].Address == BAD_MHANDLE ) { // Store the Addr HandlesTable[Handle].Address = Address; HandlesInUse ++; // if we are using unique IDs, do this #ifdef USE_UNIQUE_IDS // Using Unique IDS, so get the next id and store it away WORD UniqueID = CurrUniqueId++; HandlesTable[ Handle ].UniqueID = UniqueID; return MAKEINT32( Handle, UniqueID ); #else // TRACEUSER("Gerry", _T("ClaimHandle - %d"), Handle); return Handle; #endif } Handle --; } // Should never get here ENSURE( FALSE, "ClaimHandle: We Should never have reached this bit!" ); return BAD_MHANDLE; }
extern ULONG BuildMVMTValue ( PVOID Value, USHORT Count, MVMT_VALUE Table[] ) { /*************************************************************************** * Store the number of values. * ***************************************************************************/ PBYTE p = PBYTE(Value) ; if ( Value ) *PUSHORT(p) = Count ; p += sizeof(Count) ; /*************************************************************************** * Store the multiple values. * ***************************************************************************/ for ( int i=0; i<Count; i++ ) { if ( Value ) *PUSHORT(p) = Table[i].Type ; p += sizeof(Table[i].Type) ; if ( Value ) *PUSHORT(p) = Table[i].Length ; p += sizeof(Table[i].Length) ; if ( Value ) memcpy ( p, Table[i].Value, Table[i].Length ) ; p += Table[i].Length ; } /*************************************************************************** * Return the total byte count. * ***************************************************************************/ return ( p - PBYTE(Value) ) ; }
QByteArray QCNG::decrypt( const QByteArray &data ) { d->err = PinUnknown; DWORD size = 256; QByteArray res(int(size), 0); NCRYPT_KEY_HANDLE k = d->key(); SECURITY_STATUS err = NCryptDecrypt(k, PBYTE(data.constData()), DWORD(data.size()), nullptr, PBYTE(res.data()), DWORD(res.size()), &size, NCRYPT_PAD_PKCS1_FLAG); NCryptFreeObject( k ); switch( err ) { case ERROR_SUCCESS: d->err = PinOK; res.resize(int(size)); return res; case SCARD_W_CANCELLED_BY_USER: d->err = PinCanceled; break; default: break; } return QByteArray(); }
bool DecryptHouaissFile(PVOID pvInput, DWORD size, PVOID pvOutput, H2BOperation& op) { bool ret = true; PBYTE input = PBYTE(pvInput); PBYTE output = PBYTE(pvOutput); unsigned int sizePercent = size / 2; unsigned int factor = 2; unsigned int lastPercent = 0; unsigned int percent = 0; CString status; while( sizePercent > UINT_MAX / 100 ) { sizePercent /= 2; factor *= 2; } for( DWORD inputCount = 0; inputCount < size; ++inputCount ) { output[inputCount] = input[inputCount] + 0x0B; percent = ( inputCount / factor ) * 100 / sizePercent; if( op.Cancel() ) { ret = false; SetLastError(ERROR_CANCELLED); break; } if( percent != lastPercent ) { status.Format(_T("Desencriptando %d%%..."), percent); op.SetOperationStatus(lastPercent = percent); op.SetStatusMessage(status); } } return ret; }
// // CryptHash::GetCryptHashSize // DWORD CryptHash::GetCryptHashSize() const { if (m_hHash && m_hProv) { DWORD cbHash = 0; DWORD cbT = sizeof(cbHash); if (::CryptGetHashParam(m_hHash, HP_HASHSIZE, PBYTE(&cbHash), &cbT, 0)) { return cbHash; } } return 0; }
// // CryptHash::GetCryptHash() // caller needs to allocate memory for pvHash based on GetHashSize() // bool CryptHash::GetCryptHash(void *pvHash, DWORD cbHash) const { VSASSERT(cbHash == GetCryptHashSize(),"Wrong hash size"); DWORD cbT = cbHash; bool fSucceed = ::CryptGetHashParam(m_hHash, HP_HASHVAL, PBYTE(pvHash), &cbT, 0); if(!fSucceed) { ::memset(pvHash, 0, cbHash); } return fSucceed; }
QByteArray QCNG::Private::prop( NCRYPT_HANDLE handle, LPCWSTR param, DWORD flags ) const { QByteArray data; if(!handle) return data; DWORD size = 0; if(NCryptGetProperty(handle, param, nullptr, 0, &size, flags)) return data; data.resize(int(size)); if(NCryptGetProperty(handle, param, PBYTE(data.data()), size, &size, flags)) data.clear(); return data; }
//扩展名数据库操作,优先加载 //若返回FALSE 则文件名数据库中的扩展名部分无效 //这时需要重新生成文件名数据库 BOOL CExtArray::LoadFromFile(PWCHAR pwszExtDatabase) { HANDLE hFile=CreateFileW(pwszExtDatabase ,GENERIC_READ ,FILE_SHARE_READ ,NULL ,OPEN_EXISTING ,FILE_ATTRIBUTE_NORMAL ,NULL); if(INVALID_HANDLE_VALUE==hFile){ DebugStringA("读扩展名文件失败:%d",GetLastError()); return FALSE; } DWORD dwFileSize=GetFileSize(hFile,NULL); PBYTE pByte=g_MemoryMgr.GetMemory(dwFileSize),pEnd=pByte+dwFileSize; DWORD dwRead; ReadFile(hFile,pByte,dwFileSize,&dwRead,NULL); assert(dwFileSize==dwRead); m_size=*(DWORD*)(pByte); if(m_size>=m_dwMax) { m_dwMax=m_size+DELT; m_vpExtName=(PWCHAR*)g_MemoryMgr.realloc(m_vpExtName,sizeof(PWCHAR)*m_dwMax); m_piIcon=(int*)g_MemoryMgr.realloc(m_piIcon,sizeof(int)*m_dwMax); m_vpIndexExtName=(PINDEXNODE)g_MemoryMgr.realloc(m_vpIndexExtName,sizeof(INDEXNODE)*m_dwMax); } size_t extLen; int i=0,j; int idExt; PWCHAR pName; for(pByte+=4;pByte<pEnd;) { idExt=*(int*)pByte; m_vpIndexExtName[i].idExtName=idExt; pByte+=4; m_piIcon[idExt]=*(int*)pByte; pName=PWCHAR(pByte+4); extLen=wcslen(pName); m_vpExtName[idExt]=(PWCHAR)g_MemoryMgr.malloc((sizeof(WCHAR)*(extLen+1))); m_vpIndexExtName[i].pExtName=m_vpExtName[idExt]; for(j=0;j<extLen;++j){ m_vpExtName[idExt][j]=*pName++; } m_vpExtName[idExt][j]=L'\0'; pByte=PBYTE(pName+1); i++; } assert(i==m_size); CloseHandle(hFile); return TRUE; }
void SetupDevModeFromSettings(ULONG printer, nsIPrintSettings* aPrintSettings) { if (aPrintSettings) { int bufferSize = 3 * sizeof(DJP_ITEM); PBYTE pDJP_Buffer = new BYTE[bufferSize]; memset(pDJP_Buffer, 0, bufferSize); PDJP_ITEM pDJP = (PDJP_ITEM) pDJP_Buffer; HDC hdc = nsDeviceContextSpecOS2::PrnDlg.GetDCHandle(printer); char* driver = nsDeviceContextSpecOS2::PrnDlg.GetDriverType(printer); // Setup Orientation PRInt32 orientation; aPrintSettings->GetOrientation(&orientation); if (!strcmp(driver, "LASERJET")) pDJP->lType = DJP_ALL; else pDJP->lType = DJP_CURRENT; pDJP->cb = sizeof(DJP_ITEM); pDJP->ulNumReturned = 1; pDJP->ulProperty = DJP_SJ_ORIENTATION; pDJP->ulValue = orientation == nsIPrintSettings::kPortraitOrientation?DJP_ORI_PORTRAIT:DJP_ORI_LANDSCAPE; pDJP++; // Setup Number of Copies PRInt32 copies; aPrintSettings->GetNumCopies(&copies); pDJP->cb = sizeof(DJP_ITEM); pDJP->lType = DJP_CURRENT; pDJP->ulNumReturned = 1; pDJP->ulProperty = DJP_SJ_COPIES; pDJP->ulValue = copies; pDJP++; pDJP->cb = sizeof(DJP_ITEM); pDJP->lType = DJP_NONE; pDJP->ulNumReturned = 1; pDJP->ulProperty = 0; pDJP->ulValue = 0; LONG driverSize = nsDeviceContextSpecOS2::PrnDlg.GetPrintDriverSize(printer); GreEscape (hdc, DEVESC_SETJOBPROPERTIES, bufferSize, pDJP_Buffer, &driverSize, PBYTE(nsDeviceContextSpecOS2::PrnDlg.GetPrintDriver(printer))); delete [] pDJP_Buffer; DevCloseDC(hdc); } }
DWORD OffsetToRva(PBYTE pbImage, DWORD dwOffset) { DWORD dwSecBorder = -1; PIMAGE_NT_HEADERS pNt = PIMAGE_NT_HEADERS(pbImage + PIMAGE_DOS_HEADER(pbImage)->e_lfanew); PIMAGE_SECTION_HEADER pSec = PIMAGE_SECTION_HEADER(PBYTE(pNt) + sizeof(IMAGE_NT_HEADERS)); for(DWORD x = 0; x < pNt->FileHeader.NumberOfSections; x++) { if(dwOffset >= pSec[x].PointerToRawData && dwOffset < pSec[x].PointerToRawData + pSec[x].SizeOfRawData) return (dwOffset - pSec[x].PointerToRawData + pSec[x].VirtualAddress); if(pSec[x].PointerToRawData && pSec[x].PointerToRawData < dwSecBorder) dwSecBorder = pSec[x].PointerToRawData; } if(dwOffset < dwSecBorder) return dwOffset; else return NULL; }
PBYTE RvaToPointer(PBYTE pbImage, DWORD dwRva) { DWORD dwSecBorder = -1; PIMAGE_NT_HEADERS pNt = PIMAGE_NT_HEADERS(pbImage + PIMAGE_DOS_HEADER(pbImage)->e_lfanew); PIMAGE_SECTION_HEADER pSec = PIMAGE_SECTION_HEADER(PBYTE(pNt) + sizeof(IMAGE_NT_HEADERS)); for(DWORD x = 0; x < pNt->FileHeader.NumberOfSections; x++) { if(dwRva >= pSec[x].VirtualAddress && dwRva < pSec[x].VirtualAddress + pSec[x].Misc.VirtualSize) return (pbImage + (dwRva - pSec[x].VirtualAddress + pSec[x].PointerToRawData)); if(pSec[x].PointerToRawData && pSec[x].PointerToRawData < dwSecBorder) dwSecBorder = pSec[x].PointerToRawData; } if(dwRva < dwSecBorder) return pbImage + dwRva; else return NULL; }
BOOL ReleaseHandle( MHANDLE Handle ) { // TRACEUSER("Gerry", _T("ReleaseHandle - %d"), Handle); // make sure its not garbage ENSURE( Handle > BAD_MHANDLE, "ReleaseHandle: Handle was BAD_MHANDLE" ); ENSURE( Handle < ElementsInHandleTable, "ReleaseHandle: Handle was too big" ); if ( HandlesTable[Handle].Address != BAD_MHANDLE ) { // mark it as available HandlesTable[Handle].Address = PBYTE(BAD_MHANDLE); HandlesInUse --; return TRUE; } return FALSE; // if we got here, return false }
// DDIToDIB - Creates a DIB from a DDI // hIcon - Device dependent icon // dwCompression - Type of compression - see BITMAPINFOHEADER (It's best to use the BI_RGB) // hPalette - Logical palette HANDLE DDIToDIB( HICON hIcon, HPALETTE hPalette, DWORD *pdwDIBSize ) { ICONINFO stIconInfo; ::GetIconInfo( hIcon, &stIconInfo ); DWORD dwMaskSize; DWORD dwColorSize; HANDLE hMaskDIB = ::DDBToDIB( stIconInfo.hbmMask, hPalette, &dwMaskSize ); HANDLE hColorDIB = ::DDBToDIB( stIconInfo.hbmColor, hPalette, &dwColorSize ); ::DeleteObject( stIconInfo.hbmMask ); ::DeleteObject( stIconInfo.hbmColor ); if ( pdwDIBSize ) *pdwDIBSize = 0; HANDLE hDIB = NULL; if ( hMaskDIB && hColorDIB ) { hDIB = ::GlobalAlloc( GPTR, dwMaskSize + dwColorSize + sizeof(dwMaskSize) ); if ( hDIB ) { PBYTE pDIB = PBYTE(hDIB); memcpy( (void *)pDIB, &dwMaskSize, sizeof(dwMaskSize) ); pDIB += sizeof(dwMaskSize); memcpy( (void *)pDIB, hMaskDIB, dwMaskSize ); pDIB += dwMaskSize; memcpy( (void *)pDIB, hColorDIB, dwColorSize ); if ( pdwDIBSize ) *pdwDIBSize = dwMaskSize + dwColorSize; } } if ( hMaskDIB ) ::GlobalFree( hMaskDIB ); if ( hColorDIB ) ::GlobalFree( hColorDIB ); return hDIB; }
EXCEPTION_DISPOSITION Exc::MonitorRaw::HandlerStat(EXCEPTION_RECORD* pExc, PVOID pPtr, CONTEXT* pCpuCtx) { ASSERT(pPtr); ExcReg* pExcReg = (ExcReg*) pPtr; Monitor* pThis = (Monitor*) (PBYTE(pPtr) - offsetof(Monitor, m_pOpaque)); if (EXC_FLAG_UNWIND & pExc->ExceptionFlags) { pExcReg->m_pfnHandler = NULL; // dismissed pThis->AbnormalExit(); } else if (pThis->Handle(pExc, pCpuCtx)) { ASSERT(!(EXCEPTION_NONCONTINUABLE & pExc->ExceptionFlags)); return ExceptionContinueExecution; } return ExceptionContinueSearch; }
PIMAGE_NT_HEADERS PEHeaderFromHModule(HMODULE hModule) { PIMAGE_NT_HEADERS pNTHeader = 0; __try { if ( PIMAGE_DOS_HEADER(hModule)->e_magic != IMAGE_DOS_SIGNATURE ) __leave; pNTHeader = PIMAGE_NT_HEADERS(PBYTE(hModule) + PIMAGE_DOS_HEADER(hModule)->e_lfanew); if ( pNTHeader->Signature != IMAGE_NT_SIGNATURE ) pNTHeader = 0; } __except( EXCEPTION_EXECUTE_HANDLER ) { } return pNTHeader; }
static void BuildSkinIcons(TEnumData *lParam) { IWICImagingFactory *factory = (bIsVistaPlus) ? ARGB_GetWorker() : NULL; TSlotIPC *pct = lParam->ipch->NewIconsBegin; TShellExt *Self = lParam->Self; while (pct != NULL) { if (pct->cbSize != sizeof(TSlotIPC) || pct->fType != REQUEST_NEWICONS) break; TSlotProtoIcons *p = (TSlotProtoIcons*)(PBYTE(pct) + sizeof(TSlotIPC)); Self->ProtoIcons = (TSlotProtoIcons*)realloc(Self->ProtoIcons, (Self->ProtoIconsCount + 1) * sizeof(TSlotProtoIcons)); TSlotProtoIcons *d = &Self->ProtoIcons[Self->ProtoIconsCount]; memmove(d, p, sizeof(TSlotProtoIcons)); // if using Vista (or later), clone all the icons into bitmaps and keep these around, // if using anything older, just use the default code, the bitmaps (and/or icons) will be freed // with the shell object. for (int j = 0; j < 10; j++) { if (bIsVistaPlus) { d->hBitmaps[j] = ARGB_BitmapFromIcon(factory, Self->hMemDC, p->hIcons[j]); d->hIcons[j] = NULL; } else { d->hBitmaps[j] = NULL; d->hIcons[j] = CopyIcon(p->hIcons[j]); } } Self->ProtoIconsCount++; pct = pct->Next; } if (factory) factory->Release(); }
void KinectSensor::GotVideoAlert( ) { const NUI_IMAGE_FRAME* pImageFrame = NULL; HRESULT hr = NuiImageStreamGetNextFrame(m_pVideoStreamHandle, 0, &pImageFrame); if (FAILED(hr)) { return; } INuiFrameTexture* pTexture = pImageFrame->pFrameTexture; NUI_LOCKED_RECT LockedRect; pTexture->LockRect(0, &LockedRect, NULL, 0); if (LockedRect.Pitch) { // Copy video frame to face tracking memcpy(m_VideoBuffer->GetBuffer(), PBYTE(LockedRect.pBits), min(m_VideoBuffer->GetBufferSize(), UINT(pTexture->BufferLen()))); } else { OutputDebugString(L"Buffer length of received texture is bogus\r\n"); } hr = NuiImageStreamReleaseFrame(m_pVideoStreamHandle, pImageFrame); }
// DIBToDDI - Creates a DDI from a DIB // hDIB - Device independent bitmap HICON DIBToDDI( HANDLE hDIB ) { DWORD dwMaskSize; PBYTE pDIB = PBYTE(hDIB); memcpy( &dwMaskSize, (void *)pDIB, sizeof(dwMaskSize) ); pDIB += sizeof(dwMaskSize); HBITMAP hMaskDDB = ::DIBToDDB( HANDLE(pDIB) ); pDIB += dwMaskSize; HBITMAP hColorDDB = ::DIBToDDB( HANDLE(pDIB) ); ICONINFO stIconInfo = {0}; stIconInfo.fIcon = TRUE; stIconInfo.hbmMask = hMaskDDB; stIconInfo.hbmColor = hColorDDB; HICON hIcon = ::CreateIconIndirect( &stIconInfo ); ::DeleteObject( stIconInfo.hbmMask ); ::DeleteObject( stIconInfo.hbmColor ); return hIcon; }
static ULONG BuildExtendedAttributeItem ( PFEA pFEA, PEADATA Item ) { /*************************************************************************** * Store header. * ***************************************************************************/ PBYTE p = PBYTE ( pFEA ) ; if ( pFEA ) { pFEA->fEA = 0 ; pFEA->cbName = (BYTE) strlen ( (PCHAR)Item->Name ) ; pFEA->cbValue = USHORT ( Item->Length + 2 * sizeof(USHORT) ) ; } p += sizeof(FEA) ; /*************************************************************************** * Store name. * ***************************************************************************/ if ( pFEA ) { strcpy ( (PCHAR)p, (PCHAR)Item->Name ) ; } p += strlen ( (PCHAR)Item->Name ) + 1 ; /*************************************************************************** * Store value's type. * ***************************************************************************/ PSHORT ps = PSHORT ( p ) ; if ( pFEA ) { *ps = Item->Type ; } ps ++ ; /*************************************************************************** * Store value's length. * ***************************************************************************/ if ( pFEA ) { *ps = Item->Length ; } ps ++ ; /*************************************************************************** * Store value. * ***************************************************************************/ p = (PBYTE) ps ; if ( pFEA ) { memcpy ( p, Item->Value, Item->Length ) ; } p += Item->Length ; /*************************************************************************** * Return count of bytes needed for item. * ***************************************************************************/ return ( p - PBYTE(pFEA) ) ; }
extern PEAOP BuildExtendedAttributes ( USHORT Count, EADATA Table[] ) { /*************************************************************************** * Find out how much memory will be needed for the block. * ***************************************************************************/ ULONG cbEA = sizeof(FEALIST) - sizeof(FEA) ; for ( int i=0; i<Count; i++ ) { cbEA += BuildExtendedAttributeItem ( PFEA(NULL), &Table[i] ) ; } /*************************************************************************** * Allocate memory for the FEA list. * ***************************************************************************/ PFEALIST pFEAList = PFEALIST ( AllocateMemory ( size_t(cbEA) ) ) ; if ( pFEAList == NULL ) { return ( PEAOP(NULL) ) ; } /*************************************************************************** * Construct the extended attributes. * ***************************************************************************/ PFEA pFEA = pFEAList->list ; for ( i=0; i<Count; i++ ) { PBYTE p = PBYTE ( pFEA ) ; p += BuildExtendedAttributeItem ( pFEA, &Table[i] ) ; pFEA = PFEA ( p ) ; } pFEAList->cbList = PBYTE(pFEA) - PBYTE(pFEAList) ; /*************************************************************************** * Allocate memory for the EA header block. * ***************************************************************************/ PEAOP pExtendedAttributes = PEAOP ( AllocateMemory ( sizeof(EAOP) ) ) ; if ( pExtendedAttributes == NULL ) { FreeMemory ( pFEAList ) ; return ( PEAOP(NULL) ) ; } /*************************************************************************** * Fill in the extended attribute header block and return its address. * ***************************************************************************/ pExtendedAttributes->fpGEAList = PGEALIST(NULL) ; pExtendedAttributes->fpFEAList = pFEAList ; pExtendedAttributes->oError = 0 ; return ( pExtendedAttributes ) ; }
X PFromRva(RVA rva) { return X(PBYTE(&__ImageBase) + rva); }
static inline PIMAGE_NT_HEADERS WINAPI PinhFromImageBase(HMODULE hmod) { return PIMAGE_NT_HEADERS(PBYTE(hmod) + PIMAGE_DOS_HEADER(hmod)->e_lfanew); }
/// <summary> /// Retrieve depth data from stream frame /// </summary> void NuiDepthStream::ProcessDepth() { HRESULT hr; NUI_IMAGE_FRAME imageFrame; if (m_Recording) { //////Initializaing a video writer and allocate an image for recording ///////// if ((m_TimerCount++)%FramesPerFile==0) { WCHAR szFilename[MAX_PATH] = { 0 }; if (SUCCEEDED(GetFileName(szFilename,_countof(szFilename), m_instanceName, DepthSensor))) { char char_szFilename[MAX_PATH] = {0}; size_t convertedChars; wcstombs_s(&convertedChars,char_szFilename,sizeof(char_szFilename),szFilename,sizeof(char_szFilename)); m_pwriter=cvCreateVideoWriter(char_szFilename, CV_FOURCC('L', 'A', 'G', 'S'), //-1, //user specified FramesPerSecond,m_ImageRes); //2,m_ImageRes); } m_TimerCount%=FramesPerFile; } } // Attempt to get the depth frame hr = m_pNuiSensor->NuiImageStreamGetNextFrame(m_hStreamHandle, 0, &imageFrame); if (FAILED(hr)) { return; } if (m_paused) { // Stream paused. Skip frame process and release the frame. goto ReleaseFrame; } BOOL nearMode; INuiFrameTexture* pTexture; ///FT image texture INuiFrameTexture* pFTTexture; pFTTexture=imageFrame.pFrameTexture; // Get the depth image pixel texture hr = m_pNuiSensor->NuiImageFrameGetDepthImagePixelFrameTexture(m_hStreamHandle, &imageFrame, &nearMode, &pTexture); if (FAILED(hr)) { goto ReleaseFrame; } NUI_LOCKED_RECT lockedRect; ///FT locked rect NUI_LOCKED_RECT FTlockedRect; // Lock the frame data so the Kinect knows not to modify it while we're reading it pTexture->LockRect(0, &lockedRect, NULL, 0); // Lock the FT frame data pFTTexture->LockRect(0, &FTlockedRect, NULL, 0); // Make sure we've received valid data if (lockedRect.Pitch != 0) { // Conver depth data to color image and copy to image buffer m_imageBuffer.CopyDepth(lockedRect.pBits, lockedRect.size, nearMode, m_depthTreatment); // Convert 8 bits depth frame to 12 bits NUI_DEPTH_IMAGE_PIXEL* depthBuffer = (NUI_DEPTH_IMAGE_PIXEL*)lockedRect.pBits; cv::Mat depthMat(m_ImageRes.height, m_ImageRes.width, CV_8UC1); INT cn = 1; for(int i=0;i<depthMat.rows;i++){ for(int j=0;j<depthMat.cols;j++){ USHORT realdepth = ((depthBuffer->depth)&0x0fff); //Taking 12LSBs for depth BYTE intensity = realdepth == 0 || realdepth > 4095 ? 0 : 255 - (BYTE)(((float)realdepth / 4095.0f) * 255.0f);//Scaling to 255 scale grayscale depthMat.data[i*depthMat.cols*cn + j*cn + 0] = intensity; depthBuffer++; } } // Copy FT depth data to IFTImage buffer memcpy(m_pFTdepthBuffer->GetBuffer(), PBYTE(FTlockedRect.pBits), std::min(m_pFTdepthBuffer->GetBufferSize(), UINT(pFTTexture->BufferLen()))); if (m_Recording) { //*m_pcolorImage = depthMat; //cvWriteFrame(m_pwriter,m_pcolorImage); const NUI_SKELETON_FRAME* pSkeletonFrame = m_pPrimaryViewer->getSkeleton(); m_pDepthInbedAPPs->processFrame(depthMat, lockedRect.pBits, m_ImageRes, pSkeletonFrame); //if (m_TimerCount%FramesPerFile==0) //{ // cvReleaseVideoWriter(&m_pwriter); //} } // Draw out the data with Direct2D if (m_pStreamViewer) { m_pStreamViewer->SetImage(&m_imageBuffer); } } // Done with the texture. Unlock and release it pFTTexture->UnlockRect(0); pTexture->UnlockRect(0); pTexture->Release(); ReleaseFrame: // Release the frame m_pNuiSensor->NuiImageStreamReleaseFrame(m_hStreamHandle, &imageFrame); }
/***************************************************************************** * UnregisterServer() ***************************************************************************** */ HRESULT UnregisterServer ( IN LPTSTR TargetSymbolicLink ) { _DbgPrintF(DEBUGLVL_VERBOSE,("[UnregisterServer]")); HRESULT hr = S_OK; HKEY AsioPublicKey = NULL; DWORD w32Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ASIO_PUBLIC_KEY, 0, KEY_ALL_ACCESS, &AsioPublicKey); if (ERROR_SUCCESS == w32Error) { ULONG NumberOfSubKeys = 0; w32Error = RegQueryInfoKey(AsioPublicKey, NULL, NULL, NULL, &NumberOfSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if ((ERROR_SUCCESS == w32Error) && NumberOfSubKeys) { PASIO_DRIVER_INFORMATION DriverInfo = PASIO_DRIVER_INFORMATION(LocalAlloc(LPTR, NumberOfSubKeys * sizeof(ASIO_DRIVER_INFORMATION))); if (DriverInfo) { ZeroMemory(DriverInfo, NumberOfSubKeys * sizeof(ASIO_DRIVER_INFORMATION)); for (ULONG i=0; i<NumberOfSubKeys; i++) { ULONG FriendlyNameLength = MAX_PATH; FILETIME LastWriteTime; w32Error = RegEnumKeyEx(AsioPublicKey, i, DriverInfo[i].FriendlyName, &FriendlyNameLength, NULL, NULL, NULL, &LastWriteTime); } for (ULONG i=0; i<NumberOfSubKeys; i++) { BOOL FoundAsioDriverKey = FALSE; // Open the key up to check if our driver is the owner to this key. HKEY AsioDriverKey = NULL; w32Error = RegOpenKeyEx(AsioPublicKey, DriverInfo[i].FriendlyName, 0, KEY_ALL_ACCESS, &AsioDriverKey); if (ERROR_SUCCESS == w32Error) { ULONG Type = 0; TCHAR AsioMarker[MAX_PATH]; ULONG Size = sizeof(AsioMarker); w32Error = RegQueryValueEx(AsioDriverKey, NULL, 0, &Type, PBYTE(AsioMarker), &Size); if (ERROR_SUCCESS == w32Error) { if (!_tcsicmp(AsioMarker, ASIO_MARKER)) { // Key belong us... ULONG Type = 0; WCHAR ClsIdStr[MAX_PATH]; ULONG Size = sizeof(ClsIdStr); w32Error = RegQueryValueExW(AsioDriverKey, L"CLSID", 0, &Type, PBYTE(ClsIdStr), &Size); if (ERROR_SUCCESS == w32Error) { CLSIDFromString(ClsIdStr, &DriverInfo[i].ClassId); } if (TargetSymbolicLink) { ULONG Type = 0; ULONG Size = sizeof(DriverInfo[i].SymbolicLink); w32Error = RegQueryValueEx(AsioDriverKey, "SymbolicLink", 0, &Type, PBYTE(DriverInfo[i].SymbolicLink), &Size); if (ERROR_SUCCESS == w32Error) { if (!_tcsicmp(TargetSymbolicLink, DriverInfo[i].SymbolicLink)) { FoundAsioDriverKey = TRUE; } } } else { FoundAsioDriverKey = TRUE; } } } RegCloseKey(AsioDriverKey); } if (FoundAsioDriverKey) { UnregisterAsioDriver(DriverInfo[i].FriendlyName, DriverInfo[i].ClassId); } } LocalFree(DriverInfo); } } RegCloseKey(AsioPublicKey); } return hr; }
QList<TokenData> QCNG::tokens() const { qWarning() << "Start enumerationg providers"; QHash<SslCertificate,QCNGCache> cache; DWORD count = 0; NCryptProviderName *names = nullptr; NCryptEnumStorageProviders( &count, &names, NCRYPT_SILENT_FLAG ); for( DWORD i = 0; i < count; ++i ) { qWarning() << "Found provider" << QString::fromWCharArray(names[i].pszName); if( wcscmp( names[i].pszName, MS_SMART_CARD_KEY_STORAGE_PROVIDER ) == 0 ) { for( const QString &reader: QPCSC::instance().readers() ) { qWarning() << reader; QString scope = QString(R"(\\.\%1\)").arg(reader); d->enumKeys( cache, names[i].pszName, LPCWSTR(scope.utf16()) ); } } else d->enumKeys( cache, names[i].pszName ); } NCryptFreeBuffer( names ); d->cache = cache; qWarning() << "End enumerationg providers"; QList<TokenData> result; for(QHash<SslCertificate,QCNGCache>::const_iterator i = cache.constBegin(); i != cache.constEnd(); ++i) { TokenData t; t.setCard(i.key().type() & SslCertificate::EstEidType || i.key().type() & SslCertificate::DigiIDType ? i.value().guid : i.key().subjectInfo(QSslCertificate::CommonName)); t.setCert(i.key()); result << t; } return result; } TokenData QCNG::selectCert( const SslCertificate &cert ) { qWarning() << "Select:" << cert.subjectInfo( "CN" ); if( !d->cache.contains( cert ) ) return TokenData(); d->selected = d->cache[cert]; qWarning() << "Found:" << d->selected.guid << d->selected.key; TokenData t; t.setCard( cert.type() & SslCertificate::EstEidType || cert.type() & SslCertificate::DigiIDType ? d->selected.guid : cert.subjectInfo( QSslCertificate::CommonName ) ); t.setCert( cert ); return t; } QByteArray QCNG::sign( int method, const QByteArray &digest ) const { d->err = PinUnknown; BCRYPT_PKCS1_PADDING_INFO padInfo = { NCRYPT_SHA256_ALGORITHM }; switch( method ) { case NID_sha224: padInfo.pszAlgId = L"SHA224"; break; case NID_sha256: padInfo.pszAlgId = NCRYPT_SHA256_ALGORITHM; break; case NID_sha384: padInfo.pszAlgId = NCRYPT_SHA384_ALGORITHM; break; case NID_sha512: padInfo.pszAlgId = NCRYPT_SHA512_ALGORITHM; break; case NID_md5_sha1: //padInfo.pszAlgId = L"SHAMD5"; break; default: break; } DWORD size = 0; QByteArray res; NCRYPT_KEY_HANDLE k = d->key(); QString algo(5, 0); SECURITY_STATUS err = NCryptGetProperty(k, NCRYPT_ALGORITHM_GROUP_PROPERTY, PBYTE(algo.data()), DWORD((algo.size() + 1) * 2), &size, 0); algo.resize(size/2 - 1); bool isRSA = algo == "RSA"; err = NCryptSignHash(k, isRSA ? &padInfo : nullptr, PBYTE(digest.constData()), DWORD(digest.size()), nullptr, 0, &size, isRSA ? BCRYPT_PAD_PKCS1 : 0); if(FAILED(err)) return res; res.resize(int(size)); err = NCryptSignHash(k, isRSA ? &padInfo : nullptr, PBYTE(digest.constData()), DWORD(digest.size()), PBYTE(res.data()), DWORD(res.size()), &size, isRSA ? BCRYPT_PAD_PKCS1 : 0); NCryptFreeObject( k ); switch( err ) { case ERROR_SUCCESS: d->err = PinOK; return res; case SCARD_W_CANCELLED_BY_USER: d->err = PinCanceled; break; default: res.clear(); break; } return res; }
//************************************************************* void Get_Exception_Info(PEXCEPTION_POINTERS pException, FILE* fp, DWORD dwLastError) //************************************************************* // Allocate Str[DUMP_SIZE_MAX] and return Str with dump, if !pException - just return call stack in Str. { int i; TCHAR Module_Name[MAX_PATH]; PBYTE Module_Addr; HANDLE hFile; FILETIME Last_Write_Time; FILETIME Local_File_Time; SYSTEMTIME T; Get_Version_Str(fp); _ftprintf(fp, _T("------------------------------------------------------------------------------")NL); _ftprintf(fp, _T("Process: ") ); GetModuleFileName(NULL, Module_Name, MAX_PATH); _ftprintf(fp, _T("%s") NL, Module_Name); // If exception occurred. if (pException) { EXCEPTION_RECORD & E = *pException->ExceptionRecord; CONTEXT & C = *pException->ContextRecord; // If module with E.ExceptionAddress found - save its path and date. if (Get_Module_By_Ret_Addr((PBYTE)E.ExceptionAddress, Module_Name, Module_Addr)) { _ftprintf(fp, _T("Module: %s") NL, Module_Name); if ((hFile = CreateFile(Module_Name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE) { if (GetFileTime(hFile, NULL, NULL, &Last_Write_Time)) { FileTimeToLocalFileTime(&Last_Write_Time, &Local_File_Time); FileTimeToSystemTime(&Local_File_Time, &T); _ftprintf(fp, _T("Date Modified: %02d/%02d/%d") NL, T.wMonth, T.wDay, T.wYear); } CloseHandle(hFile); } } else { _ftprintf(fp, _T("Exception Addr: %08X") NL , (LONG_PTR)(E.ExceptionAddress)); } _ftprintf(fp, _T("------------------------------------------------------------------------------")NL); //加入具体异常解释信息 CreateExceptionDesc(pException, fp, dwLastError); _ftprintf(fp, _T("------------------------------------------------------------------------------")NL); // Save instruction that caused exception. if(E.ExceptionAddress) { _ftprintf(fp, _T("Instruction: ")NL); for (i = 0; i < 16; i++) _ftprintf(fp, _T(" %02X"), PBYTE(E.ExceptionAddress)[i]); } // Save registers at exception. _ftprintf(fp, NL _T("Registers:") NL); _ftprintf(fp, _T("EAX: %08X EBX: %08X ECX: %08X EDX: %08X") NL, C.Eax, C.Ebx, C.Ecx, C.Edx); _ftprintf(fp, _T("ESI: %08X EDI: %08X ESP: %08X EBP: %08X")NL, C.Esi, C.Edi, C.Esp, C.Ebp); _ftprintf(fp, _T("EIP: %08X EFlags: %08X")NL, C.Eip, C.EFlags); } //if (pException) _ftprintf(fp, _T("------------------------------------------------------------------------------")NL); // Save call stack info. _ftprintf(fp, _T("Call Stack:")NL); Get_Call_Stack(pException, fp); } //Get_Exception_Info
QString CCrashStack::GetExceptionInfo() { WCHAR Module_Name[MAX_PATH]; PBYTE Module_Addr; QString sRet; char buffer[512]={0}; QString sTmp = GetVersionStr(); sRet.append(sTmp); sRet.append("Process: "); GetModuleFileName(NULL, Module_Name, MAX_PATH); sRet.append(QString::fromWCharArray(Module_Name)); sRet.append("\n"); // If exception occurred. if (m_pException) { EXCEPTION_RECORD & E = *m_pException->ExceptionRecord; CONTEXT & C = *m_pException->ContextRecord; memset(buffer, 0, sizeof(buffer)); sprintf(buffer, "Exception Addr: %08X ", (int)E.ExceptionAddress); sRet.append(buffer); // If module with E.ExceptionAddress found - save its path and date. QString module = GetModuleByRetAddr((PBYTE)E.ExceptionAddress, Module_Addr); if (module.length() > 0) { sRet.append(" Module: "); sRet.append(module); } memset(buffer, 0, sizeof(buffer)); sprintf(buffer, "\nException Code: %08X\n", (int)E.ExceptionCode); sRet.append(buffer); if (E.ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { // Access violation type - Write/Read. memset(buffer, 0, sizeof(buffer)); sprintf(buffer,"%s Address: %08X\n", (E.ExceptionInformation[0]) ? "Write" : "Read", (int)E.ExceptionInformation[1]); sRet.append(buffer); } sRet.append("Instruction: "); for (int i = 0; i < 16; i++) { memset(buffer, 0, sizeof(buffer)); sprintf(buffer, " %02X", PBYTE(E.ExceptionAddress)[i]); sRet.append(buffer); } sRet.append("\nRegisters: "); memset(buffer, 0, sizeof(buffer)); sprintf(buffer, "\nEAX: %08X EBX: %08X ECX: %08X EDX: %08X", (unsigned int)C.Eax,(unsigned int) C.Ebx, (unsigned int)C.Ecx, (unsigned int)C.Edx); sRet.append(buffer); memset(buffer, 0, sizeof(buffer)); sprintf(buffer, "\nESI: %08X EDI: %08X ESP: %08X EBP: %08X", (unsigned int)C.Esi, (unsigned int)C.Edi, (unsigned int)C.Esp, (unsigned int)C.Ebp); sRet.append(buffer); memset(buffer, 0, sizeof(buffer)); sprintf(buffer, "\nEIP: %08X EFlags: %08X", (unsigned int)C.Eip,(unsigned int) C.EFlags); sRet.append(buffer); } //if (pException) sRet.append("\nCall Stack:"); QString sCallstack = this->GetCallStack(m_pException); sRet.append(sCallstack); return sRet; }
virtual PBYTE RawPixelPtr() { return PBYTE(p4); }