Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dhinakg committed May 1, 2021
0 parents commit e9b03b6
Show file tree
Hide file tree
Showing 12 changed files with 6,828 additions and 0 deletions.
399 changes: 399 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# CMakeList.txt : CMake project for Win32Test, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.16)
cmake_policy(SET CMP0091 NEW)
project ("Win32Test" LANGUAGES C CXX VERSION 0.1)
include(FetchContent)

# find static libraries (so MT can work ??)
# set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# set(BUILD_SHARED_LIBS OFF)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")

FetchContent_Declare(json
GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
GIT_TAG v3.9.1)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_compile_options(/ZH:SHA_256 /W4 /permissive- /Zc:__cplusplus)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-Wall -Werror -fno-permissive)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-Wall -Werror -fno-permissive)
endif()

if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_compile_options(/O2 /Ot /Oi /Ob3 /GL)
add_link_options(/LTCG)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-O3 -fsanitize=undefined,address)
add_link_options(-fsanitize=undefined,address)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-O3 -fsanitize=undefined,address -fsanitize-blacklist=C:/Users/dhina/Documents/GitHub/Win32Testv2/fsanitize-blacklist.txt)
add_link_options(-fsanitize=undefined,address -fsanitize-blacklist=C:/Users/dhina/Documents/GitHub/Win32Testv2/fsanitize-blacklist.txt)
endif()
endif()

FetchContent_GetProperties(json)
if(NOT json_POPULATED)
FetchContent_Populate(json)
add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

add_compile_definitions(UNICODE)

# Add source to this project's executable.
add_executable (usbdump "Win32Test.cpp" "enum.cpp" "devnode.cpp" "Win32Test.h" "usbdesc.h" "uvcdesc.h" "uvcview.h")
set_property(TARGET usbdump PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

target_link_libraries(usbdump
PRIVATE
setupapi
nlohmann_json::nlohmann_json
)
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
The Microsoft Public License (MS-PL)
Copyright (c) 2015 Microsoft

This license governs use of the accompanying software. If you use the software, you
accept this license. If you do not accept the license, do not use the software.

1. Definitions
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the
same meaning here as under U.S. copyright law.
A "contribution" is the original software, or any additions or changes to the software.
A "contributor" is any person that distributes its contribution under this license.
"Licensed patents" are a contributor's patent claims that read directly on its contribution.

2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.

3. Conditions and Limitations
(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# usbdump

Tool to serialize USB info to JSON. Modified from [USBView](https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/usbview) from [Windows driver samples](https://github.com/Microsoft/Windows-driver-samples/tree/master/usb/usbview). Additional modifications (besides serialization) include Unicode support.

## Known Issues

Basically nothing is freed

## Credits

Microsoft for USBView

@nlohmann for [the json library](https://github.com/nlohmann/json)
40 changes: 40 additions & 0 deletions Win32Test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Win32Test.cpp : Defines the entry point for the application.
//

#include "Win32Test.h"

using namespace std;
using json = nlohmann::json;

void initGlobals() {
gHubList.DeviceInfo = INVALID_HANDLE_VALUE;
InitializeListHead(&gHubList.ListHead);
gDeviceList.DeviceInfo = INVALID_HANDLE_VALUE;
InitializeListHead(&gDeviceList.ListHead);
}

int main(int argc, char* argv[]) {
if (argc >= 2) {
if (std::string(argv[1]) == "--version" || std::string(argv[1]) == "-v") {
std::cout << TOOL_VERSION << std::endl;
return 0;
} else {
return 1;
}
}
initGlobals();

ULONG devicesConnected;

std::vector<USBHOSTCONTROLLERINFO*> hostControllers = EnumerateHostControllers((HTREEITEM)1, &devicesConnected);
json ree = hostControllers;
std::cout << ree.dump(4) << std::endl;
/* for (const auto& hostController : hostControllers) {
// std::cout << hostController->DriverKey << std::endl;
json ree = hostController;
std::cout << ree.dump(4) << std::endl;
} */

// std::cout << "Done" << std::endl;
return 0;
}
50 changes: 50 additions & 0 deletions Win32Test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Win32Test.h : Include file for standard system include files,
// or project specific include files.

#pragma once

#include <iostream>

#include <windows.h>
#include <SetupAPI.h>
#include <winioctl.h>
#include <initguid.h>
#include <usbiodef.h>
#include <usbioctl.h>
#include <strsafe.h>
#include <memory>
#include <usbdi.h>
#include <usbuser.h>
#include <vector>

#include "uvcview.h"
#include "specializations.hpp"
#include "nlohmann/json.hpp"

#define TOOL_VERSION "0.1.0"


#define QUICKCOUT(...) std::cout << __VA_ARGS__ << std::endl


extern DEVICE_GUID_LIST gHubList;
extern DEVICE_GUID_LIST gDeviceList;

struct HandleDeleter
{
// By defining the pointer type, we can delete a type other than T*.
// In other words, we can declare unique_ptr<HANDLE, Deleter> instead of
// unique_ptr<void, Deleter> which leaks the HANDLE abstraction.
typedef HANDLE pointer;

void operator()(HANDLE h)
{
if(h != INVALID_HANDLE_VALUE)
{
CloseHandle(h);
}
}
};

typedef std::unique_ptr<HANDLE, HandleDeleter> handle_unique_ptr;

Loading

0 comments on commit e9b03b6

Please sign in to comment.