From 7be3d976a223220e8e48896a401ac7e56e40ce62 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 27 Apr 2017 22:35:21 +0300 Subject: um: reorganize projects * libservice -> service * libsimple -> wrappers/simple * libnt_path_converter -> wrappers/special/nt_path_converter --- um/wrappers/simple/CMakeLists.txt | 9 +++++ um/wrappers/simple/README.md | 43 ++++++++++++++++++++++++ um/wrappers/simple/include/libsimple/all.hpp | 8 +++++ um/wrappers/simple/include/libsimple/device.hpp | 19 +++++++++++ um/wrappers/simple/src/device.cpp | 37 +++++++++++++++++++++ um/wrappers/simple/utils/CMakeLists.txt | 2 ++ um/wrappers/simple/utils/exchange_ints.cpp | 44 +++++++++++++++++++++++++ 7 files changed, 162 insertions(+) create mode 100644 um/wrappers/simple/CMakeLists.txt create mode 100644 um/wrappers/simple/README.md create mode 100644 um/wrappers/simple/include/libsimple/all.hpp create mode 100644 um/wrappers/simple/include/libsimple/device.hpp create mode 100644 um/wrappers/simple/src/device.cpp create mode 100644 um/wrappers/simple/utils/CMakeLists.txt create mode 100644 um/wrappers/simple/utils/exchange_ints.cpp (limited to 'um/wrappers/simple') diff --git a/um/wrappers/simple/CMakeLists.txt b/um/wrappers/simple/CMakeLists.txt new file mode 100644 index 0000000..ff61bd7 --- /dev/null +++ b/um/wrappers/simple/CMakeLists.txt @@ -0,0 +1,9 @@ +file(GLOB_RECURSE libsimple_headers "include/*.hpp") +file(GLOB libsimple_sources "src/*.cpp") +add_library(libsimple + ${libsimple_sources} + ${libsimple_headers}) +target_link_libraries(libsimple libservice) +target_include_directories(libsimple PUBLIC include/) + +add_subdirectory(utils) diff --git a/um/wrappers/simple/README.md b/um/wrappers/simple/README.md new file mode 100644 index 0000000..51a46cb --- /dev/null +++ b/um/wrappers/simple/README.md @@ -0,0 +1,43 @@ +simple driver utilities +======================= + +[simple] driver usage examples. + +[simple]: ../../../km/src/simple + +Usage +----- + +### exchange_ints.exe + +``` +Usage: exchange_ints.exe N +``` + +Parses its argument as an `unsigned int` and exchanges it with the one stored +in [simple] driver's memory. +For example: + +``` +> exchange_ints.exe 1 +42 +``` + +``` +> exchange_ints.exe 32 +1 +``` + +``` +> exchange_ints.exe 100500 +32 +``` + +See also +-------- + +* [Building the utilities] +* [License] + +[Building the utilities]: ../../README.md#building-the-utilities +[License]: ../../../README.md#license diff --git a/um/wrappers/simple/include/libsimple/all.hpp b/um/wrappers/simple/include/libsimple/all.hpp new file mode 100644 index 0000000..474b802 --- /dev/null +++ b/um/wrappers/simple/include/libsimple/all.hpp @@ -0,0 +1,8 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "device.hpp" diff --git a/um/wrappers/simple/include/libsimple/device.hpp b/um/wrappers/simple/include/libsimple/device.hpp new file mode 100644 index 0000000..3318818 --- /dev/null +++ b/um/wrappers/simple/include/libsimple/device.hpp @@ -0,0 +1,19 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "libservice/all.hpp" + +namespace libsimple +{ + class Device : libservice::Device + { + public: + Device(); + + unsigned int exchange_ints(unsigned int) const; + }; +} diff --git a/um/wrappers/simple/src/device.cpp b/um/wrappers/simple/src/device.cpp new file mode 100644 index 0000000..57e6963 --- /dev/null +++ b/um/wrappers/simple/src/device.cpp @@ -0,0 +1,37 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libsimple/all.hpp" + +#include "libservice/all.hpp" + +#include + +namespace libsimple +{ + namespace + { + const char* const device_path = "\\\\.\\simple_device1"; + const auto exchange_ints_ctl_code = CTL_CODE(0x8001, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS); + } + + Device::Device() + : libservice::Device(libservice::Device::open(device_path)) + { } + + unsigned int Device::exchange_ints(unsigned int src) const + { + unsigned int dest; + + send_control_code( + exchange_ints_ctl_code, + &src, + sizeof(src), + &dest, + sizeof(dest)); + + return dest; + } +} diff --git a/um/wrappers/simple/utils/CMakeLists.txt b/um/wrappers/simple/utils/CMakeLists.txt new file mode 100644 index 0000000..8824e3e --- /dev/null +++ b/um/wrappers/simple/utils/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(exchange_ints exchange_ints.cpp) +target_link_libraries(exchange_ints libsimple) diff --git a/um/wrappers/simple/utils/exchange_ints.cpp b/um/wrappers/simple/utils/exchange_ints.cpp new file mode 100644 index 0000000..2935b2f --- /dev/null +++ b/um/wrappers/simple/utils/exchange_ints.cpp @@ -0,0 +1,44 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libsimple/all.hpp" + +#include +#include +#include +#include + +namespace +{ + bool parse_int(unsigned int& dest, const std::string& src) + { + std::istringstream iss(src); + char c; + return iss >> dest && !iss.get(c); + } +} + +int main(int argc, char* argv[]) +{ + try + { + unsigned int src; + + if (argc != 2 || !parse_int(src, argv[1])) + { + std::cout << "Usage: " << argv[0] << " N\n"; + return 1; + } + + std::cout << libsimple::Device().exchange_ints(src) << "\n"; + } + catch (const std::exception& e) + { + std::cerr << e.what() << "\n"; + return 1; + } + + return 0; +} -- cgit v1.2.3