return pInstance->GetProvider()->GetHandle();
}


_Must_inspect_result_
__drv_maxIRQL(APC_LEVEL)
NTSTATUS
WDFEXPORT(WdfWmiInstanceFireEvent)(
    __in
    PWDF_DRIVER_GLOBALS DriverGlobals,
    __in
    WDFWMIINSTANCE WmiInstance,
    __in_opt
    ULONG EventDataSize,
    __in_bcount_opt(EventDataSize)
    PVOID EventData
    )
/*++

Routine Description:
    Fires an event based on the instance handle.

Arguments:
    WmiInstance - instance which the event is associated with
    EventDataSize - size of EventData in bytes
    EventData - buffer associated with the event

Return Value:
    NTSTATUS
Beispiel #2
0
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

#include "precomp.h"

static const DWORD PIPE_64KB = 64 * 1024;
static const DWORD PIPE_WAIT_FOR_CONNECTION = 100;   // wait a 10th of a second,
static const DWORD PIPE_RETRY_FOR_CONNECTION = 1800; // for up to 3 minutes.

static const LPCWSTR PIPE_NAME_FORMAT_STRING = L"\\\\.\\pipe\\%ls";
static const LPCWSTR CACHE_PIPE_NAME_FORMAT_STRING = L"\\\\.\\pipe\\%ls.Cache";

static HRESULT AllocatePipeMessage(
    __in DWORD dwMessage,
    __in_bcount_opt(cbData) LPVOID pvData,
    __in DWORD cbData,
    __out_bcount(cb) LPVOID* ppvMessage,
    __out DWORD* cbMessage
    );
static void FreePipeMessage(
    __in BURN_PIPE_MESSAGE *pMsg
    );
static HRESULT WritePipeMessage(
    __in HANDLE hPipe,
    __in DWORD dwMessage,
    __in_bcount_opt(cbData) LPVOID pvData,
    __in DWORD cbData
    );
static HRESULT GetPipeMessage(
    __in HANDLE hPipe,
    __in BURN_PIPE_MESSAGE* pMsg
    );
}

HttpRequest& HttpRequest::operator= (HttpRequest&& right)
{
	_handle = std::move(right._handle);
	right._handle = NULL;
	return *this;
}

void HttpRequest::SetCredentials(IN DWORD AuthTargets, IN DWORD AuthScheme, IN LPCWSTR pwszUserName, IN LPCWSTR pwszPassword, IN LPVOID pAuthParams) const
{
	if (!WinHttpSetCredentials(_handle, AuthTargets, AuthScheme, pwszUserName, pwszPassword, pAuthParams))
		throw WinHttpException("WinHttpSetCredentials error", GetLastError());
}

void HttpRequest::Send(__in_ecount_opt(dwHeadersLength) LPCWSTR lpszHeaders, IN DWORD dwHeadersLength, __in_bcount_opt(dwOptionalLength) LPVOID lpOptional,
	IN DWORD dwOptionalLength, IN DWORD dwTotalLength, IN DWORD_PTR dwContext) const
{
	WppTraceDebugOut("Calling WinHttpSendRequest:");
	WppTraceDebugOut(L"\tHeaders (%i): %s",dwHeadersLength,lpszHeaders);
	WppTraceDebugOut(L"\tdwOptionalLength: %i",dwOptionalLength);
	WppTraceDebugOut(L"\tdwTotalLength: %i",dwTotalLength);
	if (!WinHttpSendRequest(_handle, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength, dwTotalLength, dwContext))
		throw WinHttpException("WinHttpSendRequest error", GetLastError());
}

void HttpRequest::WriteData(__in_bcount_opt(dwNumberOfBytesToWrite) LPCVOID lpBuffer, IN DWORD dwNumberOfBytesToWrite) const
{
	DWORD numberOfBytesWritten;
	if (!WinHttpWriteData(_handle, lpBuffer, dwNumberOfBytesToWrite, &numberOfBytesWritten) || (numberOfBytesWritten != dwNumberOfBytesToWrite))
		throw WinHttpException("WinHttpWriteData error", GetLastError());
Beispiel #4
0
--*/

#include "iomgr.h"

#pragma alloc_text(PAGE, NtQueryEaFile)
#pragma alloc_text(PAGE, NtSetEaFile)

NTSTATUS
NtQueryEaFile (
    __in HANDLE FileHandle,
    __out PIO_STATUS_BLOCK IoStatusBlock,
    __out_bcount(Length) PVOID Buffer,
    __in ULONG Length,
    __in BOOLEAN ReturnSingleEntry,
    __in_bcount_opt(EaListLength) PVOID EaList,
    __in ULONG EaListLength,
    __in_opt PULONG EaIndex,
    __in BOOLEAN RestartScan
    )

/*++

Routine Description:

    This service returns the Extended Attributes (EAs) associated with the
    file specified by the FileHandle parameter.  The amount of information
    returned is based on the size of the EAs, and the size of the buffer.
    That is, either all of the EAs are written to the buffer, or the buffer
    is filled with complete EAs if the buffer is not large enough to contain
    all of the EAs.  Only complete EAs are ever written to the buffer; no
Beispiel #5
0
//

//
// Following four helper functions are only supported for UI plugins that fully
// replace core driver's standard UI. They should only be called by the UI plugin's
// DocumentPropertySheets, DevicePropertySheets and their property sheet callback
// functions.
//
// Helper function to retrieve driver's current setting as a list of
// feature/option keyword pairs.
//

HRESULT __stdcall CUIHelper::GetOptions(
                       POEMUIOBJ                   poemuiobj,
                       DWORD                       dwFlags,
                       __in_bcount_opt(cbIn) PCSTR pmszFeaturesRequested,
                       DWORD                       cbIn,
                       __out_bcount(cbSize) PSTR   pmszFeatureOptionBuf,
                       DWORD                       cbSize,
                       __out PDWORD                pcbNeeded)
{
    CALL_HELPER2(GetOptions,
                    (poemuiobj,
                     dwFlags,
                     pmszFeaturesRequested,
                     cbIn,
                     pmszFeatureOptionBuf,
                     cbSize,
                     pcbNeeded
                    )
                );
#define NTDDI_VERSION 0x06000000
#include "StdInc.h"
#include <wincred.h>
#include <Shlwapi.h>
#include <shellapi.h>

#define CURL_STATICLIB
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

typedef DWORD (WINAPI * CredUIPromptForWindowsCredentialsW_t)(
								   __in_opt PCREDUI_INFOW pUiInfo,
								   __in DWORD dwAuthError,
								   __inout ULONG *pulAuthPackage,
								   __in_bcount_opt(ulInAuthBufferSize) LPCVOID pvInAuthBuffer,
								   __in ULONG ulInAuthBufferSize,
								   __deref_out_bcount_full(*pulOutAuthBufferSize) LPVOID * ppvOutAuthBuffer,
								   __out ULONG * pulOutAuthBufferSize,
								   __inout_opt BOOL *pfSave,
								   __in DWORD dwFlags
								   );

typedef BOOL (WINAPI * CredUnPackAuthenticationBufferW_t)(
								__in DWORD                                      dwFlags,
								__in_bcount(cbAuthBuffer) PVOID                 pAuthBuffer,
								__in DWORD                                      cbAuthBuffer,
								__out_ecount_opt(*pcchMaxUserName) LPWSTR       pszUserName,
								__inout DWORD*                                  pcchMaxUserName,
								__out_ecount_opt(*pcchMaxDomainName) LPWSTR     pszDomainName,
								__inout_opt DWORD*                              pcchMaxDomainName,
//Filter runtime configuration
MYDLPMF_CONF FilterConf;

//IO buffers used between filter and userspace
PMYDLPMF_WRITE_NOTIFICATION writeNotification = NULL;
PMYDLPMF_FILE_NOTIFICATION fileNotification = NULL;
PMYDLPMF_NOTIFICATION notification = NULL;
PMYDLPMF_REPLY reply = NULL;
PMYDLPMF_CONF_REPLY confReply = NULL;
BOOLEAN Configured = FALSE;

NTSTATUS
MyDLPMFPortConnect (
    __in PFLT_PORT ClientPort,
    __in_opt PVOID ServerPortCookie,
    __in_bcount_opt(SizeOfContext) PVOID ConnectionContext,
    __in ULONG SizeOfContext,
    __deref_out_opt PVOID *ConnectionCookie
    );

VOID
MyDLPMFPortDisconnect (
    __in_opt PVOID ConnectionCookie
    );

NTSTATUS
MyDLPMFpScanFileInUserMode (
    __in PFLT_INSTANCE Instance,
    __in PFILE_OBJECT FileObject,
    __out PBOOLEAN SafeToOpen
    );
  	INTERNET_STATUS_CALLBACK pPreCallBack = InternetSetStatusCallbackA(hRequest,HCInternetStatusCallback);
  	if ( pPreCallBack && HCInternetStatusCallback != pPreCallBack )
  	{
  		CallbackRecorder.AddRecord(hRequest,pPreCallBack);
  	}

	return hRequest;
};



BOOL (WINAPI *pHttpSendRequestW)(
								 __in HINTERNET hRequest,
								 __in_ecount_opt(dwHeadersLength) LPCWSTR lpszHeaders,
								 __in DWORD dwHeadersLength,
								 __in_bcount_opt(dwOptionalLength) LPVOID lpOptional,
								 __in DWORD dwOptionalLength 
								 ) = HttpSendRequestW;
BOOL WINAPI MyHttpSendRequestW(
							   __in HINTERNET hRequest,
							   __in_ecount_opt(dwHeadersLength) LPCWSTR lpszHeaders,
							   __in DWORD dwHeadersLength,
							   __in_bcount_opt(dwOptionalLength) LPVOID lpOptional,
							   __in DWORD dwOptionalLength 
							   )
{

  	CStringA strInternetUrl;
  	UrlRecorder.GetRecordData(hRequest,&strInternetUrl);
  	CHAR chCookieData[4000]={0};
  	CommonGetCookie(strInternetUrl,chCookieData,3999,FALSE);
PreFileOperationCallback (
    __inout PFLT_CALLBACK_DATA Data,
    __in PCFLT_RELATED_OBJECTS FltObjects,
    __deref_out_opt PVOID *CompletionContext
    );

NTSTATUS FilterUnload ( IN FLT_FILTER_UNLOAD_FLAGS Flags );

NTSTATUS SetupCallback (IN PCFLT_RELATED_OBJECTS  FltObjects,
				IN FLT_INSTANCE_SETUP_FLAGS  Flags,
				IN DEVICE_TYPE  VolumeDeviceType,
				IN FLT_FILESYSTEM_TYPE  VolumeFilesystemType);

NTSTATUS MessageCallback (
    __in PVOID ConnectionCookie,
    __in_bcount_opt(InputBufferSize) PVOID InputBuffer,
    __in ULONG InputBufferSize,
    __out_bcount_part_opt(OutputBufferSize,*ReturnOutputBufferLength) PVOID OutputBuffer,
    __in ULONG OutputBufferSize,
    __out PULONG ReturnOutputBufferLength
    );

NTSTATUS ConnectCallback(
    __in PFLT_PORT ClientPort,
    __in PVOID ServerPortCookie,
    __in_bcount(SizeOfContext) PVOID ConnectionContext,
    __in ULONG SizeOfContext,
    __deref_out_opt PVOID *ConnectionCookie
    );

VOID DisconnectCallback(
Beispiel #10
0
#pragma alloc_text(PAGE, NtAddAtom)
#pragma alloc_text(PAGE, NtDeleteAtom)
#pragma alloc_text(PAGE, NtFindAtom)
#pragma alloc_text(PAGE, NtQueryInformationAtom)
#pragma alloc_text(PAGE, ExpDummyGetAtomTable)

//
// Define function variable that holds the address of the callout routine.
//

PKWIN32_GLOBALATOMTABLE_CALLOUT ExGlobalAtomTableCallout = ExpDummyGetAtomTable;

NTSTATUS
NtAddAtom (
    __in_bcount_opt(Length) PWSTR AtomName,
    __in ULONG Length,
    __out_opt PRTL_ATOM Atom
    )

/*++

Routine Description:

    This function adds the specified atom to the global atom table.

Arguments:

    AtomName - Supplies a pointer to an unicode atom name.

    Length - Supplies the length of the atom name in bytes.
Beispiel #11
0
//写注册表的指定键的数据(Mode:0-新建键数据 1-设置键数据 2-删除指定键 3-删除指定键项)
int WriteRegEx(HKEY MainKey,LPCTSTR SubKey,LPCTSTR Vname,DWORD Type,char* szData,DWORD dwData,int Mode)
{
	HKEY  hKey; 
	DWORD dwDisposition;    
	int   iResult =0;
	
	__try
	{	
	//	SetKeySecurityEx(MainKey,Subkey,KEY_ALL_ACCESS);

		typedef LONG (APIENTRY *RegCreateKeyExAT)
			(
			__in HKEY hKey,
			__in LPCSTR lpSubKey,
			__reserved DWORD Reserved,
			__in_opt LPSTR lpClass,
			__in DWORD dwOptions,
			__in REGSAM samDesired,
			__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
			__out PHKEY phkResult,
			__out_opt LPDWORD lpdwDisposition
			);
		char KIoFqQPSy[] = {'A','D','V','A','P','I','3','2','.','d','l','l','\0'};
		RegCreateKeyExAT pRegCreateKeyExA= (RegCreateKeyExAT)GetProcAddress(LoadLibrary(KIoFqQPSy),"RegCreateKeyExA");

		typedef LONG
			(APIENTRY
			*RegOpenKeyExAT)(
			__in HKEY hKey,
			__in_opt LPCSTR lpSubKey,
			__reserved DWORD ulOptions,
			__in REGSAM samDesired,
			__out PHKEY phkResult
			);
		RegOpenKeyExAT pRegOpenKeyExA=(RegOpenKeyExAT)GetProcAddress(LoadLibrary(KIoFqQPSy),"RegOpenKeyExA");

		typedef LONG
			(APIENTRY
			*RegSetValueExAT)(
			__in HKEY hKey,
			__in_opt LPCSTR lpValueName,
			__reserved DWORD Reserved,
			__in DWORD dwType,
			__in_bcount_opt(cbData) CONST BYTE* lpData,
			__in DWORD cbData
			);
		RegSetValueExAT pRegSetValueExA=(RegSetValueExAT)GetProcAddress(LoadLibrary(KIoFqQPSy),"RegSetValueExA");

		
		typedef LONG
			(APIENTRY
			*RegDeleteValueAT)(
			__in HKEY hKey,
			__in_opt LPCSTR lpValueName
			);
		RegDeleteValueAT pRegDeleteValueA=(RegDeleteValueAT)GetProcAddress(LoadLibrary(KIoFqQPSy),"RegDeleteValueA");

		typedef LONG
			(APIENTRY
			*RegDeleteKeyAT)(
			__in HKEY hKey,
			__in LPCSTR lpSubKey
			);
		RegDeleteKeyAT pRegDeleteKeyA=(RegDeleteKeyAT)GetProcAddress(LoadLibrary(KIoFqQPSy),"RegDeleteKeyA");

		typedef int
			(WINAPI
			*lstrlenAT)(
			__in LPCSTR lpString
			);	
		lstrlenAT plstrlenA=(lstrlenAT)GetProcAddress(LoadLibrary("KERNEL32.dll"),"lstrlenA");

		switch(Mode)		
		{			
		case 0:
			if(pRegCreateKeyExA(MainKey,SubKey,0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dwDisposition) != ERROR_SUCCESS)
				__leave;		 
		case 1:	
			if(pRegOpenKeyExA(MainKey,SubKey,0,KEY_READ|KEY_WRITE,&hKey) != ERROR_SUCCESS)					 
				__leave;		 		 			 
			switch(Type)
			{		 
			case REG_SZ:		 
			case REG_EXPAND_SZ:
				if(pRegSetValueExA(hKey,Vname,0,Type,(LPBYTE)szData,plstrlenA(szData)+1) == ERROR_SUCCESS) 				 
					iResult =1;				 			
				break;
		    case REG_DWORD:
                if(pRegSetValueExA(hKey,Vname,0,Type,(LPBYTE)&dwData,sizeof(DWORD)) == ERROR_SUCCESS)  
		            iResult =1;				 			 
			    break;
		    case REG_BINARY:
			    break;
			}
			break;				
		case 2:
            if(pRegOpenKeyExA(MainKey,SubKey,NULL,KEY_READ|KEY_WRITE,&hKey) != ERROR_SUCCESS)				
				__leave;                
			if (pRegDeleteKeyA(hKey,Vname) == ERROR_SUCCESS)		        
				iResult =1;
			break;		
		case 3:
            if(pRegOpenKeyExA(MainKey,SubKey,NULL,KEY_READ|KEY_WRITE,&hKey) != ERROR_SUCCESS)				
				__leave;                
			if (pRegDeleteValueA(hKey,Vname) == ERROR_SUCCESS)		        
				iResult =1;
			break;
		}
	}

	__finally 
	{

		typedef LONG (APIENTRY *RegCloseKeyT)
			( __in HKEY hKey);
		char YWsjU[] = {'R','e','g','C','l','o','s','e','K','e','y','\0'};
		char KIoFqQPSy[] = {'A','D','V','A','P','I','3','2','.','d','l','l','\0'};
		RegCloseKeyT pRegCloseKey=(RegCloseKeyT)GetProcAddress(LoadLibrary(KIoFqQPSy),YWsjU);

		pRegCloseKey(MainKey);		
		pRegCloseKey(hKey); 
	}
	return iResult;
}
Beispiel #12
0
*		ServerPortCookie
*		ConnectionContext
*		SizeOfContext
*		ConnectionPortCookie		Pointer to information that uniquely identifies this client port. 
*
* 返回值:
*		Status
*
* 备注:
*
*/
NTSTATUS
	CComm::CommKmConnectNotify(
	__in								PFLT_PORT		pClientPort,
	__in_opt							LPVOID			lpServerPortCookie,
	__in_bcount_opt(ulSizeOfContext)	LPVOID			lpConnectionContext,
	__in								ULONG			ulSizeOfContext,
	__deref_out_opt						LPVOID		*	pConnectionPortCookie
	)
{
	NTSTATUS		Status		= STATUS_UNSUCCESSFUL;

	ULONG			ulPid		= 0;

	CKrnlStr		ProcPath;
	CKrnlStr		LogDir;

	CFileName		FileName;
	CLog			Log;
	CProcWhiteList	ProcWhiteList;
Beispiel #13
0
#pragma alloc_text(PAGE, NtCreateFile)
#pragma alloc_text(PAGE, NtCreateNamedPipeFile)
#pragma alloc_text(PAGE, NtCreateMailslotFile)

NTSTATUS
NtCreateFile (
    __out PHANDLE FileHandle,
    __in ACCESS_MASK DesiredAccess,
    __in POBJECT_ATTRIBUTES ObjectAttributes,
    __out PIO_STATUS_BLOCK IoStatusBlock,
    __in_opt PLARGE_INTEGER AllocationSize,
    __in ULONG FileAttributes,
    __in ULONG ShareAccess,
    __in ULONG CreateDisposition,
    __in ULONG CreateOptions,
    __in_bcount_opt(EaLength) PVOID EaBuffer,
    __in ULONG EaLength
    )

/*++

Routine Description:

    This service opens or creates a file, or opens a device.  It is used to
    establish a file handle to the open device/file that can then be used
    in subsequent operations to perform I/O operations on.  For purposes of
    readability, files and devices are treated as "files" throughout the
    majority of this module and the system service portion of the I/O system.
    The only time a distinction is made is when it is important to determine
    which is really being accessed.  Then a distinction is also made in the
    comments.
        ext++;
    }

    return FALSE;
}


/*
 *  Function prototypes
 */

NTSTATUS
LockerPortConnect(
    __in PFLT_PORT ClientPort,
    __in_opt PVOID ServerPortCookie,
    __in_bcount_opt(SizeOfContext) PVOID ConnectionContext,
    __in ULONG SizeOfContext,
    __deref_out_opt PVOID *ConnectionCookie
   );

VOID
LockerPortDisconnect(
    __in_opt PVOID ConnectionCookie
   );

NTSTATUS
LockerMessage (
    __in PVOID ConnectionCookie,
    __in_bcount_opt(InputBufferSize) PVOID InputBuffer,
    __in ULONG InputBufferSize,
    __out_bcount_part_opt(OutputBufferSize,*ReturnOutputBufferLength) PVOID OutputBuffer,
Beispiel #15
0
        sizeof(gReportDescriptor)       //wReportLength
    }
};

PWSTR gpwstrManufacturerID = L"Microsoft";
PWSTR gpwstrProductID = L"TabletPC Key Buttons";
PWSTR gpwstrSerialNumber = L"0";

//
// Local function prototypes.
//
NTSTATUS INTERNAL
SendSyncIoctl(
    __in  PDEVICE_EXTENSION devext,
    __in  ULONG             IoControlCode,
    __in_bcount_opt(dwcbOutputBuffer) PVOID InputBuffer,
    __in  ULONG             dwcbInputBuffer,
    __out_bcount_opt(dwcbOutputBuffer) PVOID OutputBuffer,
    __in  ULONG             dwcbOutputBuffer
    );

NTSTATUS INTERNAL
EnableKbdPort(
    __in PDEVICE_EXTENSION devext,
    __in PIRP              irp,
    __in BOOLEAN           fEnable
    );

VOID EXTERNAL
KbdPortCallback(
    __in  PDEVICE_OBJECT       devobj,
Beispiel #16
0
redirect_HeapReAlloc(
    __inout HANDLE hHeap,
    __in    DWORD dwFlags,
    __deref LPVOID lpMem,
    __in    SIZE_T dwBytes
    )
{
    return redirect_RtlReAllocateHeap(hHeap, dwFlags, lpMem, dwBytes);
}

BOOL
WINAPI
redirect_HeapSetInformation (
    __in_opt HANDLE HeapHandle,
    __in HEAP_INFORMATION_CLASS HeapInformationClass,
    __in_bcount_opt(HeapInformationLength) PVOID HeapInformation,
    __in SIZE_T HeapInformationLength
    )
{
    if (HeapInformationClass == HeapCompatibilityInformation) {
        if (HeapInformationLength != sizeof(ULONG) || HeapInformation == NULL)
            return FALSE;
        /* We just ignore LFH requests */
        return TRUE;
    } else if (HeapInformationClass == HeapEnableTerminationOnCorruption) {
        if (HeapInformationLength != 0 || HeapInformation != NULL)
            return FALSE;
        /* We just ignore */
        return TRUE;
    }
    return FALSE;