Code Monkey home page Code Monkey logo

windevzero's Introduction

\Device\Zero Driver

This driver is a Windows implementation of the Unix /dev/zero device.

Read operations from \Device\Zero (available from user space as \??\Zero) return as many zero characters (0x00) as requested in the read operation.

Installation

sc create DevZero type= kernel binPath= "C:\path\to\DevZero.sys"
sc start DevZero

Development

Disable driver signature enforcement for testing purposes:

bcdedit.exe -set testsigning on

Set the Component Filter Mask (in order to read debug messages in Windows Vista and later):

reg.exe ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Debug Print Filter" /v "DEFAULT" /t REG_DWORD /d 0xffffffff

Restart for the changes to take effect.

Usage

To access the device from user space, open the file \??\Zero.

Example code:

#include <Windows.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
	HANDLE hFile = INVALID_HANDLE_VALUE;
	DWORD dwBytesRead;
	char buffer[16];
    int i;

	FillMemory(buffer, sizeof(buffer), 0x01);

	hFile = CreateFile("\\??\\Zero", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (INVALID_HANDLE_VALUE == hFile) {
        fprintf(stderr, "error: CreateFile: %d\n", GetLastError());
		return 1;
	}

	if (!ReadFile(hFile, buffer, sizeof(buffer), &dwBytesRead, NULL)) {
        CloseHandle(hFile);
        fprintf(stderr, "error: ReadFile: %d\n", GetLastError());
		return 1;
    }

    CloseHandle(hFile);

    printf("Read %d bytes:\n", dwBytesRead);
    for (i = 0; i < dwBytesRead; i++) {
        printf("buffer[%d] = 0x%02x\n", i, buffer[i]);
    }

	return 0;
}

windevzero's People

Contributors

shshu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.