From 487e95bfd9db3fb9e4410bf1adfbae5588ff7f0e Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Thu, 28 Mar 2019 14:13:30 +0100 Subject: initial commit Signed-off-by: Toni Uhlig --- PastDSECtrl/Driver.h | 23 +++++ PastDSECtrl/PastDSECtrl.cpp | 66 ++++++++++++ PastDSECtrl/PastDSECtrl.vcxproj | 178 ++++++++++++++++++++++++++++++++ PastDSECtrl/PastDSECtrl.vcxproj.filters | 33 ++++++ PastDSECtrl/pch.cpp | 5 + PastDSECtrl/pch.h | 14 +++ 6 files changed, 319 insertions(+) create mode 100644 PastDSECtrl/Driver.h create mode 100644 PastDSECtrl/PastDSECtrl.cpp create mode 100644 PastDSECtrl/PastDSECtrl.vcxproj create mode 100644 PastDSECtrl/PastDSECtrl.vcxproj.filters create mode 100644 PastDSECtrl/pch.cpp create mode 100644 PastDSECtrl/pch.h (limited to 'PastDSECtrl') diff --git a/PastDSECtrl/Driver.h b/PastDSECtrl/Driver.h new file mode 100644 index 0000000..692dd9d --- /dev/null +++ b/PastDSECtrl/Driver.h @@ -0,0 +1,23 @@ +/****************************************************** +* FILENAME: +* Driver.h +* +* DESCRIPTION: +* Driver utility functions. +* +* Copyright Toni Uhlig 2019. All rights reserved. +* +* AUTHOR: +* Toni Uhlig START DATE : 27 Mar 19 +*/ + +#pragma once + +#define DEVICE_NAME L"PastDSE" +#define PASTDSE_DEVICE 0x9C40 +#define MMAPDRV_MAXPATH 512 +#define IOCTL_PASTDSE_MMAP_DRIVER (ULONG)CTL_CODE(PASTDSE_DEVICE, 0x800, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) + +typedef struct MMAP_DRIVER_INFO { + wchar_t path[MMAPDRV_MAXPATH]; +} MMAP_DRIVER_INFO; \ No newline at end of file diff --git a/PastDSECtrl/PastDSECtrl.cpp b/PastDSECtrl/PastDSECtrl.cpp new file mode 100644 index 0000000..372842d --- /dev/null +++ b/PastDSECtrl/PastDSECtrl.cpp @@ -0,0 +1,66 @@ +/****************************************************** +* FILENAME: +* PastDSECtrl.cpp +* +* DESCRIPTION: +* Driver utility functions. +* +* Copyright Toni Uhlig 2019. All rights reserved. +* +* AUTHOR: +* Toni Uhlig START DATE : 27 Mar 19 +*/ + +#include "pch.h" +#include "Driver.h" + +#include +#include +#include +#include + +#pragma comment(lib, "Shlwapi.lib") + +int main(int argc, char **argv) +{ + HANDLE hDevice; + wchar_t wpath[MMAPDRV_MAXPATH] = { L".\\DummyDrv.sys" }; + wchar_t fullpath[MMAPDRV_MAXPATH] = { L'\0' }; + MMAP_DRIVER_INFO mmdrvinf = { { L'\0' } }; + BOOL ret; + + if (argc > 1) { + mbstowcs_s(NULL, wpath, MMAPDRV_MAXPATH, argv[1], strlen(argv[1])); + } + + if (!_wfullpath(mmdrvinf.path, wpath, MMAPDRV_MAXPATH)) { + wprintf(L"Realpath failed for: %ws\n", wpath); + return 1; + } + + wnsprintfW(fullpath, MMAPDRV_MAXPATH, L"%s%s", L"\\??\\", mmdrvinf.path); + memcpy(mmdrvinf.path, fullpath, MMAPDRV_MAXPATH * sizeof(wchar_t)); + + wprintf(L"Driver for manual mapping: %ws\n", mmdrvinf.path); + wprintf(L"Device file: %ws\n", L"\\\\.\\" DEVICE_NAME); + + hDevice = CreateFile(L"\\\\.\\" DEVICE_NAME, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (hDevice == INVALID_HANDLE_VALUE) { + wprintf(L"CreateFile Error: 0x%X", GetLastError()); + return 1; + } + wprintf(L"Handle : %p\n", hDevice); + + ret = DeviceIoControl(hDevice, IOCTL_PASTDSE_MMAP_DRIVER, /* argv[1], strlen(argv[1]) */ (LPVOID)&mmdrvinf, (DWORD) sizeof(mmdrvinf), NULL, 0, NULL, NULL); + if (!ret) { + wprintf(L"DeviceIoControl Error: 0x%X", GetLastError()); + return 1; + } + wprintf(L"DeviceIoControl returned: %s , GetLastError: 0x%X\n", + (ret ? L"TRUE" : L"FALSE"), + GetLastError()); + + CloseHandle(hDevice); + + return 0; +} \ No newline at end of file diff --git a/PastDSECtrl/PastDSECtrl.vcxproj b/PastDSECtrl/PastDSECtrl.vcxproj new file mode 100644 index 0000000..b3b6ff3 --- /dev/null +++ b/PastDSECtrl/PastDSECtrl.vcxproj @@ -0,0 +1,178 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {03D1195B-3152-4DD3-8CB1-F0939DB8086A} + Win32Proj + PastDSECtrl + 10.0.17763.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + Static + false + + + Application + false + v141 + true + Unicode + Static + false + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + + + Console + true + + + + + Use + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + %(AdditionalIncludeDirectories) + MultiThreaded + + + Console + true + C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + + + Console + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + %(AdditionalIncludeDirectories) + + + Console + true + true + true + C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64;%(AdditionalLibraryDirectories) + + + + + + + + + + Create + Create + Create + Create + + + + + + \ No newline at end of file diff --git a/PastDSECtrl/PastDSECtrl.vcxproj.filters b/PastDSECtrl/PastDSECtrl.vcxproj.filters new file mode 100644 index 0000000..1ec2765 --- /dev/null +++ b/PastDSECtrl/PastDSECtrl.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/PastDSECtrl/pch.cpp b/PastDSECtrl/pch.cpp new file mode 100644 index 0000000..3a3d12b --- /dev/null +++ b/PastDSECtrl/pch.cpp @@ -0,0 +1,5 @@ +// pch.cpp: source file corresponding to pre-compiled header; necessary for compilation to succeed + +#include "pch.h" + +// In general, ignore this file, but keep it around if you are using pre-compiled headers. diff --git a/PastDSECtrl/pch.h b/PastDSECtrl/pch.h new file mode 100644 index 0000000..b04e71e --- /dev/null +++ b/PastDSECtrl/pch.h @@ -0,0 +1,14 @@ +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file + +#ifndef PCH_H +#define PCH_H + +// TODO: add headers that you want to pre-compile here + +#endif //PCH_H -- cgit v1.2.3