Skip to content

Commit

Permalink
fix win10 17764 and Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
renjiajun committed Feb 25, 2019
1 parent 21ba6a9 commit 5504eea
Show file tree
Hide file tree
Showing 25 changed files with 691 additions and 9,698 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@
*.exe
*.out
*.app
.vs/
Temp/
4 changes: 2 additions & 2 deletions Input_dll/Input_dll.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)\Bin\</OutDir>
<IntDir>$(SolutionDir)\Temp\$(Configuration)\</IntDir>
<IntDir>$(SolutionDir)\Temp\$(ProjectName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_d</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\Bin\</OutDir>
<IntDir>$(SolutionDir)\Temp\$(Configuration)\</IntDir>
<IntDir>$(SolutionDir)\Temp\$(ProjectName)\$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down
5,130 changes: 0 additions & 5,130 deletions Input_dll/dll_x64.h

This file was deleted.

4,362 changes: 0 additions & 4,362 deletions Input_dll/dll_x86.h

This file was deleted.

124 changes: 97 additions & 27 deletions Input_dll/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,132 @@
#include <iostream>
#include <devioctl.h>

#include "dll_x86.h"
#include "dll_x64.h"


#define IOCTL_SET_INJECT_X86DLL \
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x900, METHOD_IN_DIRECT, FILE_ANY_ACCESS)

#define IOCTL_SET_INJECT_X64DLL \
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x901, METHOD_IN_DIRECT, FILE_ANY_ACCESS)


PVOID MyReadFile(WCHAR* fileName, PULONG fileSize)
{
HANDLE fileHandle = NULL;
DWORD readd = 0;
PVOID fileBufPtr = NULL;

fileHandle = CreateFile(
fileName,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);

if (fileHandle == INVALID_HANDLE_VALUE)
{
*fileSize = 0;
return NULL;
}

*fileSize = GetFileSize(fileHandle, NULL);

fileBufPtr = calloc(1, *fileSize);

if (!ReadFile(fileHandle, fileBufPtr, *fileSize, &readd, NULL))
{
free(fileBufPtr);
fileBufPtr = NULL;
*fileSize = 0;
}

CloseHandle(fileHandle);
return fileBufPtr;

}


int main()
{
BOOL result;
DWORD returnLen;
char output;

HANDLE hDevice = CreateFile(L"\\\\.\\CrashDumpUpload",
NULL,
NULL,
NULL,
OPEN_EXISTING,
NULL,
NULL);
HANDLE hDevice = NULL;

PVOID dllx64Ptr = NULL;
PVOID dllx86Ptr = NULL;

ULONG dllx64Size = 0;
ULONG dllx86Size = 0;

hDevice = CreateFile(L"\\\\.\\CrashDumpUpload",
NULL,
NULL,
NULL,
OPEN_EXISTING,
NULL,
NULL);

if (hDevice == INVALID_HANDLE_VALUE)
{
std::cout << "connect device fail." << std::endl;
goto __exit;
}

result = DeviceIoControl(hDevice,
IOCTL_SET_INJECT_X86DLL,
&dll_x86,
sizeof(dll_x86),
&output,
sizeof(char),
&returnLen,
NULL);

dllx64Ptr = MyReadFile(L"MyDll_x64.dll", &dllx64Size);
if (dllx64Ptr == NULL)
{
std::cout << "can not read MyDll_x64.dll." << std::endl;
goto __exit;
}

dllx86Ptr = MyReadFile(L"MyDll_x86.dll", &dllx86Size);
if (dllx86Ptr == NULL)
{
std::cout << "can not read MyDll_x86.dll." << std::endl;
goto __exit;
}

result = DeviceIoControl(
hDevice,
IOCTL_SET_INJECT_X86DLL,
dllx86Ptr,
dllx86Size,
&output,
sizeof(char),
&returnLen,
NULL);

std::cout << (result ? "ok x86dll" : "fail x86dll") << std::endl;

result = DeviceIoControl(hDevice,
IOCTL_SET_INJECT_X64DLL,
&dll_x64,
sizeof(dll_x64),
&output,
sizeof(char),
&returnLen,
NULL);
result = DeviceIoControl(
hDevice,
IOCTL_SET_INJECT_X64DLL,
dllx64Ptr,
dllx64Size,
&output,
sizeof(char),
&returnLen,
NULL);

std::cout << (result ? "ok x64dll" : "fail x64dll") << std::endl;


__exit:
if (hDevice != NULL)
{
CloseHandle(hDevice);
}
if (dllx64Ptr)
{
free(dllx64Ptr);
}
if (dllx86Ptr)
{
free(dllx86Ptr);
}
getchar();
return 0;
}
6 changes: 6 additions & 0 deletions MyDll/MyDll.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// MyDll.cpp : 定义 DLL 应用程序的导出函数。
//

#include "stdafx.h"


182 changes: 182 additions & 0 deletions MyDll/MyDll.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{F6721DAC-1A78-4272-AD2E-A5F0189CF384}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>MyDll</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)\Temp\$(ProjectName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)\bin\</OutDir>
<TargetName>$(ProjectName)_x64</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetName>$(ProjectName)_x86</TargetName>
<OutDir>$(SolutionDir)\bin\</OutDir>
<IntDir>$(SolutionDir)\Temp\$(ProjectName)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)\bin\</OutDir>
<IntDir>$(SolutionDir)\Temp\$(ProjectName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_x64</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<TargetName>$(ProjectName)_x86</TargetName>
<OutDir>$(SolutionDir)\bin\</OutDir>
<IntDir>$(SolutionDir)\Temp\$(ProjectName)\$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;MYDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;MYDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;MYDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;MYDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="MyDll.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Loading

0 comments on commit 5504eea

Please sign in to comment.