I N C L U D E S *****************************************************************************/ #include "uvcview.h" /***************************************************************************** DriverNameToDeviceInst() Finds the Device instance of the DevNode with the matching DriverName. Returns FALSE if the matching DevNode is not found and TRUE if found *****************************************************************************/ BOOL DriverNameToDeviceInst( _In_reads_bytes_(cbDriverName) PCHAR DriverName, _In_ size_t cbDriverName, _Out_ HDEVINFO *pDevInfo, _Out_writes_bytes_(sizeof(SP_DEVINFO_DATA)) PSP_DEVINFO_DATA pDevInfoData ) { HDEVINFO deviceInfo = INVALID_HANDLE_VALUE; BOOL status = TRUE; ULONG deviceIndex; SP_DEVINFO_DATA deviceInfoData; BOOL bResult = FALSE; PCHAR pDriverName = NULL; PSTR buf = NULL; BOOL done = FALSE; if (pDevInfo == NULL)
// Private scanner-specific fields begin here. // ULONG ThreadId; } SCANNER_REPLY_MESSAGE, *PSCANNER_REPLY_MESSAGE; #define SCANNER_REPLY_MESSAGE_SIZE (sizeof(FILTER_REPLY_HEADER) + sizeof(ULONG)) // // Local routines // AVSCAN_RESULT UserScanMemoryStream( _In_reads_bytes_(Size) PUCHAR StartingAddress, _In_ SIZE_T Size, _Inout_ PBOOLEAN pAbort ); HRESULT UserScanHandleStartScanMsg( _In_ PUSER_SCAN_CONTEXT Context, _In_ PSCANNER_MESSAGE Message, _In_ PSCANNER_THREAD_CONTEXT ThreadCtx ); HRESULT UserScanWorker ( _Inout_ PUSER_SCAN_CONTEXT Context );
// Prints error information to the console // //---------------------------------------------------------------------------- void ReportError( _In_ DWORD dwErrCode ) { wprintf( L"Error: 0x%08x (%d)\n", dwErrCode, dwErrCode ); } NTSTATUS EncryptData( _In_ BCRYPT_KEY_HANDLE KeyHandle, _In_ DWORD KeyObjectLength, _In_reads_bytes_(InitVectorLength) PBYTE InitVector, _In_ DWORD InitVectorLength, _In_reads_bytes_(ChainingModeLength) PBYTE ChainingMode, _In_ DWORD ChainingModeLength, _In_reads_bytes_(PlainTextLength) PBYTE PlainText, _In_ DWORD PlainTextLength, _Outptr_result_bytebuffer_(*CipherTextLengthPointer) PBYTE *CipherTextPointer, _Out_ DWORD *CipherTextLengthPointer ) { NTSTATUS Status;
_In_ DWORD dwErrCode ) { wprintf( L"Error: 0x%08x (%d)\n", dwErrCode, dwErrCode ); } //---------------------------------------------------------------------------- // // ComputeHash // Computes the hash of a message using SHA-256 // //---------------------------------------------------------------------------- NTSTATUS ComputeHash( _In_reads_bytes_(DataLength) PBYTE Data, _In_ DWORD DataLength, _Outptr_result_bytebuffer_maybenull_(*DataDigestLengthPointer) PBYTE *DataDigestPointer, _Out_ DWORD *DataDigestLengthPointer ) { NTSTATUS Status; BCRYPT_ALG_HANDLE HashAlgHandle = NULL; BCRYPT_HASH_HANDLE HashHandle = NULL; PBYTE HashDigest = NULL; DWORD HashDigestLength = 0;
VOID NTAPI RtlpFreeMemory ( _In_ PVOID Mem, _In_ ULONG Tag ) { UNREFERENCED_PARAMETER(Tag); BlMmFreeHeap(Mem); } NTSTATUS NTAPI RtlpSafeCopyMemory ( _Out_writes_bytes_all_(Length) VOID UNALIGNED *Destination, _In_reads_bytes_(Length) CONST VOID UNALIGNED *Source, _In_ SIZE_T Length ) { RtlCopyMemory(Destination, Source, Length); return STATUS_SUCCESS; } VOID NTAPI RtlAssert ( IN PVOID FailedAssertion, IN PVOID FileName, IN ULONG LineNumber, IN PCHAR Message OPTIONAL )
None Return Value None --*/ { printf( "Connects to the scanner filter and scans buffers \n" ); printf( "Usage: scanuser [requests per thread] [number of threads(1-64)]\n" ); } BOOL ScanBuffer ( _In_reads_bytes_(BufferSize) PUCHAR Buffer, _In_ ULONG BufferSize ) /*++ Routine Description Scans the supplied buffer for an instance of FoulString. Note: Pattern matching algorithm used here is just for illustration purposes, there are many better algorithms available for real world filters Arguments Buffer - Pointer to buffer BufferSize - Size of passed in buffer
return E_POINTER; for( size_t y = 0; y < image->height; ++y ) { _CopyScanline( pPixels, image->rowPitch, pPixels, image->rowPitch, image->format, TEXP_SCANLINE_SETALPHA ); pPixels += image->rowPitch; } return S_OK; } //------------------------------------------------------------------------------------- // Uncompress pixel data from a TGA into the target image //------------------------------------------------------------------------------------- static HRESULT _UncompressPixels( _In_reads_bytes_(size) LPCVOID pSource, size_t size, _In_ const Image* image, _In_ DWORD convFlags ) { assert( pSource && size > 0 ); if ( !image || !image->pixels ) return E_POINTER; // Compute TGA image data pitch size_t rowPitch; if ( convFlags & CONV_FLAGS_EXPAND ) { rowPitch = image->width * 3; } else { size_t slicePitch;
* receive data from the device * cbOutDataSize - caller-supplied length, in bytes, of the buffer * pointed to by lpOutData * pdwActualData - receives the number of bytes actually written to pOutData * * Return Value: * * If the operation succeeds, the method must return S_OK. Otherwise, it * should return one of the STIERR-prefixed error codes defined in stierr.h * or another standard COM error code. This driver returns STIERR_UNSUPPORTED. * \**************************************************************************/ HRESULT CWiaDriver::Escape( STI_RAW_CONTROL_CODE EscapeFunction, _In_reads_bytes_(cbInDataSize) LPVOID lpInData, DWORD cbInDataSize, _Out_writes_bytes_(cbOutDataSize) LPVOID pOutData, DWORD cbOutDataSize, _Out_ LPDWORD pdwActualData) { UNREFERENCED_PARAMETER(EscapeFunction); UNREFERENCED_PARAMETER(cbInDataSize); UNREFERENCED_PARAMETER(lpInData); UNREFERENCED_PARAMETER(cbOutDataSize); UNREFERENCED_PARAMETER(pOutData); WIAEX_ERROR((g_hInst, "This method is not implemented or supported for this driver"));
szFileName - The name of the part pBuffer - The buffer containing the part data cbBuffer - The size of the data buffer eCompType - The requested compression type Return Value: HRESULT S_OK - On success E_* - On error --*/ HRESULT CXPSArchive::SendFile( _In_z_ PCSTR szFileName, _In_reads_bytes_(cbBuffer) PVOID pBuffer, _In_ ULONG cbBuffer, _In_ ECompressionType eCompType ) { HRESULT hr = S_OK; if (SUCCEEDED(hr = CHECK_POINTER(m_pPkArchive, E_NOINTERFACE)) && SUCCEEDED(hr = CHECK_POINTER(szFileName, E_POINTER)) && SUCCEEDED(hr = CHECK_POINTER(pBuffer, E_POINTER))) { if (eCompType == CompDeflated || eCompType == CompNone) { try {
#endif /* NSP_REDIRECT */ End: if (wsaErr != 0) { WSASetLastError(wsaErr); return SOCKET_ERROR; } return NO_ERROR; } INT WSAAPI mwsNSPIoCtl(_In_ HANDLE hLookup, _In_ DWORD dwControlCode, _In_reads_bytes_(cbInBuffer) LPVOID lpvInBuffer, _In_ DWORD cbInBuffer, _Out_writes_bytes_to_(cbOutBuffer, *lpcbBytesReturned) LPVOID lpvOutBuffer, _In_ DWORD cbOutBuffer, _Out_ LPDWORD lpcbBytesReturned, _In_opt_ LPWSACOMPLETION lpCompletion, _In_ LPWSATHREADID lpThreadId) { WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED); return ERROR_CALL_NOT_IMPLEMENTED; } INT WSAAPI mwsNSPLookupServiceEnd(_In_ HANDLE hLookup) {
OnRemoveCanceled( _In_ WUDF_TARGET_CONTEXT RegistrationID ); VOID __stdcall OnRemoveComplete( _In_ WUDF_TARGET_CONTEXT RegistrationID ); VOID __stdcall OnCustomEvent( _In_ WUDF_TARGET_CONTEXT RegistrationID, _In_ REFGUID Event, _In_reads_bytes_(DataSize) BYTE * Data, _In_ DWORD DataSize, _In_ DWORD NameBufferOffset ); HRESULT __stdcall QueryInterface( __in const IID& iid, __out void ** ppv ) { if (NULL == ppv) { return E_INVALIDARG; }
ptMessageTable = NULL; eStatus = STATUS_SUCCESS; lblCleanup: #pragma warning(suppress: 4133) // warning C4133: 'function': incompatible types - from 'PMESSAGE_TABLE' to 'HMESSAGETABLE' CLOSE(ptMessageTable, MESSAGETABLE_Destroy); return eStatus; } _IRQL_requires_(PASSIVE_LEVEL) PAGEABLE NTSTATUS MESSAGETABLE_CreateFromResource( _In_reads_bytes_(cbMessageTableResource) PVOID pvMessageTableResource, _In_ ULONG cbMessageTableResource, _In_ BOOLEAN bCompact, _Out_ PHMESSAGETABLE phMessageTable ) { NTSTATUS eStatus = STATUS_UNSUCCESSFUL; HMESSAGETABLE hMessageTable = NULL; PCMESSAGE_RESOURCE_DATA ptResourceData = (PCMESSAGE_RESOURCE_DATA)pvMessageTableResource; ULONG nCurrentBlock = 0; PCMESSAGE_RESOURCE_BLOCK ptCurrentBlock = NULL; ULONG nCurrentId = 0; PCMESSAGE_RESOURCE_ENTRY ptCurrentEntry = NULL; ASSERT(PASSIVE_LEVEL == KeGetCurrentIrql());
{ RtlZeroMemory(m_Payload, sizeof(m_Payload)); InitializeListHead(&m_ListEntry); m_dwSequenceNum = m_pSmartCard->AddRequest(this); } CSmartCardRequest::~CSmartCardRequest() { m_pSmartCard->RemoveRequest(this); SAFE_CLOSEHANDLE(m_hCompletionEvent); } VOID CSmartCardRequest::CompleteRequest( _In_ DWORD cbPayload, _In_reads_bytes_(cbPayload) PBYTE pbPayload ) { RtlZeroMemory(m_Payload, sizeof(m_Payload)); if (cbPayload <= sizeof(m_Payload)) { RtlCopyMemory(m_Payload, pbPayload, cbPayload); m_cbPayload = cbPayload; } SetEvent(m_hCompletionEvent); } NTSTATUS CSmartCardRequest::WaitForCompletion() { return (WaitForSingleObject(m_hCompletionEvent, ResponseTimeoutInMs) == WAIT_OBJECT_0) ? STATUS_SUCCESS : STATUS_IO_TIMEOUT;
case Microsoft::Console::Interactivity::ApiLevel::Win32: fIsDesktop = true; break; } } fAlreadyQueried = true; } return fIsDesktop; } [[nodiscard]] NTSTATUS SetUpConsole(_Inout_ Settings* pStartupSettings, _In_ DWORD TitleLength, _In_reads_bytes_(TitleLength) LPWSTR Title, _In_ LPCWSTR CurDir, _In_ LPCWSTR AppName) { // We will find and locate all relevant preference settings and then create the console here. // The precedence order for settings is: // 0. Launch arguments passed on the commandline. // 1. STARTUPINFO settings // 2a. Shortcut/Link settings // 2b. Registry specific settings // 3. Registry default settings // 4. Hardcoded default settings // To establish this hierarchy, we will need to load the settings and apply them in reverse order. // 4. Initializing Settings will establish hardcoded defaults. // Set to reference of global console information since that's the only place we need to hold the settings.
0 ); if (!NT_SUCCESS(ntStatus)) { DPF(D_TERSE, ("[CSaveData::FileOpen : Error opening data file]")); } } return ntStatus; } // FileOpen //============================================================================= NTSTATUS CSaveData::FileWrite ( _In_reads_bytes_(ulDataSize) PBYTE pData, _In_ ULONG ulDataSize ) { PAGED_CODE(); ASSERT(pData); ASSERT(m_pFilePtr); NTSTATUS ntStatus; if (m_FileHandle) { IO_STATUS_BLOCK ioStatusBlock; ntStatus = ZwWriteFile( m_FileHandle,
{ if (pStopBssReq) { FREE_MEM(pStopBssReq); } } return ndisStatus; } NDIS_STATUS VNicAllocateDefaultKeyReq( _In_ PVNIC pVNic, _In_ PNDIS_EVENT CompletionEvent, _In_reads_bytes_(DOT11_ADDRESS_SIZE) DOT11_MAC_ADDRESS MacAddr, _In_ ULONG KeyID, _In_ BOOLEAN Persistent, _In_ DOT11_CIPHER_ALGORITHM AlgoId, _In_ ULONG KeyLength, _In_reads_bytes_(KeyLength) PUCHAR KeyValue, PDEF_KEY_REQ *ppDefKeyReq ) { NDIS_STATUS ndisStatus = NDIS_STATUS_SUCCESS; PDEF_KEY_REQ pDefKeyReq = NULL; do { *ppDefKeyReq = NULL;
#include "processmod.h" #include "logger.h" BOOL __declspec(dllexport) __stdcall _writeProcessMemory( IN HANDLE hProcess, IN LPVOID lpBaseAddress, _In_reads_bytes_(nSize) LPCVOID lpBuffer, IN SIZE_T nSize, _Out_opt_ SIZE_T * lpNumberOfBytesWritten ) { Logger::logged_binary_dump(DIRNAME, "write_mem", "[PROCESSWRITE]", (BYTE*)lpBuffer, nSize); if (search_pe_hdr((BYTE*)lpBuffer, nSize)) { Logger::append("[PROCESSWRITE] PE HEADER detected!"); } BOOL res = WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesWritten); if (res == FALSE) Logger::append("[PROCESSWRITE] Failed"); return res; }
RingBuffer.c Abstract: This file implements the Ring Buffer Environment: --*/ #include "internal.h" VOID RingBufferInitialize( _In_ PRING_BUFFER Self, _In_reads_bytes_(BufferSize) BYTE* Buffer, _In_ size_t BufferSize ) { Self->Size = BufferSize; Self->Base = Buffer; Self->End = Buffer + BufferSize; Self->Head = Buffer; Self->Tail = Buffer; } VOID RingBufferGetAvailableSpace( _In_ PRING_BUFFER Self,
Return Value: None --*/ { // Service the interrupt message queue to drain any outstanding // requests OsrUsbIoctlGetInterruptMessage(Device, STATUS_DEVICE_REMOVED); } _IRQL_requires_(PASSIVE_LEVEL) USBD_STATUS OsrFxValidateConfigurationDescriptor( _In_reads_bytes_(BufferLength) PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, _In_ ULONG BufferLength, _Inout_ PUCHAR *Offset ) /*++ Routine Description: Validates a USB Configuration Descriptor Parameters: ConfigDesc: Pointer to the entire USB Configuration descriptor returned by the device BufferLength: Known size of buffer pointed to by ConfigDesc (Not wTotalLength)
if (FAILED(hr)) { if (buffer) { delete[] buffer; m_Base = NULL; } } return hr; } HRESULT CRingBuffer::Write( _In_reads_bytes_(DataSize) PBYTE Data, _In_ SIZE_T DataSize ) { SIZE_T availableSpace; SIZE_T bytesToCopy; SIZE_T spaceFromCurrToEnd; WUDF_TEST_DRIVER_ASSERT(Data && (0 != DataSize)); if (m_Tail >= m_End) { return E_UNEXPECTED; } //
// Remove any private key that may still be around if (PeerNode->PrivateKeyTable[i].Key.Valid) { HwFreeKey(&PeerNode->PrivateKeyTable[i]); } } PeerNode->Valid = FALSE; PeerNode->AssociateId = 0; HwMac->PeerNodeCount--; } } PHW_PEER_NODE HwFindPeerNode( _In_ PHW_MAC_CONTEXT HwMac, _In_reads_bytes_(DOT11_ADDRESS_SIZE) DOT11_MAC_ADDRESS MacAddr, _In_ BOOLEAN Allocate ) { UCHAR index; UCHAR emptyIndex; PHW_PEER_NODE peerNode = NULL; // // Search the peer key table to find the matching peer node // emptyIndex = HW11_PEER_TABLE_SIZE; for (index = 0; index < HW11_PEER_TABLE_SIZE; index++) { if ((HwMac->PeerTable[index].Valid) &&
#include "datapath.tmh" #ifdef LOG_BUFFERS __forceinline CHAR ToHex(CHAR n) { if (n > 9) return 'A' + (n - 10); else return '0' + n; } #define otLogLineLength 32 // Helper to log a buffer void otLogBuffer( _In_reads_bytes_(BufferLength) PUCHAR Buffer, _In_ ULONG BufferLength ) { ULONG index = 0; while (index < BufferLength) { CHAR szBuffer[otLogLineLength * 4] = " "; PCHAR buf = szBuffer + 2; for (ULONG i = 0; i < otLogLineLength && i + index < BufferLength; i++) { buf[0] = ToHex(Buffer[i + index] >> 4); buf[1] = ToHex(Buffer[i + index] & 0x0F); buf[2] = ' '; buf += 3; }
} if (LocalValueName.Buffer != NULL) { FreeCapturedUnicodeString(&LocalValueName, REGFLTR_CAPTURE_POOL_TAG); } return Status; } NTSTATUS CaptureBuffer( _Outptr_result_maybenull_ PVOID *CapturedBuffer, _In_reads_bytes_(Length) PVOID Buffer, _In_ SIZE_T Length, _In_ ULONG PoolTag ) /*++ Routine Description: Captures a buffer using allocations with the specified pool tag. Captured buffer should be freed using FreeCapturedBuffer. Arguments: CapturedBuffer - pointer to a variable that receives the location of the captured buffer.
pPayload = CPayload::FromListEntry(m_Queue.Flink); if (CompleteRequest(pPayload->GetSize(), pPayload->GetPayload())) { m_dwQueueSize--; RemoveHeadList(&m_Queue); delete pPayload; } } } Exit: LeaveCriticalSection(&m_RoleLock); MethodReturn(Status, "Status = %!STATUS!", Status); } NTSTATUS CFileObject::SetPayload(_In_ DWORD cbPayload, _In_reads_bytes_(cbPayload) PBYTE pbPayload) { MethodEntry("..."); NTSTATUS Status = STATUS_SUCCESS; EnterCriticalSection(&m_RoleLock); NT_ASSERT(IsPublication()); if (m_Payload.GetPayload() != nullptr) { Status = STATUS_INVALID_DEVICE_STATE; goto Exit; } Status = m_Payload.Initialize(cbPayload, pbPayload);
NTSTATUS SpyMessage ( _In_ PVOID ConnectionCookie, _In_reads_bytes_opt_(InputBufferSize) PVOID InputBuffer, _In_ ULONG InputBufferSize, _Out_writes_bytes_to_opt_(OutputBufferSize,*ReturnOutputBufferLength) PVOID OutputBuffer, _In_ ULONG OutputBufferSize, _Out_ PULONG ReturnOutputBufferLength ); NTSTATUS SpyConnect( _In_ PFLT_PORT ClientPort, _In_ PVOID ServerPortCookie, _In_reads_bytes_(SizeOfContext) PVOID ConnectionContext, _In_ ULONG SizeOfContext, _Flt_ConnectionCookie_Outptr_ PVOID *ConnectionCookie ); VOID SpyDisconnect( _In_opt_ PVOID ConnectionCookie ); NTSTATUS SpyEnlistInTransaction ( _In_ PCFLT_RELATED_OBJECTS FltObjects ); //---------------------------------------------------------------------------
inputfile.read(reinterpret_cast<char*>(buffer.data()), buffer.size()); inputfile.close(); } } void WriteBufferToFile(_In_ std::wstring path, _In_ std::vector<uint8_t>& buffer) { std::ofstream outputfile(path,std::ios_base::binary); if (outputfile.is_open()) { outputfile.write(reinterpret_cast<char*>(buffer.data()), buffer.size()); outputfile.close(); } } void WriteBufferToFile(_In_ std::wstring path, _In_reads_bytes_(bufferSize) uint8_t* buffer, _In_ uint32_t bufferSize) { std::ofstream outputfile(path,std::ios_base::binary); if (outputfile.is_open()) { outputfile.write(reinterpret_cast<char*>(buffer), bufferSize); outputfile.close(); } } void WriteTextureToFile(_In_ std::wstring path, _In_ std::shared_ptr<GDK::TextureContent>& content) { std::ofstream outputfile(path,std::ios_base::binary); if (outputfile.is_open()) { content->Save(outputfile);
Irp->IoStatus.Status = Status; Irp->IoStatus.Information = InfoLength; IoCompleteRequest(Irp, IO_NO_INCREMENT); return Status; } _IRQL_requires_max_(DISPATCH_LEVEL) PMS_FILTER filterFindFilterModule( _In_reads_bytes_(BufferLength) PUCHAR Buffer, _In_ ULONG BufferLength ) { PMS_FILTER pFilter; PLIST_ENTRY Link; BOOLEAN bFalse = FALSE; FILTER_ACQUIRE_LOCK(&FilterListLock, bFalse); Link = FilterModuleList.Flink; while (Link != &FilterModuleList) {
_Out_ A_SHA_CTX *Context ) { /* SHA1 initialization constants */ Context->state[0] = 0x67452301; Context->state[1] = 0xEFCDAB89; Context->state[2] = 0x98BADCFE; Context->state[3] = 0x10325476; Context->state[4] = 0xC3D2E1F0; Context->count[0] = 0; Context->count[1] = 0; } VOID A_SHAUpdate( _Inout_ A_SHA_CTX *Context, _In_reads_bytes_(Length) UCHAR *Input, _In_ ULONG Length ) { ULONG InputContentSize; InputContentSize = Context->count[1] & 63; Context->count[1] += Length; if (Context->count[1] < Length) Context->count[0]++; Context->count[0] += (Length >> 29); if (InputContentSize + Length < 64) { RtlCopyMemory(&Context->buffer[InputContentSize], Input, Length);
Environment: Kernel mode --*/ #include "avscan.h" // // Local routines prototypes. // AVSCAN_RESULT AvScanMemoryStream( _In_reads_bytes_(Size) PVOID StartingAddress, _In_ SIZE_T Size, _In_ PBOOLEAN OperationCanceled ); NTSTATUS AvMapSectionAndScan( _Inout_ PAV_SECTION_CONTEXT SectionContext, _Out_ AVSCAN_RESULT *ScanResult ); // // Routine implementaions // AVSCAN_RESULT
* to do this it does the following: * * - Deserializes pBuffer into an IPortableDeviceValues which holds the command * input parameters from the WPD application. * - Creates an IPortableDeviceValues for the results. * - Calls the WpdBaseDriver to handle the message. (The results of this * operation are put into the previously created results IPortableDeviceValues.) * - The results IPortableDeviceValues is then serialized back into pBuffer, making * sure that it does not overrun ulOutputBufferLength. * *****************************************************************************/ HRESULT CQueue::ProcessWpdMessage( ULONG ControlCode, _In_ ContextMap* pClientContextMap, _In_ IWDFDevice* pDevice, _In_reads_bytes_(ulInputBufferLength) PVOID pInBuffer, ULONG ulInputBufferLength, _Out_writes_bytes_to_(ulOutputBufferLength, *pdwBytesWritten) PVOID pOutBuffer, ULONG ulOutputBufferLength, _Out_ DWORD* pdwBytesWritten) { HRESULT hr = S_OK; CComPtr<IPortableDeviceValues> pParams; CComPtr<IPortableDeviceValues> pResults; CComPtr<WpdBaseDriver> pWpdBaseDriver; *pdwBytesWritten = 0; if (hr == S_OK) { hr = m_pWpdSerializer->GetIPortableDeviceValuesFromBuffer((BYTE*)pInBuffer,