add Ultimate ASI Loader

This commit is contained in:
EricPlayZ
2024-12-30 16:11:23 +02:00
parent 131086a282
commit 92a84d71d1
544 changed files with 392666 additions and 0 deletions

3
.gitignore vendored
View File

@ -2,6 +2,9 @@
data/
!data/**/*.ini
# Temporary files created by Visual Studio extensions
*.TMP
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##

View File

@ -9,6 +9,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EGameTools", "EGameTools\EG
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EGameSDK", "EGameSDK\EGameSDK.vcxproj", "{152BCFEC-E42D-4370-AEDD-36F044085C0C}"
ProjectSection(ProjectDependencies) = postProject
{47F0BD81-B327-0619-BC31-6A3C28E82C12} = {47F0BD81-B327-0619-BC31-6A3C28E82C12}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Ultimate-ASI-Loader-x64", "Ultimate-ASI-Loader-x64\Ultimate-ASI-Loader-x64.vcxproj", "{47F0BD81-B327-0619-BC31-6A3C28E82C12}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -34,6 +39,14 @@ Global
{152BCFEC-E42D-4370-AEDD-36F044085C0C}.Release|x64.Build.0 = Release|x64
{152BCFEC-E42D-4370-AEDD-36F044085C0C}.Release|x86.ActiveCfg = Release|x64
{152BCFEC-E42D-4370-AEDD-36F044085C0C}.Release|x86.Build.0 = Release|x64
{47F0BD81-B327-0619-BC31-6A3C28E82C12}.Debug|x64.ActiveCfg = Debug|x64
{47F0BD81-B327-0619-BC31-6A3C28E82C12}.Debug|x64.Build.0 = Debug|x64
{47F0BD81-B327-0619-BC31-6A3C28E82C12}.Debug|x86.ActiveCfg = Debug|x64
{47F0BD81-B327-0619-BC31-6A3C28E82C12}.Debug|x86.Build.0 = Debug|x64
{47F0BD81-B327-0619-BC31-6A3C28E82C12}.Release|x64.ActiveCfg = Release|x64
{47F0BD81-B327-0619-BC31-6A3C28E82C12}.Release|x64.Build.0 = Release|x64
{47F0BD81-B327-0619-BC31-6A3C28E82C12}.Release|x86.ActiveCfg = Release|x64
{47F0BD81-B327-0619-BC31-6A3C28E82C12}.Release|x86.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{47F0BD81-B327-0619-BC31-6A3C28E82C12}</ProjectGuid>
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Ultimate-ASI-Loader-x64</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</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>
<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>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>..\x64\Release\</OutDir>
<IntDir>x64\Release\</IntDir>
<TargetName>winmm</TargetName>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>..\x64\Debug\</OutDir>
<IntDir>x64\Debug\</IntDir>
<TargetName>winmm</TargetName>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>rsc_CompanyName="ThirteenAG";rsc_LegalCopyright="MIT License";rsc_InternalName="Ultimate-ASI-Loader-x64";rsc_ProductName="Ultimate-ASI-Loader-x64";rsc_OriginalFilename="Ultimate-ASI-Loader-x64.dll";rsc_FileDescription="Ultimate ASI Loader";rsc_UpdateUrl="https://github.com/ThirteenAG/Ultimate-ASI-Loader";rsc_FileVersion_MAJOR=7;rsc_FileVersion_MINOR=0;rsc_FileVersion_BUILD=0;rsc_FileVersion_REVISION=0;rsc_FileVersion="7.0.0";rsc_ProductVersion="7.0.0";X64;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>source;external;external\injector\minhook\include;external\injector\utility;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<MinimalRebuild>false</MinimalRebuild>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<ExceptionHandling>Async</ExceptionHandling>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>rsc_CompanyName=\"ThirteenAG\";rsc_LegalCopyright=\"MIT License\";rsc_InternalName=\"Ultimate-ASI-Loader-x64\";rsc_ProductName=\"Ultimate-ASI-Loader-x64\";rsc_OriginalFilename=\"Ultimate-ASI-Loader-x64.dll\";rsc_FileDescription=\"Ultimate ASI Loader\";rsc_UpdateUrl=\"https://github.com/ThirteenAG/Ultimate-ASI-Loader\";rsc_FileVersion_MAJOR=7;rsc_FileVersion_MINOR=0;rsc_FileVersion_BUILD=0;rsc_FileVersion_REVISION=0;rsc_FileVersion=\"7.0.0\";rsc_ProductVersion=\"7.0.0\";X64;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>source;external;external\injector\minhook\include;external\injector\utility;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ImportLibrary>..\x64\Release\winmm.lib</ImportLibrary>
<ModuleDefinitionFile>source/x64.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>rsc_CompanyName="ThirteenAG";rsc_LegalCopyright="MIT License";rsc_InternalName="Ultimate-ASI-Loader-x64";rsc_ProductName="Ultimate-ASI-Loader-x64";rsc_OriginalFilename="Ultimate-ASI-Loader-x64.dll";rsc_FileDescription="Ultimate ASI Loader";rsc_UpdateUrl="https://github.com/ThirteenAG/Ultimate-ASI-Loader";rsc_FileVersion_MAJOR=7;rsc_FileVersion_MINOR=0;rsc_FileVersion_BUILD=0;rsc_FileVersion_REVISION=0;rsc_FileVersion="7.0.0";rsc_ProductVersion="7.0.0";X64;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>source;external;external\injector\minhook\include;external\injector\utility;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<ExceptionHandling>Async</ExceptionHandling>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>rsc_CompanyName=\"ThirteenAG\";rsc_LegalCopyright=\"MIT License\";rsc_InternalName=\"Ultimate-ASI-Loader-x64\";rsc_ProductName=\"Ultimate-ASI-Loader-x64\";rsc_OriginalFilename=\"Ultimate-ASI-Loader-x64.dll\";rsc_FileDescription=\"Ultimate ASI Loader\";rsc_UpdateUrl=\"https://github.com/ThirteenAG/Ultimate-ASI-Loader\";rsc_FileVersion_MAJOR=7;rsc_FileVersion_MINOR=0;rsc_FileVersion_BUILD=0;rsc_FileVersion_REVISION=0;rsc_FileVersion=\"7.0.0\";rsc_ProductVersion=\"7.0.0\";X64;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>source;external;external\injector\minhook\include;external\injector\utility;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ImportLibrary>..\x64\Debug\winmm.lib</ImportLibrary>
<ModuleDefinitionFile>source/x64.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="external\injector\minhook\include\MinHook.h" />
<ClInclude Include="external\injector\minhook\src\buffer.h" />
<ClInclude Include="external\injector\minhook\src\hde\hde32.h" />
<ClInclude Include="external\injector\minhook\src\hde\hde64.h" />
<ClInclude Include="external\injector\minhook\src\hde\pstdint.h" />
<ClInclude Include="external\injector\minhook\src\hde\table32.h" />
<ClInclude Include="external\injector\minhook\src\hde\table64.h" />
<ClInclude Include="external\injector\minhook\src\trampoline.h" />
<ClInclude Include="external\injector\utility\FunctionHookMinHook.hpp" />
<ClInclude Include="source\dllmain.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="external\injector\minhook\src\buffer.c" />
<ClCompile Include="external\injector\minhook\src\hde\hde32.c" />
<ClCompile Include="external\injector\minhook\src\hde\hde64.c" />
<ClCompile Include="external\injector\minhook\src\hook.c" />
<ClCompile Include="external\injector\minhook\src\trampoline.c" />
<ClCompile Include="external\injector\utility\FunctionHookMinHook.cpp" />
<ClCompile Include="source\dllmain.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="source\x64.def" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="source\resources\Versioninfo.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="external">
<UniqueIdentifier>{2839F3DC-1406-4EE8-3D1F-3C90294B8376}</UniqueIdentifier>
</Filter>
<Filter Include="external\injector">
<UniqueIdentifier>{D5F34776-410A-460C-8A81-D12DF6D61694}</UniqueIdentifier>
</Filter>
<Filter Include="external\injector\minhook">
<UniqueIdentifier>{190CA6FB-85CE-D985-CE7E-68123A80B263}</UniqueIdentifier>
</Filter>
<Filter Include="external\injector\minhook\include">
<UniqueIdentifier>{8C3CA671-F8AA-FBF0-4194-B6F0AD41F18C}</UniqueIdentifier>
</Filter>
<Filter Include="external\injector\minhook\src">
<UniqueIdentifier>{B02EAC39-1C47-9363-E5F3-22FD51CB27FD}</UniqueIdentifier>
</Filter>
<Filter Include="external\injector\minhook\src\hde">
<UniqueIdentifier>{30949F7C-9C02-F5FB-E5EB-AFFB5199EA97}</UniqueIdentifier>
</Filter>
<Filter Include="external\injector\utility">
<UniqueIdentifier>{384FC87C-A411-FC06-EDC1-8A9359C3D4E4}</UniqueIdentifier>
</Filter>
<Filter Include="source">
<UniqueIdentifier>{76FF3A1C-62A1-65F2-4B5C-7946379DEC42}</UniqueIdentifier>
</Filter>
<Filter Include="source\resources">
<UniqueIdentifier>{80903071-6C89-4FC3-95BB-344881132FCF}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="external\injector\minhook\include\MinHook.h">
<Filter>external\injector\minhook\include</Filter>
</ClInclude>
<ClInclude Include="external\injector\minhook\src\buffer.h">
<Filter>external\injector\minhook\src</Filter>
</ClInclude>
<ClInclude Include="external\injector\minhook\src\hde\hde32.h">
<Filter>external\injector\minhook\src\hde</Filter>
</ClInclude>
<ClInclude Include="external\injector\minhook\src\hde\hde64.h">
<Filter>external\injector\minhook\src\hde</Filter>
</ClInclude>
<ClInclude Include="external\injector\minhook\src\hde\pstdint.h">
<Filter>external\injector\minhook\src\hde</Filter>
</ClInclude>
<ClInclude Include="external\injector\minhook\src\hde\table32.h">
<Filter>external\injector\minhook\src\hde</Filter>
</ClInclude>
<ClInclude Include="external\injector\minhook\src\hde\table64.h">
<Filter>external\injector\minhook\src\hde</Filter>
</ClInclude>
<ClInclude Include="external\injector\minhook\src\trampoline.h">
<Filter>external\injector\minhook\src</Filter>
</ClInclude>
<ClInclude Include="external\injector\utility\FunctionHookMinHook.hpp">
<Filter>external\injector\utility</Filter>
</ClInclude>
<ClInclude Include="source\dllmain.h">
<Filter>source</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="external\injector\minhook\src\buffer.c">
<Filter>external\injector\minhook\src</Filter>
</ClCompile>
<ClCompile Include="external\injector\minhook\src\hde\hde32.c">
<Filter>external\injector\minhook\src\hde</Filter>
</ClCompile>
<ClCompile Include="external\injector\minhook\src\hde\hde64.c">
<Filter>external\injector\minhook\src\hde</Filter>
</ClCompile>
<ClCompile Include="external\injector\minhook\src\hook.c">
<Filter>external\injector\minhook\src</Filter>
</ClCompile>
<ClCompile Include="external\injector\minhook\src\trampoline.c">
<Filter>external\injector\minhook\src</Filter>
</ClCompile>
<ClCompile Include="external\injector\utility\FunctionHookMinHook.cpp">
<Filter>external\injector\utility</Filter>
</ClCompile>
<ClCompile Include="source\dllmain.cpp">
<Filter>source</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="source\x64.def">
<Filter>source</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="source\resources\Versioninfo.rc">
<Filter>source\resources</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,11 @@
* text=auto
# Native line endings.
*.c text
*.cpp text
*.h text
*.rc text
# Windows line endings.
*.bat text eol=crlf
*.eln text eol=crlf

View File

@ -0,0 +1,8 @@
*.o
*.obj
*.exe
tests/*.dll
tests/*.res
tests/SampleExports.cpp
tests/SampleExports.h

View File

@ -0,0 +1,95 @@
sudo: true
matrix:
include:
- env: PLATFORM=x86_64 UNICODE= CMAKE= WINE_PACKAGE=winehq-stable:amd64
addons:
apt:
packages:
- binutils-mingw-w64-x86-64
- mingw-w64-x86-64-dev
- g++-mingw-w64-x86-64
- gcc-mingw-w64-x86-64
- env: PLATFORM=i686 UNICODE= CMAKE= WINE_PACKAGE=winehq-stable:i386
addons:
apt:
packages:
- binutils-mingw-w64-i686
- mingw-w64-i686-dev
- g++-mingw-w64-i686
- gcc-mingw-w64-i686
- env: PLATFORM=x86_64 UNICODE=1 CMAKE= WINE_PACKAGE=winehq-stable:amd64
addons:
apt:
packages:
- binutils-mingw-w64-x86-64
- mingw-w64-x86-64-dev
- g++-mingw-w64-x86-64
- gcc-mingw-w64-x86-64
- env: PLATFORM=i686 UNICODE=1 CMAKE= WINE_PACKAGE=winehq-stable:i386
addons:
apt:
packages:
- binutils-mingw-w64-i686
- mingw-w64-i686-dev
- g++-mingw-w64-i686
- gcc-mingw-w64-i686
- env: PLATFORM=x86_64 UNICODE= CMAKE=1 WINE_PACKAGE=winehq-stable:amd64
addons:
apt:
packages:
- binutils-mingw-w64-x86-64
- mingw-w64-x86-64-dev
- g++-mingw-w64-x86-64
- gcc-mingw-w64-x86-64
- env: PLATFORM=i686 UNICODE= CMAKE=1 WINE_PACKAGE=winehq-stable:i386
addons:
apt:
packages:
- binutils-mingw-w64-i686
- cmake
- mingw-w64-i686-dev
- g++-mingw-w64-i686
- gcc-mingw-w64-i686
- env: PLATFORM=x86_64 UNICODE=1 CMAKE=1 WINE_PACKAGE=winehq-stable:amd64
addons:
apt:
packages:
- binutils-mingw-w64-x86-64
- cmake
- mingw-w64-x86-64-dev
- g++-mingw-w64-x86-64
- gcc-mingw-w64-x86-64
- env: PLATFORM=i686 UNICODE=1 CMAKE=1 WINE_PACKAGE=winehq-stable:i386
addons:
apt:
packages:
- binutils-mingw-w64-i686
- cmake
- mingw-w64-i686-dev
- g++-mingw-w64-i686
- gcc-mingw-w64-i686
language: cpp
dist: xenial
cache:
- apt
- ccache
before_script:
- curl https://dl.winehq.org/wine-builds/winehq.key | sudo apt-key add -
- echo "deb https://dl.winehq.org/wine-builds/ubuntu/ xenial main" | sudo tee /etc/apt/sources.list.d/winehq.list
- sudo apt-get -y update && sudo apt-get -y install --install-recommends $WINE_PACKAGE
- if [ ! -z "$CMAKE" ]; then cmake -DPLATFORM=$PLATFORM -DUNICODE=$UNICODE -DTESTSUITE=ON -H. -B.; fi
script:
- if [ -z "$CMAKE" ]; then make PLATFORM=$PLATFORM UNICODE=$UNICODE; fi
- if [ -z "$CMAKE" ]; then make test PLATFORM=$PLATFORM UNICODE=$UNICODE; fi
- if [ ! -z "$CMAKE" ]; then cmake --build .; fi
- cd example/DllLoader
- ../../tests/runwine.sh $PLATFORM ./DllLoader.exe
- ../../tests/runwine.sh $PLATFORM ./DllLoaderLoader.exe
- cd ../../tests
- ./runwine.sh $PLATFORM ./TestSuite.exe

View File

@ -0,0 +1,60 @@
project (MemoryModule)
cmake_minimum_required (VERSION 2.8.7)
set (PLATFORM "x86_64" CACHE STRING "Platform to compile for")
message (STATUS "Compile for ${PLATFORM} platform")
if (NOT MSVC)
set (CMAKE_SYSTEM_NAME Windows)
set (CMAKE_POSITION_INDEPENDENT_CODE False)
set (COMPILER_PREFIX "${PLATFORM}-w64-mingw32")
set (CMAKE_C_COMPILER "${COMPILER_PREFIX}-gcc")
set (CMAKE_CXX_COMPILER "${COMPILER_PREFIX}-g++")
set (CMAKE_RC_COMPILER "${COMPILER_PREFIX}-windres")
set (CMAKE_AR "${COMPILER_PREFIX}-ar")
set (CMAKE_RANLIB "${COMPILER_PREFIX}-ranlib")
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
set (CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
endif ()
if (NOT MSVC)
add_definitions ("-Wall")
else ()
# Show level 4 warnings.
add_definitions ("-W4")
endif ()
option(UNICODE "Compile with UNICODE support" OFF)
if (UNICODE)
message (STATUS "Compile with UNICODE support")
add_definitions ("-DUNICODE" "-D_UNICODE")
else ()
message (STATUS "Compile without UNICODE support")
endif ()
option(TESTSUITE "Compile with TESTSUITE support" OFF)
if (TESTSUITE)
message (STATUS "Compile with TESTSUITE support")
add_definitions ("-DTESTSUITE")
else ()
message (STATUS "Compile without TESTSUITE support")
endif ()
add_library (MemoryModule STATIC MemoryModule.c MemoryModule.h)
target_include_directories(MemoryModule PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
if (NOT MSVC)
set_target_properties ("MemoryModule" PROPERTIES PREFIX "")
endif ()
add_subdirectory (example)
add_subdirectory (tests)
enable_language (RC)

View File

@ -0,0 +1,373 @@
Mozilla Public License Version 2.0
==================================
1. Definitions
--------------
1.1. "Contributor"
means each individual or legal entity that creates, contributes to
the creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used
by a Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached
the notice in Exhibit A, the Executable Form of such Source Code
Form, and Modifications of such Source Code Form, in each case
including portions thereof.
1.5. "Incompatible With Secondary Licenses"
means
(a) that the initial Contributor has attached the notice described
in Exhibit B to the Covered Software; or
(b) that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the
terms of a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in
a separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible,
whether at the time of the initial grant or subsequently, any and
all of the rights conveyed by this License.
1.10. "Modifications"
means any of the following:
(a) any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered
Software; or
(b) any new file in Source Code Form that contains any Covered
Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the
License, by the making, using, selling, offering for sale, having
made, import, or transfer of either its Contributions or its
Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU
Lesser General Public License, Version 2.1, the GNU Affero General
Public License, Version 3.0, or any later versions of those
licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that
controls, is controlled by, or is under common control with You. For
purposes of this definition, "control" means (a) the power, direct
or indirect, to cause the direction or management of such entity,
whether by contract or otherwise, or (b) ownership of more than
fifty percent (50%) of the outstanding shares or beneficial
ownership of such entity.
2. License Grants and Conditions
--------------------------------
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
(a) under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
(b) under Patent Claims of such Contributor to make, use, sell, offer
for sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
(a) for any code that a Contributor has removed from Covered Software;
or
(b) for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
(c) under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights
to grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
in Section 2.1.
3. Responsibilities
-------------------
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
(a) such Covered Software must also be made available in Source Code
Form, as described in Section 3.1, and You must inform recipients of
the Executable Form how they can obtain a copy of such Source Code
Form by reasonable means in a timely manner, at a charge no more
than the cost of distribution to the recipient; and
(b) You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter
the recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty,
or limitations of liability) contained within the Source Code Form of
the Covered Software, except that You may alter any license notices to
the extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
---------------------------------------------------
If it is impossible for You to comply with any of the terms of this
License with respect to some or all of the Covered Software due to
statute, judicial order, or regulation then You must: (a) comply with
the terms of this License to the maximum extent possible; and (b)
describe the limitations and the code they affect. Such description must
be placed in a text file included with all distributions of the Covered
Software under this License. Except to the extent prohibited by statute
or regulation, such description must be sufficiently detailed for a
recipient of ordinary skill to be able to understand it.
5. Termination
--------------
5.1. The rights granted under this License will terminate automatically
if You fail to comply with any of its terms. However, if You become
compliant, then the rights granted under this License from a particular
Contributor are reinstated (a) provisionally, unless and until such
Contributor explicitly and finally terminates Your grants, and (b) on an
ongoing basis, if such Contributor fails to notify You of the
non-compliance by some reasonable means prior to 60 days after You have
come back into compliance. Moreover, Your grants from a particular
Contributor are reinstated on an ongoing basis if such Contributor
notifies You of the non-compliance by some reasonable means, this is the
first time You have received notice of non-compliance with this License
from such Contributor, and You become compliant prior to 30 days after
Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
end user license agreements (excluding distributors and resellers) which
have been validly granted by You or Your distributors under this License
prior to termination shall survive termination.
************************************************************************
* *
* 6. Disclaimer of Warranty *
* ------------------------- *
* *
* Covered Software is provided under this License on an "as is" *
* basis, without warranty of any kind, either expressed, implied, or *
* statutory, including, without limitation, warranties that the *
* Covered Software is free of defects, merchantable, fit for a *
* particular purpose or non-infringing. The entire risk as to the *
* quality and performance of the Covered Software is with You. *
* Should any Covered Software prove defective in any respect, You *
* (not any Contributor) assume the cost of any necessary servicing, *
* repair, or correction. This disclaimer of warranty constitutes an *
* essential part of this License. No use of any Covered Software is *
* authorized under this License except under this disclaimer. *
* *
************************************************************************
************************************************************************
* *
* 7. Limitation of Liability *
* -------------------------- *
* *
* Under no circumstances and under no legal theory, whether tort *
* (including negligence), contract, or otherwise, shall any *
* Contributor, or anyone who distributes Covered Software as *
* permitted above, be liable to You for any direct, indirect, *
* special, incidental, or consequential damages of any character *
* including, without limitation, damages for lost profits, loss of *
* goodwill, work stoppage, computer failure or malfunction, or any *
* and all other commercial damages or losses, even if such party *
* shall have been informed of the possibility of such damages. This *
* limitation of liability shall not apply to liability for death or *
* personal injury resulting from such party's negligence to the *
* extent applicable law prohibits such limitation. Some *
* jurisdictions do not allow the exclusion or limitation of *
* incidental or consequential damages, so this exclusion and *
* limitation may not apply to You. *
* *
************************************************************************
8. Litigation
-------------
Any litigation relating to this License may be brought only in the
courts of a jurisdiction where the defendant maintains its principal
place of business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions.
Nothing in this Section shall prevent a party's ability to bring
cross-claims or counter-claims.
9. Miscellaneous
----------------
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides
that the language of a contract shall be construed against the drafter
shall not be used to construe this License against a Contributor.
10. Versions of the License
---------------------------
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses
If You choose to distribute Source Code Form that is Incompatible With
Secondary Licenses under the terms of this version of the License, the
notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
-------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular
file, then You may include the notice in a location (such as a LICENSE
file in a relevant directory) where a recipient would be likely to look
for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
---------------------------------------------------------
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.

View File

@ -0,0 +1,20 @@
SUBDIRS = example tests
.PHONY: subdirs $(SUBDIRS)
subdirs: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@
CLEANDIRS = $(SUBDIRS:%=clean-%)
clean: $(CLEANDIRS)
$(CLEANDIRS):
$(MAKE) -C $(@:clean-%=%) clean
test:
$(MAKE) -C tests test
.PHONY: subdirs $(INSTALLDIRS)
.PHONY: clean test

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,168 @@
/*
* Memory DLL loading code
* Version 0.0.4
*
* Copyright (c) 2004-2015 by Joachim Bauch / mail@joachim-bauch.de
* http://www.joachim-bauch.de
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is MemoryModule.h
*
* The Initial Developer of the Original Code is Joachim Bauch.
*
* Portions created by Joachim Bauch are Copyright (C) 2004-2015
* Joachim Bauch. All Rights Reserved.
*
*/
#ifndef __MEMORY_MODULE_HEADER
#define __MEMORY_MODULE_HEADER
#include <windows.h>
typedef void *HMEMORYMODULE;
typedef void *HMEMORYRSRC;
typedef void *HCUSTOMMODULE;
#ifdef __cplusplus
extern "C" {
#endif
typedef LPVOID (*CustomAllocFunc)(LPVOID, SIZE_T, DWORD, DWORD, void*);
typedef BOOL (*CustomFreeFunc)(LPVOID, SIZE_T, DWORD, void*);
typedef HCUSTOMMODULE (*CustomLoadLibraryFunc)(LPCSTR, void *);
typedef FARPROC (*CustomGetProcAddressFunc)(HCUSTOMMODULE, LPCSTR, void *);
typedef void (*CustomFreeLibraryFunc)(HCUSTOMMODULE, void *);
/**
* Load EXE/DLL from memory location with the given size.
*
* All dependencies are resolved using default LoadLibrary/GetProcAddress
* calls through the Windows API.
*/
HMEMORYMODULE MemoryLoadLibrary(const void *, size_t);
/**
* Load EXE/DLL from memory location with the given size using custom dependency
* resolvers.
*
* Dependencies will be resolved using passed callback methods.
*/
HMEMORYMODULE MemoryLoadLibraryEx(const void *, size_t,
CustomAllocFunc,
CustomFreeFunc,
CustomLoadLibraryFunc,
CustomGetProcAddressFunc,
CustomFreeLibraryFunc,
void *);
/**
* Get address of exported method. Supports loading both by name and by
* ordinal value.
*/
FARPROC MemoryGetProcAddress(HMEMORYMODULE, LPCSTR);
/**
* Free previously loaded EXE/DLL.
*/
void MemoryFreeLibrary(HMEMORYMODULE);
/**
* Execute entry point (EXE only). The entry point can only be executed
* if the EXE has been loaded to the correct base address or it could
* be relocated (i.e. relocation information have not been stripped by
* the linker).
*
* Important: calling this function will not return, i.e. once the loaded
* EXE finished running, the process will terminate.
*
* Returns a negative value if the entry point could not be executed.
*/
int MemoryCallEntryPoint(HMEMORYMODULE);
/**
* Find the location of a resource with the specified type and name.
*/
HMEMORYRSRC MemoryFindResource(HMEMORYMODULE, LPCTSTR, LPCTSTR);
/**
* Find the location of a resource with the specified type, name and language.
*/
HMEMORYRSRC MemoryFindResourceEx(HMEMORYMODULE, LPCTSTR, LPCTSTR, WORD);
/**
* Get the size of the resource in bytes.
*/
DWORD MemorySizeofResource(HMEMORYMODULE, HMEMORYRSRC);
/**
* Get a pointer to the contents of the resource.
*/
LPVOID MemoryLoadResource(HMEMORYMODULE, HMEMORYRSRC);
/**
* Load a string resource.
*/
int MemoryLoadString(HMEMORYMODULE, UINT, LPTSTR, int);
/**
* Load a string resource with a given language.
*/
int MemoryLoadStringEx(HMEMORYMODULE, UINT, LPTSTR, int, WORD);
/**
* Default implementation of CustomAllocFunc that calls VirtualAlloc
* internally to allocate memory for a library
*
* This is the default as used by MemoryLoadLibrary.
*/
LPVOID MemoryDefaultAlloc(LPVOID, SIZE_T, DWORD, DWORD, void *);
/**
* Default implementation of CustomFreeFunc that calls VirtualFree
* internally to free the memory used by a library
*
* This is the default as used by MemoryLoadLibrary.
*/
BOOL MemoryDefaultFree(LPVOID, SIZE_T, DWORD, void *);
/**
* Default implementation of CustomLoadLibraryFunc that calls LoadLibraryA
* internally to load an additional libary.
*
* This is the default as used by MemoryLoadLibrary.
*/
HCUSTOMMODULE MemoryDefaultLoadLibrary(LPCSTR, void *);
/**
* Default implementation of CustomGetProcAddressFunc that calls GetProcAddress
* internally to get the address of an exported function.
*
* This is the default as used by MemoryLoadLibrary.
*/
FARPROC MemoryDefaultGetProcAddress(HCUSTOMMODULE, LPCSTR, void *);
/**
* Default implementation of CustomFreeLibraryFunc that calls FreeLibrary
* internally to release an additional libary.
*
* This is the default as used by MemoryLoadLibrary.
*/
void MemoryDefaultFreeLibrary(HCUSTOMMODULE, void *);
#ifdef __cplusplus
}
#endif
#endif // __MEMORY_MODULE_HEADER

View File

@ -0,0 +1,43 @@
# Status available at
# https://ci.appveyor.com/project/fancycode/memorymodule
version: 1.0.{build}
os:
- Visual Studio 2015
environment:
matrix:
- GENERATOR: "Visual Studio 9 2008"
UNICODE: ON
- GENERATOR: "Visual Studio 9 2008"
UNICODE: OFF
- GENERATOR: "Visual Studio 10 2010"
UNICODE: ON
- GENERATOR: "Visual Studio 10 2010"
UNICODE: OFF
- GENERATOR: "Visual Studio 11 2012"
UNICODE: ON
- GENERATOR: "Visual Studio 11 2012"
UNICODE: OFF
- GENERATOR: "Visual Studio 12 2013"
UNICODE: ON
- GENERATOR: "Visual Studio 12 2013"
UNICODE: OFF
- GENERATOR: "Visual Studio 14 2015"
UNICODE: ON
- GENERATOR: "Visual Studio 14 2015"
UNICODE: OFF
platform:
- x86
- x64
configuration:
- Debug
install:
- call scripts\run-appveyor.bat
build: off
test: off
deploy: off

View File

@ -0,0 +1,546 @@
:author: Joachim Bauch
:contact: mail@joachim-bauch.de
:copyright: `Creative Commons License (by-sa)`__
__ http://creativecommons.org/licenses/by-sa/2.5/
.. contents::
Overview
=========
The default windows API functions to load external libraries into a program
(LoadLibrary, LoadLibraryEx) only work with files on the filesystem. It's
therefore impossible to load a DLL from memory.
But sometimes, you need exactly this functionality (e.g. you don't want to
distribute a lot of files or want to make disassembling harder). Common
workarounds for this problems are to write the DLL into a temporary file
first and import it from there. When the program terminates, the temporary
file gets deleted.
In this tutorial, I will describe first, how DLL files are structured and
will present some code that can be used to load a DLL completely from memory -
without storing on the disk first.
Windows executables - the PE format
====================================
Most windows binaries that can contain executable code (.exe, .dll, .sys)
share a common file format that consists of the following parts:
+----------------+
| DOS header |
| |
| DOS stub |
+----------------+
| PE header |
+----------------+
| Section header |
+----------------+
| Section 1 |
+----------------+
| Section 2 |
+----------------+
| . . . |
+----------------+
| Section n |
+----------------+
All structures given below can be found in the header file `winnt.h`.
DOS header / stub
------------------
The DOS header is only used for backwards compatibility. It precedes the DOS
stub that normally just displays an error message about the program not being
able to be run from DOS mode.
Microsoft defines the DOS header as follows::
typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
WORD e_magic; // Magic number
WORD e_cblp; // Bytes on last page of file
WORD e_cp; // Pages in file
WORD e_crlc; // Relocations
WORD e_cparhdr; // Size of header in paragraphs
WORD e_minalloc; // Minimum extra paragraphs needed
WORD e_maxalloc; // Maximum extra paragraphs needed
WORD e_ss; // Initial (relative) SS value
WORD e_sp; // Initial SP value
WORD e_csum; // Checksum
WORD e_ip; // Initial IP value
WORD e_cs; // Initial (relative) CS value
WORD e_lfarlc; // File address of relocation table
WORD e_ovno; // Overlay number
WORD e_res[4]; // Reserved words
WORD e_oemid; // OEM identifier (for e_oeminfo)
WORD e_oeminfo; // OEM information; e_oemid specific
WORD e_res2[10]; // Reserved words
LONG e_lfanew; // File address of new exe header
} IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
PE header
----------
The PE header contains informations about the different sections inside the
executable that are used to store code and data or to define imports from other
libraries or exports this libraries provides.
It's defined as follows::
typedef struct _IMAGE_NT_HEADERS {
DWORD Signature;
IMAGE_FILE_HEADER FileHeader;
IMAGE_OPTIONAL_HEADER32 OptionalHeader;
} IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32;
The `FileHeader` describes the *physical* format of the file, i.e. contents, informations
about symbols, etc::
typedef struct _IMAGE_FILE_HEADER {
WORD Machine;
WORD NumberOfSections;
DWORD TimeDateStamp;
DWORD PointerToSymbolTable;
DWORD NumberOfSymbols;
WORD SizeOfOptionalHeader;
WORD Characteristics;
} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
.. _OptionalHeader:
The `OptionalHeader` contains informations about the *logical* format of the library,
including required OS version, memory requirements and entry points::
typedef struct _IMAGE_OPTIONAL_HEADER {
//
// Standard fields.
//
WORD Magic;
BYTE MajorLinkerVersion;
BYTE MinorLinkerVersion;
DWORD SizeOfCode;
DWORD SizeOfInitializedData;
DWORD SizeOfUninitializedData;
DWORD AddressOfEntryPoint;
DWORD BaseOfCode;
DWORD BaseOfData;
//
// NT additional fields.
//
DWORD ImageBase;
DWORD SectionAlignment;
DWORD FileAlignment;
WORD MajorOperatingSystemVersion;
WORD MinorOperatingSystemVersion;
WORD MajorImageVersion;
WORD MinorImageVersion;
WORD MajorSubsystemVersion;
WORD MinorSubsystemVersion;
DWORD Win32VersionValue;
DWORD SizeOfImage;
DWORD SizeOfHeaders;
DWORD CheckSum;
WORD Subsystem;
WORD DllCharacteristics;
DWORD SizeOfStackReserve;
DWORD SizeOfStackCommit;
DWORD SizeOfHeapReserve;
DWORD SizeOfHeapCommit;
DWORD LoaderFlags;
DWORD NumberOfRvaAndSizes;
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
} IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32;
.. _DataDirectory:
The `DataDirectory` contains 16 (`IMAGE_NUMBEROF_DIRECTORY_ENTRIES`) entries
defining the logical components of the library:
===== ==========================
Index Description
===== ==========================
0 Exported functions
----- --------------------------
1 Imported functions
----- --------------------------
2 Resources
----- --------------------------
3 Exception informations
----- --------------------------
4 Security informations
----- --------------------------
5 Base relocation table
----- --------------------------
6 Debug informations
----- --------------------------
7 Architecture specific data
----- --------------------------
8 Global pointer
----- --------------------------
9 Thread local storage
----- --------------------------
10 Load configuration
----- --------------------------
11 Bound imports
----- --------------------------
12 Import address table
----- --------------------------
13 Delay load imports
----- --------------------------
14 COM runtime descriptor
===== ==========================
For importing the DLL we only need the entries describing the imports and the
base relocation table. In order to provide access to the exported functions,
the exports entry is required.
Section header
---------------
The section header is stored after the OptionalHeader_ structure in the PE
header. Microsoft provides the macro `IMAGE_FIRST_SECTION` to get the start
address based on the PE header.
Actually, the section header is a list of informations about each section in
the file::
typedef struct _IMAGE_SECTION_HEADER {
BYTE Name[IMAGE_SIZEOF_SHORT_NAME];
union {
DWORD PhysicalAddress;
DWORD VirtualSize;
} Misc;
DWORD VirtualAddress;
DWORD SizeOfRawData;
DWORD PointerToRawData;
DWORD PointerToRelocations;
DWORD PointerToLinenumbers;
WORD NumberOfRelocations;
WORD NumberOfLinenumbers;
DWORD Characteristics;
} IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
A section can contain code, data, relocation informations, resources, export or
import definitions, etc.
Loading the library
====================
To emulate the PE loader, we must first understand, which steps are neccessary
to load the file to memory and prepare the structures so they can be called from
other programs.
When issuing the API call `LoadLibrary`, Windows basically performs these tasks:
1. Open the given file and check the DOS and PE headers.
2. Try to allocate a memory block of `PEHeader.OptionalHeader.SizeOfImage` bytes
at position `PEHeader.OptionalHeader.ImageBase`.
3. Parse section headers and copy sections to their addresses. The destination
address for each section, relative to the base of the allocated memory block,
is stored in the `VirtualAddress` attribute of the `IMAGE_SECTION_HEADER`
structure.
4. If the allocated memory block differs from `ImageBase`, various references in
the code and/or data sections must be adjusted. This is called *Base
relocation*.
5. The required imports for the library must be resolved by loading the
corresponding libraries.
6. The memory regions of the different sections must be protected depending on
the section's characteristics. Some sections are marked as *discardable*
and therefore can be safely freed at this point. These sections normally
contain temporary data that is only needed during the import, like the
informations for the base relocation.
7. Now the library is loaded completely. It must be notified about this by
calling the entry point using the flag `DLL_PROCESS_ATTACH`.
In the following paragraphs, each step is described.
Allocate memory
----------------
All memory required for the library must be reserved / allocated using
`VirtualAlloc`, as Windows provides functions to protect these memory blocks.
This is required to restrict access to the memory, like blocking write access
to the code or constant data.
The OptionalHeader_ structure defines the size of the required memory block
for the library. It must be reserved at the address specified by `ImageBase`
if possible::
memory = VirtualAlloc((LPVOID)(PEHeader->OptionalHeader.ImageBase),
PEHeader->OptionalHeader.SizeOfImage,
MEM_RESERVE,
PAGE_READWRITE);
If the reserved memory differs from the address given in `ImageBase`, base
relocation as described below must be done.
Copy sections
--------------
Once the memory has been reserved, the file contents can be copied to the
system. The section header must get evaluated in order to determine the
position in the file and the target area in memory.
Before copying the data, the memory block must get committed::
dest = VirtualAlloc(baseAddress + section->VirtualAddress,
section->SizeOfRawData,
MEM_COMMIT,
PAGE_READWRITE);
Sections without data in the file (like data sections for the used variables)
have a `SizeOfRawData` of `0`, so you can use the `SizeOfInitializedData`
or `SizeOfUninitializedData` of the OptionalHeader_. Which one must get
choosen depending on the bit flags `IMAGE_SCN_CNT_INITIALIZED_DATA` and
`IMAGE_SCN_CNT_UNINITIALIZED_DATA` that may be set in the section`s
characteristics.
Base relocation
----------------
All memory addresses in the code / data sections of a library are stored relative
to the address defined by `ImageBase` in the OptionalHeader_. If the library
can't be imported to this memory address, the references must get adjusted
=> *relocated*. The file format helps for this by storing informations about
all these references in the base relocation table, which can be found in the
directory entry 5 of the DataDirectory_ in the OptionalHeader_.
This table consists of a series of this structure
::
typedef struct _IMAGE_BASE_RELOCATION {
DWORD VirtualAddress;
DWORD SizeOfBlock;
} IMAGE_BASE_RELOCATION;
It contains `(SizeOfBlock - IMAGE_SIZEOF_BASE_RELOCATION) / 2` entries of 16 bits
each. The upper 4 bits define the type of relocation, the lower 12 bits define
the offset relative to the `VirtualAddress`.
The only types that seem to be used in DLLs are
IMAGE_REL_BASED_ABSOLUTE
No operation relocation. Used for padding.
IMAGE_REL_BASED_HIGHLOW
Add the delta between the `ImageBase` and the allocated memory block to the
32 bits found at the offset.
Resolve imports
----------------
The directory entry 1 of the DataDirectory_ in the OptionalHeader_ specifies
a list of libraries to import symbols from. Each entry in this list is defined
as follows::
typedef struct _IMAGE_IMPORT_DESCRIPTOR {
union {
DWORD Characteristics; // 0 for terminating null import descriptor
DWORD OriginalFirstThunk; // RVA to original unbound IAT (PIMAGE_THUNK_DATA)
};
DWORD TimeDateStamp; // 0 if not bound,
// -1 if bound, and real date\time stamp
// in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
// O.W. date/time stamp of DLL bound to (Old BIND)
DWORD ForwarderChain; // -1 if no forwarders
DWORD Name;
DWORD FirstThunk; // RVA to IAT (if bound this IAT has actual addresses)
} IMAGE_IMPORT_DESCRIPTOR;
The `Name` entry describes the offset to the NULL-terminated string of the library
name (e.g. `KERNEL32.DLL`). The `OriginalFirstThunk` entry points to a list
of references to the function names to import from the external library.
`FirstThunk` points to a list of addresses that gets filled with pointers to
the imported symbols.
When we resolve the imports, we walk both lists in parallel, import the function
defined by the name in the first list and store the pointer to the symbol in the
second list::
nameRef = (DWORD *)(baseAddress + importDesc->OriginalFirstThunk);
symbolRef = (DWORD *)(baseAddress + importDesc->FirstThunk);
for (; *nameRef; nameRef++, symbolRef++)
{
PIMAGE_IMPORT_BY_NAME thunkData = (PIMAGE_IMPORT_BY_NAME)(codeBase + *nameRef);
*symbolRef = (DWORD)GetProcAddress(handle, (LPCSTR)&thunkData->Name);
if (*funcRef == 0)
{
handleImportError();
return;
}
}
Protect memory
---------------
Every section specifies permission flags in it's `Characteristics` entry.
These flags can be one or a combination of
IMAGE_SCN_MEM_EXECUTE
The section contains data that can be executed.
IMAGE_SCN_MEM_READ
The section contains data that is readable.
IMAGE_SCN_MEM_WRITE
The section contains data that is writeable.
These flags must get mapped to the protection flags
- PAGE_NOACCESS
- PAGE_WRITECOPY
- PAGE_READONLY
- PAGE_READWRITE
- PAGE_EXECUTE
- PAGE_EXECUTE_WRITECOPY
- PAGE_EXECUTE_READ
- PAGE_EXECUTE_READWRITE
Now, the function `VirtualProtect` can be used to limit access to the memory.
If the program tries to access it in a unauthorized way, an exception gets
raised by Windows.
In addition the section flags above, the following can be added:
IMAGE_SCN_MEM_DISCARDABLE
The data in this section can be freed after the import. Usually this is
specified for relocation data.
IMAGE_SCN_MEM_NOT_CACHED
The data in this section must not get cached by Windows. Add the bit
flag `PAGE_NOCACHE` to the protection flags above.
Notify library
---------------
The last thing to do is to call the DLL entry point (defined by
`AddressOfEntryPoint`) and so notifying the library about being attached
to a process.
The function at the entry point is defined as
::
typedef BOOL (WINAPI *DllEntryProc)(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved);
So the last code we need to execute is
::
DllEntryProc entry = (DllEntryProc)(baseAddress + PEHeader->OptionalHeader.AddressOfEntryPoint);
(*entry)((HINSTANCE)baseAddress, DLL_PROCESS_ATTACH, 0);
Afterwards we can use the exported functions as with any normal library.
Exported functions
===================
If you want to access the functions that are exported by the library, you need to find the entry
point to a symbol, i.e. the name of the function to call.
The directory entry 0 of the DataDirectory_ in the OptionalHeader_ contains informations about
the exported functions. It's defined as follows::
typedef struct _IMAGE_EXPORT_DIRECTORY {
DWORD Characteristics;
DWORD TimeDateStamp;
WORD MajorVersion;
WORD MinorVersion;
DWORD Name;
DWORD Base;
DWORD NumberOfFunctions;
DWORD NumberOfNames;
DWORD AddressOfFunctions; // RVA from base of image
DWORD AddressOfNames; // RVA from base of image
DWORD AddressOfNameOrdinals; // RVA from base of image
} IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
First thing to do, is to map the name of the function to the ordinal number of the exported
symbol. Therefore, just walk the arrays defined by `AddressOfNames` and `AddressOfNameOrdinals`
parallel until you found the required name.
Now you can use the ordinal number to read the address by evaluating the n-th element of the
`AddressOfFunctions` array.
Freeing the library
====================
To free the custom loaded library, perform the steps
- Call entry point to notify library about being detached::
DllEntryProc entry = (DllEntryProc)(baseAddress + PEHeader->OptionalHeader.AddressOfEntryPoint);
(*entry)((HINSTANCE)baseAddress, DLL_PROCESS_ATTACH, 0);
- Free external libraries used to resolve imports.
- Free allocated memory.
MemoryModule
=============
MemoryModule is a C-library that can be used to load a DLL from memory.
The interface is very similar to the standard methods for loading of libraries::
typedef void *HMEMORYMODULE;
HMEMORYMODULE MemoryLoadLibrary(const void *, size_t);
FARPROC MemoryGetProcAddress(HMEMORYMODULE, const char *);
void MemoryFreeLibrary(HMEMORYMODULE);
Downloads
----------
The latest development release can always be grabbed from Github at
http://github.com/fancycode/MemoryModule/
Known issues
-------------
- All memory that is not protected by section flags is gets committed using `PAGE_READWRITE`.
I don't know if this is correct.
License
--------
Since version 0.0.2, the MemoryModule library is released under the Mozilla Public License (MPL).
Version 0.0.1 has been released unter the Lesser General Public License (LGPL).
It is provided as-is without ANY warranty. You may use it at your own risk.
Copyright
==========
The MemoryModule library and this tutorial are
Copyright (c) 2004-2015 by Joachim Bauch.

View File

@ -0,0 +1,2 @@
add_subdirectory (DllLoader)
add_subdirectory (SampleDLL)

View File

@ -0,0 +1,2 @@
*.o
*.exe

View File

@ -0,0 +1,26 @@
set (sources_dllloader
DllLoader.cpp
)
set (sources_dllloaderloader
DllLoaderLoader.cpp
)
if (NOT MSVC)
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-static")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-static")
endif ()
add_executable (DllLoader ${sources_dllloader})
target_link_libraries ("DllLoader" "MemoryModule")
if (NOT MSVC)
set_target_properties ("DllLoader" PROPERTIES SUFFIX ".exe")
set_target_properties ("DllLoader" PROPERTIES LINK_FLAGS "-Wl,--image-base -Wl,0x20000000")
endif ()
add_executable (DllLoaderLoader ${sources_dllloaderloader})
target_link_libraries ("DllLoaderLoader" "MemoryModule")
if (NOT MSVC)
set_target_properties ("DllLoaderLoader" PROPERTIES SUFFIX ".exe")
set_target_properties ("DllLoaderLoader" PROPERTIES LINK_FLAGS "-Wl,--image-base -Wl,0x10000000")
endif ()

View File

@ -0,0 +1,343 @@
#define WIN32_LEAN_AND_MEAN
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <assert.h>
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <malloc.h>
#include "../../MemoryModule.h"
typedef int (*addNumberProc)(int, int);
#define DLL_FILE TEXT("..\\SampleDLL\\SampleDLL.dll")
void LoadFromFile(void)
{
addNumberProc addNumber;
HRSRC resourceInfo;
DWORD resourceSize;
LPVOID resourceData;
TCHAR buffer[100];
HINSTANCE handle = LoadLibrary(DLL_FILE);
if (handle == NULL)
return;
addNumber = (addNumberProc)GetProcAddress(handle, "addNumbers");
_tprintf(_T("From file: %d\n"), addNumber(1, 2));
resourceInfo = FindResource(handle, MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);
_tprintf(_T("FindResource returned 0x%p\n"), resourceInfo);
resourceSize = SizeofResource(handle, resourceInfo);
resourceData = LoadResource(handle, resourceInfo);
_tprintf(_T("Resource data: %ld bytes at 0x%p\n"), resourceSize, resourceData);
LoadString(handle, 1, buffer, sizeof(buffer));
_tprintf(_T("String1: %s\n"), buffer);
LoadString(handle, 20, buffer, sizeof(buffer));
_tprintf(_T("String2: %s\n"), buffer);
FreeLibrary(handle);
}
void* ReadLibrary(size_t* pSize) {
size_t read;
void* result;
FILE* fp;
fp = _tfopen(DLL_FILE, _T("rb"));
if (fp == NULL)
{
_tprintf(_T("Can't open DLL file \"%s\"."), DLL_FILE);
return NULL;
}
fseek(fp, 0, SEEK_END);
*pSize = static_cast<size_t>(ftell(fp));
if (*pSize == 0)
{
fclose(fp);
return NULL;
}
result = (unsigned char *)malloc(*pSize);
if (result == NULL)
{
return NULL;
}
fseek(fp, 0, SEEK_SET);
read = fread(result, 1, *pSize, fp);
fclose(fp);
if (read != *pSize)
{
free(result);
return NULL;
}
return result;
}
void LoadFromMemory(void)
{
void *data;
size_t size;
HMEMORYMODULE handle;
addNumberProc addNumber;
HMEMORYRSRC resourceInfo;
DWORD resourceSize;
LPVOID resourceData;
TCHAR buffer[100];
data = ReadLibrary(&size);
if (data == NULL)
{
return;
}
handle = MemoryLoadLibrary(data, size);
if (handle == NULL)
{
_tprintf(_T("Can't load library from memory.\n"));
goto exit;
}
addNumber = (addNumberProc)MemoryGetProcAddress(handle, "addNumbers");
_tprintf(_T("From memory: %d\n"), addNumber(1, 2));
resourceInfo = MemoryFindResource(handle, MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);
_tprintf(_T("MemoryFindResource returned 0x%p\n"), resourceInfo);
resourceSize = MemorySizeofResource(handle, resourceInfo);
resourceData = MemoryLoadResource(handle, resourceInfo);
_tprintf(_T("Memory resource data: %ld bytes at 0x%p\n"), resourceSize, resourceData);
MemoryLoadString(handle, 1, buffer, sizeof(buffer));
_tprintf(_T("String1: %s\n"), buffer);
MemoryLoadString(handle, 20, buffer, sizeof(buffer));
_tprintf(_T("String2: %s\n"), buffer);
MemoryFreeLibrary(handle);
exit:
free(data);
}
#define MAX_CALLS 20
struct CallList {
int current_alloc_call, current_free_call;
CustomAllocFunc alloc_calls[MAX_CALLS];
CustomFreeFunc free_calls[MAX_CALLS];
};
LPVOID MemoryFailingAlloc(LPVOID address, SIZE_T size, DWORD allocationType, DWORD protect, void* userdata)
{
UNREFERENCED_PARAMETER(address);
UNREFERENCED_PARAMETER(size);
UNREFERENCED_PARAMETER(allocationType);
UNREFERENCED_PARAMETER(protect);
UNREFERENCED_PARAMETER(userdata);
return NULL;
}
LPVOID MemoryMockAlloc(LPVOID address, SIZE_T size, DWORD allocationType, DWORD protect, void* userdata)
{
CallList* calls = (CallList*)userdata;
CustomAllocFunc current_func = calls->alloc_calls[calls->current_alloc_call++];
assert(current_func != NULL);
return current_func(address, size, allocationType, protect, NULL);
}
BOOL MemoryMockFree(LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType, void* userdata)
{
CallList* calls = (CallList*)userdata;
CustomFreeFunc current_func = calls->free_calls[calls->current_free_call++];
assert(current_func != NULL);
return current_func(lpAddress, dwSize, dwFreeType, NULL);
}
void InitFuncs(void** funcs, va_list args) {
for (int i = 0; ; i++) {
assert(i < MAX_CALLS);
funcs[i] = va_arg(args, void*);
if (funcs[i] == NULL) break;
}
}
void InitAllocFuncs(CallList* calls, ...) {
va_list args;
va_start(args, calls);
InitFuncs((void**)calls->alloc_calls, args);
va_end(args);
calls->current_alloc_call = 0;
}
void InitFreeFuncs(CallList* calls, ...) {
va_list args;
va_start(args, calls);
InitFuncs((void**)calls->free_calls, args);
va_end(args);
calls->current_free_call = 0;
}
void InitFreeFunc(CallList* calls, CustomFreeFunc freeFunc) {
for (int i = 0; i < MAX_CALLS; i++) {
calls->free_calls[i] = freeFunc;
}
calls->current_free_call = 0;
}
void TestFailingAllocation(void *data, size_t size) {
CallList expected_calls;
HMEMORYMODULE handle;
InitAllocFuncs(&expected_calls, MemoryFailingAlloc, MemoryFailingAlloc, NULL);
InitFreeFuncs(&expected_calls, NULL);
handle = MemoryLoadLibraryEx(
data, size, MemoryMockAlloc, MemoryMockFree, MemoryDefaultLoadLibrary,
MemoryDefaultGetProcAddress, MemoryDefaultFreeLibrary, &expected_calls);
assert(handle == NULL);
assert(GetLastError() == ERROR_OUTOFMEMORY);
assert(expected_calls.current_free_call == 0);
MemoryFreeLibrary(handle);
assert(expected_calls.current_free_call == 0);
}
void TestCleanupAfterFailingAllocation(void *data, size_t size) {
CallList expected_calls;
HMEMORYMODULE handle;
int free_calls_after_loading;
InitAllocFuncs(&expected_calls,
MemoryDefaultAlloc,
MemoryDefaultAlloc,
MemoryDefaultAlloc,
MemoryDefaultAlloc,
MemoryFailingAlloc,
NULL);
InitFreeFuncs(&expected_calls, MemoryDefaultFree, NULL);
handle = MemoryLoadLibraryEx(
data, size, MemoryMockAlloc, MemoryMockFree, MemoryDefaultLoadLibrary,
MemoryDefaultGetProcAddress, MemoryDefaultFreeLibrary, &expected_calls);
free_calls_after_loading = expected_calls.current_free_call;
MemoryFreeLibrary(handle);
assert(expected_calls.current_free_call == free_calls_after_loading);
}
void TestFreeAfterDefaultAlloc(void *data, size_t size) {
CallList expected_calls;
HMEMORYMODULE handle;
int free_calls_after_loading;
// Note: free might get called internally multiple times
InitFreeFunc(&expected_calls, MemoryDefaultFree);
handle = MemoryLoadLibraryEx(
data, size, MemoryDefaultAlloc, MemoryMockFree, MemoryDefaultLoadLibrary,
MemoryDefaultGetProcAddress, MemoryDefaultFreeLibrary, &expected_calls);
assert(handle != NULL);
free_calls_after_loading = expected_calls.current_free_call;
MemoryFreeLibrary(handle);
assert(expected_calls.current_free_call == free_calls_after_loading + 1);
}
#ifdef _WIN64
LPVOID MemoryAllocHigh(LPVOID address, SIZE_T size, DWORD allocationType, DWORD protect, void* userdata)
{
int* counter = static_cast<int*>(userdata);
if (*counter == 0) {
// Make sure the image gets loaded to an address above 32bit.
uintptr_t offset = 0x10000000000;
address = (LPVOID) ((uintptr_t) address + offset);
}
(*counter)++;
return MemoryDefaultAlloc(address, size, allocationType, protect, NULL);
}
void TestAllocHighMemory(void *data, size_t size) {
HMEMORYMODULE handle;
int counter = 0;
addNumberProc addNumber;
HMEMORYRSRC resourceInfo;
DWORD resourceSize;
LPVOID resourceData;
TCHAR buffer[100];
handle = MemoryLoadLibraryEx(
data, size, MemoryAllocHigh, MemoryDefaultFree, MemoryDefaultLoadLibrary,
MemoryDefaultGetProcAddress, MemoryDefaultFreeLibrary, &counter);
assert(handle != NULL);
addNumber = (addNumberProc)MemoryGetProcAddress(handle, "addNumbers");
_tprintf(_T("From memory: %d\n"), addNumber(1, 2));
resourceInfo = MemoryFindResource(handle, MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);
_tprintf(_T("MemoryFindResource returned 0x%p\n"), resourceInfo);
resourceSize = MemorySizeofResource(handle, resourceInfo);
resourceData = MemoryLoadResource(handle, resourceInfo);
_tprintf(_T("Memory resource data: %ld bytes at 0x%p\n"), resourceSize, resourceData);
MemoryLoadString(handle, 1, buffer, sizeof(buffer));
_tprintf(_T("String1: %s\n"), buffer);
MemoryLoadString(handle, 20, buffer, sizeof(buffer));
_tprintf(_T("String2: %s\n"), buffer);
MemoryFreeLibrary(handle);
}
#endif // _WIN64
void TestCustomAllocAndFree(void)
{
void *data;
size_t size;
data = ReadLibrary(&size);
if (data == NULL)
{
return;
}
_tprintf(_T("Test MemoryLoadLibraryEx after initially failing allocation function\n"));
TestFailingAllocation(data, size);
_tprintf(_T("Test cleanup after MemoryLoadLibraryEx with failing allocation function\n"));
TestCleanupAfterFailingAllocation(data, size);
_tprintf(_T("Test custom free function after MemoryLoadLibraryEx\n"));
TestFreeAfterDefaultAlloc(data, size);
#ifdef _WIN64
_tprintf(_T("Test allocating in high memory\n"));
TestAllocHighMemory(data, size);
#endif
free(data);
}
int main()
{
LoadFromFile();
printf("\n\n");
LoadFromMemory();
printf("\n\n");
TestCustomAllocAndFree();
return 0;
}

View File

@ -0,0 +1,138 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="DllLoader"
ProjectGUID="{D0226BB5-3A02-4C91-893A-F36567AED5C5}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/DllLoader.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/DllLoader.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="4"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/DllLoader.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Quelldateien"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\DllLoader.cpp">
</File>
<File
RelativePath="..\..\MemoryModule.c">
</File>
</Filter>
<Filter
Name="Headerdateien"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath="..\..\MemoryModule.h">
</File>
</Filter>
<Filter
Name="Ressourcendateien"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,64 @@
#define WIN32_LEAN_AND_MEAN
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <assert.h>
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <malloc.h>
#include "../../MemoryModule.h"
#define EXE_FILE TEXT("DllLoader.exe")
int RunFromMemory(void)
{
FILE *fp;
unsigned char *data=NULL;
long size;
size_t read;
HMEMORYMODULE handle;
int result = -1;
fp = _tfopen(EXE_FILE, _T("rb"));
if (fp == NULL)
{
_tprintf(_T("Can't open executable \"%s\"."), EXE_FILE);
goto exit;
}
fseek(fp, 0, SEEK_END);
size = ftell(fp);
assert(size >= 0);
data = (unsigned char *)malloc(size);
assert(data != NULL);
fseek(fp, 0, SEEK_SET);
read = fread(data, 1, size, fp);
assert(read == static_cast<size_t>(size));
fclose(fp);
handle = MemoryLoadLibrary(data, size);
if (handle == NULL)
{
_tprintf(_T("Can't load library from memory.\n"));
goto exit;
}
result = MemoryCallEntryPoint(handle);
if (result < 0) {
_tprintf(_T("Could not execute entry point: %d\n"), result);
}
MemoryFreeLibrary(handle);
exit:
free(data);
return result;
}
int main()
{
return RunFromMemory();
}

View File

@ -0,0 +1,42 @@
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
ifndef PLATFORM
PLATFORM = i686
endif
CC = $(PLATFORM)-w64-mingw32-g++
CXX = $(PLATFORM)-w64-mingw32-g++
LINK = $(PLATFORM)-w64-mingw32-ld
else
CC = g++
CXX = g++
LINK = ld
endif
RM = rm
CFLAGS = -Wall -g
LDFLAGS = -static
ifdef UNICODE
CFLAGS += -DUNICODE -D_UNICODE
endif
OBJ = DllLoader.o ../../MemoryModule.o
OBJ_LOADER = DllLoaderLoader.o ../../MemoryModule.o
all: DllLoader.exe DllLoaderLoader.exe
DllLoader.exe: $(OBJ)
$(CC) $(LDFLAGS) -Wl,--image-base -Wl,0x20000000 -o DllLoader.exe $(OBJ)
DllLoaderLoader.exe: $(OBJ_LOADER)
$(CC) $(LDFLAGS) -Wl,--image-base -Wl,0x10000000 -o DllLoaderLoader.exe $(OBJ_LOADER)
%.o: %.cpp
$(CXX) $(CFLAGS) -c $<
%.o: %.cc
$(CC) $(CFLAGS) -c $<
clean:
$(RM) -rf $(OBJ) $(OBJ_LOADER) DllLoader.exe DllLoaderLoader.exe

View File

@ -0,0 +1,30 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SampleDLL", "SampleDLL\SampleDLL.vcproj", "{B293DAC4-5BCA-4413-9B7B-92CB56459875}"
ProjectSection(ProjectDependencies) = postProject
{D0226BB5-3A02-4C91-893A-F36567AED5C5} = {D0226BB5-3A02-4C91-893A-F36567AED5C5}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DllLoader", "DllLoader\DllLoader.vcproj", "{D0226BB5-3A02-4C91-893A-F36567AED5C5}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{B293DAC4-5BCA-4413-9B7B-92CB56459875}.Debug.ActiveCfg = Debug|Win32
{B293DAC4-5BCA-4413-9B7B-92CB56459875}.Debug.Build.0 = Debug|Win32
{B293DAC4-5BCA-4413-9B7B-92CB56459875}.Release.ActiveCfg = Release|Win32
{B293DAC4-5BCA-4413-9B7B-92CB56459875}.Release.Build.0 = Release|Win32
{D0226BB5-3A02-4C91-893A-F36567AED5C5}.Debug.ActiveCfg = Debug|Win32
{D0226BB5-3A02-4C91-893A-F36567AED5C5}.Debug.Build.0 = Debug|Win32
{D0226BB5-3A02-4C91-893A-F36567AED5C5}.Release.ActiveCfg = Release|Win32
{D0226BB5-3A02-4C91-893A-F36567AED5C5}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,17 @@
SUBDIRS = DllLoader SampleDLL
.PHONY: subdirs $(SUBDIRS)
subdirs: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@
CLEANDIRS = $(SUBDIRS:%=clean-%)
clean: $(CLEANDIRS)
$(CLEANDIRS):
$(MAKE) -C $(@:clean-%=%) clean
.PHONY: subdirs $(INSTALLDIRS)
.PHONY: clean

View File

@ -0,0 +1,3 @@
*.o
*.dll
*.res

View File

@ -0,0 +1,12 @@
set (sources
SampleDLL.cpp
SampleDLL.h
SampleDLL.rc
)
add_definitions (-DSAMPLEDLL_EXPORTS)
add_library (SampleDLL MODULE ${sources})
if (NOT MSVC)
set_target_properties ("SampleDLL" PROPERTIES PREFIX "")
set_target_properties ("SampleDLL" PROPERTIES SUFFIX ".dll")
endif ()

View File

@ -0,0 +1,39 @@
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
ifndef PLATFORM
PLATFORM = i686
endif
CC = $(PLATFORM)-w64-mingw32-g++
CXX = $(PLATFORM)-w64-mingw32-g++
LINK = $(PLATFORM)-w64-mingw32-g++
RC = $(PLATFORM)-w64-mingw32-windres
else
CC = g++
CXX = g++
LINK = ld
RC = rc
endif
RM = rm
CFLAGS = -Wall -g -DSAMPLEDLL_EXPORTS
LDFLAGS = -shared
RCFLAGS = -O coff
ifdef UNICODE
CFLAGS += -DUNICODE -D_UNICODE
endif
OBJ = SampleDLL.o SampleDLL.res
SampleDLL.dll: $(OBJ)
$(LINK) $(LDFLAGS) -o SampleDLL.dll $(OBJ)
%.o: %.cpp
$(CXX) $(CFLAGS) -c $<
%.res: %.rc
$(RC) $(RCFLAGS) -o $*.res $<
clean:
$(RM) -rf $(OBJ) SampleDLL.dll

View File

@ -0,0 +1,10 @@
#include "SampleDLL.h"
extern "C" {
SAMPLEDLL_API int addNumbers(int a, int b)
{
return a + b;
}
}

View File

@ -0,0 +1,11 @@
extern "C" {
#ifdef SAMPLEDLL_EXPORTS
#define SAMPLEDLL_API __declspec(dllexport)
#else
#define SAMPLEDLL_API __declspec(dllimport)
#endif
SAMPLEDLL_API int addNumbers(int a, int b);
}

View File

@ -0,0 +1,34 @@
1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4"
BEGIN
VALUE "CompanyName", "fancy.code"
VALUE "FileDescription", "SampleDLL"
VALUE "FileVersion", "1.0"
VALUE "InternalName", "SampleDLL"
VALUE "LegalCopyright", "Copyright (c) 2004-2015 Joachim Bauch"
VALUE "OriginalFilename", "SampleDLL.dll"
VALUE "ProductName", "MemoryModule"
VALUE "ProductVersion", "0.0.4"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1252
END
END
#define IDS_HELLO 1
#define IDS_WORLD 20
STRINGTABLE
{
IDS_HELLO, "Hello"
IDS_WORLD, "World!"
}

View File

@ -0,0 +1,137 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="SampleDLL"
ProjectGUID="{B293DAC4-5BCA-4413-9B7B-92CB56459875}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;SAMPLEDLL_EXPORTS"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/SampleDLL.dll"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/SampleDLL.pdb"
SubSystem="2"
ImportLibrary="$(OutDir)/SampleDLL.lib"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SAMPLEDLL_EXPORTS"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/SampleDLL.dll"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
ImportLibrary="$(OutDir)/SampleDLL.lib"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Quelldateien"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\SampleDLL.cpp">
</File>
</Filter>
<Filter
Name="Headerdateien"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\SampleDLL.h">
</File>
</Filter>
<Filter
Name="Ressourcendateien"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,20 @@
MemoryModule
============
[![Build Status](https://travis-ci.org/fancycode/MemoryModule.svg?branch=master)](https://travis-ci.org/fancycode/MemoryModule)[![Build status](https://ci.appveyor.com/api/projects/status/qcrfxbno0jbbl9cx/branch/master?svg=true)](https://ci.appveyor.com/project/fancycode/memorymodule)
The default windows API functions to load external libraries into a program
(`LoadLibrary`, `LoadLibraryEx`) only work with files on the filesystem. It's
therefore impossible to load a DLL from memory.
But sometimes, you need exactly this functionality (e.g. you don't want to
distribute a lot of files or want to make disassembling harder). Common
workarounds for this problems are to write the DLL into a temporary file
first and import it from there. When the program terminates, the temporary
file gets deleted.
`MemoryModule` is a library that can be used to load a DLL completely from
memory - without storing on the disk first.
See `doc/readme.rst` for more informations about the format of a DLL file and
a tutorial how they can be loaded directly.

View File

@ -0,0 +1,48 @@
@echo off
setlocal
if /I "%PLATFORM%" == "x64" (
set CMAKE_GEN_SUFFIX= Win64
if /I "%GENERATOR%" == "Visual Studio 9 2008" (
echo Skipping %CONFIGURATION% build using %GENERATOR%%CMAKE_GEN_SUFFIX% on %PLATFORM%
exit 0
)
) else (
set CMAKE_GEN_SUFFIX=
)
echo.
echo Preparing %CONFIGURATION% build environment for %GENERATOR%%CMAKE_GEN_SUFFIX% ...
cmake "-G%GENERATOR%%CMAKE_GEN_SUFFIX%" -DPLATFORM=%PLATFORM% -DUNICODE=%UNICODE% -DTESTSUITE=ON -H. -Bbuild
if %errorlevel% neq 0 exit /b %errorlevel%
echo.
echo Building ...
cmake --build build --config %CONFIGURATION%
if %errorlevel% neq 0 exit /b %errorlevel%
echo.
echo Copying generated files ...
copy /y build\example\DllLoader\%CONFIGURATION%\DllLoader.exe build\example\DllLoader\ > NUL
copy /y build\example\DllLoader\%CONFIGURATION%\DllLoaderLoader.exe build\example\DllLoader\ > NUL
copy /y build\example\SampleDLL\%CONFIGURATION%\SampleDLL.dll build\example\SampleDLL\ > NUL
copy /y build\tests\%CONFIGURATION%\TestSuite.exe build\tests\ > NUL
cd build\example\DllLoader
echo.
echo Running DllLoader.exe ...
DllLoader.exe
if %errorlevel% neq 0 exit /b %errorlevel%
echo.
echo Running DllLoaderLoader.exe ...
DllLoaderLoader.exe
if %errorlevel% neq 0 exit /b %errorlevel%
cd ..\..\tests
echo.
echo Running TestSuite.exe ...
TestSuite.exe
if %errorlevel% neq 0 exit /b %errorlevel%

View File

@ -0,0 +1,14 @@
set (sources_testsuite
TestSuite.c
)
if (NOT MSVC)
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-static")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-static")
endif ()
add_executable (TestSuite ${sources_testsuite})
target_link_libraries ("TestSuite" "MemoryModule")
if (NOT MSVC)
set_target_properties ("TestSuite" PROPERTIES SUFFIX ".exe")
endif ()

View File

@ -0,0 +1,304 @@
#define WIN32_LEAN_AND_MEAN
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <assert.h>
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <malloc.h>
#include "../MemoryModule.h"
typedef int (*addProc)(int);
typedef int (*addNumberProc)(int, int);
// Thanks to Tim Cooper (from http://stackoverflow.com/a/8584708)
const char *sstrstr(const char *haystack, const char *needle, size_t length) {
size_t needle_length = strlen(needle);
size_t i;
for (i = 0; i < length; i++) {
if (i + needle_length > length) {
return NULL;
}
if (strncmp(&haystack[i], needle, needle_length) == 0) {
return &haystack[i];
}
}
return NULL;
}
const wchar_t *swcsstr(const wchar_t *haystack, const wchar_t *needle, size_t length) {
size_t needle_length = wcslen(needle);
size_t i;
for (i = 0; i < length; i++) {
if (i + needle_length > length) {
return NULL;
}
if (wcsncmp(&haystack[i], needle, needle_length) == 0) {
return &haystack[i];
}
}
return NULL;
}
BOOL CheckResourceStrings(LPVOID data, DWORD size, const char *first, const wchar_t *second) {
const char *first_pos;
const wchar_t *second_pos;
const wchar_t *src;
if (data == NULL || size == 0) {
return FALSE;
}
first_pos = sstrstr((const char *) data, first, size);
if (first_pos == NULL) {
fprintf(stderr, "ERROR: data doesn't start with %s\n", first);
return FALSE;
}
src = (const wchar_t *) (((const char *) data) + strlen(first) + 1);
second_pos = swcsstr(src, second, (size - strlen(first) - 1) / sizeof(wchar_t));
if (second_pos == NULL) {
fwprintf(stderr, L"ERROR: data doesn't continue with %s\n", second);
return FALSE;
}
return TRUE;
}
BOOL LoadFromMemory(char *filename)
{
FILE *fp;
unsigned char *data=NULL;
long size;
size_t read;
HMEMORYMODULE handle = NULL;
addNumberProc addNumber;
addNumberProc addNumber2;
HMEMORYRSRC resourceInfo;
DWORD resourceSize;
LPVOID resourceData;
TCHAR buffer[100];
BOOL result = TRUE;
fp = fopen(filename, "rb");
if (fp == NULL)
{
printf("Can't open DLL file \"%s\".", filename);
result = FALSE;
goto exit;
}
fseek(fp, 0, SEEK_END);
size = ftell(fp);
assert(size > 0);
data = (unsigned char *)malloc(size);
assert(data != NULL);
fseek(fp, 0, SEEK_SET);
read = fread(data, 1, size, fp);
assert(read == static_cast<size_t>(size));
fclose(fp);
handle = MemoryLoadLibrary(data, size);
if (handle == NULL)
{
_tprintf(_T("Can't load library from memory.\n"));
result = FALSE;
goto exit;
}
addNumber = (addNumberProc)MemoryGetProcAddress(handle, NULL);
if (addNumber != NULL) {
_tprintf(_T("MemoryGetProcAddress(NULL) returned %p\n"), addNumber);
result = FALSE;
goto exit;
}
addNumber = (addNumberProc)MemoryGetProcAddress(handle, reinterpret_cast<LPCSTR>(0xff));
if (addNumber != NULL) {
_tprintf(_T("MemoryGetProcAddress(0xff) returned %p\n"), addNumber);
result = FALSE;
goto exit;
}
addNumber = (addNumberProc)MemoryGetProcAddress(handle, "addNumbers");
if (!addNumber) {
_tprintf(_T("MemoryGetProcAddress(\"addNumber\") returned NULL\n"));
result = FALSE;
goto exit;
}
_tprintf(_T("From memory: %d\n"), addNumber(1, 2));
// the DLL only exports one function, try to load by ordinal value
addNumber2 = (addNumberProc)MemoryGetProcAddress(handle, reinterpret_cast<LPCSTR>(0x01));
if (addNumber != addNumber2) {
_tprintf(_T("MemoryGetProcAddress(0x01) returned %p (expected %p)\n"), addNumber2, addNumber);
result = FALSE;
goto exit;
}
resourceInfo = MemoryFindResource(handle, MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);
_tprintf(_T("MemoryFindResource returned 0x%p\n"), resourceInfo);
if (resourceInfo != NULL) {
resourceSize = MemorySizeofResource(handle, resourceInfo);
resourceData = MemoryLoadResource(handle, resourceInfo);
_tprintf(_T("Memory resource data: %ld bytes at 0x%p\n"), resourceSize, resourceData);
MemoryLoadString(handle, 1, buffer, sizeof(buffer));
_tprintf(_T("String1: %s\n"), buffer);
MemoryLoadString(handle, 20, buffer, sizeof(buffer));
_tprintf(_T("String2: %s\n"), buffer);
} else {
result = FALSE;
}
resourceInfo = MemoryFindResource(handle, _T("stringres"), RT_RCDATA);
_tprintf(_T("MemoryFindResource returned 0x%p\n"), resourceInfo);
if (resourceInfo != NULL) {
resourceSize = MemorySizeofResource(handle, resourceInfo);
resourceData = MemoryLoadResource(handle, resourceInfo);
_tprintf(_T("Memory resource data: %ld bytes at 0x%p\n"), resourceSize, resourceData);
if (!CheckResourceStrings(resourceData, resourceSize, "This is a ANSI string", L"This is a UNICODE string")) {
result = FALSE;
}
} else {
result = FALSE;
}
resourceInfo = MemoryFindResource(handle, _T("stringres1"), RT_RCDATA);
_tprintf(_T("MemoryFindResource returned 0x%p\n"), resourceInfo);
if (resourceInfo != NULL) {
resourceSize = MemorySizeofResource(handle, resourceInfo);
resourceData = MemoryLoadResource(handle, resourceInfo);
_tprintf(_T("Memory resource data: %ld bytes at 0x%p\n"), resourceSize, resourceData);
if (!CheckResourceStrings(resourceData, resourceSize, "This is ANSI string 1", L"This is UNICODE string 1")) {
result = FALSE;
}
} else {
result = FALSE;
}
resourceInfo = MemoryFindResource(handle, _T("stringres2"), RT_RCDATA);
_tprintf(_T("MemoryFindResource returned 0x%p\n"), resourceInfo);
if (resourceInfo != NULL) {
resourceSize = MemorySizeofResource(handle, resourceInfo);
resourceData = MemoryLoadResource(handle, resourceInfo);
_tprintf(_T("Memory resource data: %ld bytes at 0x%p\n"), resourceSize, resourceData);
if (!CheckResourceStrings(resourceData, resourceSize, "This is ANSI string 2", L"This is UNICODE string 2")) {
result = FALSE;
}
} else {
result = FALSE;
}
resourceInfo = MemoryFindResource(handle, _T("stringres3"), RT_RCDATA);
_tprintf(_T("MemoryFindResource returned 0x%p\n"), resourceInfo);
if (resourceInfo != NULL) {
resourceSize = MemorySizeofResource(handle, resourceInfo);
resourceData = MemoryLoadResource(handle, resourceInfo);
_tprintf(_T("Memory resource data: %ld bytes at 0x%p\n"), resourceSize, resourceData);
if (!CheckResourceStrings(resourceData, resourceSize, "This is ANSI string 3", L"This is UNICODE string 3")) {
result = FALSE;
}
} else {
result = FALSE;
}
exit:
MemoryFreeLibrary(handle);
free(data);
return result;
}
BOOL LoadExportsFromMemory(char *filename)
{
FILE *fp;
unsigned char *data=NULL;
long size;
size_t read;
HMEMORYMODULE handle = NULL;
int i;
BOOL result = TRUE;
fp = fopen(filename, "rb");
if (fp == NULL)
{
printf("Can't open DLL file \"%s\".", filename);
result = FALSE;
goto exit;
}
fseek(fp, 0, SEEK_END);
size = ftell(fp);
assert(size > 0);
data = (unsigned char *)malloc(size);
assert(data != NULL);
fseek(fp, 0, SEEK_SET);
read = fread(data, 1, size, fp);
assert(read == static_cast<size_t>(size));
fclose(fp);
handle = MemoryLoadLibrary(data, size);
if (handle == NULL)
{
_tprintf(_T("Can't load library from memory.\n"));
result = FALSE;
goto exit;
}
for (i = 1; i <= 100; i++) {
char name[100];
sprintf(name, "add%d", i);
addProc addNumber = (addProc)MemoryGetProcAddress(handle, name);
if (!addNumber) {
_tprintf(_T("MemoryGetProcAddress(\"%s\") returned NULL\n"), name);
result = FALSE;
goto exit;
}
int result = addNumber(1);
if (result != 1 + i) {
_tprintf(_T("(\"%s\") returned %d, expected %d\n"), name, result, 1 + i);
result = FALSE;
goto exit;
}
_tprintf(_T("%s: %d\n"), name, result);
}
exit:
MemoryFreeLibrary(handle);
free(data);
return result;
}
int main(int argc, char* argv[])
{
if (argc < 2) {
fprintf(stderr, "USAGE: %s <filename.dll>\n", argv[0]);
return 1;
}
if (!strstr((const char *) argv[1], "exports")) {
if (!LoadFromMemory(argv[1])) {
return 2;
}
} else {
if (!LoadExportsFromMemory(argv[1])) {
return 2;
}
}
return 0;
}

View File

@ -0,0 +1,96 @@
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
ifndef PLATFORM
PLATFORM = i686
endif
CC = $(PLATFORM)-w64-mingw32-g++
CXX = $(PLATFORM)-w64-mingw32-g++
LD = $(PLATFORM)-w64-mingw32-ld
RC = $(PLATFORM)-w64-mingw32-windres
else
CC = g++
CXX = g++
LD = ld
RC = rc
endif
RM = rm
CFLAGS = -Wall -g -DTESTSUITE
LDFLAGS =
RCFLAGS = -O coff
ifdef UNICODE
CFLAGS += -DUNICODE -D_UNICODE
endif
CFLAGS_DLL = -DSAMPLEDLL_EXPORTS
CFLAGS_EXE =
LDFLAGS_DLL = -shared
LDFLAGS_EXE = -static
TEST_DLLS = \
test-align-128.dll \
test-align-256.dll \
test-align-512.dll \
test-align-768.dll \
test-align-1024.dll \
test-align-2048.dll \
test-align-3072.dll \
test-align-4096.dll \
test-align-100.dll \
test-align-200.dll \
test-align-300.dll \
test-align-400.dll \
test-align-500.dll \
test-align-600.dll \
test-align-800.dll \
test-align-900.dll \
test-relocate.dll \
test-exports.dll
LOADDLL_OBJ = LoadDll.o ../MemoryModule.o
TESTSUITE_OBJ = TestSuite.o ../MemoryModule.o
DLL_OBJ = SampleDLL.o SampleDLL.res
all: prepare_testsuite LoadDll.exe TestSuite.exe $(TEST_DLLS)
prepare_testsuite:
rm -f $(TESTSUITE_OBJ)
LoadDll.exe: $(LOADDLL_OBJ)
$(CC) $(LDFLAGS_EXE) $(LDFLAGS) -Wl,--image-base -Wl,0x20000000 -o LoadDll.exe $(LOADDLL_OBJ)
TestSuite.exe: $(TESTSUITE_OBJ)
$(CC) $(LDFLAGS_EXE) $(LDFLAGS) -o TestSuite.exe $(TESTSUITE_OBJ)
LoadDll.o: LoadDll.cpp
$(CXX) $(CFLAGS) $(CFLAGS_EXE) -c $<
test-align-%.dll: $(DLL_OBJ)
$(LD) $(LDFLAGS_DLL) $(LDFLAGS) --file-alignment $* --section-alignment $* -o $@ $(DLL_OBJ)
test-relocate.dll: $(DLL_OBJ)
$(CXX) $(LDFLAGS_DLL) $(LDFLAGS) -Wl,--image-base -Wl,0x20000000 -o $@ $(DLL_OBJ)
test-exports.dll: SampleExports.o
$(CXX) $(LDFLAGS_DLL) $(LDFLAGS) -o $@ SampleExports.o
SampleExports.cpp: generate-exports.sh
./generate-exports.sh
%.o: %.cpp
$(CXX) $(CFLAGS) $(CFLAGS_DLL) -c $<
%.o: %.cc
$(CC) $(CFLAGS) $(CFLAGS_DLL) -c $<
%.res: %.rc
$(RC) $(RCFLAGS) -o $*.res $<
clean:
$(RM) -rf LoadDll.exe $(TEST_DLLS) $(LOADDLL_OBJ) $(DLL_OBJ) $(TESTSUITE_OBJ) SampleExports.o
test: all
./runwine.sh $(PLATFORM) TestSuite.exe
./runtests.sh $(PLATFORM) "$(TEST_DLLS)"

View File

@ -0,0 +1,10 @@
#include "SampleDLL.h"
extern "C" {
SAMPLEDLL_API int addNumbers(int a, int b)
{
return a + b;
}
}

View File

@ -0,0 +1,11 @@
extern "C" {
#ifdef SAMPLEDLL_EXPORTS
#define SAMPLEDLL_API __declspec(dllexport)
#else
#define SAMPLEDLL_API __declspec(dllimport)
#endif
SAMPLEDLL_API int addNumbers(int a, int b);
}

View File

@ -0,0 +1,58 @@
1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4"
BEGIN
VALUE "CompanyName", "fancy.code"
VALUE "FileDescription", "SampleDLL"
VALUE "FileVersion", "1.0"
VALUE "InternalName", "SampleDLL"
VALUE "LegalCopyright", "Copyright (c) 2004-2015 Joachim Bauch"
VALUE "OriginalFilename", "SampleDLL.dll"
VALUE "ProductName", "MemoryModule"
VALUE "ProductVersion", "0.0.4"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1252
END
END
#define IDS_HELLO 1
#define IDS_WORLD 20
STRINGTABLE
{
IDS_HELLO, "Hello"
IDS_WORLD, "World!"
}
STRINGRES RCDATA
{
"This is a ANSI string\0",
L"This is a UNICODE string\0",
}
STRINGRES1 RCDATA
{
"This is ANSI string 1\0",
L"This is UNICODE string 1\0",
}
STRINGRES2 RCDATA
{
"This is ANSI string 2\0",
L"This is UNICODE string 2\0",
}
STRINGRES3 RCDATA
{
"This is ANSI string 3\0",
L"This is UNICODE string 3\0",
}

View File

@ -0,0 +1,19 @@
#define WIN32_LEAN_AND_MEAN
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <windows.h>
extern BOOL MemoryModuleTestsuite();
int main(int argc, char* argv[])
{
UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(argv);
if (!MemoryModuleTestsuite()) {
return 1;
}
return 0;
}

View File

@ -0,0 +1,52 @@
#!/bin/sh
##
## Generate header file.
##
cat > SampleExports.h << EOF
extern "C" {
#ifdef SAMPLEDLL_EXPORTS
#define SAMPLEDLL_API __declspec(dllexport)
#else
#define SAMPLEDLL_API __declspec(dllimport)
#endif
EOF
for i in `seq 1 100`;
do
cat >> SampleExports.h << EOF
SAMPLEDLL_API int add$i(int a);
EOF
done
cat >> SampleExports.h << EOF
}
EOF
##
## Generate source file.
##
cat > SampleExports.cpp << EOF
#include "SampleExports.h"
extern "C" {
EOF
for i in `seq 1 100 | sort -R`;
do
cat >> SampleExports.cpp << EOF
SAMPLEDLL_API int add$i(int a)
{
return a + $i;
}
EOF
done
cat >> SampleExports.cpp << EOF
}
EOF

View File

@ -0,0 +1,16 @@
#!/bin/bash
PLATFORM=$1
read -a TEST_DLLS <<< $2
for filename in "${TEST_DLLS[@]}"
do
:
echo "Testing $filename"
./runwine.sh "${PLATFORM}" ./LoadDll.exe $filename
if [ "$?" != "0" ]; then
exit 1
fi
done
echo "${#TEST_DLLS[@]} tests completed successfully"

View File

@ -0,0 +1,15 @@
#!/bin/bash
set -eu
PLATFORM=$1
shift
if [ "${PLATFORM}" = "x86_64" ]; then
export WINEPREFIX=${HOME}/.wine64/
WINE=wine64
else
export WINEPREFIX=${HOME}/.wine/
WINE=wine
fi
export WINEPATH=/usr/lib/gcc/${PLATFORM}-w64-mingw32/4.8/:/usr/${PLATFORM}-w64-mingw32/lib
exec ${WINE} $@

View File

@ -0,0 +1,185 @@
#pragma once
#include <vector>
#include <algorithm>
#include <cassert>
#include <tuple>
std::wstring GetModuleFileNameW(HMODULE hModule)
{
static constexpr auto INITIAL_BUFFER_SIZE = MAX_PATH;
static constexpr auto MAX_ITERATIONS = 7;
std::wstring ret;
auto bufferSize = INITIAL_BUFFER_SIZE;
for (size_t iterations = 0; iterations < MAX_ITERATIONS; ++iterations)
{
ret.resize(bufferSize);
auto charsReturned = GetModuleFileNameW(hModule, &ret[0], bufferSize);
if (charsReturned < ret.length())
{
ret.resize(charsReturned);
return ret;
}
else
{
bufferSize *= 2;
}
}
return L"";
}
auto starts_with = [](const std::wstring &big_str, const std::wstring &small_str) -> auto
{
return big_str.compare(0, small_str.length(), small_str) == 0;
};
// Stores a list of loaded modules with their names, WITHOUT extension
class ModuleList
{
public:
enum class SearchLocation
{
All,
LocalOnly,
SystemOnly,
};
// Initializes module list
// Needs to be called before any calls to Get or GetAll
void Enumerate( SearchLocation location = SearchLocation::All )
{
constexpr size_t INITIAL_SIZE = sizeof(HMODULE) * 256;
HMODULE* modules = static_cast<HMODULE*>(malloc( INITIAL_SIZE ));
if ( modules != nullptr )
{
typedef BOOL (WINAPI * Func)(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded);
HMODULE hLib = LoadLibrary( TEXT("kernel32") );
assert( hLib != nullptr ); // If this fails then everything is probably broken anyway
Func pEnumProcessModules = reinterpret_cast<Func>(GetProcAddress( hLib, "K32EnumProcessModules" ));
if ( pEnumProcessModules == nullptr )
{
// Try psapi
FreeLibrary( hLib );
hLib = LoadLibrary( TEXT("psapi") );
if ( hLib != nullptr )
{
pEnumProcessModules = reinterpret_cast<Func>(GetProcAddress( hLib, "EnumProcessModules" ));
}
}
if ( pEnumProcessModules != nullptr )
{
const HANDLE currentProcess = GetCurrentProcess();
DWORD cbNeeded = 0;
if ( pEnumProcessModules( currentProcess, modules, INITIAL_SIZE, &cbNeeded ) != 0 )
{
if ( cbNeeded > INITIAL_SIZE )
{
HMODULE* newModules = static_cast<HMODULE*>(realloc( modules, cbNeeded ));
if ( newModules != nullptr )
{
modules = newModules;
if ( pEnumProcessModules( currentProcess, modules, cbNeeded, &cbNeeded ) != 0 )
{
EnumerateInternal( modules, location, cbNeeded / sizeof(HMODULE) );
}
}
}
else
{
EnumerateInternal( modules, location, cbNeeded / sizeof(HMODULE) );
}
}
}
if ( hLib != nullptr )
{
FreeLibrary( hLib );
}
free( modules );
}
}
// Recreates module list
void ReEnumerate( SearchLocation location = SearchLocation::All )
{
Clear();
Enumerate( location );
}
// Clears module list
void Clear()
{
m_moduleList.clear();
}
// Gets handle of a loaded module with given name, NULL otherwise
HMODULE Get( const wchar_t* moduleName ) const
{
// If vector is empty then we're trying to call it without calling Enumerate first
assert( m_moduleList.size() != 0 );
auto it = std::find_if( m_moduleList.begin(), m_moduleList.end(), [&]( const auto& e ) {
return _wcsicmp( moduleName, std::get<1>(e).c_str() ) == 0;
} );
return it != m_moduleList.end() ? std::get<0>(*it) : nullptr;
}
// Gets handles to all loaded modules with given name
std::vector<HMODULE> GetAll( const wchar_t* moduleName ) const
{
// If vector is empty then we're trying to call it without calling Enumerate first
assert( m_moduleList.size() != 0 );
std::vector<HMODULE> results;
for ( auto& e : m_moduleList )
{
if ( _wcsicmp( moduleName, std::get<1>(e).c_str()) == 0 )
{
results.push_back(std::get<0>(e));
}
}
return results;
}
private:
void EnumerateInternal( HMODULE* modules, SearchLocation location, size_t numModules )
{
const auto exeModulePath = GetModuleFileNameW(NULL).substr(0, GetModuleFileNameW(NULL).find_last_of(L"/\\"));
m_moduleList.reserve(numModules);
for (size_t i = 0; i < numModules; i++)
{
// Obtain module name, with resizing if necessary
auto moduleName = GetModuleFileNameW(*modules);
if (!moduleName.empty())
{
const wchar_t* nameBegin = wcsrchr(moduleName.c_str(), '\\') + 1;
const wchar_t* dotPos = wcsrchr(nameBegin, '.');
bool isLocal = starts_with(std::wstring(moduleName), exeModulePath);
if ( (isLocal && location != SearchLocation::SystemOnly) || (!isLocal && location != SearchLocation::LocalOnly) )
{
if (dotPos != nullptr)
{
m_moduleList.emplace_back(*modules, std::wstring(nameBegin, dotPos), isLocal);
}
else
{
m_moduleList.emplace_back(*modules, nameBegin, isLocal);
}
}
}
modules++;
}
}
public: std::vector< std::tuple<HMODULE, std::wstring, bool> > m_moduleList;
};

View File

@ -0,0 +1,29 @@
# Build results
bin/
obj/
intermediate/
[Bb]uild/
Debug/
Release/
# Visual Studio cache files
.vs/
ipch/
*.aps
*.VC.db
*.VC.opendb
# Visual Studio user config files
*.sdf
*.opensdf
*.suo
*.vcxproj.user
*.Args.json
*.ArgsCfg.json
# Visual Studio Code
.vscode/
# Temporary OS files
.DS_Store
Thumbs.db

View File

@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 3.12)
project(d3d8to9 CXX)
set(SRCS
source/d3d8.hpp
source/d3d8to9.cpp
source/d3d8to9.hpp
source/d3d8to9_base.cpp
source/d3d8to9_device.cpp
source/d3d8to9_index_buffer.cpp
source/d3d8to9_surface.cpp
source/d3d8to9_swap_chain.cpp
source/d3d8to9_texture.cpp
source/d3d8to9_vertex_buffer.cpp
source/d3d8to9_volume.cpp
source/d3d8types.cpp
source/d3d8types.hpp
source/d3dx9.hpp
source/interface_query.cpp
source/interface_query.hpp
res/d3d8to9.rc
)
set(CMAKE_CXX_STANDARD 17)
option(D3D8TO9_STATIC "Build as a static library" OFF)
if(D3D8TO9_STATIC)
add_library(d3d8to9 STATIC ${SRCS})
else()
add_library(d3d8to9 SHARED ${SRCS})
set_target_properties(d3d8to9 PROPERTIES PREFIX "")
set_target_properties(d3d8to9 PROPERTIES OUTPUT_NAME "d3d8")
endif()
target_compile_definitions(d3d8to9 PUBLIC
$<$<CONFIG:Debug>:D3D_DEBUG_INFO;_DEBUG>
$<$<CONFIG:RelWithDebInfo>:D3D_DEBUG_INFO;_DEBUG>
$<$<CONFIG:Release>:D3D8TO9NOLOG>
$<$<CONFIG:MinSizeRel>:D3D8TO9NOLOG>
)
if(MSVC)
target_compile_options(d3d8to9 PRIVATE /W3)
target_link_options(d3d8to9 PRIVATE /DEF:${CMAKE_CURRENT_SOURCE_DIR}/res/d3d8.def)
else()
target_compile_options(d3d8to9 PRIVATE -Wall -Wno-delete-non-virtual-dtor -Wno-unknown-pragmas)
target_link_options(d3d8to9 PRIVATE -Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/res/d3d8.def)
endif()
target_link_libraries(d3d8to9 d3d9)

View File

@ -0,0 +1,8 @@
Copyright (C) 2015 Patrick Mours. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,32 @@
d3d8to9
=======
[![Build Status](https://ci.appveyor.com/api/projects/status/aqupdda60ixgenyd?svg=true)](https://ci.appveyor.com/project/crosire/d3d8to9)
This is a pseudo-driver module that intends to improve compatibility and stability in games using Direct3D 8 for rendering by converting all API calls and low-level shaders to equivalent Direct3D 9 ones. By that it also opens those games to new possibilities from proven modding tools written for Direct3D 9, including [ReShade](http://reshade.me).
Note that d3d8to9 does exact translation from Direct3D 8 to Direct3D 9 only. But on recent versions of Windows, depending on system settings, GPU drivers and other factors, rendering behavior in Direct3D 9 using d3d8to9 may differ from native Direct3D 8. One common issue is VSync getting enabled with d3d8to9, even though it appears inactive in native Direct3D 8, despite the application enabling it. This may give an inaccurate impression of lower performance with d3d8to9, while it actually follows what the application requests. If you want to tweak this behavior, such as forcing VSync to be off, it is recommended to use a separate tool, such as [dxwrapper](https://github.com/elishacloud/dxwrapper), which uses d3d8to9 internally for API call conversion, but adds additional configuration opportunities.
## Building
You'll need Visual Studio 2013 or higher to build d3d8to9. It is recommended to install the old standalone DirectX end-user runtime, which is required for the D3DX libraries used for disassembling and assembling the shaders.
A quick overview of what some of the source code files contain:
|File |Description |
|----------------------------------------------------------|---------------------------------------------------------------------------------|
|[d3d8to9.cpp](source/d3d8to9.cpp) | Definition of the main D3D8 entry point `Direct3DCreate8` |
|[d3d8to9_base.cpp](source/d3d8to9_base.cpp) | Implementation of the `IDirect3D8` interface, including device creation |
|[d3d8to9_device.cpp](source/d3d8to9_device.cpp) | Implementation of the `IDirect3DDevice8` interface, including shader conversion |
|[d3d8types.hpp](source/d3d8types.hpp) | Declaration of all used D3D8 types one would otherwise find in d3d8.h |
|[interface_query.hpp](source/interface_query.hpp) | Table to map D3D9 interface addresses to their matching D3D8 implementations |
## Contributing
Any contributions to the project are welcomed, it's recommended to use GitHub [pull requests](https://help.github.com/articles/using-pull-requests/).
A big shout-out to all the existing [contributors](https://github.com/crosire/d3d8to9/graphs/contributors) who worked on improving compatibility, especially [elishacloud](https://github.com/elishacloud)!
## License
All source code in this repository is licensed under a [BSD 2-clause license](LICENSE.md).

View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "d3d8to9", "d3d8to9.vcxproj", "{7EE21ADA-3B02-4CD6-A891-C2257A54B061}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7EE21ADA-3B02-4CD6-A891-C2257A54B061}.Debug|x86.ActiveCfg = Debug|Win32
{7EE21ADA-3B02-4CD6-A891-C2257A54B061}.Debug|x86.Build.0 = Debug|Win32
{7EE21ADA-3B02-4CD6-A891-C2257A54B061}.Release|x86.ActiveCfg = Release|Win32
{7EE21ADA-3B02-4CD6-A891-C2257A54B061}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,107 @@
<?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>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{7EE21ADA-3B02-4CD6-A891-C2257A54B061}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)'=='16.0'">v142</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)'=='17.0'">v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup>
<TargetName>d3d8</TargetName>
<OutDir>bin\$(Configuration)\</OutDir>
<IntDir>intermediate\$(Configuration)\</IntDir>
<IncludePath>$(IncludePath);$(DXSDK_DIR)\Include</IncludePath>
<LibraryPath>$(DXSDK_DIR)\Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;D3D_DEBUG_INFO;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>res\d3d8.def</ModuleDefinitionFile>
<AdditionalDependencies>d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;D3D8TO9NOLOG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile>
<Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile>res\d3d8.def</ModuleDefinitionFile>
<AdditionalDependencies>d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="source\d3d8to9.cpp" />
<ClCompile Include="source\d3d8to9_base.cpp" />
<ClCompile Include="source\d3d8to9_device.cpp" />
<ClCompile Include="source\d3d8to9_index_buffer.cpp" />
<ClCompile Include="source\d3d8to9_surface.cpp" />
<ClCompile Include="source\d3d8to9_swap_chain.cpp" />
<ClCompile Include="source\d3d8to9_texture.cpp" />
<ClCompile Include="source\d3d8to9_vertex_buffer.cpp" />
<ClCompile Include="source\d3d8to9_volume.cpp" />
<ClCompile Include="source\d3d8types.cpp" />
<ClCompile Include="source\interface_query.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="res\resource.h" />
<ClInclude Include="source\d3d8.hpp" />
<ClInclude Include="source\d3d8to9.hpp" />
<ClInclude Include="source\d3d8types.hpp" />
<ClInclude Include="source\d3dx9.hpp" />
<ClInclude Include="source\interface_query.hpp" />
</ItemGroup>
<ItemGroup>
<None Include="res\d3d8.def" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\d3d8to9.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="helpers">
<UniqueIdentifier>{709e8cf8-ebdb-4573-8524-20b04c6a5883}</UniqueIdentifier>
</Filter>
<Filter Include="resources">
<UniqueIdentifier>{2d5bd44f-68df-4a2e-967b-57e194c0eac4}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\d3d8to9.cpp" />
<ClCompile Include="source\d3d8to9_base.cpp" />
<ClCompile Include="source\d3d8to9_device.cpp" />
<ClCompile Include="source\d3d8to9_index_buffer.cpp" />
<ClCompile Include="source\d3d8to9_surface.cpp" />
<ClCompile Include="source\d3d8to9_swap_chain.cpp" />
<ClCompile Include="source\d3d8to9_texture.cpp" />
<ClCompile Include="source\d3d8to9_vertex_buffer.cpp" />
<ClCompile Include="source\d3d8to9_volume.cpp" />
<ClCompile Include="source\d3d8types.cpp">
<Filter>helpers</Filter>
</ClCompile>
<ClCompile Include="source\interface_query.cpp">
<Filter>helpers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="res\resource.h">
<Filter>resources</Filter>
</ClInclude>
<ClInclude Include="source\d3d8.hpp">
<Filter>helpers</Filter>
</ClInclude>
<ClInclude Include="source\d3d8to9.hpp" />
<ClInclude Include="source\d3d8types.hpp">
<Filter>helpers</Filter>
</ClInclude>
<ClInclude Include="source\d3dx9.hpp">
<Filter>helpers</Filter>
</ClInclude>
<ClInclude Include="source\interface_query.hpp">
<Filter>helpers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="res\d3d8.def">
<Filter>resources</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\d3d8to9.rc">
<Filter>resources</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,2 @@
EXPORTS
Direct3DCreate8

View File

@ -0,0 +1,100 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#pragma code_page(65001)
#include <winresrc.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Neutral (Default) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEUD)
LANGUAGE LANG_NEUTRAL, SUBLANG_DEFAULT
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#pragma code_page(65001)\r\n"
"#include <winresrc.h>\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,12,0,0
PRODUCTVERSION 3,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040004b0"
BEGIN
VALUE "CompanyName", "crosire"
VALUE "FileDescription", "d3d8to9"
VALUE "FileVersion", "1.12.0.0"
VALUE "LegalCopyright", "Copyright © 2015. All rights reserved."
VALUE "OriginalFilename", "d3d8.dll"
VALUE "ProductName", "ReShade"
VALUE "ProductVersion", "3.0.0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x400, 1200
END
END
#endif // Neutral (Default) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -0,0 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by d3d8to9.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -0,0 +1,246 @@
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#pragma once
#include "d3d8types.hpp"
#ifndef interface
#define interface struct
#endif
interface DECLSPEC_UUID("1DD9E8DA-1C77-4D40-B0CF-98FEFDFF9512") IDirect3D8;
interface DECLSPEC_UUID("7385E5DF-8FE8-41D5-86B6-D7B48547B6CF") IDirect3DDevice8;
interface DECLSPEC_UUID("928C088B-76B9-4C6B-A536-A590853876CD") IDirect3DSwapChain8;
interface DECLSPEC_UUID("1B36BB7B-09B7-410A-B445-7D1430D7B33F") IDirect3DResource8;
interface DECLSPEC_UUID("B4211CFA-51B9-4A9F-AB78-DB99B2BB678E") IDirect3DBaseTexture8;
interface DECLSPEC_UUID("E4CDD575-2866-4F01-B12E-7EECE1EC9358") IDirect3DTexture8;
interface DECLSPEC_UUID("3EE5B968-2ACA-4C34-8BB5-7E0C3D19B750") IDirect3DCubeTexture8;
interface DECLSPEC_UUID("4B8AAAFA-140F-42BA-9131-597EAFAA2EAD") IDirect3DVolumeTexture8;
interface DECLSPEC_UUID("B96EEBCA-B326-4EA5-882F-2FF5BAE021DD") IDirect3DSurface8;
interface DECLSPEC_UUID("BD7349F5-14F1-42E4-9C79-972380DB40C0") IDirect3DVolume8;
interface DECLSPEC_UUID("8AEEEAC7-05F9-44D4-B591-000B0DF1CB95") IDirect3DVertexBuffer8;
interface DECLSPEC_UUID("0E689C9A-053D-44A0-9D92-DB0E3D750F86") IDirect3DIndexBuffer8;
// MinGW support
#ifdef __CRT_UUID_DECL
__CRT_UUID_DECL(IDirect3D8, 0x1DD9E8DA, 0x1C77, 0x4D40, 0xB0, 0xCF, 0x98,0xFE,0xFD,0xFF,0x95,0x12)
__CRT_UUID_DECL(IDirect3DDevice8, 0x7385E5DF, 0x8FE8, 0x41D5, 0x86, 0xB6, 0xD7,0xB4,0x85,0x47,0xB6,0xCF)
__CRT_UUID_DECL(IDirect3DSwapChain8, 0x928C088B, 0x76B9, 0x4C6B, 0xA5, 0x36, 0xA5,0x90,0x85,0x38,0x76,0xCD)
__CRT_UUID_DECL(IDirect3DResource8, 0x1B36BB7B, 0x09B7, 0x410A, 0xB4, 0x45, 0x7D,0x14,0x30,0xD7,0xB3,0x3F)
__CRT_UUID_DECL(IDirect3DBaseTexture8, 0xB4211CFA, 0x51B9, 0x4A9F, 0xAB, 0x78, 0xDB,0x99,0xB2,0xBB,0x67,0x8E)
__CRT_UUID_DECL(IDirect3DTexture8, 0xE4CDD575, 0x2866, 0x4F01, 0xB1, 0x2E, 0x7E,0xEC,0xE1,0xEC,0x93,0x58)
__CRT_UUID_DECL(IDirect3DCubeTexture8, 0x3EE5B968, 0x2ACA, 0x4C34, 0x8B, 0xB5, 0x7E,0x0C,0x3D,0x19,0xB7,0x50)
__CRT_UUID_DECL(IDirect3DVolumeTexture8, 0x4B8AAAFA, 0x140F, 0x42BA, 0x91, 0x31, 0x59,0x7E,0xAF,0xAA,0x2E,0xAD)
__CRT_UUID_DECL(IDirect3DSurface8, 0xB96EEBCA, 0xB326, 0x4EA5, 0x88, 0x2F, 0x2F,0xF5,0xBA,0xE0,0x21,0xDD)
__CRT_UUID_DECL(IDirect3DVolume8, 0xBD7349F5, 0x14F1, 0x42E4, 0x9C, 0x79, 0x97,0x23,0x80,0xDB,0x40,0xC0)
__CRT_UUID_DECL(IDirect3DVertexBuffer8, 0x8AEEEAC7, 0x05F9, 0x44D4, 0xB5, 0x91, 0x00,0x0B,0x0D,0xF1,0xCB,0x95)
__CRT_UUID_DECL(IDirect3DIndexBuffer8, 0x0E689C9A, 0x053D, 0x44A0, 0x9D, 0x92, 0xDB,0x0E,0x3D,0x75,0x0F,0x86)
#endif
interface IDirect3D8 : public IUnknown
{
virtual HRESULT STDMETHODCALLTYPE RegisterSoftwareDevice(void *pInitializeFunction) = 0;
virtual UINT STDMETHODCALLTYPE GetAdapterCount() = 0;
virtual HRESULT STDMETHODCALLTYPE GetAdapterIdentifier(UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8 *pIdentifier) = 0;
virtual UINT STDMETHODCALLTYPE GetAdapterModeCount(UINT Adapter) = 0;
virtual HRESULT STDMETHODCALLTYPE EnumAdapterModes(UINT Adapter, UINT Mode, D3DDISPLAYMODE *pMode) = 0;
virtual HRESULT STDMETHODCALLTYPE GetAdapterDisplayMode(UINT Adapter, D3DDISPLAYMODE *pMode) = 0;
virtual HRESULT STDMETHODCALLTYPE CheckDeviceType(UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed) = 0;
virtual HRESULT STDMETHODCALLTYPE CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) = 0;
virtual HRESULT STDMETHODCALLTYPE CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType) = 0;
virtual HRESULT STDMETHODCALLTYPE CheckDepthStencilMatch(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) = 0;
virtual HRESULT STDMETHODCALLTYPE GetDeviceCaps(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8 *pCaps) = 0;
virtual HMONITOR STDMETHODCALLTYPE GetAdapterMonitor(UINT Adapter) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS8 *pPresentationParameters, IDirect3DDevice8 **ppReturnedDeviceInterface) = 0;
};
interface IDirect3DDevice8 : public IUnknown
{
virtual HRESULT STDMETHODCALLTYPE TestCooperativeLevel() = 0;
virtual UINT STDMETHODCALLTYPE GetAvailableTextureMem() = 0;
virtual HRESULT STDMETHODCALLTYPE ResourceManagerDiscardBytes(DWORD Bytes) = 0;
virtual HRESULT STDMETHODCALLTYPE GetDirect3D(IDirect3D8 **ppD3D8) = 0;
virtual HRESULT STDMETHODCALLTYPE GetDeviceCaps(D3DCAPS8 *pCaps) = 0;
virtual HRESULT STDMETHODCALLTYPE GetDisplayMode(D3DDISPLAYMODE *pMode) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS *pParameters) = 0;
virtual HRESULT STDMETHODCALLTYPE SetCursorProperties(UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8 *pCursorBitmap) = 0;
virtual void STDMETHODCALLTYPE SetCursorPosition(UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) = 0;
virtual BOOL STDMETHODCALLTYPE ShowCursor(BOOL bShow) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS8 *pPresentationParameters, IDirect3DSwapChain8 **ppSwapChain) = 0;
virtual HRESULT STDMETHODCALLTYPE Reset(D3DPRESENT_PARAMETERS8 *pPresentationParameters) = 0;
virtual HRESULT STDMETHODCALLTYPE Present(const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion) = 0;
virtual HRESULT STDMETHODCALLTYPE GetBackBuffer(UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8 **ppBackBuffer) = 0;
virtual HRESULT STDMETHODCALLTYPE GetRasterStatus(D3DRASTER_STATUS *pRasterStatus) = 0;
virtual void STDMETHODCALLTYPE SetGammaRamp(DWORD Flags, const D3DGAMMARAMP *pRamp) = 0;
virtual void STDMETHODCALLTYPE GetGammaRamp(D3DGAMMARAMP *pRamp) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateTexture(UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8 **ppTexture) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateVolumeTexture(UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8 **ppVolumeTexture) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateCubeTexture(UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8 **ppCubeTexture) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateVertexBuffer(UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8 **ppVertexBuffer) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8 **ppIndexBuffer) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateRenderTarget(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8 **ppSurface) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateDepthStencilSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8 **ppSurface) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateImageSurface(UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8 **ppSurface) = 0;
virtual HRESULT STDMETHODCALLTYPE CopyRects(IDirect3DSurface8 *pSourceSurface, const RECT *pSourceRectsArray, UINT cRects, IDirect3DSurface8 *pDestinationSurface, const POINT *pDestPointsArray) = 0;
virtual HRESULT STDMETHODCALLTYPE UpdateTexture(IDirect3DBaseTexture8 *pSourceTexture, IDirect3DBaseTexture8 *pDestinationTexture) = 0;
virtual HRESULT STDMETHODCALLTYPE GetFrontBuffer(IDirect3DSurface8 *pDestSurface) = 0;
virtual HRESULT STDMETHODCALLTYPE SetRenderTarget(IDirect3DSurface8 *pRenderTarget, IDirect3DSurface8 *pNewZStencil) = 0;
virtual HRESULT STDMETHODCALLTYPE GetRenderTarget(IDirect3DSurface8 **ppRenderTarget) = 0;
virtual HRESULT STDMETHODCALLTYPE GetDepthStencilSurface(IDirect3DSurface8 **ppZStencilSurface) = 0;
virtual HRESULT STDMETHODCALLTYPE BeginScene() = 0;
virtual HRESULT STDMETHODCALLTYPE EndScene() = 0;
virtual HRESULT STDMETHODCALLTYPE Clear(DWORD Count, const D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) = 0;
virtual HRESULT STDMETHODCALLTYPE SetTransform(D3DTRANSFORMSTATETYPE State, const D3DMATRIX *pMatrix) = 0;
virtual HRESULT STDMETHODCALLTYPE GetTransform(D3DTRANSFORMSTATETYPE State, D3DMATRIX *pMatrix) = 0;
virtual HRESULT STDMETHODCALLTYPE MultiplyTransform(D3DTRANSFORMSTATETYPE State, const D3DMATRIX *pMatrix) = 0;
virtual HRESULT STDMETHODCALLTYPE SetViewport(const D3DVIEWPORT8 *pViewport) = 0;
virtual HRESULT STDMETHODCALLTYPE GetViewport(D3DVIEWPORT8 *pViewport) = 0;
virtual HRESULT STDMETHODCALLTYPE SetMaterial(const D3DMATERIAL8 *pMaterial) = 0;
virtual HRESULT STDMETHODCALLTYPE GetMaterial(D3DMATERIAL8 *pMaterial) = 0;
virtual HRESULT STDMETHODCALLTYPE SetLight(DWORD Index, const D3DLIGHT8 *pLight) = 0;
virtual HRESULT STDMETHODCALLTYPE GetLight(DWORD Index, D3DLIGHT8 *pLight) = 0;
virtual HRESULT STDMETHODCALLTYPE LightEnable(DWORD Index, BOOL Enable) = 0;
virtual HRESULT STDMETHODCALLTYPE GetLightEnable(DWORD Index, BOOL *pEnable) = 0;
virtual HRESULT STDMETHODCALLTYPE SetClipPlane(DWORD Index, const float *pPlane) = 0;
virtual HRESULT STDMETHODCALLTYPE GetClipPlane(DWORD Index, float *pPlane) = 0;
virtual HRESULT STDMETHODCALLTYPE SetRenderState(D3DRENDERSTATETYPE State, DWORD Value) = 0;
virtual HRESULT STDMETHODCALLTYPE GetRenderState(D3DRENDERSTATETYPE State, DWORD *pValue) = 0;
virtual HRESULT STDMETHODCALLTYPE BeginStateBlock() = 0;
virtual HRESULT STDMETHODCALLTYPE EndStateBlock(DWORD *pToken) = 0;
virtual HRESULT STDMETHODCALLTYPE ApplyStateBlock(DWORD Token) = 0;
virtual HRESULT STDMETHODCALLTYPE CaptureStateBlock(DWORD Token) = 0;
virtual HRESULT STDMETHODCALLTYPE DeleteStateBlock(DWORD Token) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateStateBlock(D3DSTATEBLOCKTYPE Type, DWORD *pToken) = 0;
virtual HRESULT STDMETHODCALLTYPE SetClipStatus(const D3DCLIPSTATUS8 *pClipStatus) = 0;
virtual HRESULT STDMETHODCALLTYPE GetClipStatus(D3DCLIPSTATUS8 *pClipStatus) = 0;
virtual HRESULT STDMETHODCALLTYPE GetTexture(DWORD Stage, IDirect3DBaseTexture8 **ppTexture) = 0;
virtual HRESULT STDMETHODCALLTYPE SetTexture(DWORD Stage, IDirect3DBaseTexture8 *pTexture) = 0;
virtual HRESULT STDMETHODCALLTYPE GetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *pValue) = 0;
virtual HRESULT STDMETHODCALLTYPE SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) = 0;
virtual HRESULT STDMETHODCALLTYPE ValidateDevice(DWORD *pNumPasses) = 0;
virtual HRESULT STDMETHODCALLTYPE GetInfo(DWORD DevInfoID, void *pDevInfoStruct, DWORD DevInfoStructSize) = 0;
virtual HRESULT STDMETHODCALLTYPE SetPaletteEntries(UINT PaletteNumber, const PALETTEENTRY *pEntries) = 0;
virtual HRESULT STDMETHODCALLTYPE GetPaletteEntries(UINT PaletteNumber, PALETTEENTRY *pEntries) = 0;
virtual HRESULT STDMETHODCALLTYPE SetCurrentTexturePalette(UINT PaletteNumber) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCurrentTexturePalette(UINT *PaletteNumber) = 0;
virtual HRESULT STDMETHODCALLTYPE DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) = 0;
virtual HRESULT STDMETHODCALLTYPE DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount) = 0;
virtual HRESULT STDMETHODCALLTYPE DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride) = 0;
virtual HRESULT STDMETHODCALLTYPE DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices, UINT PrimitiveCount, const void *pIndexData, D3DFORMAT IndexDataFormat, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride) = 0;
virtual HRESULT STDMETHODCALLTYPE ProcessVertices(UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer8 *pDestBuffer, DWORD Flags) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateVertexShader(const DWORD *pDeclaration, const DWORD *pFunction, DWORD *pHandle, DWORD Usage) = 0;
virtual HRESULT STDMETHODCALLTYPE SetVertexShader(DWORD Handle) = 0;
virtual HRESULT STDMETHODCALLTYPE GetVertexShader(DWORD *pHandle) = 0;
virtual HRESULT STDMETHODCALLTYPE DeleteVertexShader(DWORD Handle) = 0;
virtual HRESULT STDMETHODCALLTYPE SetVertexShaderConstant(DWORD Register, const void *pConstantData, DWORD ConstantCount) = 0;
virtual HRESULT STDMETHODCALLTYPE GetVertexShaderConstant(DWORD Register, void *pConstantData, DWORD ConstantCount) = 0;
virtual HRESULT STDMETHODCALLTYPE GetVertexShaderDeclaration(DWORD Handle, void *pData, DWORD *pSizeOfData) = 0;
virtual HRESULT STDMETHODCALLTYPE GetVertexShaderFunction(DWORD Handle, void *pData, DWORD *pSizeOfData) = 0;
virtual HRESULT STDMETHODCALLTYPE SetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer8 *pStreamData, UINT Stride) = 0;
virtual HRESULT STDMETHODCALLTYPE GetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer8 **ppStreamData, UINT *pStride) = 0;
virtual HRESULT STDMETHODCALLTYPE SetIndices(IDirect3DIndexBuffer8 *pIndexData, UINT BaseVertexIndex) = 0;
virtual HRESULT STDMETHODCALLTYPE GetIndices(IDirect3DIndexBuffer8 **ppIndexData, UINT *pBaseVertexIndex) = 0;
virtual HRESULT STDMETHODCALLTYPE CreatePixelShader(const DWORD *pFunction, DWORD *pHandle) = 0;
virtual HRESULT STDMETHODCALLTYPE SetPixelShader(DWORD Handle) = 0;
virtual HRESULT STDMETHODCALLTYPE GetPixelShader(DWORD *pHandle) = 0;
virtual HRESULT STDMETHODCALLTYPE DeletePixelShader(DWORD Handle) = 0;
virtual HRESULT STDMETHODCALLTYPE SetPixelShaderConstant(DWORD Register, const void *pConstantData, DWORD ConstantCount) = 0;
virtual HRESULT STDMETHODCALLTYPE GetPixelShaderConstant(DWORD Register, void *pConstantData, DWORD ConstantCount) = 0;
virtual HRESULT STDMETHODCALLTYPE GetPixelShaderFunction(DWORD Handle, void *pData, DWORD *pSizeOfData) = 0;
virtual HRESULT STDMETHODCALLTYPE DrawRectPatch(UINT Handle, const float *pNumSegs, const D3DRECTPATCH_INFO *pRectPatchInfo) = 0;
virtual HRESULT STDMETHODCALLTYPE DrawTriPatch(UINT Handle, const float *pNumSegs, const D3DTRIPATCH_INFO *pTriPatchInfo) = 0;
virtual HRESULT STDMETHODCALLTYPE DeletePatch(UINT Handle) = 0;
};
interface IDirect3DSwapChain8 : public IUnknown
{
virtual HRESULT STDMETHODCALLTYPE Present(const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion) = 0;
virtual HRESULT STDMETHODCALLTYPE GetBackBuffer(UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8 **ppBackBuffer) = 0;
};
interface IDirect3DResource8 : public IUnknown
{
virtual HRESULT STDMETHODCALLTYPE GetDevice(IDirect3DDevice8 **ppDevice) = 0;
virtual HRESULT STDMETHODCALLTYPE SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) = 0;
virtual HRESULT STDMETHODCALLTYPE GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData) = 0;
virtual HRESULT STDMETHODCALLTYPE FreePrivateData(REFGUID refguid) = 0;
virtual DWORD STDMETHODCALLTYPE SetPriority(DWORD PriorityNew) = 0;
virtual DWORD STDMETHODCALLTYPE GetPriority() = 0;
virtual void STDMETHODCALLTYPE PreLoad() = 0;
virtual D3DRESOURCETYPE STDMETHODCALLTYPE GetType() = 0;
};
interface IDirect3DBaseTexture8 : public IDirect3DResource8
{
virtual DWORD STDMETHODCALLTYPE SetLOD(DWORD LODNew) = 0;
virtual DWORD STDMETHODCALLTYPE GetLOD() = 0;
virtual DWORD STDMETHODCALLTYPE GetLevelCount() = 0;
};
interface IDirect3DTexture8 : public IDirect3DBaseTexture8
{
virtual HRESULT STDMETHODCALLTYPE GetLevelDesc(UINT Level, D3DSURFACE_DESC8 *pDesc) = 0;
virtual HRESULT STDMETHODCALLTYPE GetSurfaceLevel(UINT Level, IDirect3DSurface8 **ppSurfaceLevel) = 0;
virtual HRESULT STDMETHODCALLTYPE LockRect(UINT Level, D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags) = 0;
virtual HRESULT STDMETHODCALLTYPE UnlockRect(UINT Level) = 0;
virtual HRESULT STDMETHODCALLTYPE AddDirtyRect(const RECT *pDirtyRect) = 0;
};
interface IDirect3DCubeTexture8 : public IDirect3DBaseTexture8
{
virtual HRESULT STDMETHODCALLTYPE GetLevelDesc(UINT Level, D3DSURFACE_DESC8 *pDesc) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8 **ppCubeMapSurface) = 0;
virtual HRESULT STDMETHODCALLTYPE LockRect(D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags) = 0;
virtual HRESULT STDMETHODCALLTYPE UnlockRect(D3DCUBEMAP_FACES FaceType, UINT Level) = 0;
virtual HRESULT STDMETHODCALLTYPE AddDirtyRect(D3DCUBEMAP_FACES FaceType, const RECT *pDirtyRect) = 0;
};
interface IDirect3DVolumeTexture8 : public IDirect3DBaseTexture8
{
virtual HRESULT STDMETHODCALLTYPE GetLevelDesc(UINT Level, D3DVOLUME_DESC8 *pDesc) = 0;
virtual HRESULT STDMETHODCALLTYPE GetVolumeLevel(UINT Level, IDirect3DVolume8 **ppVolumeLevel) = 0;
virtual HRESULT STDMETHODCALLTYPE LockBox(UINT Level, D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox, DWORD Flags) = 0;
virtual HRESULT STDMETHODCALLTYPE UnlockBox(UINT Level) = 0;
virtual HRESULT STDMETHODCALLTYPE AddDirtyBox(const D3DBOX *pDirtyBox) = 0;
};
interface IDirect3DSurface8 : public IUnknown
{
virtual HRESULT STDMETHODCALLTYPE GetDevice(IDirect3DDevice8 **ppDevice) = 0;
virtual HRESULT STDMETHODCALLTYPE SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) = 0;
virtual HRESULT STDMETHODCALLTYPE GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData) = 0;
virtual HRESULT STDMETHODCALLTYPE FreePrivateData(REFGUID refguid) = 0;
virtual HRESULT STDMETHODCALLTYPE GetContainer(REFIID riid, void **ppContainer) = 0;
virtual HRESULT STDMETHODCALLTYPE GetDesc(D3DSURFACE_DESC8 *pDesc) = 0;
virtual HRESULT STDMETHODCALLTYPE LockRect(D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags) = 0;
virtual HRESULT STDMETHODCALLTYPE UnlockRect() = 0;
};
interface IDirect3DVolume8 : public IUnknown
{
virtual HRESULT STDMETHODCALLTYPE GetDevice(IDirect3DDevice8 **ppDevice) = 0;
virtual HRESULT STDMETHODCALLTYPE SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) = 0;
virtual HRESULT STDMETHODCALLTYPE GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData) = 0;
virtual HRESULT STDMETHODCALLTYPE FreePrivateData(REFGUID refguid) = 0;
virtual HRESULT STDMETHODCALLTYPE GetContainer(REFIID riid, void **ppContainer) = 0;
virtual HRESULT STDMETHODCALLTYPE GetDesc(D3DVOLUME_DESC8 *pDesc) = 0;
virtual HRESULT STDMETHODCALLTYPE LockBox(D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox, DWORD Flags) = 0;
virtual HRESULT STDMETHODCALLTYPE UnlockBox() = 0;
};
interface IDirect3DVertexBuffer8 : public IDirect3DResource8
{
virtual HRESULT STDMETHODCALLTYPE Lock(UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) = 0;
virtual HRESULT STDMETHODCALLTYPE Unlock() = 0;
virtual HRESULT STDMETHODCALLTYPE GetDesc(D3DVERTEXBUFFER_DESC *pDesc) = 0;
};
interface IDirect3DIndexBuffer8 : public IDirect3DResource8
{
virtual HRESULT STDMETHODCALLTYPE Lock(UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) = 0;
virtual HRESULT STDMETHODCALLTYPE Unlock() = 0;
virtual HRESULT STDMETHODCALLTYPE GetDesc(D3DINDEXBUFFER_DESC *pDesc) = 0;
};

View File

@ -0,0 +1,74 @@
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#include "d3dx9.hpp"
#include "d3d8to9.hpp"
PFN_D3DXAssembleShader D3DXAssembleShader = nullptr;
PFN_D3DXDisassembleShader D3DXDisassembleShader = nullptr;
PFN_D3DXLoadSurfaceFromSurface D3DXLoadSurfaceFromSurface = nullptr;
#ifndef D3D8TO9NOLOG
// Very simple logging for the purpose of debugging only.
std::ofstream LOG;
#endif
extern "C" IDirect3D8 *WINAPI Direct3DCreate8(UINT SDKVersion)
{
#ifndef D3D8TO9NOLOG
static bool LogMessageFlag = true;
if (!LOG.is_open())
{
LOG.open("d3d8.log", std::ios::trunc);
}
if (!LOG.is_open() && LogMessageFlag)
{
LogMessageFlag = false;
MessageBox(nullptr, TEXT("Failed to open debug log file \"d3d8.log\"!"), nullptr, MB_ICONWARNING);
}
LOG << "Redirecting '" << "Direct3DCreate8" << "(" << SDKVersion << ")' ..." << std::endl;
LOG << "> Passing on to 'Direct3DCreate9':" << std::endl;
#endif
IDirect3D9 *const d3d = Direct3DCreate9(D3D_SDK_VERSION);
if (d3d == nullptr)
{
return nullptr;
}
// Load D3DX
if (!D3DXAssembleShader || !D3DXDisassembleShader || !D3DXLoadSurfaceFromSurface)
{
const HMODULE module = LoadLibrary(TEXT("d3dx9_43.dll"));
if (module != nullptr)
{
D3DXAssembleShader = reinterpret_cast<PFN_D3DXAssembleShader>(GetProcAddress(module, "D3DXAssembleShader"));
D3DXDisassembleShader = reinterpret_cast<PFN_D3DXDisassembleShader>(GetProcAddress(module, "D3DXDisassembleShader"));
D3DXLoadSurfaceFromSurface = reinterpret_cast<PFN_D3DXLoadSurfaceFromSurface>(GetProcAddress(module, "D3DXLoadSurfaceFromSurface"));
}
else
{
#ifndef D3D8TO9NOLOG
LOG << "Failed to load d3dx9_43.dll! Some features will not work correctly." << std::endl;
#endif
if (MessageBox(nullptr, TEXT(
"Failed to load d3dx9_43.dll! Some features will not work correctly.\n\n"
"It's required to install the \"Microsoft DirectX End-User Runtime\" in order to use d3d8to9, or alternatively get the DLLs from this NuGet package:\nhttps://www.nuget.org/packages/Microsoft.DXSDK.D3DX\n\n"
"Please click \"OK\" to open the official download page or \"Cancel\" to continue anyway."), nullptr, MB_ICONWARNING | MB_TOPMOST | MB_SETFOREGROUND | MB_OKCANCEL | MB_DEFBUTTON1) == IDOK)
{
ShellExecute(nullptr, TEXT("open"), TEXT("https://www.microsoft.com/download/details.aspx?id=35"), nullptr, nullptr, SW_SHOW);
return nullptr;
}
}
}
return new Direct3D8(d3d);
}

View File

@ -0,0 +1,449 @@
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#pragma once
#include <vector>
#include <unordered_set>
#include "d3d8.hpp"
#include "interface_query.hpp"
class Direct3D8 : public IDirect3D8
{
Direct3D8(const Direct3D8 &) = delete;
Direct3D8 &operator=(const Direct3D8 &) = delete;
public:
Direct3D8(IDirect3D9 *ProxyInterface);
~Direct3D8();
IDirect3D9 *GetProxyInterface() const { return ProxyInterface; }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObj) override;
virtual ULONG STDMETHODCALLTYPE AddRef() override;
virtual ULONG STDMETHODCALLTYPE Release() override;
virtual HRESULT STDMETHODCALLTYPE RegisterSoftwareDevice(void *pInitializeFunction) override;
virtual UINT STDMETHODCALLTYPE GetAdapterCount() override;
virtual HRESULT STDMETHODCALLTYPE GetAdapterIdentifier(UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8 *pIdentifier) override;
virtual UINT STDMETHODCALLTYPE GetAdapterModeCount(UINT Adapter) override;
virtual HRESULT STDMETHODCALLTYPE EnumAdapterModes(UINT Adapter, UINT Mode, D3DDISPLAYMODE *pMode) override;
virtual HRESULT STDMETHODCALLTYPE GetAdapterDisplayMode(UINT Adapter, D3DDISPLAYMODE *pMode) override;
virtual HRESULT STDMETHODCALLTYPE CheckDeviceType(UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed) override;
virtual HRESULT STDMETHODCALLTYPE CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) override;
virtual HRESULT STDMETHODCALLTYPE CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType) override;
virtual HRESULT STDMETHODCALLTYPE CheckDepthStencilMatch(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) override;
virtual HRESULT STDMETHODCALLTYPE GetDeviceCaps(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8 *pCaps) override;
virtual HMONITOR STDMETHODCALLTYPE GetAdapterMonitor(UINT Adapter) override;
virtual HRESULT STDMETHODCALLTYPE CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS8 *pPresentationParameters, IDirect3DDevice8 **ppReturnedDeviceInterface) override;
private:
IDirect3D9 *const ProxyInterface;
static const UINT MaxAdapters = 8;
UINT CurrentAdapterCount = 0;
UINT CurrentAdapterModeCount[MaxAdapters] = { 0 };
std::vector<D3DDISPLAYMODE> CurrentAdapterModes[MaxAdapters];
};
class Direct3DDevice8 : public IDirect3DDevice8
{
Direct3DDevice8(const Direct3DDevice8 &) = delete;
Direct3DDevice8 &operator=(const Direct3DDevice8 &) = delete;
public:
Direct3DDevice8(Direct3D8 *d3d, IDirect3DDevice9 *ProxyInterface, BOOL EnableZBufferDiscarding = FALSE);
~Direct3DDevice8();
IDirect3DDevice9 *GetProxyInterface() const { return ProxyInterface; }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObj) override;
virtual ULONG STDMETHODCALLTYPE AddRef() override;
virtual ULONG STDMETHODCALLTYPE Release() override;
virtual HRESULT STDMETHODCALLTYPE TestCooperativeLevel() override;
virtual UINT STDMETHODCALLTYPE GetAvailableTextureMem() override;
virtual HRESULT STDMETHODCALLTYPE ResourceManagerDiscardBytes(DWORD Bytes) override;
virtual HRESULT STDMETHODCALLTYPE GetDirect3D(IDirect3D8 **ppD3D8) override;
virtual HRESULT STDMETHODCALLTYPE GetDeviceCaps(D3DCAPS8 *pCaps) override;
virtual HRESULT STDMETHODCALLTYPE GetDisplayMode(D3DDISPLAYMODE *pMode) override;
virtual HRESULT STDMETHODCALLTYPE GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS *pParameters) override;
virtual HRESULT STDMETHODCALLTYPE SetCursorProperties(UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8 *pCursorBitmap) override;
virtual void STDMETHODCALLTYPE SetCursorPosition(UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) override;
virtual BOOL STDMETHODCALLTYPE ShowCursor(BOOL bShow) override;
virtual HRESULT STDMETHODCALLTYPE CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS8 *pPresentationParameters, IDirect3DSwapChain8 **ppSwapChain) override;
virtual HRESULT STDMETHODCALLTYPE Reset(D3DPRESENT_PARAMETERS8 *pPresentationParameters) override;
virtual HRESULT STDMETHODCALLTYPE Present(const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion) override;
virtual HRESULT STDMETHODCALLTYPE GetBackBuffer(UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8 **ppBackBuffer) override;
virtual HRESULT STDMETHODCALLTYPE GetRasterStatus(D3DRASTER_STATUS *pRasterStatus) override;
virtual void STDMETHODCALLTYPE SetGammaRamp(DWORD Flags, const D3DGAMMARAMP *pRamp) override;
virtual void STDMETHODCALLTYPE GetGammaRamp(D3DGAMMARAMP *pRamp) override;
virtual HRESULT STDMETHODCALLTYPE CreateTexture(UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8 **ppTexture) override;
virtual HRESULT STDMETHODCALLTYPE CreateVolumeTexture(UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8 **ppVolumeTexture) override;
virtual HRESULT STDMETHODCALLTYPE CreateCubeTexture(UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8 **ppCubeTexture) override;
virtual HRESULT STDMETHODCALLTYPE CreateVertexBuffer(UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8 **ppVertexBuffer) override;
virtual HRESULT STDMETHODCALLTYPE CreateIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8 **ppIndexBuffer) override;
virtual HRESULT STDMETHODCALLTYPE CreateRenderTarget(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8 **ppSurface) override;
virtual HRESULT STDMETHODCALLTYPE CreateDepthStencilSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8 **ppSurface) override;
virtual HRESULT STDMETHODCALLTYPE CreateImageSurface(UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8 **ppSurface) override;
virtual HRESULT STDMETHODCALLTYPE CopyRects(IDirect3DSurface8 *pSourceSurface, const RECT *pSourceRectsArray, UINT cRects, IDirect3DSurface8 *pDestinationSurface, const POINT *pDestPointsArray) override;
virtual HRESULT STDMETHODCALLTYPE UpdateTexture(IDirect3DBaseTexture8 *pSourceTexture, IDirect3DBaseTexture8 *pDestinationTexture) override;
virtual HRESULT STDMETHODCALLTYPE GetFrontBuffer(IDirect3DSurface8 *pDestSurface) override;
virtual HRESULT STDMETHODCALLTYPE SetRenderTarget(IDirect3DSurface8 *pRenderTarget, IDirect3DSurface8 *pNewZStencil) override;
virtual HRESULT STDMETHODCALLTYPE GetRenderTarget(IDirect3DSurface8 **ppRenderTarget) override;
virtual HRESULT STDMETHODCALLTYPE GetDepthStencilSurface(IDirect3DSurface8 **ppZStencilSurface) override;
virtual HRESULT STDMETHODCALLTYPE BeginScene() override;
virtual HRESULT STDMETHODCALLTYPE EndScene() override;
virtual HRESULT STDMETHODCALLTYPE Clear(DWORD Count, const D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) override;
virtual HRESULT STDMETHODCALLTYPE SetTransform(D3DTRANSFORMSTATETYPE State, const D3DMATRIX *pMatrix) override;
virtual HRESULT STDMETHODCALLTYPE GetTransform(D3DTRANSFORMSTATETYPE State, D3DMATRIX *pMatrix) override;
virtual HRESULT STDMETHODCALLTYPE MultiplyTransform(D3DTRANSFORMSTATETYPE State, const D3DMATRIX *pMatrix) override;
virtual HRESULT STDMETHODCALLTYPE SetViewport(const D3DVIEWPORT8 *pViewport) override;
virtual HRESULT STDMETHODCALLTYPE GetViewport(D3DVIEWPORT8 *pViewport) override;
virtual HRESULT STDMETHODCALLTYPE SetMaterial(const D3DMATERIAL8 *pMaterial) override;
virtual HRESULT STDMETHODCALLTYPE GetMaterial(D3DMATERIAL8 *pMaterial) override;
virtual HRESULT STDMETHODCALLTYPE SetLight(DWORD Index, const D3DLIGHT8 *pLight) override;
virtual HRESULT STDMETHODCALLTYPE GetLight(DWORD Index, D3DLIGHT8 *pLight) override;
virtual HRESULT STDMETHODCALLTYPE LightEnable(DWORD Index, BOOL Enable) override;
virtual HRESULT STDMETHODCALLTYPE GetLightEnable(DWORD Index, BOOL *pEnable) override;
virtual HRESULT STDMETHODCALLTYPE SetClipPlane(DWORD Index, const float *pPlane) override;
virtual HRESULT STDMETHODCALLTYPE GetClipPlane(DWORD Index, float *pPlane) override;
virtual HRESULT STDMETHODCALLTYPE SetRenderState(D3DRENDERSTATETYPE State, DWORD Value) override;
virtual HRESULT STDMETHODCALLTYPE GetRenderState(D3DRENDERSTATETYPE State, DWORD *pValue) override;
virtual HRESULT STDMETHODCALLTYPE BeginStateBlock() override;
virtual HRESULT STDMETHODCALLTYPE EndStateBlock(DWORD *pToken) override;
virtual HRESULT STDMETHODCALLTYPE ApplyStateBlock(DWORD Token) override;
virtual HRESULT STDMETHODCALLTYPE CaptureStateBlock(DWORD Token) override;
virtual HRESULT STDMETHODCALLTYPE DeleteStateBlock(DWORD Token) override;
virtual HRESULT STDMETHODCALLTYPE CreateStateBlock(D3DSTATEBLOCKTYPE Type, DWORD *pToken) override;
virtual HRESULT STDMETHODCALLTYPE SetClipStatus(const D3DCLIPSTATUS8 *pClipStatus) override;
virtual HRESULT STDMETHODCALLTYPE GetClipStatus(D3DCLIPSTATUS8 *pClipStatus) override;
virtual HRESULT STDMETHODCALLTYPE GetTexture(DWORD Stage, IDirect3DBaseTexture8 **ppTexture) override;
virtual HRESULT STDMETHODCALLTYPE SetTexture(DWORD Stage, IDirect3DBaseTexture8 *pTexture) override;
virtual HRESULT STDMETHODCALLTYPE GetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *pValue) override;
virtual HRESULT STDMETHODCALLTYPE SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) override;
virtual HRESULT STDMETHODCALLTYPE ValidateDevice(DWORD *pNumPasses) override;
virtual HRESULT STDMETHODCALLTYPE GetInfo(DWORD DevInfoID, void *pDevInfoStruct, DWORD DevInfoStructSize) override;
virtual HRESULT STDMETHODCALLTYPE SetPaletteEntries(UINT PaletteNumber, const PALETTEENTRY *pEntries) override;
virtual HRESULT STDMETHODCALLTYPE GetPaletteEntries(UINT PaletteNumber, PALETTEENTRY *pEntries) override;
virtual HRESULT STDMETHODCALLTYPE SetCurrentTexturePalette(UINT PaletteNumber) override;
virtual HRESULT STDMETHODCALLTYPE GetCurrentTexturePalette(UINT *PaletteNumber) override;
virtual HRESULT STDMETHODCALLTYPE DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) override;
virtual HRESULT STDMETHODCALLTYPE DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount) override;
virtual HRESULT STDMETHODCALLTYPE DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride) override;
virtual HRESULT STDMETHODCALLTYPE DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices, UINT PrimitiveCount, const void *pIndexData, D3DFORMAT IndexDataFormat, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride) override;
virtual HRESULT STDMETHODCALLTYPE ProcessVertices(UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer8 *pDestBuffer, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE CreateVertexShader(const DWORD *pDeclaration, const DWORD *pFunction, DWORD *pHandle, DWORD Usage) override;
virtual HRESULT STDMETHODCALLTYPE SetVertexShader(DWORD Handle) override;
virtual HRESULT STDMETHODCALLTYPE GetVertexShader(DWORD *pHandle) override;
virtual HRESULT STDMETHODCALLTYPE DeleteVertexShader(DWORD Handle) override;
virtual HRESULT STDMETHODCALLTYPE SetVertexShaderConstant(DWORD Register, const void *pConstantData, DWORD ConstantCount) override;
virtual HRESULT STDMETHODCALLTYPE GetVertexShaderConstant(DWORD Register, void *pConstantData, DWORD ConstantCount) override;
virtual HRESULT STDMETHODCALLTYPE GetVertexShaderDeclaration(DWORD Handle, void *pData, DWORD *pSizeOfData) override;
virtual HRESULT STDMETHODCALLTYPE GetVertexShaderFunction(DWORD Handle, void *pData, DWORD *pSizeOfData) override;
virtual HRESULT STDMETHODCALLTYPE SetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer8 *pStreamData, UINT Stride) override;
virtual HRESULT STDMETHODCALLTYPE GetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer8 **ppStreamData, UINT *pStride) override;
virtual HRESULT STDMETHODCALLTYPE SetIndices(IDirect3DIndexBuffer8 *pIndexData, UINT BaseVertexIndex) override;
virtual HRESULT STDMETHODCALLTYPE GetIndices(IDirect3DIndexBuffer8 **ppIndexData, UINT *pBaseVertexIndex) override;
virtual HRESULT STDMETHODCALLTYPE CreatePixelShader(const DWORD *pFunction, DWORD *pHandle) override;
virtual HRESULT STDMETHODCALLTYPE SetPixelShader(DWORD Handle) override;
virtual HRESULT STDMETHODCALLTYPE GetPixelShader(DWORD *pHandle) override;
virtual HRESULT STDMETHODCALLTYPE DeletePixelShader(DWORD Handle) override;
virtual HRESULT STDMETHODCALLTYPE SetPixelShaderConstant(DWORD Register, const void *pConstantData, DWORD ConstantCount) override;
virtual HRESULT STDMETHODCALLTYPE GetPixelShaderConstant(DWORD Register, void *pConstantData, DWORD ConstantCount) override;
virtual HRESULT STDMETHODCALLTYPE GetPixelShaderFunction(DWORD Handle, void *pData, DWORD *pSizeOfData) override;
virtual HRESULT STDMETHODCALLTYPE DrawRectPatch(UINT Handle, const float *pNumSegs, const D3DRECTPATCH_INFO *pRectPatchInfo) override;
virtual HRESULT STDMETHODCALLTYPE DrawTriPatch(UINT Handle, const float *pNumSegs, const D3DTRIPATCH_INFO *pTriPatchInfo) override;
virtual HRESULT STDMETHODCALLTYPE DeletePatch(UINT Handle) override;
AddressLookupTable *ProxyAddressLookupTable;
private:
void ApplyClipPlanes();
void ReleaseShaders();
Direct3D8 *const D3D;
IDirect3DDevice9 *const ProxyInterface;
INT CurrentBaseVertexIndex = 0;
const BOOL ZBufferDiscarding = FALSE;
DWORD CurrentVertexShaderHandle = 0, CurrentPixelShaderHandle = 0;
IDirect3DSurface9 *pCurrentRenderTarget = nullptr;
bool PaletteFlag = false;
static constexpr size_t MAX_CLIP_PLANES = 6;
float StoredClipPlanes[MAX_CLIP_PLANES][4] = {};
DWORD ClipPlaneRenderState = 0;
// Store Shader Handles so they can be destroyed later to mirror D3D8 behavior
std::unordered_set<DWORD> PixelShaderHandles, VertexShaderHandles;
unsigned int VertexShaderAndDeclarationCount = 0;
};
class Direct3DSwapChain8 : public IDirect3DSwapChain8, public AddressLookupTableObject
{
Direct3DSwapChain8(const Direct3DSwapChain8 &) = delete;
Direct3DSwapChain8 &operator=(const Direct3DSwapChain8 &) = delete;
public:
Direct3DSwapChain8(Direct3DDevice8 *device, IDirect3DSwapChain9 *ProxyInterface);
~Direct3DSwapChain8();
IDirect3DSwapChain9 *GetProxyInterface() const { return ProxyInterface; }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObj) override;
virtual ULONG STDMETHODCALLTYPE AddRef() override;
virtual ULONG STDMETHODCALLTYPE Release() override;
virtual HRESULT STDMETHODCALLTYPE Present(const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion) override;
virtual HRESULT STDMETHODCALLTYPE GetBackBuffer(UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8 **ppBackBuffer) override;
private:
Direct3DDevice8 *const Device;
IDirect3DSwapChain9 *const ProxyInterface;
};
class Direct3DTexture8 : public IDirect3DTexture8, public AddressLookupTableObject
{
Direct3DTexture8(const Direct3DTexture8 &) = delete;
Direct3DTexture8 &operator=(const Direct3DTexture8 &) = delete;
public:
Direct3DTexture8(Direct3DDevice8 *device, IDirect3DTexture9 *ProxyInterface);
~Direct3DTexture8();
IDirect3DTexture9 *GetProxyInterface() const { return ProxyInterface; }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObj) override;
virtual ULONG STDMETHODCALLTYPE AddRef() override;
virtual ULONG STDMETHODCALLTYPE Release() override;
virtual HRESULT STDMETHODCALLTYPE GetDevice(IDirect3DDevice8 **ppDevice) override;
virtual HRESULT STDMETHODCALLTYPE SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData) override;
virtual HRESULT STDMETHODCALLTYPE FreePrivateData(REFGUID refguid) override;
virtual DWORD STDMETHODCALLTYPE SetPriority(DWORD PriorityNew) override;
virtual DWORD STDMETHODCALLTYPE GetPriority() override;
virtual void STDMETHODCALLTYPE PreLoad() override;
virtual D3DRESOURCETYPE STDMETHODCALLTYPE GetType() override;
virtual DWORD STDMETHODCALLTYPE SetLOD(DWORD LODNew) override;
virtual DWORD STDMETHODCALLTYPE GetLOD() override;
virtual DWORD STDMETHODCALLTYPE GetLevelCount() override;
virtual HRESULT STDMETHODCALLTYPE GetLevelDesc(UINT Level, D3DSURFACE_DESC8 *pDesc) override;
virtual HRESULT STDMETHODCALLTYPE GetSurfaceLevel(UINT Level, IDirect3DSurface8 **ppSurfaceLevel) override;
virtual HRESULT STDMETHODCALLTYPE LockRect(UINT Level, D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE UnlockRect(UINT Level) override;
virtual HRESULT STDMETHODCALLTYPE AddDirtyRect(const RECT *pDirtyRect) override;
private:
Direct3DDevice8 *const Device;
IDirect3DTexture9 *const ProxyInterface;
};
class Direct3DCubeTexture8 : public IDirect3DCubeTexture8, public AddressLookupTableObject
{
Direct3DCubeTexture8(const Direct3DCubeTexture8 &) = delete;
Direct3DCubeTexture8 &operator=(const Direct3DCubeTexture8 &) = delete;
public:
Direct3DCubeTexture8(Direct3DDevice8 *device, IDirect3DCubeTexture9 *ProxyInterface);
~Direct3DCubeTexture8();
IDirect3DCubeTexture9 *GetProxyInterface() const { return ProxyInterface; }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObj) override;
virtual ULONG STDMETHODCALLTYPE AddRef() override;
virtual ULONG STDMETHODCALLTYPE Release() override;
virtual HRESULT STDMETHODCALLTYPE GetDevice(IDirect3DDevice8 **ppDevice) override;
virtual HRESULT STDMETHODCALLTYPE SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData) override;
virtual HRESULT STDMETHODCALLTYPE FreePrivateData(REFGUID refguid) override;
virtual DWORD STDMETHODCALLTYPE SetPriority(DWORD PriorityNew) override;
virtual DWORD STDMETHODCALLTYPE GetPriority() override;
virtual void STDMETHODCALLTYPE PreLoad() override;
virtual D3DRESOURCETYPE STDMETHODCALLTYPE GetType() override;
virtual DWORD STDMETHODCALLTYPE SetLOD(DWORD LODNew) override;
virtual DWORD STDMETHODCALLTYPE GetLOD() override;
virtual DWORD STDMETHODCALLTYPE GetLevelCount() override;
virtual HRESULT STDMETHODCALLTYPE GetLevelDesc(UINT Level, D3DSURFACE_DESC8 *pDesc) override;
virtual HRESULT STDMETHODCALLTYPE GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8 **ppCubeMapSurface) override;
virtual HRESULT STDMETHODCALLTYPE LockRect(D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE UnlockRect(D3DCUBEMAP_FACES FaceType, UINT Level) override;
virtual HRESULT STDMETHODCALLTYPE AddDirtyRect(D3DCUBEMAP_FACES FaceType, const RECT *pDirtyRect) override;
private:
Direct3DDevice8 *const Device;
IDirect3DCubeTexture9 *const ProxyInterface;
};
class Direct3DVolumeTexture8 : public IDirect3DVolumeTexture8, public AddressLookupTableObject
{
Direct3DVolumeTexture8(const Direct3DVolumeTexture8 &) = delete;
Direct3DVolumeTexture8 &operator=(const Direct3DVolumeTexture8 &) = delete;
public:
Direct3DVolumeTexture8(Direct3DDevice8 *device, IDirect3DVolumeTexture9 *ProxyInterface);
~Direct3DVolumeTexture8();
IDirect3DVolumeTexture9 *GetProxyInterface() const { return ProxyInterface; }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObj) override;
virtual ULONG STDMETHODCALLTYPE AddRef() override;
virtual ULONG STDMETHODCALLTYPE Release() override;
virtual HRESULT STDMETHODCALLTYPE GetDevice(IDirect3DDevice8 **ppDevice) override;
virtual HRESULT STDMETHODCALLTYPE SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData) override;
virtual HRESULT STDMETHODCALLTYPE FreePrivateData(REFGUID refguid) override;
virtual DWORD STDMETHODCALLTYPE SetPriority(DWORD PriorityNew) override;
virtual DWORD STDMETHODCALLTYPE GetPriority() override;
virtual void STDMETHODCALLTYPE PreLoad() override;
virtual D3DRESOURCETYPE STDMETHODCALLTYPE GetType() override;
virtual DWORD STDMETHODCALLTYPE SetLOD(DWORD LODNew) override;
virtual DWORD STDMETHODCALLTYPE GetLOD() override;
virtual DWORD STDMETHODCALLTYPE GetLevelCount() override;
virtual HRESULT STDMETHODCALLTYPE GetLevelDesc(UINT Level, D3DVOLUME_DESC8 *pDesc) override;
virtual HRESULT STDMETHODCALLTYPE GetVolumeLevel(UINT Level, IDirect3DVolume8 **ppVolumeLevel) override;
virtual HRESULT STDMETHODCALLTYPE LockBox(UINT Level, D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE UnlockBox(UINT Level) override;
virtual HRESULT STDMETHODCALLTYPE AddDirtyBox(const D3DBOX *pDirtyBox) override;
private:
Direct3DDevice8 *const Device;
IDirect3DVolumeTexture9 *const ProxyInterface;
};
class Direct3DSurface8 : public IDirect3DSurface8, public AddressLookupTableObject
{
Direct3DSurface8(const Direct3DSurface8 &) = delete;
Direct3DSurface8 &operator=(const Direct3DSurface8 &) = delete;
public:
Direct3DSurface8(Direct3DDevice8 *device, IDirect3DSurface9 *ProxyInterface);
~Direct3DSurface8();
IDirect3DSurface9 *GetProxyInterface() const { return ProxyInterface; }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObj) override;
virtual ULONG STDMETHODCALLTYPE AddRef() override;
virtual ULONG STDMETHODCALLTYPE Release() override;
virtual HRESULT STDMETHODCALLTYPE GetDevice(IDirect3DDevice8 **ppDevice) override;
virtual HRESULT STDMETHODCALLTYPE SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData) override;
virtual HRESULT STDMETHODCALLTYPE FreePrivateData(REFGUID refguid) override;
virtual HRESULT STDMETHODCALLTYPE GetContainer(REFIID riid, void **ppContainer) override;
virtual HRESULT STDMETHODCALLTYPE GetDesc(D3DSURFACE_DESC8 *pDesc) override;
virtual HRESULT STDMETHODCALLTYPE LockRect(D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE UnlockRect() override;
private:
Direct3DDevice8 *const Device;
IDirect3DSurface9 *const ProxyInterface;
};
class Direct3DVolume8 : public IDirect3DVolume8, public AddressLookupTableObject
{
Direct3DVolume8(const Direct3DVolume8 &) = delete;
Direct3DVolume8 &operator=(const Direct3DVolume8 &) = delete;
public:
Direct3DVolume8(Direct3DDevice8 *Device, IDirect3DVolume9 *ProxyInterface);
~Direct3DVolume8();
IDirect3DVolume9 *GetProxyInterface() const { return ProxyInterface; }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObj) override;
virtual ULONG STDMETHODCALLTYPE AddRef() override;
virtual ULONG STDMETHODCALLTYPE Release() override;
virtual HRESULT STDMETHODCALLTYPE GetDevice(IDirect3DDevice8 **ppDevice) override;
virtual HRESULT STDMETHODCALLTYPE SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData) override;
virtual HRESULT STDMETHODCALLTYPE FreePrivateData(REFGUID refguid) override;
virtual HRESULT STDMETHODCALLTYPE GetContainer(REFIID riid, void **ppContainer) override;
virtual HRESULT STDMETHODCALLTYPE GetDesc(D3DVOLUME_DESC8 *pDesc) override;
virtual HRESULT STDMETHODCALLTYPE LockBox(D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE UnlockBox() override;
private:
Direct3DDevice8 *const Device;
IDirect3DVolume9 *const ProxyInterface;
};
class Direct3DVertexBuffer8 : public IDirect3DVertexBuffer8, public AddressLookupTableObject
{
Direct3DVertexBuffer8(const Direct3DVertexBuffer8 &) = delete;
Direct3DVertexBuffer8 &operator=(const Direct3DVertexBuffer8 &) = delete;
public:
Direct3DVertexBuffer8(Direct3DDevice8 *Device, IDirect3DVertexBuffer9 *ProxyInterface);
~Direct3DVertexBuffer8();
IDirect3DVertexBuffer9 *GetProxyInterface() const { return ProxyInterface; }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObj) override;
virtual ULONG STDMETHODCALLTYPE AddRef() override;
virtual ULONG STDMETHODCALLTYPE Release() override;
virtual HRESULT STDMETHODCALLTYPE GetDevice(IDirect3DDevice8 **ppDevice) override;
virtual HRESULT STDMETHODCALLTYPE SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData) override;
virtual HRESULT STDMETHODCALLTYPE FreePrivateData(REFGUID refguid) override;
virtual DWORD STDMETHODCALLTYPE SetPriority(DWORD PriorityNew) override;
virtual DWORD STDMETHODCALLTYPE GetPriority() override;
virtual void STDMETHODCALLTYPE PreLoad() override;
virtual D3DRESOURCETYPE STDMETHODCALLTYPE GetType() override;
virtual HRESULT STDMETHODCALLTYPE Lock(UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE Unlock() override;
virtual HRESULT STDMETHODCALLTYPE GetDesc(D3DVERTEXBUFFER_DESC *pDesc) override;
private:
Direct3DDevice8 *const Device;
IDirect3DVertexBuffer9 *const ProxyInterface;
};
class Direct3DIndexBuffer8 : public IDirect3DIndexBuffer8, public AddressLookupTableObject
{
Direct3DIndexBuffer8(const Direct3DIndexBuffer8 &) = delete;
Direct3DIndexBuffer8 &operator=(const Direct3DIndexBuffer8 &) = delete;
public:
Direct3DIndexBuffer8(Direct3DDevice8 *Device, IDirect3DIndexBuffer9 *ProxyInterface);
~Direct3DIndexBuffer8();
IDirect3DIndexBuffer9 *GetProxyInterface() const { return ProxyInterface; }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObj) override;
virtual ULONG STDMETHODCALLTYPE AddRef() override;
virtual ULONG STDMETHODCALLTYPE Release() override;
virtual HRESULT STDMETHODCALLTYPE GetDevice(IDirect3DDevice8 **ppDevice) override;
virtual HRESULT STDMETHODCALLTYPE SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData) override;
virtual HRESULT STDMETHODCALLTYPE FreePrivateData(REFGUID refguid) override;
virtual DWORD STDMETHODCALLTYPE SetPriority(DWORD PriorityNew) override;
virtual DWORD STDMETHODCALLTYPE GetPriority() override;
virtual void STDMETHODCALLTYPE PreLoad() override;
virtual D3DRESOURCETYPE STDMETHODCALLTYPE GetType() override;
virtual HRESULT STDMETHODCALLTYPE Lock(UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) override;
virtual HRESULT STDMETHODCALLTYPE Unlock() override;
virtual HRESULT STDMETHODCALLTYPE GetDesc(D3DINDEXBUFFER_DESC *pDesc) override;
private:
Direct3DDevice8 *const Device;
IDirect3DIndexBuffer9 *const ProxyInterface;
};
#include <fstream>
#ifndef D3D8TO9NOLOG
extern std::ofstream LOG;
#endif

View File

@ -0,0 +1,210 @@
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#include "d3d8to9.hpp"
static const D3DFORMAT AdapterFormats[] = {
D3DFMT_A8R8G8B8,
D3DFMT_X8R8G8B8,
D3DFMT_R5G6B5,
D3DFMT_X1R5G5B5,
D3DFMT_A1R5G5B5
};
Direct3D8::Direct3D8(IDirect3D9 *ProxyInterface) :
ProxyInterface(ProxyInterface)
{
D3DDISPLAYMODE pMode;
CurrentAdapterCount = ProxyInterface->GetAdapterCount();
if (CurrentAdapterCount > MaxAdapters)
CurrentAdapterCount = MaxAdapters;
for (UINT Adapter = 0; Adapter < CurrentAdapterCount; Adapter++)
{
for (D3DFORMAT Format : AdapterFormats)
{
const UINT ModeCount = ProxyInterface->GetAdapterModeCount(Adapter, Format);
for (UINT Mode = 0; Mode < ModeCount; Mode++)
{
ProxyInterface->EnumAdapterModes(Adapter, Format, Mode, &pMode);
CurrentAdapterModes[Adapter].push_back(pMode);
CurrentAdapterModeCount[Adapter]++;
}
}
}
}
Direct3D8::~Direct3D8()
{
}
HRESULT STDMETHODCALLTYPE Direct3D8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
return E_POINTER;
if (riid == __uuidof(IDirect3D8) ||
riid == __uuidof(IUnknown))
{
AddRef();
*ppvObj = static_cast<IDirect3D8 *>(this);
return S_OK;
}
return ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
}
ULONG STDMETHODCALLTYPE Direct3D8::AddRef()
{
return ProxyInterface->AddRef();
}
ULONG STDMETHODCALLTYPE Direct3D8::Release()
{
const ULONG LastRefCount = ProxyInterface->Release();
if (LastRefCount == 0)
delete this;
return LastRefCount;
}
HRESULT STDMETHODCALLTYPE Direct3D8::RegisterSoftwareDevice(void *pInitializeFunction)
{
return ProxyInterface->RegisterSoftwareDevice(pInitializeFunction);
}
UINT STDMETHODCALLTYPE Direct3D8::GetAdapterCount()
{
return CurrentAdapterCount;
}
HRESULT STDMETHODCALLTYPE Direct3D8::GetAdapterIdentifier(UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8 *pIdentifier)
{
if (pIdentifier == nullptr)
return D3DERR_INVALIDCALL;
D3DADAPTER_IDENTIFIER9 AdapterIndentifier;
if ((Flags & D3DENUM_NO_WHQL_LEVEL) == 0)
{
Flags |= D3DENUM_WHQL_LEVEL;
}
else
{
Flags ^= D3DENUM_NO_WHQL_LEVEL;
}
const HRESULT hr = ProxyInterface->GetAdapterIdentifier(Adapter, Flags, &AdapterIndentifier);
if (FAILED(hr))
return hr;
ConvertAdapterIdentifier(AdapterIndentifier, *pIdentifier);
return D3D_OK;
}
UINT STDMETHODCALLTYPE Direct3D8::GetAdapterModeCount(UINT Adapter)
{
return CurrentAdapterModeCount[Adapter];
}
HRESULT STDMETHODCALLTYPE Direct3D8::EnumAdapterModes(UINT Adapter, UINT Mode, D3DDISPLAYMODE *pMode)
{
if (pMode == nullptr || !(Adapter < CurrentAdapterCount && Mode < CurrentAdapterModeCount[Adapter]))
return D3DERR_INVALIDCALL;
pMode->Format = CurrentAdapterModes[Adapter].at(Mode).Format;
pMode->Height = CurrentAdapterModes[Adapter].at(Mode).Height;
pMode->RefreshRate = CurrentAdapterModes[Adapter].at(Mode).RefreshRate;
pMode->Width = CurrentAdapterModes[Adapter].at(Mode).Width;
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3D8::GetAdapterDisplayMode(UINT Adapter, D3DDISPLAYMODE *pMode)
{
return ProxyInterface->GetAdapterDisplayMode(Adapter, pMode);
}
HRESULT STDMETHODCALLTYPE Direct3D8::CheckDeviceType(UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed)
{
return ProxyInterface->CheckDeviceType(Adapter, CheckType, DisplayFormat, BackBufferFormat, bWindowed);
}
HRESULT STDMETHODCALLTYPE Direct3D8::CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat)
{
if (CheckFormat == D3DFMT_UYVY ||
CheckFormat == D3DFMT_YUY2 ||
CheckFormat == MAKEFOURCC('Y', 'V', '1', '2') ||
CheckFormat == MAKEFOURCC('N', 'V', '1', '2'))
{
return D3DERR_NOTAVAILABLE;
}
return ProxyInterface->CheckDeviceFormat(Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
}
HRESULT STDMETHODCALLTYPE Direct3D8::CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType)
{
return ProxyInterface->CheckDeviceMultiSampleType(Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, nullptr);
}
HRESULT STDMETHODCALLTYPE Direct3D8::CheckDepthStencilMatch(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat)
{
return ProxyInterface->CheckDepthStencilMatch(Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
}
HRESULT STDMETHODCALLTYPE Direct3D8::GetDeviceCaps(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8 *pCaps)
{
if (pCaps == nullptr)
return D3DERR_INVALIDCALL;
D3DCAPS9 DeviceCaps;
const HRESULT hr = ProxyInterface->GetDeviceCaps(Adapter, DeviceType, &DeviceCaps);
if (FAILED(hr))
return hr;
ConvertCaps(DeviceCaps, *pCaps);
return D3D_OK;
}
HMONITOR STDMETHODCALLTYPE Direct3D8::GetAdapterMonitor(UINT Adapter)
{
return ProxyInterface->GetAdapterMonitor(Adapter);
}
HRESULT STDMETHODCALLTYPE Direct3D8::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS8 *pPresentationParameters, IDirect3DDevice8 **ppReturnedDeviceInterface)
{
#ifndef D3D8TO9NOLOG
LOG << "Redirecting '" << "IDirect3D8::CreateDevice" << "(" << this << ", " << Adapter << ", " << DeviceType << ", " << hFocusWindow << ", " << BehaviorFlags << ", " << pPresentationParameters << ", " << ppReturnedDeviceInterface << ")' ..." << std::endl;
#endif
if (pPresentationParameters == nullptr || ppReturnedDeviceInterface == nullptr)
return D3DERR_INVALIDCALL;
*ppReturnedDeviceInterface = nullptr;
D3DPRESENT_PARAMETERS PresentParams;
ConvertPresentParameters(*pPresentationParameters, PresentParams);
// Get multisample quality level
if (PresentParams.MultiSampleType != D3DMULTISAMPLE_NONE)
{
DWORD QualityLevels = 0;
if (ProxyInterface->CheckDeviceMultiSampleType(Adapter,
DeviceType, PresentParams.BackBufferFormat, PresentParams.Windowed,
PresentParams.MultiSampleType, &QualityLevels) == S_OK &&
ProxyInterface->CheckDeviceMultiSampleType(Adapter,
DeviceType, PresentParams.AutoDepthStencilFormat, PresentParams.Windowed,
PresentParams.MultiSampleType, &QualityLevels) == S_OK)
{
PresentParams.MultiSampleQuality = (QualityLevels != 0) ? QualityLevels - 1 : 0;
}
}
IDirect3DDevice9 *DeviceInterface = nullptr;
const HRESULT hr = ProxyInterface->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, &PresentParams, &DeviceInterface);
if (FAILED(hr))
return hr;
*ppReturnedDeviceInterface = new Direct3DDevice8(this, DeviceInterface, (PresentParams.Flags & D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL) != 0);
// Set default vertex declaration
DeviceInterface->SetFVF(D3DFVF_XYZ);
return D3D_OK;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,109 @@
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#include "d3d8to9.hpp"
Direct3DIndexBuffer8::Direct3DIndexBuffer8(Direct3DDevice8 *Device, IDirect3DIndexBuffer9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DIndexBuffer8::~Direct3DIndexBuffer8()
{
}
HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
return E_POINTER;
if (riid == __uuidof(IDirect3DIndexBuffer8) ||
riid == __uuidof(IUnknown) ||
riid == __uuidof(IDirect3DResource8))
{
AddRef();
*ppvObj = static_cast<IDirect3DIndexBuffer8 *>(this);
return S_OK;
}
const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
ULONG STDMETHODCALLTYPE Direct3DIndexBuffer8::AddRef()
{
return ProxyInterface->AddRef();
}
ULONG STDMETHODCALLTYPE Direct3DIndexBuffer8::Release()
{
return ProxyInterface->Release();
}
HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Device->AddRef();
*ppDevice = Device;
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
{
return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData)
{
return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData);
}
HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::FreePrivateData(REFGUID refguid)
{
return ProxyInterface->FreePrivateData(refguid);
}
DWORD STDMETHODCALLTYPE Direct3DIndexBuffer8::SetPriority(DWORD PriorityNew)
{
return ProxyInterface->SetPriority(PriorityNew);
}
DWORD STDMETHODCALLTYPE Direct3DIndexBuffer8::GetPriority()
{
return ProxyInterface->GetPriority();
}
void STDMETHODCALLTYPE Direct3DIndexBuffer8::PreLoad()
{
ProxyInterface->PreLoad();
}
D3DRESOURCETYPE STDMETHODCALLTYPE Direct3DIndexBuffer8::GetType()
{
return D3DRTYPE_INDEXBUFFER;
}
HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::Lock(UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags)
{
if ((Flags & D3DLOCK_DISCARD) != 0)
{
D3DINDEXBUFFER_DESC desc;
ProxyInterface->GetDesc(&desc);
if ((desc.Usage & D3DUSAGE_DYNAMIC) == 0 ||
(desc.Usage & D3DUSAGE_WRITEONLY) == 0)
{
Flags ^= D3DLOCK_DISCARD;
}
}
return ProxyInterface->Lock(OffsetToLock, SizeToLock, reinterpret_cast<void **>(ppbData), Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::Unlock()
{
return ProxyInterface->Unlock();
}
HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::GetDesc(D3DINDEXBUFFER_DESC *pDesc)
{
return ProxyInterface->GetDesc(pDesc);
}

View File

@ -0,0 +1,99 @@
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#include "d3d8to9.hpp"
Direct3DSurface8::Direct3DSurface8(Direct3DDevice8 *Device, IDirect3DSurface9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DSurface8::~Direct3DSurface8()
{
}
HRESULT STDMETHODCALLTYPE Direct3DSurface8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
return E_POINTER;
if (riid == __uuidof(IDirect3DSurface8) ||
riid == __uuidof(IUnknown))
{
AddRef();
*ppvObj = static_cast<IDirect3DSurface8 *>(this);
return S_OK;
}
const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
ULONG STDMETHODCALLTYPE Direct3DSurface8::AddRef()
{
return ProxyInterface->AddRef();
}
ULONG STDMETHODCALLTYPE Direct3DSurface8::Release()
{
return ProxyInterface->Release();
}
HRESULT STDMETHODCALLTYPE Direct3DSurface8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Device->AddRef();
*ppDevice = Device;
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DSurface8::SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
{
return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DSurface8::GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData)
{
return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData);
}
HRESULT STDMETHODCALLTYPE Direct3DSurface8::FreePrivateData(REFGUID refguid)
{
return ProxyInterface->FreePrivateData(refguid);
}
HRESULT STDMETHODCALLTYPE Direct3DSurface8::GetContainer(REFIID riid, void **ppContainer)
{
const HRESULT hr = ProxyInterface->GetContainer(ConvertREFIID(riid), ppContainer);
if (SUCCEEDED(hr))
GenericQueryInterface(riid, ppContainer, Device);
return hr;
}
HRESULT STDMETHODCALLTYPE Direct3DSurface8::GetDesc(D3DSURFACE_DESC8 *pDesc)
{
if (pDesc == nullptr)
return D3DERR_INVALIDCALL;
D3DSURFACE_DESC SurfaceDesc;
const HRESULT hr = ProxyInterface->GetDesc(&SurfaceDesc);
if (FAILED(hr))
return hr;
ConvertSurfaceDesc(SurfaceDesc, *pDesc);
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DSurface8::LockRect(D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags)
{
return ProxyInterface->LockRect(pLockedRect, pRect, Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DSurface8::UnlockRect()
{
return ProxyInterface->UnlockRect();
}

View File

@ -0,0 +1,68 @@
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#include "d3d8to9.hpp"
Direct3DSwapChain8::Direct3DSwapChain8(Direct3DDevice8 *Device, IDirect3DSwapChain9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DSwapChain8::~Direct3DSwapChain8()
{
}
HRESULT STDMETHODCALLTYPE Direct3DSwapChain8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
return E_POINTER;
if (riid == __uuidof(IDirect3DSwapChain8) ||
riid == __uuidof(IUnknown))
{
AddRef();
*ppvObj = static_cast<IDirect3DSwapChain8 *>(this);
return S_OK;
}
const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
ULONG STDMETHODCALLTYPE Direct3DSwapChain8::AddRef()
{
return ProxyInterface->AddRef();
}
ULONG STDMETHODCALLTYPE Direct3DSwapChain8::Release()
{
return ProxyInterface->Release();
}
HRESULT STDMETHODCALLTYPE Direct3DSwapChain8::Present(const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion)
{
UNREFERENCED_PARAMETER(pDirtyRegion);
return ProxyInterface->Present(pSourceRect, pDestRect, hDestWindowOverride, nullptr, 0);
}
HRESULT STDMETHODCALLTYPE Direct3DSwapChain8::GetBackBuffer(UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8 **ppBackBuffer)
{
if (ppBackBuffer == nullptr)
return D3DERR_INVALIDCALL;
*ppBackBuffer = nullptr;
IDirect3DSurface9 *SurfaceInterface = nullptr;
const HRESULT hr = ProxyInterface->GetBackBuffer(iBackBuffer, Type, &SurfaceInterface);
if (FAILED(hr))
return hr;
*ppBackBuffer = Device->ProxyAddressLookupTable->FindAddress<Direct3DSurface8>(SurfaceInterface);
return D3D_OK;
}

View File

@ -0,0 +1,419 @@
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#include "d3d8to9.hpp"
Direct3DTexture8::Direct3DTexture8(Direct3DDevice8 *Device, IDirect3DTexture9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DTexture8::~Direct3DTexture8()
{
}
HRESULT STDMETHODCALLTYPE Direct3DTexture8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
return E_POINTER;
if (riid == __uuidof(IDirect3DTexture8) ||
riid == __uuidof(IUnknown) ||
riid == __uuidof(IDirect3DResource8) ||
riid == __uuidof(IDirect3DBaseTexture8))
{
AddRef();
*ppvObj = static_cast<IDirect3DTexture8 *>(this);
return S_OK;
}
const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
ULONG STDMETHODCALLTYPE Direct3DTexture8::AddRef()
{
return ProxyInterface->AddRef();
}
ULONG STDMETHODCALLTYPE Direct3DTexture8::Release()
{
return ProxyInterface->Release();
}
HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Device->AddRef();
*ppDevice = Device;
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DTexture8::SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
{
return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData)
{
return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData);
}
HRESULT STDMETHODCALLTYPE Direct3DTexture8::FreePrivateData(REFGUID refguid)
{
return ProxyInterface->FreePrivateData(refguid);
}
DWORD STDMETHODCALLTYPE Direct3DTexture8::SetPriority(DWORD PriorityNew)
{
return ProxyInterface->SetPriority(PriorityNew);
}
DWORD STDMETHODCALLTYPE Direct3DTexture8::GetPriority()
{
return ProxyInterface->GetPriority();
}
void STDMETHODCALLTYPE Direct3DTexture8::PreLoad()
{
ProxyInterface->PreLoad();
}
D3DRESOURCETYPE STDMETHODCALLTYPE Direct3DTexture8::GetType()
{
return D3DRTYPE_TEXTURE;
}
DWORD STDMETHODCALLTYPE Direct3DTexture8::SetLOD(DWORD LODNew)
{
return ProxyInterface->SetLOD(LODNew);
}
DWORD STDMETHODCALLTYPE Direct3DTexture8::GetLOD()
{
return ProxyInterface->GetLOD();
}
DWORD STDMETHODCALLTYPE Direct3DTexture8::GetLevelCount()
{
return ProxyInterface->GetLevelCount();
}
HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetLevelDesc(UINT Level, D3DSURFACE_DESC8 *pDesc)
{
if (pDesc == nullptr)
return D3DERR_INVALIDCALL;
D3DSURFACE_DESC SurfaceDesc;
const HRESULT hr = ProxyInterface->GetLevelDesc(Level, &SurfaceDesc);
if (FAILED(hr))
return hr;
ConvertSurfaceDesc(SurfaceDesc, *pDesc);
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetSurfaceLevel(UINT Level, IDirect3DSurface8 **ppSurfaceLevel)
{
if (ppSurfaceLevel == nullptr)
return D3DERR_INVALIDCALL;
*ppSurfaceLevel = nullptr;
IDirect3DSurface9 *SurfaceInterface = nullptr;
const HRESULT hr = ProxyInterface->GetSurfaceLevel(Level, &SurfaceInterface);
if (FAILED(hr))
return hr;
*ppSurfaceLevel = Device->ProxyAddressLookupTable->FindAddress<Direct3DSurface8>(SurfaceInterface);
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DTexture8::LockRect(UINT Level, D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags)
{
return ProxyInterface->LockRect(Level, pLockedRect, pRect, Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DTexture8::UnlockRect(UINT Level)
{
return ProxyInterface->UnlockRect(Level);
}
HRESULT STDMETHODCALLTYPE Direct3DTexture8::AddDirtyRect(const RECT *pDirtyRect)
{
return ProxyInterface->AddDirtyRect(pDirtyRect);
}
Direct3DCubeTexture8::Direct3DCubeTexture8(Direct3DDevice8 *device, IDirect3DCubeTexture9 *ProxyInterface) :
Device(device),
ProxyInterface(ProxyInterface)
{
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DCubeTexture8::~Direct3DCubeTexture8()
{
}
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
return E_POINTER;
if (riid == __uuidof(IDirect3DCubeTexture8) ||
riid == __uuidof(IUnknown) ||
riid == __uuidof(IDirect3DResource8) ||
riid == __uuidof(IDirect3DBaseTexture8))
{
AddRef();
*ppvObj = static_cast<IDirect3DCubeTexture8 *>(this);
return S_OK;
}
const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
ULONG STDMETHODCALLTYPE Direct3DCubeTexture8::AddRef()
{
return ProxyInterface->AddRef();
}
ULONG STDMETHODCALLTYPE Direct3DCubeTexture8::Release()
{
return ProxyInterface->Release();
}
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Device->AddRef();
*ppDevice = Device;
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
{
return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData)
{
return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData);
}
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::FreePrivateData(REFGUID refguid)
{
return ProxyInterface->FreePrivateData(refguid);
}
DWORD STDMETHODCALLTYPE Direct3DCubeTexture8::SetPriority(DWORD PriorityNew)
{
return ProxyInterface->SetPriority(PriorityNew);
}
DWORD STDMETHODCALLTYPE Direct3DCubeTexture8::GetPriority()
{
return ProxyInterface->GetPriority();
}
void STDMETHODCALLTYPE Direct3DCubeTexture8::PreLoad()
{
ProxyInterface->PreLoad();
}
D3DRESOURCETYPE STDMETHODCALLTYPE Direct3DCubeTexture8::GetType()
{
return D3DRTYPE_CUBETEXTURE;
}
DWORD STDMETHODCALLTYPE Direct3DCubeTexture8::SetLOD(DWORD LODNew)
{
return ProxyInterface->SetLOD(LODNew);
}
DWORD STDMETHODCALLTYPE Direct3DCubeTexture8::GetLOD()
{
return ProxyInterface->GetLOD();
}
DWORD STDMETHODCALLTYPE Direct3DCubeTexture8::GetLevelCount()
{
return ProxyInterface->GetLevelCount();
}
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetLevelDesc(UINT Level, D3DSURFACE_DESC8 *pDesc)
{
if (pDesc == nullptr)
return D3DERR_INVALIDCALL;
D3DSURFACE_DESC SurfaceDesc;
const HRESULT hr = ProxyInterface->GetLevelDesc(Level, &SurfaceDesc);
if (FAILED(hr))
return hr;
ConvertSurfaceDesc(SurfaceDesc, *pDesc);
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8 **ppCubeMapSurface)
{
if (ppCubeMapSurface == nullptr)
return D3DERR_INVALIDCALL;
*ppCubeMapSurface = nullptr;
IDirect3DSurface9 *SurfaceInterface = nullptr;
const HRESULT hr = ProxyInterface->GetCubeMapSurface(FaceType, Level, &SurfaceInterface);
if (FAILED(hr))
return hr;
*ppCubeMapSurface = Device->ProxyAddressLookupTable->FindAddress<Direct3DSurface8>(SurfaceInterface);
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::LockRect(D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags)
{
return ProxyInterface->LockRect(FaceType, Level, pLockedRect, pRect, Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::UnlockRect(D3DCUBEMAP_FACES FaceType, UINT Level)
{
return ProxyInterface->UnlockRect(FaceType, Level);
}
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::AddDirtyRect(D3DCUBEMAP_FACES FaceType, const RECT *pDirtyRect)
{
return ProxyInterface->AddDirtyRect(FaceType, pDirtyRect);
}
Direct3DVolumeTexture8::Direct3DVolumeTexture8(Direct3DDevice8 *device, IDirect3DVolumeTexture9 *ProxyInterface) :
Device(device),
ProxyInterface(ProxyInterface)
{
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DVolumeTexture8::~Direct3DVolumeTexture8()
{
}
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
return E_POINTER;
if (riid == __uuidof(IDirect3DVolumeTexture8) ||
riid == __uuidof(IUnknown) ||
riid == __uuidof(IDirect3DResource8) ||
riid == __uuidof(IDirect3DBaseTexture8))
{
AddRef();
*ppvObj = static_cast<IDirect3DVolumeTexture8 *>(this);
return S_OK;
}
const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
ULONG STDMETHODCALLTYPE Direct3DVolumeTexture8::AddRef()
{
return ProxyInterface->AddRef();
}
ULONG STDMETHODCALLTYPE Direct3DVolumeTexture8::Release()
{
return ProxyInterface->Release();
}
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Device->AddRef();
*ppDevice = Device;
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
{
return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData)
{
return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData);
}
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::FreePrivateData(REFGUID refguid)
{
return ProxyInterface->FreePrivateData(refguid);
}
DWORD STDMETHODCALLTYPE Direct3DVolumeTexture8::SetPriority(DWORD PriorityNew)
{
return ProxyInterface->SetPriority(PriorityNew);
}
DWORD STDMETHODCALLTYPE Direct3DVolumeTexture8::GetPriority()
{
return ProxyInterface->GetPriority();
}
void STDMETHODCALLTYPE Direct3DVolumeTexture8::PreLoad()
{
ProxyInterface->PreLoad();
}
D3DRESOURCETYPE STDMETHODCALLTYPE Direct3DVolumeTexture8::GetType()
{
return D3DRTYPE_VOLUMETEXTURE;
}
DWORD STDMETHODCALLTYPE Direct3DVolumeTexture8::SetLOD(DWORD LODNew)
{
return ProxyInterface->SetLOD(LODNew);
}
DWORD STDMETHODCALLTYPE Direct3DVolumeTexture8::GetLOD()
{
return ProxyInterface->GetLOD();
}
DWORD STDMETHODCALLTYPE Direct3DVolumeTexture8::GetLevelCount()
{
return ProxyInterface->GetLevelCount();
}
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetLevelDesc(UINT Level, D3DVOLUME_DESC8 *pDesc)
{
if (pDesc == nullptr)
return D3DERR_INVALIDCALL;
D3DVOLUME_DESC VolumeDesc;
const HRESULT hr = ProxyInterface->GetLevelDesc(Level, &VolumeDesc);
if (FAILED(hr))
return hr;
ConvertVolumeDesc(VolumeDesc, *pDesc);
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetVolumeLevel(UINT Level, IDirect3DVolume8 **ppVolumeLevel)
{
if (ppVolumeLevel == nullptr)
return D3DERR_INVALIDCALL;
*ppVolumeLevel = nullptr;
IDirect3DVolume9 *VolumeInterface = nullptr;
const HRESULT hr = ProxyInterface->GetVolumeLevel(Level, &VolumeInterface);
if (FAILED(hr))
return hr;
*ppVolumeLevel = Device->ProxyAddressLookupTable->FindAddress<Direct3DVolume8>(VolumeInterface);
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::LockBox(UINT Level, D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox, DWORD Flags)
{
return ProxyInterface->LockBox(Level, pLockedVolume, pBox, Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::UnlockBox(UINT Level)
{
return ProxyInterface->UnlockBox(Level);
}
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::AddDirtyBox(const D3DBOX *pDirtyBox)
{
return ProxyInterface->AddDirtyBox(pDirtyBox);
}

View File

@ -0,0 +1,109 @@
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#include "d3d8to9.hpp"
Direct3DVertexBuffer8::Direct3DVertexBuffer8(Direct3DDevice8 *Device, IDirect3DVertexBuffer9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DVertexBuffer8::~Direct3DVertexBuffer8()
{
}
HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
return E_POINTER;
if (riid == __uuidof(IDirect3DVertexBuffer8) ||
riid == __uuidof(IUnknown) ||
riid == __uuidof(IDirect3DResource8))
{
AddRef();
*ppvObj = static_cast<IDirect3DVertexBuffer8 *>(this);
return S_OK;
}
const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
ULONG STDMETHODCALLTYPE Direct3DVertexBuffer8::AddRef()
{
return ProxyInterface->AddRef();
}
ULONG STDMETHODCALLTYPE Direct3DVertexBuffer8::Release()
{
return ProxyInterface->Release();
}
HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Device->AddRef();
*ppDevice = Device;
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
{
return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData)
{
return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData);
}
HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::FreePrivateData(REFGUID refguid)
{
return ProxyInterface->FreePrivateData(refguid);
}
DWORD STDMETHODCALLTYPE Direct3DVertexBuffer8::SetPriority(DWORD PriorityNew)
{
return ProxyInterface->SetPriority(PriorityNew);
}
DWORD STDMETHODCALLTYPE Direct3DVertexBuffer8::GetPriority()
{
return ProxyInterface->GetPriority();
}
void STDMETHODCALLTYPE Direct3DVertexBuffer8::PreLoad()
{
ProxyInterface->PreLoad();
}
D3DRESOURCETYPE STDMETHODCALLTYPE Direct3DVertexBuffer8::GetType()
{
return D3DRTYPE_VERTEXBUFFER;
}
HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::Lock(UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags)
{
if ((Flags & D3DLOCK_DISCARD) != 0)
{
D3DVERTEXBUFFER_DESC desc;
ProxyInterface->GetDesc(&desc);
if ((desc.Usage & D3DUSAGE_DYNAMIC) == 0 ||
(desc.Usage & D3DUSAGE_WRITEONLY) == 0)
{
Flags ^= D3DLOCK_DISCARD;
}
}
return ProxyInterface->Lock(OffsetToLock, SizeToLock, reinterpret_cast<void **>(ppbData), Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::Unlock()
{
return ProxyInterface->Unlock();
}
HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::GetDesc(D3DVERTEXBUFFER_DESC *pDesc)
{
return ProxyInterface->GetDesc(pDesc);
}

View File

@ -0,0 +1,98 @@
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#include "d3d8to9.hpp"
Direct3DVolume8::Direct3DVolume8(Direct3DDevice8 *Device, IDirect3DVolume9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DVolume8::~Direct3DVolume8()
{
}
HRESULT STDMETHODCALLTYPE Direct3DVolume8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
return E_POINTER;
if (riid == __uuidof(IDirect3DVolume8) ||
riid == __uuidof(IUnknown))
{
AddRef();
*ppvObj = static_cast<IDirect3DVolume8 *>(this);
return S_OK;
}
const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
ULONG STDMETHODCALLTYPE Direct3DVolume8::AddRef()
{
return ProxyInterface->AddRef();
}
ULONG STDMETHODCALLTYPE Direct3DVolume8::Release()
{
return ProxyInterface->Release();
}
HRESULT STDMETHODCALLTYPE Direct3DVolume8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Device->AddRef();
*ppDevice = Device;
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DVolume8::SetPrivateData(REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
{
return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DVolume8::GetPrivateData(REFGUID refguid, void *pData, DWORD *pSizeOfData)
{
return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData);
}
HRESULT STDMETHODCALLTYPE Direct3DVolume8::FreePrivateData(REFGUID refguid)
{
return ProxyInterface->FreePrivateData(refguid);
}
HRESULT STDMETHODCALLTYPE Direct3DVolume8::GetContainer(REFIID riid, void **ppContainer)
{
const HRESULT hr = ProxyInterface->GetContainer(ConvertREFIID(riid), ppContainer);
if (SUCCEEDED(hr))
GenericQueryInterface(riid, ppContainer, Device);
return hr;
}
HRESULT STDMETHODCALLTYPE Direct3DVolume8::GetDesc(D3DVOLUME_DESC8 *pDesc)
{
if (pDesc == nullptr)
return D3DERR_INVALIDCALL;
D3DVOLUME_DESC VolumeDesc;
const HRESULT hr = ProxyInterface->GetDesc(&VolumeDesc);
if (FAILED(hr))
return hr;
ConvertVolumeDesc(VolumeDesc, *pDesc);
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DVolume8::LockBox(D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox, DWORD Flags)
{
return ProxyInterface->LockBox(pLockedVolume, pBox, Flags);
}
HRESULT STDMETHODCALLTYPE Direct3DVolume8::UnlockBox()
{
return ProxyInterface->UnlockBox();
}

View File

@ -0,0 +1,191 @@
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#include "d3d8types.hpp"
#include <assert.h>
#include <algorithm>
bool SupportsPalettes()
{
HDC hDC = GetDC(nullptr);
bool hasPalette = (GetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE) != 0;
ReleaseDC(nullptr, hDC);
return hasPalette;
}
static UINT CalcTextureSize(UINT Width, UINT Height, UINT Depth, D3DFORMAT Format)
{
switch (static_cast<DWORD>(Format))
{
default:
case D3DFMT_UNKNOWN:
return 0;
case D3DFMT_R3G3B2:
case D3DFMT_A8:
case D3DFMT_P8:
case D3DFMT_L8:
case D3DFMT_A4L4:
return Width * Height * Depth;
case D3DFMT_R5G6B5:
case D3DFMT_X1R5G5B5:
case D3DFMT_A1R5G5B5:
case D3DFMT_A4R4G4B4:
case D3DFMT_A8R3G3B2:
case D3DFMT_X4R4G4B4:
case D3DFMT_A8P8:
case D3DFMT_A8L8:
case D3DFMT_V8U8:
case D3DFMT_L6V5U5:
case D3DFMT_D16_LOCKABLE:
case D3DFMT_D15S1:
case D3DFMT_D16:
case D3DFMT_UYVY:
case D3DFMT_YUY2:
return Width * 2 * Height * Depth;
case D3DFMT_R8G8B8:
return Width * 3 * Height * Depth;
case D3DFMT_A8R8G8B8:
case D3DFMT_X8R8G8B8:
case D3DFMT_A2B10G10R10:
case D3DFMT_A8B8G8R8:
case D3DFMT_X8B8G8R8:
case D3DFMT_G16R16:
case D3DFMT_X8L8V8U8:
case D3DFMT_Q8W8V8U8:
case D3DFMT_V16U16:
case D3DFMT_W11V11U10:
case D3DFMT_A2W10V10U10:
case D3DFMT_D32:
case D3DFMT_D24S8:
case D3DFMT_D24X8:
case D3DFMT_D24X4S4:
return Width * 4 * Height * Depth;
case D3DFMT_DXT1:
assert(Depth <= 1);
return ((Width + 3) >> 2) * ((Height + 3) >> 2) * 8;
case D3DFMT_DXT2:
case D3DFMT_DXT3:
case D3DFMT_DXT4:
case D3DFMT_DXT5:
assert(Depth <= 1);
return ((Width + 3) >> 2) * ((Height + 3) >> 2) * 16;
}
}
void ConvertCaps(D3DCAPS9 &Input, D3DCAPS8 &Output)
{
CopyMemory(&Output, &Input, sizeof(Output));
// Tell application that window mode is supported
Output.Caps2 |= D3DCAPS2_CANRENDERWINDOWED;
// Tell application that z-bias is supported
Output.RasterCaps |= D3DPRASTERCAPS_ZBIAS;
// Remove unsupported stencil capability
Output.StencilCaps &= ~D3DSTENCILCAPS_TWOSIDED;
// Set default pixel shader version to 1.4 for D3D8 compatibility
Output.PixelShaderVersion = D3DPS_VERSION(1, 4);
// Set default vertex shader version to 1.1 for D3D8 compatibility
Output.VertexShaderVersion = D3DVS_VERSION(1, 1);
// D3D8 can only handle up to 256 for MaxVertexShaderConst
Output.MaxVertexShaderConst = std::min(256ul, Input.MaxVertexShaderConst);
}
void ConvertVolumeDesc(D3DVOLUME_DESC &Input, D3DVOLUME_DESC8 &Output)
{
Output.Format = Input.Format;
Output.Type = Input.Type;
Output.Usage = Input.Usage;
Output.Pool = Input.Pool;
Output.Size = CalcTextureSize(Input.Width, Input.Height, Input.Depth, Input.Format);
Output.Width = Input.Width;
Output.Height = Input.Height;
Output.Depth = Input.Depth;
}
void ConvertSurfaceDesc(D3DSURFACE_DESC &Input, D3DSURFACE_DESC8 &Output)
{
Output.Format = Input.Format;
Output.Type = Input.Type;
Output.Usage = Input.Usage;
Output.Pool = Input.Pool;
Output.Size = CalcTextureSize(Input.Width, Input.Height, 1, Input.Format);
Output.MultiSampleType = Input.MultiSampleType;
Output.Width = Input.Width;
Output.Height = Input.Height;
}
void ConvertPresentParameters(D3DPRESENT_PARAMETERS8 &Input, D3DPRESENT_PARAMETERS &Output)
{
Output.BackBufferWidth = Input.BackBufferWidth;
Output.BackBufferHeight = Input.BackBufferHeight;
Output.BackBufferFormat = Input.BackBufferFormat;
Output.BackBufferCount = Input.BackBufferCount;
Output.MultiSampleType = Input.MultiSampleType;
Output.MultiSampleQuality = 0;
Output.SwapEffect = Input.SwapEffect;
Output.hDeviceWindow = Input.hDeviceWindow;
Output.Windowed = Input.Windowed;
Output.EnableAutoDepthStencil = Input.EnableAutoDepthStencil;
Output.AutoDepthStencilFormat = Input.AutoDepthStencilFormat;
Output.Flags = Input.Flags;
// MultiSampleType must be D3DMULTISAMPLE_NONE unless SwapEffect has been set to D3DSWAPEFFECT_DISCARD or if there is a lockable backbuffer
if (Input.SwapEffect != D3DSWAPEFFECT_DISCARD || (Input.Flags & D3DPRESENTFLAG_LOCKABLE_BACKBUFFER))
{
Output.MultiSampleType = D3DMULTISAMPLE_NONE;
}
if (Input.Windowed)
{
Output.FullScreen_RefreshRateInHz = 0;
// D3D8 always presents without waiting for vblank when windowed
Output.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
}
else
{
Output.FullScreen_RefreshRateInHz = Input.FullScreen_RefreshRateInHz;
// D3DPRESENT_RATE_UNLIMITED is no longer supported in D3D9
if (Input.FullScreen_RefreshRateInHz == D3DPRESENT_RATE_UNLIMITED)
{
Output.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
}
Output.PresentationInterval = Input.FullScreen_PresentationInterval;
}
// D3DSWAPEFFECT_COPY_VSYNC is no longer supported in D3D9
if (Input.SwapEffect == D3DSWAPEFFECT_COPY_VSYNC)
{
Output.SwapEffect = D3DSWAPEFFECT_COPY;
// Need to wait for vblank before copying (both when windowed and full-screen)
if (Input.Windowed)
{
Output.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
}
else
{
// As per documentation the D3DPRESENT_INTERVAL_IMMEDIATE flag is meaningless when used in conjunction with D3DSWAPEFFECT_COPY_VSYNC
if (Input.FullScreen_PresentationInterval == D3DPRESENT_INTERVAL_IMMEDIATE)
{
Output.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
}
}
}
}
void ConvertAdapterIdentifier(D3DADAPTER_IDENTIFIER9 &Input, D3DADAPTER_IDENTIFIER8 &Output)
{
CopyMemory(Output.Driver, Input.Driver, MAX_DEVICE_IDENTIFIER_STRING);
CopyMemory(Output.Description, Input.Description, MAX_DEVICE_IDENTIFIER_STRING);
Output.DriverVersion = Input.DriverVersion;
Output.VendorId = Input.VendorId;
Output.DeviceId = Input.DeviceId;
Output.SubSysId = Input.SubSysId;
Output.Revision = Input.Revision;
Output.DeviceIdentifier = Input.DeviceIdentifier;
Output.WHQLLevel = Input.WHQLLevel;
}

View File

@ -0,0 +1,180 @@
#pragma once
struct IUnknown;
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <d3d9.h>
#define D3DFMT_W11V11U10 65
#define D3DRS_LINEPATTERN 10
#define D3DRS_ZVISIBLE 30
#define D3DRS_EDGEANTIALIAS 40
#define D3DRS_ZBIAS 47
#define D3DRS_SOFTWAREVERTEXPROCESSING 153
#define D3DRS_PATCHSEGMENTS 164
#define D3DTSS_ADDRESSU 13
#define D3DTSS_ADDRESSV 14
#define D3DTSS_ADDRESSW 25
#define D3DTSS_BORDERCOLOR 15
#define D3DTSS_MAGFILTER 16
#define D3DTSS_MINFILTER 17
#define D3DTSS_MIPFILTER 18
#define D3DTSS_MIPMAPLODBIAS 19
#define D3DTSS_MAXMIPLEVEL 20
#define D3DTSS_MAXANISOTROPY 21
#define D3DTEXF_FLATCUBIC 4
#define D3DTEXF_GAUSSIANCUBIC 5
#define D3DVSD_TOKEN_STREAM 1
#define D3DVSD_TOKEN_STREAMDATA 2
#define D3DVSD_TOKEN_TESSELLATOR 3
#define D3DVSD_TOKEN_CONSTMEM 4
#define D3DVSD_TOKENTYPESHIFT 29
#define D3DVSD_TOKENTYPEMASK (0x7 << D3DVSD_TOKENTYPESHIFT)
#define D3DVSD_STREAMNUMBERSHIFT 0
#define D3DVSD_STREAMNUMBERMASK (0xF << D3DVSD_STREAMNUMBERSHIFT)
#define D3DVSD_VERTEXREGSHIFT 0
#define D3DVSD_VERTEXREGMASK (0x1F << D3DVSD_VERTEXREGSHIFT)
#define D3DVSD_VERTEXREGINSHIFT 20
#define D3DVSD_VERTEXREGINMASK (0xF << D3DVSD_VERTEXREGINSHIFT)
#define D3DVSD_DATATYPESHIFT 16
#define D3DVSD_DATATYPEMASK (0xF << D3DVSD_DATATYPESHIFT)
#define D3DVSD_SKIPCOUNTSHIFT 16
#define D3DVSD_SKIPCOUNTMASK (0xF << D3DVSD_SKIPCOUNTSHIFT)
#define D3DVSD_CONSTCOUNTSHIFT 25
#define D3DVSD_CONSTCOUNTMASK (0xF << D3DVSD_CONSTCOUNTSHIFT)
#define D3DVSD_CONSTADDRESSSHIFT 0
#define D3DVSD_CONSTADDRESSMASK (0x7F << D3DVSD_CONSTADDRESSSHIFT)
#define D3DVSD_END() 0xFFFFFFFF
// Fix for MinGW headers which are missing defines in d3d9.h...
#ifndef D3DENUM_WHQL_LEVEL
#define D3DENUM_WHQL_LEVEL 0x00000002L
#endif
// Fix for MinGW headers which have some d3d8 defines in d3d9.h...
#ifndef D3DENUM_NO_WHQL_LEVEL
#define D3DENUM_NO_WHQL_LEVEL 0x00000002L
#endif
#define D3DSWAPEFFECT_COPY_VSYNC 4
#define D3DPRESENT_RATE_UNLIMITED 0x7FFFFFFF
// Fix for MinGW headers which have some d3d8 defines in d3d9.h...
#ifndef D3DCAPS2_CANRENDERWINDOWED
#define D3DCAPS2_CANRENDERWINDOWED 0x00080000L
#endif
#define D3DPRASTERCAPS_ZBIAS 0x00004000L
typedef D3DLIGHT9 D3DLIGHT8;
typedef D3DMATERIAL9 D3DMATERIAL8;
typedef D3DVIEWPORT9 D3DVIEWPORT8;
typedef D3DCLIPSTATUS9 D3DCLIPSTATUS8;
struct D3DCAPS8
{
D3DDEVTYPE DeviceType;
UINT AdapterOrdinal;
DWORD Caps, Caps2, Caps3;
DWORD PresentationIntervals;
DWORD CursorCaps;
DWORD DevCaps;
DWORD PrimitiveMiscCaps;
DWORD RasterCaps;
DWORD ZCmpCaps;
DWORD SrcBlendCaps;
DWORD DestBlendCaps;
DWORD AlphaCmpCaps;
DWORD ShadeCaps;
DWORD TextureCaps;
DWORD TextureFilterCaps;
DWORD CubeTextureFilterCaps;
DWORD VolumeTextureFilterCaps;
DWORD TextureAddressCaps;
DWORD VolumeTextureAddressCaps;
DWORD LineCaps;
DWORD MaxTextureWidth, MaxTextureHeight;
DWORD MaxVolumeExtent;
DWORD MaxTextureRepeat;
DWORD MaxTextureAspectRatio;
DWORD MaxAnisotropy;
float MaxVertexW;
float GuardBandLeft, GuardBandTop, GuardBandRight, GuardBandBottom;
float ExtentsAdjust;
DWORD StencilCaps;
DWORD FVFCaps;
DWORD TextureOpCaps;
DWORD MaxTextureBlendStages;
DWORD MaxSimultaneousTextures;
DWORD VertexProcessingCaps;
DWORD MaxActiveLights;
DWORD MaxUserClipPlanes;
DWORD MaxVertexBlendMatrices;
DWORD MaxVertexBlendMatrixIndex;
float MaxPointSize;
DWORD MaxPrimitiveCount;
DWORD MaxVertexIndex;
DWORD MaxStreams;
DWORD MaxStreamStride;
DWORD VertexShaderVersion;
DWORD MaxVertexShaderConst;
DWORD PixelShaderVersion;
float MaxPixelShaderValue;
};
struct D3DVOLUME_DESC8
{
D3DFORMAT Format;
D3DRESOURCETYPE Type;
DWORD Usage;
D3DPOOL Pool;
UINT Size;
UINT Width, Height, Depth;
};
struct D3DSURFACE_DESC8
{
D3DFORMAT Format;
D3DRESOURCETYPE Type;
DWORD Usage;
D3DPOOL Pool;
UINT Size;
D3DMULTISAMPLE_TYPE MultiSampleType;
UINT Width, Height;
};
struct D3DPRESENT_PARAMETERS8
{
UINT BackBufferWidth, BackBufferHeight;
D3DFORMAT BackBufferFormat;
UINT BackBufferCount;
D3DMULTISAMPLE_TYPE MultiSampleType;
D3DSWAPEFFECT SwapEffect;
HWND hDeviceWindow;
BOOL Windowed;
BOOL EnableAutoDepthStencil;
D3DFORMAT AutoDepthStencilFormat;
DWORD Flags;
UINT FullScreen_RefreshRateInHz, FullScreen_PresentationInterval;
};
struct D3DADAPTER_IDENTIFIER8
{
char Driver[MAX_DEVICE_IDENTIFIER_STRING];
char Description[MAX_DEVICE_IDENTIFIER_STRING];
LARGE_INTEGER DriverVersion;
DWORD VendorId, DeviceId, SubSysId;
DWORD Revision;
GUID DeviceIdentifier;
DWORD WHQLLevel;
};
bool SupportsPalettes();
void ConvertCaps(D3DCAPS9 &input, D3DCAPS8 &output);
void ConvertVolumeDesc(D3DVOLUME_DESC &input, D3DVOLUME_DESC8 &output);
void ConvertSurfaceDesc(D3DSURFACE_DESC &input, D3DSURFACE_DESC8 &output);
void ConvertPresentParameters(D3DPRESENT_PARAMETERS8 &input, D3DPRESENT_PARAMETERS &output);
void ConvertAdapterIdentifier(D3DADAPTER_IDENTIFIER9 &input, D3DADAPTER_IDENTIFIER8 &output);

View File

@ -0,0 +1,47 @@
#pragma once
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <d3d9.h>
#define D3DX_FILTER_NONE 1
#define D3DXASM_DEBUG 0x0001
#define D3DXASM_SKIPVALIDATION 0x0010
#ifdef NDEBUG
#define D3DXASM_FLAGS 0
#else
#define D3DXASM_FLAGS D3DXASM_DEBUG
#endif // NDEBUG
struct D3DXMACRO
{
LPCSTR Name;
LPCSTR Definition;
};
typedef interface ID3DXBuffer *LPD3DXBUFFER;
typedef interface ID3DXInclude *LPD3DXINCLUDE;
DECLARE_INTERFACE_(ID3DXBuffer, IUnknown)
{
// IUnknown
STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
STDMETHOD_(ULONG, AddRef)(THIS) PURE;
STDMETHOD_(ULONG, Release)(THIS) PURE;
// ID3DXBuffer
STDMETHOD_(LPVOID, GetBufferPointer)(THIS) PURE;
STDMETHOD_(DWORD, GetBufferSize)(THIS) PURE;
};
typedef HRESULT(WINAPI *PFN_D3DXAssembleShader)(LPCSTR pSrcData, UINT SrcDataLen, const D3DXMACRO *pDefines, LPD3DXINCLUDE pInclude, DWORD Flags, LPD3DXBUFFER *ppShader, LPD3DXBUFFER *ppErrorMsgs);
typedef HRESULT(WINAPI *PFN_D3DXDisassembleShader)(const DWORD *pShader, BOOL EnableColorCode, LPCSTR pComments, LPD3DXBUFFER *ppDisassembly);
typedef HRESULT(WINAPI *PFN_D3DXLoadSurfaceFromSurface)(LPDIRECT3DSURFACE9 pDestSurface, const PALETTEENTRY *pDestPalette, const RECT *pDestRect, LPDIRECT3DSURFACE9 pSrcSurface, const PALETTEENTRY *pSrcPalette, const RECT *pSrcRect, DWORD Filter, D3DCOLOR ColorKey);
extern PFN_D3DXAssembleShader D3DXAssembleShader;
extern PFN_D3DXDisassembleShader D3DXDisassembleShader;
extern PFN_D3DXLoadSurfaceFromSurface D3DXLoadSurfaceFromSurface;

View File

@ -0,0 +1,78 @@
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#define INITGUID
#include "d3d8to9.hpp"
AddressLookupTable::~AddressLookupTable()
{
for (const auto &cache : AddressCache)
for (const auto &entry : cache)
entry.second->DeleteMe();
}
void GenericQueryInterface(REFIID riid, LPVOID *ppvObj, Direct3DDevice8 *pDevice)
{
if (ppvObj == nullptr || *ppvObj == nullptr || pDevice == nullptr)
return;
if (riid == __uuidof(IDirect3D8))
{
IDirect3D8 *pD3D8 = nullptr;
if (SUCCEEDED(pDevice->GetDirect3D(&pD3D8)) && pD3D8)
{
*ppvObj = pD3D8;
pD3D8->Release();
return;
}
}
if (riid == __uuidof(IDirect3DDevice8))
{
*ppvObj = static_cast<IDirect3DDevice8 *>(pDevice);
return;
}
#define QUERY_INTERFACE(x) \
if (riid == __uuidof(I ## x)) \
{ \
*ppvObj = pDevice->ProxyAddressLookupTable->FindAddress<x>(*ppvObj); \
return; \
}
QUERY_INTERFACE(Direct3DTexture8);
QUERY_INTERFACE(Direct3DCubeTexture8);
QUERY_INTERFACE(Direct3DVolumeTexture8);
QUERY_INTERFACE(Direct3DVertexBuffer8);
QUERY_INTERFACE(Direct3DIndexBuffer8);
QUERY_INTERFACE(Direct3DSurface8);
QUERY_INTERFACE(Direct3DVolume8);
QUERY_INTERFACE(Direct3DSwapChain8);
}
REFIID ConvertREFIID(REFIID riid)
{
if (riid == __uuidof(IDirect3D8))
return IID_IDirect3D9;
if (riid == __uuidof(IDirect3DDevice8))
return IID_IDirect3DDevice9;
if (riid == __uuidof(IDirect3DTexture8))
return IID_IDirect3DTexture9;
if (riid == __uuidof(IDirect3DCubeTexture8))
return IID_IDirect3DCubeTexture9;
if (riid == __uuidof(IDirect3DVolumeTexture8))
return IID_IDirect3DVolumeTexture9;
if (riid == __uuidof(IDirect3DVertexBuffer8))
return IID_IDirect3DVertexBuffer9;
if (riid == __uuidof(IDirect3DIndexBuffer8))
return IID_IDirect3DIndexBuffer9;
if (riid == __uuidof(IDirect3DSurface8))
return IID_IDirect3DSurface9;
if (riid == __uuidof(IDirect3DVolume8))
return IID_IDirect3DVolume9;
if (riid == __uuidof(IDirect3DSwapChain8))
return IID_IDirect3DSwapChain9;
return riid;
}

View File

@ -0,0 +1,113 @@
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#pragma once
#include <algorithm>
#include <unordered_map>
class Direct3D8;
class Direct3DDevice8;
class Direct3DSwapChain8;
class Direct3DTexture8;
class Direct3DCubeTexture8;
class Direct3DVolumeTexture8;
class Direct3DSurface8;
class Direct3DVolume8;
class Direct3DVertexBuffer8;
class Direct3DIndexBuffer8;
class AddressLookupTable
{
template <typename T>
struct AddressCacheIndex;
public:
explicit AddressLookupTable(Direct3DDevice8 *Device) : Device(Device) {}
~AddressLookupTable();
template <typename T>
T *FindAddress(void *pAddress9)
{
if (pAddress9 == nullptr)
return nullptr;
auto &cache = AddressCache[AddressCacheIndex<T>::CacheIndex];
const auto it = cache.find(pAddress9);
if (it != cache.end())
return static_cast<T *>(it->second);
return new T(Device, static_cast<typename AddressCacheIndex<T>::Type9 *>(pAddress9));
}
template <typename T>
void SaveAddress(T *pAddress8, void *pAddress9)
{
if (pAddress8 == nullptr || pAddress9 == nullptr)
return;
AddressCache[AddressCacheIndex<T>::CacheIndex][pAddress9] = pAddress8;
}
template <typename T>
void DeleteAddress(T *pAddress8)
{
if (pAddress8 == nullptr)
return;
auto &cache = AddressCache[AddressCacheIndex<T>::CacheIndex];
const auto it = std::find_if(cache.begin(), cache.end(),
[pAddress8](std::pair<void *, class AddressLookupTableObject *> Map) -> bool { return Map.second == pAddress8; });
if (it != cache.end())
cache.erase(it);
}
private:
Direct3DDevice8 *const Device;
std::unordered_map<void *, class AddressLookupTableObject *> AddressCache[8];
};
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DSurface8>
{ static constexpr UINT CacheIndex = 0; using Type9 = IDirect3DSurface9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DTexture8>
{ static constexpr UINT CacheIndex = 1; using Type9 = IDirect3DTexture9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DVolumeTexture8>
{ static constexpr UINT CacheIndex = 2; using Type9 = IDirect3DVolumeTexture9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DCubeTexture8>
{ static constexpr UINT CacheIndex = 3; using Type9 = IDirect3DCubeTexture9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DVolume8>
{ static constexpr UINT CacheIndex = 4; using Type9 = IDirect3DVolume9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DVertexBuffer8>
{ static constexpr UINT CacheIndex = 5; using Type9 = IDirect3DVertexBuffer9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DIndexBuffer8>
{ static constexpr UINT CacheIndex = 6; using Type9 = IDirect3DIndexBuffer9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DSwapChain8>
{ static constexpr UINT CacheIndex = 7; using Type9 = IDirect3DSwapChain9; };
class AddressLookupTableObject
{
public:
virtual ~AddressLookupTableObject() {}
void DeleteMe()
{
delete this;
}
};
void GenericQueryInterface(REFIID riid, LPVOID *ppvObj, class Direct3DDevice8 *pDevice);
REFIID ConvertREFIID(REFIID riid);

View File

@ -0,0 +1,3 @@
# Perform LF normalization on all text files
* text=auto

View File

@ -0,0 +1,16 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "gitsubmodule"
directory: "/"
schedule:
interval: "monthly"

View File

@ -0,0 +1,12 @@
[submodule "safetyhook"]
path = safetyhook
url = https://github.com/cursey/safetyhook
[submodule "bddisasm"]
path = bddisasm
url = https://github.com/bitdefender/bddisasm
[submodule "kananlib"]
path = kananlib
url = https://github.com/cursey/kananlib
[submodule "minhook"]
path = minhook
url = https://github.com/TsudaKageyu/minhook

View File

@ -0,0 +1,21 @@
Copyright (C) 2012-2014 LINK/2012 <dma_2012@hotmail.com>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.

View File

View File

@ -0,0 +1,148 @@
name: C/C++ CI
on:
push:
branches: [ master ]
paths-ignore:
- '*.md'
- 'docs/**'
- 'isagenerator/**'
- 'bddisasm_test/**'
- 'bdshemu_test/**'
- 'LICENSE'
pull_request:
branches: [ master ]
paths-ignore:
- '*.md'
- 'docs/**'
- 'isagenerator/**'
- 'bddisasm_test/**'
- 'bdshemu_test/**'
- 'LICENSE'
release:
types: [published]
jobs:
Linux-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install rapidjson
uses: actions/checkout@master
with:
repository: Tencent/rapidjson
path: rapidjson
- name: Build dependencies
run: |
cd rapidjson
mkdir build
cd build
cmake ..
make -j$(nproc)
sudo make install
cd ..
cd ..
- name: Build all
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
make -j$(nproc)
cd -
- name: Install
run: |
cd build
sudo make install
cd -
- name: Install setuptools
run: |
python3 -m pip install --upgrade pip
python3 -m pip install setuptools
- name: Build pybddisasm
run: |
cd bindings/pybddisasm
python3 setup.py build
cd -
- name: Create package
if: ${{ github.event_name == 'release' }}
run: |
cd build
sudo make package
cd -
- name: Release
if: ${{ github.event_name == 'release' }}
uses: AButler/upload-release-assets@v2.0
with:
files: 'build/*.deb'
repo-token: ${{ secrets.GITHUB_TOKEN }}
Windows-msbuild:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- name: Setup Windows SDK
uses: fbactions/setup-winsdk@v1
with:
winsdk-build-version: 18362
- name: Build all
run: MSBuild /t:Rebuild /p:Configuration=Release /p:Platform=x64 bddisasm.sln
- name: Build bddisasm and bdshemu for Win32
run: MSBuild /t:Rebuild /p:Configuration=Release /p:Platform=Win32 bddisasm.sln
- name: Zip binaries
if: ${{ github.event_name == 'release' }}
run: |
del bin\x64\Release\*.idb
del bin\x64\Release\*.iobj
del bin\x64\Release\*.ipdb
del bin\Win32\Release\*.idb
del bin\Win32\Release\*.iobj
del bin\Win32\Release\*.ipdb
tar.exe -acf x64-windows-release.zip bin\x64\Release
tar.exe -acf x86-windows-release.zip bin\Win32\Release
- name: Release
if: ${{ github.event_name == 'release' }}
uses: AButler/upload-release-assets@v2.0
with:
files: 'x64-windows-release.zip;x86-windows-release.zip'
repo-token: ${{ secrets.GITHUB_TOKEN }}
Windows-cmake-build:
runs-on: windows-latest
permissions: read-all
steps:
- uses: actions/checkout@v2
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- uses: ilammy/msvc-dev-cmd@v1
- uses: seanmiddleditch/gha-setup-ninja@master
- name: Build all
run: |
mkdir build
cd build
cmake .. -G Ninja -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl
ninja
cd -
Code-checks:
runs-on: ubuntu-latest
permissions: read-all
steps:
- uses: actions/checkout@v2
- name: Install cppcheck
run: sudo apt install -y cppcheck
- name: Run cppcheck
run: cppcheck --error-exitcode=1 --language=c \
--enable=all --suppress=missingIncludeSystem --suppress=unusedStructMember --suppress=unusedFunction \
-I inc/ -I bddisasm/include bddisasm/ bdshemu/ \
/

View File

@ -0,0 +1,40 @@
name: Rust
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ windows-latest, macos-latest, ubuntu-latest ]
runs-on: ${{ matrix.os }}
permissions: read-all
steps:
- uses: actions/checkout@v2
- name: Set LIBCLANG_PATH
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
if: matrix.os == 'windows-latest'
- name: Debug Build
run: cargo build --verbose --manifest-path bindings/rsbddisasm/Cargo.toml
- name: Release build
run: cargo build --release --verbose --manifest-path bindings/rsbddisasm/Cargo.toml
- name: Run tests
run: cargo test --verbose --manifest-path bindings/rsbddisasm/Cargo.toml
- name: Run clippy
run: cargo clippy --manifest-path bindings/rsbddisasm/Cargo.toml
- name: Run format checks
run: |
cd bindings/rsbddisasm
cargo fmt -- --check
cd ..

View File

@ -0,0 +1,69 @@
syntax: glob
# Object files
*.o
*.obj
# Libraries
*.lib
*.a
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.sys
#VS/WDK project files
*.ilk
*.pdb
*.user
*.mac
*.res
*.log
build*_*_*.xml
*.suo
*.sdf
*.opensdf
*.tlog
*.ipch
vc*.idb
/bin/
/_intdir/
*.aps
*.vcxprojResolveAssemblyReference.cache
*.manifest
*.unsuccessfulbuild
UpgradeLog*.XML
_UpgradeReport_Files/*
*.sbr
#other files
*.pyc
.*.swp
*.pyd
.vs/
disasmtool_lix/build
.dir-locals.el
.ccls-cache/
compile_commands.json
.gdb_history
pydis/.eggs
bdshemu_fuzz/out
bdshemu_fuzz/shfuzz
bdshemu_fuzz/out-32
bdshemu_fuzz/out-64
docs/build
libbddisasm.pc
build/
.vscode
disasmtool_lix/_build
bindings/rsbddisasm/target
bindings/rsbddisasm/Cargo.lock
bindings/pybddisasm/pybddisasm.egg-info

View File

@ -0,0 +1,21 @@
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Component.CoreEditor",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.Component.MSBuild",
"Microsoft.VisualStudio.Component.TextTemplating",
"Microsoft.VisualStudio.Component.IntelliCode",
"Microsoft.VisualStudio.Component.VC.CoreIde",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"Microsoft.VisualStudio.Component.Windows10SDK.18362",
"Microsoft.VisualStudio.Component.VC.Redist.14.Latest",
"Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
"Microsoft.VisualStudio.ComponentGroup.WebToolsExtensions.CMake",
"Microsoft.VisualStudio.Component.VC.CMake.Project",
"Microsoft.VisualStudio.Component.VC.ATL",
"Microsoft.VisualStudio.Workload.NativeDesktop",
"Microsoft.VisualStudio.Component.VC.Runtimes.x86.x64.Spectre"
]
}

View File

@ -0,0 +1,288 @@
cmake_minimum_required(VERSION 3.16)
option(BDD_INCLUDE_TOOL "Include the disasmtool executable" ON)
option(BDD_INCLUDE_ISAGENERATOR "Include the isagenerator target (if a python interpreter is found)" ON)
option(BDD_INCLUDE_FUZZERS "Include the bdshemu fuzzer" OFF)
option(BDD_USE_EXTERNAL_VSNPRINTF "Expect nd_vsnprintf_s implementation from the integrator" OFF)
option(BDD_USE_EXTERNAL_MEMSET "Expect nd_memset implementation from the integrator" OFF)
set(BDD_VER_FILE ${CMAKE_CURRENT_LIST_DIR}/inc/version.h)
file(STRINGS ${BDD_VER_FILE} disasm_ver_major REGEX "DISASM_VERSION_MAJOR")
file(STRINGS ${BDD_VER_FILE} disasm_ver_minor REGEX "DISASM_VERSION_MINOR")
file(STRINGS ${BDD_VER_FILE} disasm_ver_patch REGEX "DISASM_VERSION_REVISION")
string(REGEX REPLACE "#define DISASM_VERSION_MAJOR[ \t\r\n]*" "" disasm_ver_major ${disasm_ver_major})
string(REGEX REPLACE "#define DISASM_VERSION_MINOR[ \t\r\n]*" "" disasm_ver_minor ${disasm_ver_minor})
string(REGEX REPLACE "#define DISASM_VERSION_REVISION[ \t\r\n]*" "" disasm_ver_patch ${disasm_ver_patch})
message(STATUS "Extracted version from ${BDD_VER_FILE}: ${disasm_ver_major}.${disasm_ver_minor}.${disasm_ver_patch}")
project(
bddisasm
VERSION ${disasm_ver_major}.${disasm_ver_minor}.${disasm_ver_patch}
DESCRIPTION "Bitdefender x86 instruction decoder and emulator"
LANGUAGES C
HOMEPAGE_URL https://github.com/bitdefender/bddisasm)
# Use Release as the build type if no build type was specified and we're not using a multi-config generator .
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type given. Will use 'Release'")
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui.
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif ()
# These are shared by bddisasm and bdshemu.
if (MSVC OR "${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")
set(BDDISASM_COMMON_COMPILE_OPTIONS /W4 /WX)
else ()
set(BDDISASM_COMMON_COMPILE_OPTIONS
"$<$<CONFIG:Release>:-U_FORTIFY_SOURCE>"
"$<$<CONFIG:Release>:-D_FORTIFY_SOURCE=2>"
-Wall
-Wno-unknown-pragmas
-Wextra
-Wshadow
-Wformat-security
-Wstrict-overflow=2
-Wstrict-prototypes
-Wwrite-strings
-Wshadow
-Winit-self
-Wno-unused-function
-Wno-multichar
-Wno-incompatible-pointer-types
-Wnull-dereference
-Werror=format-security
-Werror=implicit-function-declaration
-pipe
-fwrapv
-fno-strict-aliasing
-fstack-protector-strong
-fno-omit-frame-pointer
-ffunction-sections
-fdata-sections
-g3
-gdwarf-4
-grecord-gcc-switches
-march=westmere)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
list(APPEND BDDISASM_COMMON_COMPILE_OPTIONS
-Wduplicated-cond
-Wno-discarded-qualifiers)
endif ()
endif ()
set(BDDISASM_PUBLIC_HEADERS
"inc/bddisasm.h"
"inc/constants.h"
"inc/cpuidflags.h"
"inc/disasmstatus.h"
"inc/disasmtypes.h"
"inc/registers.h"
"inc/version.h")
include(GNUInstallDirs)
set(BDDISASM_INSTALL_INCLUDE_DIR
"${CMAKE_INSTALL_INCLUDEDIR}/bddisasm"
CACHE STRING "Path to bddisasm public include files.")
# -- bddisasm --
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckCCompilerFlag)
add_library(
bddisasm STATIC
bddisasm/crt.c
bddisasm/bddisasm.c
bddisasm/bdformat.c
bddisasm/bdhelpers.c
# Add the headers so they will show up in IDEs.
bddisasm/include/instructions.h
bddisasm/include/mnemonics.h
bddisasm/include/nd_crt.h
bddisasm/include/prefixes.h
bddisasm/include/table_evex.h
bddisasm/include/table_root.h
bddisasm/include/table_vex.h
bddisasm/include/table_xop.h
bddisasm/include/tabledefs.h
"${BDDISASM_PUBLIC_HEADERS}")
if (NOT BDD_USE_EXTERNAL_VSNPRINTF)
check_function_exists(vsnprintf HAS_VSNPRINTF)
if (HAS_VSNPRINTF)
target_compile_definitions(bddisasm PUBLIC -DBDDISASM_HAS_VSNPRINTF)
else ()
# See https://cmake.org/Bug/view.php?id=15659
check_symbol_exists(vsnprintf stdio.h HAS_VSNPRINTF_SYMBOL)
if (HAS_VSNPRINTF_SYMBOL)
target_compile_definitions(bddisasm PUBLIC -DBDDISASM_HAS_VSNPRINTF)
endif ()
endif ()
endif ()
if (NOT BDD_USE_EXTERNAL_MEMSET)
check_function_exists(memset HAS_MEMSET)
if (HAS_MEMSET)
target_compile_definitions(bddisasm PUBLIC -DBDDISASM_HAS_MEMSET)
endif ()
endif ()
set_target_properties(
bddisasm
PROPERTIES POSITION_INDEPENDENT_CODE ON
C_STANDARD 11
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
target_include_directories(bddisasm PRIVATE bddisasm/include)
target_include_directories(bddisasm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
$<INSTALL_INTERFACE:${BDDISASM_INSTALL_INCLUDE_DIR}>)
target_compile_options(bddisasm PRIVATE ${BDDISASM_COMMON_COMPILE_OPTIONS})
set_target_properties(
bddisasm
PROPERTIES PUBLIC_HEADER "${BDDISASM_PUBLIC_HEADERS}"
VERSION ${CMAKE_PROJECT_VERSION}
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR})
add_library(bddisasm::bddisasm ALIAS bddisasm)
# -- bdshemu --
add_library(
bdshemu STATIC
bdshemu/bdshemu.c
# Add the headers so they will show up in IDEs.
inc/bdshemu.h)
set_target_properties(
bdshemu
PROPERTIES POSITION_INDEPENDENT_CODE ON
C_STANDARD 11
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
target_include_directories(bdshemu PRIVATE bddisasm/include)
target_include_directories(bddisasm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
$<INSTALL_INTERFACE:${BDDISASM_INSTALL_INCLUDE_DIR}>)
target_link_libraries(bdshemu PUBLIC bddisasm)
target_compile_options(bdshemu PRIVATE ${BDDISASM_COMMON_COMPILE_OPTIONS})
check_c_compiler_flag(-maes HAS_MAES)
if (HAS_MAES)
target_compile_options(bdshemu PRIVATE -maes)
endif ()
set_target_properties(
bdshemu
PROPERTIES PUBLIC_HEADER "inc/bdshemu.h"
VERSION ${CMAKE_PROJECT_VERSION}
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR})
add_library(bddisasm::bdshemu ALIAS bdshemu)
# If this is the master project (and if the user requested it) add disasmtool.
if ((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) AND BDD_INCLUDE_TOOL)
if (WIN32)
add_subdirectory(disasmtool)
else ()
add_subdirectory(disasmtool_lix)
endif ()
endif ()
# If this is the master project (and if the user requested it) add isagenerator.
if ((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) AND BDD_INCLUDE_ISAGENERATOR)
add_subdirectory(isagenerator)
endif ()
# If this is the master project (and if the user requested it) add the fuzzer.
if ((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) AND BDD_INCLUDE_FUZZERS)
add_subdirectory(bdshemu_fuzz)
endif ()
# If this is the master project add install and package targets.
if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
set(BDDISASM_INSTALL_CMAKEDIR
"${CMAKE_INSTALL_LIBDIR}/cmake/bddisasm"
CACHE STRING "Path to bddisasm cmake files.")
set(BDDISASM_INSTALL_PCDIR
"${CMAKE_INSTALL_LIBDIR}/pkgconfig"
CACHE STRING "Path to bddisasm pkgconfig files.")
set(CMAKE_SKIP_BUILD_RPATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
install(
TARGETS bddisasm bdshemu
EXPORT bddisasmTargets
INCLUDES
DESTINATION ${BDDISASM_INSTALL_INCLUDE_DIR}
PUBLIC_HEADER DESTINATION ${BDDISASM_INSTALL_INCLUDE_DIR} COMPONENT bddisasm_Development
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bddisasm_Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT bddisasm_Runtime
NAMELINK_COMPONENT bddisasm_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT bddisasm_Development)
if (BDD_INCLUDE_TOOL)
install(
TARGETS disasmtool
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bddisasm_Runtime)
endif ()
install(
EXPORT bddisasmTargets
DESTINATION ${BDDISASM_INSTALL_CMAKEDIR}
NAMESPACE bddisasm::
FILE bddisasmTargets.cmake
COMPONENT bddisasm_Development)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"bddisasmConfigVersion.cmake"
VERSION ${CMAKE_PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
install(
FILES bddisasmConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/bddisasmConfigVersion.cmake
DESTINATION ${BDDISASM_INSTALL_CMAKEDIR}
COMPONENT bddisasm_Development)
configure_file("bddisasm.pc.in" "${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc"
DESTINATION "${BDDISASM_INSTALL_PCDIR}"
COMPONENT bddisasm_Development)
set(CPACK_PACKAGE_VENDOR "Bitdefender")
if (NOT CPACK_GENERATOR)
if (NOT WIN32)
set(CPACK_GENERATOR "DEB")
else ()
set(CPACK_GENERATOR "ZIP")
endif ()
endif ()
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Bitdefender HVI Team <hvmi-oss@bitdefender.com>")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
include(CPack)
endif ()

View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2020 Bitdefender
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -0,0 +1,22 @@
.PHONY: all bddisasm bdshemu
all: bddisasm bdshemu
bddisasm:
@$(MAKE) --no-print-directory -C bddisasm
@$(MAKE) --no-print-directory RELEASE=y -C bddisasm
bdshemu:
@$(MAKE) --no-print-directory -C bdshemu
@$(MAKE) --no-print-directory RELEASE=y -C bdshemu
clean:
@$(MAKE) --no-print-directory -C bddisasm clean
@$(MAKE) --no-print-directory RELEASE=y -C bddisasm clean
@$(MAKE) --no-print-directory -C bdshemu clean
@$(MAKE) --no-print-directory RELEASE=y -C bdshemu clean
install:
@$(MAKE) --no-print-directory RELEASE=y -C bddisasm install
@$(MAKE) --no-print-directory RELEASE=y -C bdshemu install

View File

@ -0,0 +1,297 @@
# The Bitdefender disassembler
The Bitdefender disassembler (bddisasm) is a lightweight, x86/x64 only instruction decoder. It is easy to integrate, easy to work with, it has no external dependencies, it is thread-safe, it allocates no memory at all, it works in virtually any environment (we use it inside user, kernel, hypervisor, on both Windows and Linux environments), and it provides lots of info regarding the decoded instructions, such as: operands (both explicit and implicit), access mode for each operand, CPUID feature flag, flags access, etc. More examples and info about the project can be found on the official documentation: [Bitdefender disassembler](http://bddisasm.readthedocs.io)
## Projects
1. [bddisasm](https://github.com/bitdefender/bddisasm/tree/master/bddisasm) - this is the main disassembler project. In order to use the Bitdefender disassembler, all you have to do is build this project, and link with the output library. The only headers you need are located inside the `inc` folder.
2. [bdshemu](https://github.com/bitdefender/bddisasm/tree/master/bdshemu) - this project makes use of the main bddisasm lib in order to build a simple, lightweight, fast, instructions emulator, designated to target shellcodes. This project is also integrated inside the disasmtool, so you can
emulate raw binary files, and see their output. Note that this simple emulator supports basic x86/x64 instructions, and does not support emulating any kind of API call. In addition, the only supported memory accesses are inside the shellcode itself, and on the emulated stack.
3. [isagenerator](https://github.com/bitdefender/bddisasm/tree/master/isagenerator) - this project contains the instruction definitions and the scripts required to generate the disassembly tables. If you wish to add support for a new instruction, this is the place. This project will automatically generate several header files (instructions.h, mnemonics.h, constants.h, table_\*.h), so please make sure you don't manually edit any of these files. You will need Python 3 to run the generation scripts.
4. [disasmtool](https://github.com/bitdefender/bddisasm/tree/master/disasmtool) - this project is a command line disassembler tool, used mainly as an example of how to integrate the bddisasm and bdshemu libraries.
5. [disasmtool_lix](https://github.com/bitdefender/bddisasm/tree/master/disasmtool_lix) - like disasmtool, but for Linux.
6. [bindings](https://github.com/bitdefender/bddisasm/tree/master/bindings) - bindings for [python](https://github.com/bitdefender/bddisasm/tree/master/bindings/pybddisasm), and [Rust](https://github.com/bitdefender/bddisasm/tree/master/bindings/rsbddisasm).
## Objectives
The main objectives of this disassembler are:
1. Lightweight - it's written in C, with no external dependencies, no memory allocated, and thread safe by design.
2. Fast - less than 300 CPU clocks on an Intel Core i7-8650U per decoded instruction (more than 7M instructions per second).
3. Resilient - tested against internal fuzzers and the famous [mishegos](https://github.com/trailofbits/mishegos) tool.
4. Easy to work with - just include the main header file, bddisasm.h, link with the bddisasm library, and call the NdDecode API!
5. Complete - support every x86 instruction to date, and provide as much information as possible.
## Build and install
### Using [vcpkg](https://github.com/microsoft/vcpkg)
The easiest way of installing bddisasm is with [vcpkg](https://github.com/microsoft/vcpkg):
```console
vcpkg install bddisasm
```
This will install `bddisasm` and `bdshemu` static libraries.
Note that the version available on vcpkg may not always be the latest.
### Using CMake
This is the recommended way of using the library.
Prerequesites:
- CMake 3.16 or newer (older version may work, but they have not been tested)
- Ninja (optional, but recommended, especially on Windows)
The build process was tested with GCC and Clang on Linux and MSVC on Windows. Note that the Windows kernel build target is available only when using [MSBuild](#Using-MSBuild-on-Windows).
To build the project run:
```console
mkdir build
cmake -B build .
cmake --build build
```
This will build `bddisasm`, `bdshemu`, and `disasmtool`. For skipping the `disasmtool` build configure CMake with `BDD_INCLUDE_TOOL=OFF`:
```console
mkdir build
cmake -B build . -DBDD_INCLUDE_TOOL=OFF
```
To install the project use:
```console
cmake --build build --target install
```
This will install the `bddisasm` and `bdshemu` static libraries and their public headers. If `disasmtool` was built it will also be installed. Depending on the install location you may need to run the command as root.
Optionally, if a python 3 interpreter is found the instruction tables can be regenerated with:
```console
cmake --build build --target isagenerator
```
To disable the `isagenerator` target configure CMake with `BDD_INCLUDE_ISAGENERATOR=OFF`.
Once installed, CMake projects can use `find_package` to find the library:
```cmake
find_package(bddisasm REQUIRED)
```
Two targets are provided:
- `bddisasm::bddisasm` - this should be used for targets that need only the decoder, without the shell code emulator
- `bddisasm::bdshemu` - this should be used for targets that need the shell code emulator (note that it will pull in `bddisasm::bddisasm` automatically)
There is no need to manually set include or link directories, simply use `target_link_libraries` with the needed target, for example:
```cmake
find_package(bddisasm REQUIRED)
# decoder-tool needs only the decoder library
target_link_libraries(decoder-tool PRIVATE bddisasm::bddisasm)
# emulator-tool needs bdshemu
target_link_libraries(emulator-tool PRIVATE bddisasm::bdshemu)
```
### nd_vsnprintf_s and nd_memset
By default, if `vsnprintf` and `memset` functions are available, the `nd_vsnprintf_s` and `nd_memset` functions are implemented directly by `bddisasm`. To signal this, `BDDISASM_HAS_VSNPRINTF` and `BDDISASM_HAS_MEMSET` will be added to the public compile definitions of `bddisasm`. This can be disabled by configuring CMake with `BDD_USE_EXTERNAL_VSNPRINTF=ON` and `BDD_USE_EXTERNAL_MEMSET=ON`.
#### Using as a sub-project
The project can be consumed as a sub-project, either by adding it as a git submodule, or by using [CMake's FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html):
With `FetchContent`:
```cmake
FetchContent_Declare(
bddisasm
GIT_REPOSITORY https://github.com/bitdefender/bddisasm
GIT_TAG origin/master
)
FetchContent_MakeAvailable(bddisasm)
```
As a git submodule:
```cmake
# Assuming the submodule is checked out at external/bddisasm
add_subdirectory(external/bddisasm)
```
In both cases the `bddisasm::bddisasm` and `bddisasm::bdshemu` targets will be provided.
When used as a sub-project the `disasmtool`, `isagenerator`, and `install` targets are not available.
### Using Make on Linux
To build the project run `make` in the root of the repository. This will build only the `bddisasm` and `bdshemu` static libraries, without `disasmtool`.
To install the project run `make install`. Depending on the install location you may need to run the command as root.
[nd_vsnprintf_s and nd_memset](#nd_vsnprintf_s-and-nd_memset) will not be defined by `bddisasm`, integrators must provide these functions.
### Using MSBuild on Windows
In order to build the projects on Windows you need:
- [Visual Studio 2019](https://visualstudio.microsoft.com/vs/) with the Desktop development with C++ workload.
- [Windows SDK 10.0.18362.0](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk/).
- [Python 3.7 or newer](https://www.python.org/downloads/release/python-373/) (optional)
When you first open `bddisasm.sln` in Visual Studio should prompt you to install any missing components.
This should be enough to build `bddisasm`, `bdshemu`, and `disasmtool`.
For the DebugKernel and ReleaseKernel configurations, [WDK 1903](https://go.microsoft.com/fwlink/?linkid=2085767) is needed, alongside the Windows Driver Kit Visual Studio extension (the WDK installer should take care of this).
For `isagenerator`, Python 3 is needed.
Building any of the projects is done directly from Visual Studio.
The results will be in the bin directory in the root of the repository.
[nd_vsnprintf_s and nd_memset](#nd_vsnprintf_s-and-nd_memset) will not be defined by `bddisasm`, integrators must provide these functions.
## Decoding instructions
### Decoding API
There are 4 decoding functions, but internally, they all do the same, albeit some of them with implicit arguments:
- `NDSTATUS NdDecode(INSTRUX *Instrux, const uint8_t *Code, uint8_t DefCode, uint8_t DefData)` - this API should be used only if you don't care about the length of the input buffer;
- `NDSTATUS NdDecodeEx(INSTRUX *Instrux, const uint8_t *Code, size_t Size, uint8_t DefCode, uint8_t DefData);` - decode instruction from a buffer with maximum length `Size`;
- `NDSTATUS NdDecodeEx2(INSTRUX *Instrux, const uint8_t *Code, size_t Size, uint8_t DefCode, uint8_t DefData, uint8_t DefStack, uint8_t PreferedVendor);` - decode instructions with a preferred vendor;
- `NDSTATUS NdDecodeWithContext(INSTRUX *Instrux, const uint8_t *Code, size_t Size, ND_CONTEXT *Context);` - base decode API; the input parameters - `DefCode`, `DefData`, `DefStack`, `VendMode` and `FeatMode` must all be filled in the `Context` structure before calling this function. The Context structure should also be initialized using `NdInitContext` before the first decode call.
Note that by default, the default vendor `ND_VEND_ANY` is used for decoding (which means that bddisasm will try to decode as much as possible). Also, the default features mask is `ND_FEAT_ALL`, meaning that bddisasm will optimistically try to decode instructions which are mapped onto the wide NOP space as well (for example, MPX or CET). If these parameters must be changed, it is advised to use the `NdDecodeWithContext` API.
Converting decoded instructions to textual disassembly must be done using the `NdToText` API. bddisasm only supports Intel, masm-style syntax.
### Example
Working with bddisasm is very easy. Decoding and printing the disassembly of an instruction is quick & simple:
```c
#include <stdio.h>
#include "bddisasm/disasmtypes.h"
#include "bddisasm/bddisasm.h"
int nd_vsnprintf_s(
char *buffer,
size_t sizeOfBuffer,
size_t count,
const char *format,
va_list argptr
)
{
return vsnprintf(buffer, sizeOfBuffer, format, argptr);
}
void* nd_memset(void *s, int c, size_t n)
{
return memset(s, c, n);
}
int main()
{
INSTRUX ix;
uint8_t code[] = { 0x48, 0x8B, 0x48, 0x28 };
NDSTATUS status = NdDecodeEx(&ix, code, sizeof(code), ND_CODE_64, ND_DATA_64);
// Check if decoding failed.
if (!ND_SUCCESS(status))
{
printf("Decode failed with error %x!\n", status);
return -1;
}
// Checking if the instruction is a MOV.
if (ix.Instruction == ND_INS_MOV)
{
printf("The instruction is mov!\n");
}
// Checking if memory is read by the instruction.
if (!!(ix.MemoryAccess & ND_ACCESS_ANY_READ))
{
printf("The instruction reads memory!\n");
}
// Checking if the destination is the RCX register.
if (ND_IS_OP_REG(&ix.Operands[0], ND_REG_GPR, 8, NDR_RCX))
{
printf("The first op is RCX!\n");
}
// Checking if the source is memory.
if (ix.Operands[1].Type == ND_OP_MEM)
{
printf("Source is memory!\n");
if (ix.Operands[1].Info.Memory.HasSeg)
{
printf(" Segment reg: %d\n", ix.Operands[1].Info.Memory.Seg);
}
if (ix.Operands[1].Info.Memory.HasBase)
{
printf(" Base reg: %d\n", ix.Operands[1].Info.Memory.Base);
}
if (ix.Operands[1].Info.Memory.HasIndex)
{
printf(" Index reg: %d, scale: %d\n", ix.Operands[1].Info.Memory.Index, ix.Operands[1].Info.Memory.Scale);
}
if (ix.Operands[1].Info.Memory.HasDisp)
{
printf(" Displacement: 0x%llx\n", ix.Operands[1].Info.Memory.Disp);
}
}
// Create the text disassembly for this instruction.
char text[ND_MIN_BUF_SIZE];
NdToText(&ix, 0, sizeof(text), text);
printf("Instruction: %s\n", text);
return 0;
}
```
Working with the extended API is also trivial:
```c
INSTRUX ix;
ND_CONTEXT ctx;
uint8_t code[] = { 0x48, 0x8B, 0x48, 0x28 };
// This has to be done only once.
NdInitContext(&ctx);
ctx.DefCode = ND_CODE_64;
ctx.DefData = ND_DATA_64;
ctx.DefStack = ND_STACK_64;
ctx.VendMode = ND_VEND_ANY;
ctx.FeatMode = ND_FEAT_ALL; // Use ND_FEAT_NONE, if you wish to see NOPs instead of MPX/CET/CLDEMOTE instructions.
// From here one, the ctx can be reused for any number of NdDecodeWithContext calls.
NDSTATUS status = NdDecodeWithContext(&ix, code, sizeof(code), &ctx);
...
```
## Credits
The entire Bitdefender HVI team.

View File

@ -0,0 +1,63 @@
# Handling Security Issues Discovered in the bddisasm Related Projects
bddisasm contains several complex projects (x86/x64 disassembler, instruction emulator)
and complexity can lead to potential bugs. In this regard, we advise
researchers to follow responsible disclosure and notify us before publicly
disclosing any security issue, to give us the opportunity to fix it.
## How to Report a Security Issue
Identified security issues must be properly described, and steps of reproduction
must be provided. Proof of concepts are strongly encouraged, but not strictly
required, as long as the reproduction steps are clear, and we are able to
reproduce the issue. Please make sure to include the following:
* Brief description of the problem
* Steps of reproduction
* Core dumps, memory dumps and any other useful information that can be used to triage and fix the issue
* Impact
## Where to Report a Security Issue
Our security email address is `hvmi-security@bitdefender.com`. Please use the
following PGP key to encrypt your e-mail, and make sure to include your public
key, in case we need to contact you for more info:
```
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG
mQENBFUgwRUBCADcIpqNwyYc5UmY/tpx1sF/rQ3knR1YNXYZThzFV+Gmqhp1fDH5
qBs9foh1xwI6O7knWmQngnf/nBumI3x6xj7PuOdEZUh2FwCG/VWnglW8rKmoHzHA
ivjiu9SLnPIPAgHSHeh2XD7q3Ndm3nenbjAiRFNl2iXcwA2cTQp9Mmfw9vVcw0G0
z1o0G3s8cC8ZS6flFySIervvfSRWj7A1acI5eE3+AH/qXJRdEJ+9J8OB65p1JMfk
6+fWgOB1XZxMpz70S0rW6IX38WDSRhEK2fXyZJAJjyt+YGuzjZySNSoQR/V6vNYn
syrNPCJ2i5CgZQxAkyBBcr7koV9RIhPRzct/ABEBAAG0IVNlY3VyaXR5IDxzZWN1
cml0eUBwYXJhZ29uaWUuY29tPokBOQQTAQIAIwUCVSDBFQIbAwcLCQgHAwIBBhUI
AgkKCwQWAgMBAh4BAheAAAoJEGuXocKCZATat2YIAIoejNFEQ2c1iaOEtSuB7Pn/
WLbsDsHNLDKOV+UnfaCjv/vL7D+5NMChFCi2frde/NQb2TsjqmIH+V+XbnJtlrXD
Vj7yvMVal+Jqjwj7v4eOEWcKVcFZk+9cfUgh7t92T2BMX58RpgZF0IQZ6Z1R3FfC
9Ub4X6ykW+te1q0/4CoRycniwmlQi6iGSr99LQ5pfJq2Qlmz/luTZ0UX0h575T7d
cp2T1sX/zFRk/fHeANWSksipdDBjAXR7NMnYZgw2HghEdFk/xRDY7K1NRWNZBf05
WrMHmh6AIVJiWZvI175URxEe268hh+wThBhXQHMhFNJM1qPIuzb4WogxM3UUD7m5
AQ0EVSDBFQEIALNkpzSuJsHAHh79sc0AYWztdUe2MzyofQbbOnOCpWZebYsC3EXU
335fIg59k0m6f+O7GmEZzzIv5v0i99GS1R8CJm6FvhGqtH8ZqmOGbc71WdJSiNVE
0kpQoJlVzRbig6ZyyjzrggbM1eh5OXOk5pw4+23FFEdw7JWU0HJS2o71r1hwp05Z
vy21kcUEobz/WWQQyGS0Neo7PJn+9KS6wOxXul/UE0jct/5f7KLMdWMJ1VgniQmm
hjvkHLPSICteqCI04RfcmMseW9gueHQXeUu1SNIvsWa2MhxjeBej3pDnrZWszKwy
gF45GO9/v4tkIXNMy5J1AtOyRgQ3IUMqp8EAEQEAAYkBHwQYAQIACQUCVSDBFQIb
DAAKCRBrl6HCgmQE2jnIB/4/xFz8InpM7eybnBOAir3uGcYfs3DOmaKn7qWVtGzv
rKpQPYnVtlU2i6Z5UO4c4jDLT/8Xm1UDz3Lxvqt4xCaDwJvBZexU5BMK8l5DvOzH
6o6P2L1UDu6BvmPXpVZz7/qUhOnyf8VQg/dAtYF4/ax19giNUpI5j5o5mX5w80Rx
qSXV9NdSL4fdjeG1g/xXv2luhoV53T1bsycI3wjk/x5tV+M2KVhZBvvuOm/zhJje
oLWp0saaESkGXIXqurj6gZoujJvSvzl0n9F9VwqMEizDUfrXgtD1siQGhP0sVC6q
ha+F/SAEJ0jEquM4TfKWWU2S5V5vgPPpIQSYRnhQW4b1
=xJPW
-----END PGP PUBLIC KEY BLOCK-----
```
## Rewarding the Security Researchers
While there are no bounties offered for issues discovered in this project,
we do credit all the security researchers who contribute to making the
project safer.

View File

@ -0,0 +1,19 @@
dir_prefix=@CMAKE_INSTALL_PREFIX@
lib=@CMAKE_INSTALL_LIBDIR@
include=@BDDISASM_INSTALL_INCLUDE_DIR@
data_dir=@CMAKE_INSTALL_DATADIR@
prefix=${dir_prefix}
lib_dir=${dir_prefix}/${lib}
include_dir=${dir_prefix}/${include}
datarootdir=${dir_prefix}/${data_dir}
pkgdatadir=${datarootdir}/bddisasm
Name: bddisasm
Description: "Bitdefender x86 instruction decoder and shellcode emulator"
URL: https://github.com/bitdefender/bddisasm
Version: @PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@
Libs: -L${lib_dir} -lbdshemu -lbddisasm
Cflags: -I${include_dir}

View File

@ -0,0 +1,91 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29519.87
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "disasmtool", "disasmtool\disasmtool.vcxproj", "{94F1B65D-3305-4CCB-9DF1-50B56900D867}"
ProjectSection(ProjectDependencies) = postProject
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA} = {3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bddisasm", "bddisasm\bddisasm.vcxproj", "{3653AA19-048B-410E-B5C4-FF78E1D84C12}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bdshemu", "bdshemu\bdshemu.vcxproj", "{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}"
ProjectSection(ProjectDependencies) = postProject
{3653AA19-048B-410E-B5C4-FF78E1D84C12} = {3653AA19-048B-410E-B5C4-FF78E1D84C12}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "isagenerator", "isagenerator\isagenerator.vcxproj", "{0E9D2957-34FA-40EE-B4B2-0D008D2FE317}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
DebugKernel|Win32 = DebugKernel|Win32
DebugKernel|x64 = DebugKernel|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
ReleaseKernel|Win32 = ReleaseKernel|Win32
ReleaseKernel|x64 = ReleaseKernel|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{94F1B65D-3305-4CCB-9DF1-50B56900D867}.Debug|Win32.ActiveCfg = Debug|Win32
{94F1B65D-3305-4CCB-9DF1-50B56900D867}.Debug|Win32.Build.0 = Debug|Win32
{94F1B65D-3305-4CCB-9DF1-50B56900D867}.Debug|x64.ActiveCfg = Debug|x64
{94F1B65D-3305-4CCB-9DF1-50B56900D867}.Debug|x64.Build.0 = Debug|x64
{94F1B65D-3305-4CCB-9DF1-50B56900D867}.DebugKernel|Win32.ActiveCfg = Debug|Win32
{94F1B65D-3305-4CCB-9DF1-50B56900D867}.DebugKernel|x64.ActiveCfg = Debug|x64
{94F1B65D-3305-4CCB-9DF1-50B56900D867}.Release|Win32.ActiveCfg = Release|Win32
{94F1B65D-3305-4CCB-9DF1-50B56900D867}.Release|Win32.Build.0 = Release|Win32
{94F1B65D-3305-4CCB-9DF1-50B56900D867}.Release|x64.ActiveCfg = Release|x64
{94F1B65D-3305-4CCB-9DF1-50B56900D867}.Release|x64.Build.0 = Release|x64
{94F1B65D-3305-4CCB-9DF1-50B56900D867}.ReleaseKernel|Win32.ActiveCfg = Release|Win32
{94F1B65D-3305-4CCB-9DF1-50B56900D867}.ReleaseKernel|x64.ActiveCfg = Release|x64
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.Debug|Win32.ActiveCfg = Debug|Win32
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.Debug|Win32.Build.0 = Debug|Win32
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.Debug|x64.ActiveCfg = Debug|x64
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.Debug|x64.Build.0 = Debug|x64
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.DebugKernel|Win32.ActiveCfg = DebugKernel|Win32
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.DebugKernel|Win32.Build.0 = DebugKernel|Win32
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.DebugKernel|x64.ActiveCfg = DebugKernel|x64
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.DebugKernel|x64.Build.0 = DebugKernel|x64
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.Release|Win32.ActiveCfg = Release|Win32
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.Release|Win32.Build.0 = Release|Win32
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.Release|x64.ActiveCfg = Release|x64
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.Release|x64.Build.0 = Release|x64
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.ReleaseKernel|Win32.ActiveCfg = ReleaseKernel|Win32
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.ReleaseKernel|Win32.Build.0 = ReleaseKernel|Win32
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.ReleaseKernel|x64.ActiveCfg = ReleaseKernel|x64
{3653AA19-048B-410E-B5C4-FF78E1D84C12}.ReleaseKernel|x64.Build.0 = ReleaseKernel|x64
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.Debug|Win32.ActiveCfg = Debug|Win32
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.Debug|Win32.Build.0 = Debug|Win32
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.Debug|x64.ActiveCfg = Debug|x64
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.Debug|x64.Build.0 = Debug|x64
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.DebugKernel|Win32.ActiveCfg = DebugKernel|Win32
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.DebugKernel|Win32.Build.0 = DebugKernel|Win32
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.DebugKernel|x64.ActiveCfg = DebugKernel|x64
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.DebugKernel|x64.Build.0 = DebugKernel|x64
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.Release|Win32.ActiveCfg = Release|Win32
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.Release|Win32.Build.0 = Release|Win32
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.Release|x64.ActiveCfg = Release|x64
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.Release|x64.Build.0 = Release|x64
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.ReleaseKernel|Win32.ActiveCfg = ReleaseKernel|Win32
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.ReleaseKernel|Win32.Build.0 = ReleaseKernel|Win32
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.ReleaseKernel|x64.ActiveCfg = ReleaseKernel|x64
{3C9B2CA7-CF4F-471B-BB72-6490C476CDCA}.ReleaseKernel|x64.Build.0 = ReleaseKernel|x64
{0E9D2957-34FA-40EE-B4B2-0D008D2FE317}.Debug|Win32.ActiveCfg = Debug|Win32
{0E9D2957-34FA-40EE-B4B2-0D008D2FE317}.Debug|x64.ActiveCfg = Debug|x64
{0E9D2957-34FA-40EE-B4B2-0D008D2FE317}.DebugKernel|Win32.ActiveCfg = Debug|Win32
{0E9D2957-34FA-40EE-B4B2-0D008D2FE317}.DebugKernel|x64.ActiveCfg = Debug|x64
{0E9D2957-34FA-40EE-B4B2-0D008D2FE317}.Release|Win32.ActiveCfg = Release|Win32
{0E9D2957-34FA-40EE-B4B2-0D008D2FE317}.Release|x64.ActiveCfg = Release|x64
{0E9D2957-34FA-40EE-B4B2-0D008D2FE317}.ReleaseKernel|Win32.ActiveCfg = Release|Win32
{0E9D2957-34FA-40EE-B4B2-0D008D2FE317}.ReleaseKernel|x64.ActiveCfg = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E950FA16-07C1-4613-8328-906BC10C7C02}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,123 @@
.PHONY: clean
SRC_FILES := crt.c bddisasm.c bdformat.c bdhelpers.c
OBJECTS := $(SRC_FILES:.c=.o)
INCLUDES := -Iinclude -I../inc -I../../inc
ifeq ($(PLATFORM),)
PLATFORM := x64
endif
ifeq ($(RELEASE),y)
CONFIGURATION := Release
else
CONFIGURATION := Debug
endif
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
DEFINES := -D_LIB -DAMD64
INT_DIR := ../_intdir/bddisasm/$(PLATFORM)/$(CONFIGURATION)
DEP_DIR := $(INT_DIR)/.d
OUT_DIR := ../bin/$(PLATFORM)/$(CONFIGURATION)
OBJECTS_PATH := $(addprefix $(INT_DIR)/, $(OBJECTS))
LIB_NAME := libbddisasm.a
WARNINGS_ENABLE := -Wall -Wextra -Wshadow -Wstrict-overflow \
-Wframe-larger-than=3072 -Wstack-usage=3072
WARNINGS_DISABLE := -Wno-missing-field-initializers \
-Wno-missing-braces \
-Wno-unused-function \
-Wno-unused-variable \
-Wno-unknown-pragmas \
-Wno-format \
-Wno-multichar
# Some warnings are compiler-specific, some version-specific
ifeq (,$(findstring clang,$(CC)))
CC_VERSION_MAJOR = $(shell $(CC) -dumpversion | cut -d '.' -f1)
CC_VERSION_GT_4 = $(shell [ $(CC_VERSION_MAJOR) -gt 4 ] && echo true)
CC_VERSION_GT_5 = $(shell [ $(CC_VERSION_MAJOR) -gt 5 ] && echo true)
ifeq (true,$(CC_VERSION_GT_4))
WARNINGS_DISABLE += -Wno-incompatible-pointer-types
endif
ifeq (true,$(CC_VERSION_GT_5))
WARNINGS_ENABLE += -Wshift-overflow=2 \
-Wnull-dereference \
-Wduplicated-cond
endif
else
WARNINGS_DISABLE += -Wno-typedef-redefinition \
-Wno-missing-braces \
-Wno-incompatible-pointer-types \
-Wno-missing-field-initializers
endif
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEP_DIR)/$*.Td
CFLAGS = -pipe -c -std=c11 -fpic -fno-strict-aliasing \
-D_REENTRANT -fstack-protector -ffunction-sections -fdata-sections \
$(WARNINGS_ENABLE) $(WARNINGS_DISABLE) $(DEFINES) $(INCLUDES)
ifeq ($(RELEASE),y)
CFLAGS += -Ofast -g3 -DNDEBUG -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
else
CFLAGS += -O0 -g3 -D_DEBUG -DDEBUG
endif
all: $(LIB_NAME)
# Here it will link the objects created below in the final .a
$(LIB_NAME): $(OBJECTS_PATH)
@mkdir -p $(OUT_DIR)
@ar rcs $(OUT_DIR)/$(LIB_NAME) $(OBJECTS_PATH)
@echo Disasm library in $(OUT_DIR)/$(LIB_NAME)
# We need to mkdir inside the rule, so each subfolder gets created,
# and avoiding conflicts:
# ./linux/example.c => $(INT_DIR)/linux/example.o
# ./example.c => $(INT_DIR)/example.o
$(INT_DIR)/%.o: %.c $(DEP_DIR)/%.d
@mkdir -p $(dir $@)
@mkdir -p $(dir $(DEP_DIR)/$<) >/dev/null
@echo $<
@$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@
@mv -f $(DEP_DIR)/$*.Td $(DEP_DIR)/$*.d
# So 'make' won't fail if the dependecy file doesn't exist
$(DEP_DIR)/%.d: ;
# Don't delete the dependecy files
.PRECIOUS: $(DEP_DIR)/%.d
# Include all the dependecy files (this will trigger a rebuild if a header is changed)
-include $(patsubst %,$(DEP_DIR)/%.d,$(basename $(SRC_FILES)))
clean_lib_file:
@rm $(OUT_DIR)/$(LIB_NAME) 2>/dev/null ||:
clean_int_dir:
@rm -r $(INT_DIR) 2>/dev/null ||:
clean_dep_dir:
@rm -r $(DEP_DIR) 2>/dev/null ||:
clean: clean_lib_file clean_int_dir clean_dep_dir
install: all
install -d $(DESTDIR)$(PREFIX)/lib/
install -m 644 $(OUT_DIR)/$(LIB_NAME) $(DESTDIR)$(PREFIX)/lib/
install -d $(DESTDIR)$(PREFIX)/include/bddisasm
cp -r ../inc/* $(DESTDIR)$(PREFIX)/include/bddisasm/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,474 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="bddisasm"
ProjectGUID="{3653AA19-048B-410E-B5C4-FF78E1D84C12}"
RootNamespace="bddisasmlib"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)bin\$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(SolutionDir)_intdir\$(ProjectName)\$(PlatformName)\$(ConfigurationName)\"
ConfigurationType="4"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
CommandLine="generate_tables.py instructions"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
FavorSizeOrSpeed="1"
AdditionalIncludeDirectories="include;..\inc"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;DEBUG;"
IgnoreStandardIncludePath="true"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="4"
WarnAsError="true"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(SolutionDir)bin\$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(SolutionDir)_intdir\$(ProjectName)\$(PlatformName)\$(ConfigurationName)\"
ConfigurationType="4"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
CommandLine="generate_tables.py instructions"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/D &quot;AMD64&quot;"
Optimization="0"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
AdditionalIncludeDirectories="include;..\inc"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;DEBUG;"
IgnoreStandardIncludePath="true"
StringPooling="true"
MinimalRebuild="true"
BasicRuntimeChecks="0"
RuntimeLibrary="3"
BufferSecurityCheck="false"
UsePrecompiledHeader="0"
WarningLevel="4"
WarnAsError="true"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
LinkLibraryDependencies="true"
AdditionalLibraryDirectories="&quot;x:\Projects-devel\dacia-hg\bin\$(PlatformName)\$(ConfigurationName)&quot;"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)bin\$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(SolutionDir)_intdir\$(ProjectName)\$(PlatformName)\$(ConfigurationName)\"
ConfigurationType="4"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
CommandLine="generate_tables.py instructions"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
AdditionalIncludeDirectories="include;..\inc"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
IgnoreStandardIncludePath="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="4"
WarnAsError="true"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(SolutionDir)bin\$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(SolutionDir)_intdir\$(ProjectName)\$(PlatformName)\$(ConfigurationName)\"
ConfigurationType="4"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
CommandLine="generate_tables.py instructions"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/D &quot;AMD64&quot;"
Optimization="2"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
WholeProgramOptimization="true"
AdditionalIncludeDirectories="include;..\inc"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
IgnoreStandardIncludePath="true"
StringPooling="true"
BasicRuntimeChecks="0"
RuntimeLibrary="0"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="4"
WarnAsError="true"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
LinkLibraryDependencies="false"
AdditionalLibraryDirectories=""
IgnoreAllDefaultLibraries="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\crt.c"
>
</File>
<File
RelativePath=".\bddisasm.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\include\crt.h"
>
</File>
<File
RelativePath=".\include\instructions.h"
>
</File>
<File
RelativePath=".\include\mnemonics.h"
>
</File>
<File
RelativePath=".\include\prefixes.h"
>
</File>
<File
RelativePath=".\include\sal.h"
>
</File>
<File
RelativePath=".\include\table_evex.h"
>
</File>
<File
RelativePath=".\include\table_root.h"
>
</File>
<File
RelativePath=".\include\table_vex.h"
>
</File>
<File
RelativePath=".\include\table_xop.h"
>
</File>
<File
RelativePath=".\include\tabledefs.h"
>
</File>
<Filter
Name="public"
>
<File
RelativePath="..\inc\constants.h"
>
</File>
<File
RelativePath="..\inc\bddisasm.h"
>
</File>
<File
RelativePath="..\inc\disasmstatus.h"
>
</File>
<File
RelativePath="..\inc\disasmtypes.h"
>
</File>
<File
RelativePath="..\inc\registers.h"
>
</File>
</Filter>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<Filter
Name="Instructions"
>
<File
RelativePath=".\instructions\table_0F.dat"
>
</File>
<File
RelativePath=".\instructions\table_0F_38.dat"
>
</File>
<File
RelativePath=".\instructions\table_0F_3A.dat"
>
</File>
<File
RelativePath=".\instructions\table_3dnow.dat"
>
</File>
<File
RelativePath=".\instructions\table_base.dat"
>
</File>
<File
RelativePath=".\instructions\table_evex1.dat"
>
</File>
<File
RelativePath=".\instructions\table_evex2.dat"
>
</File>
<File
RelativePath=".\instructions\table_evex3.dat"
>
</File>
<File
RelativePath=".\instructions\table_fpu.dat"
>
</File>
<File
RelativePath=".\instructions\table_vex1.dat"
>
</File>
<File
RelativePath=".\instructions\table_vex2.dat"
>
</File>
<File
RelativePath=".\instructions\table_vex3.dat"
>
</File>
<File
RelativePath=".\instructions\table_xop.dat"
>
</File>
</Filter>
<Filter
Name="Scripts"
>
<File
RelativePath=".\generate_tables.py"
>
</File>
</Filter>
<Filter
Name="Other"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,688 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="DebugKernel|ARM64">
<Configuration>DebugKernel</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="DebugKernel|Win32">
<Configuration>DebugKernel</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="DebugKernel|x64">
<Configuration>DebugKernel</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="ReleaseKernel|ARM64">
<Configuration>ReleaseKernel</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="ReleaseKernel|Win32">
<Configuration>ReleaseKernel</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="ReleaseKernel|x64">
<Configuration>ReleaseKernel</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{3653AA19-048B-410E-B5C4-FF78E1D84C12}</ProjectGuid>
<RootNamespace>bddisasm</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
<ProjectName>bddisasm</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<TargetVersion>Windows7</TargetVersion>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
<SupportsPackaging>false</SupportsPackaging>
<ALLOW_DATE_TIME>1</ALLOW_DATE_TIME>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugKernel|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<TargetVersion>Windows7</TargetVersion>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
<SupportsPackaging>false</SupportsPackaging>
<ALLOW_DATE_TIME>1</ALLOW_DATE_TIME>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<TargetVersion>Windows7</TargetVersion>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
<SupportsPackaging>false</SupportsPackaging>
<ALLOW_DATE_TIME>1</ALLOW_DATE_TIME>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|ARM64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<TargetVersion></TargetVersion>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
<SupportsPackaging>false</SupportsPackaging>
<ALLOW_DATE_TIME>1</ALLOW_DATE_TIME>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugKernel|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<TargetVersion>Windows7</TargetVersion>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
<SupportsPackaging>false</SupportsPackaging>
<ALLOW_DATE_TIME>1</ALLOW_DATE_TIME>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugKernel|ARM64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<TargetVersion></TargetVersion>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
<SupportsPackaging>false</SupportsPackaging>
<ALLOW_DATE_TIME>1</ALLOW_DATE_TIME>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='DebugKernel|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|ARM64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='DebugKernel|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='DebugKernel|ARM64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>14.0.23107.0</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)_intdir\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugKernel|Win32'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)_intdir\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)_intdir\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)_intdir\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugKernel|x64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)_intdir\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugKernel|ARM64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)_intdir\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)_intdir\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|Win32'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)_intdir\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)_intdir\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)_intdir\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|x64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)_intdir\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|ARM64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)_intdir\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<ClCompile>
<Optimization>Disabled</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories>include;..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ProgramDataBaseFileName>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName).pdb</ProgramDataBaseFileName>
</ClCompile>
<Lib>
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugKernel|Win32'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<ClCompile>
<Optimization>Disabled</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories>include;..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ProgramDataBaseFileName>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName).pdb</ProgramDataBaseFileName>
<ForcedIncludeFiles />
<AdditionalOptions>/kernel /D %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Lib>
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalOptions>/D "AMD64" %(AdditionalOptions)</AdditionalOptions>
<Optimization>Disabled</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories>include;..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<StringPooling>true</StringPooling>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ProgramDataBaseFileName>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName).pdb</ProgramDataBaseFileName>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
<Lib>
<AdditionalLibraryDirectories>x:\Projects-devel\dacia-hg\bin\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<Midl />
<ClCompile>
<AdditionalOptions>/D "AMD64" %(AdditionalOptions)</AdditionalOptions>
<Optimization>Disabled</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories>include;..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<StringPooling>true</StringPooling>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ProgramDataBaseFileName>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName).pdb</ProgramDataBaseFileName>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
<Lib>
<AdditionalLibraryDirectories>x:\Projects-devel\dacia-hg\bin\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugKernel|x64'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalOptions>/kernel /D "AMD64" %(AdditionalOptions)</AdditionalOptions>
<Optimization>Disabled</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories>include;..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<StringPooling>true</StringPooling>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ProgramDataBaseFileName>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName).pdb</ProgramDataBaseFileName>
<ForcedIncludeFiles />
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
<Lib>
<AdditionalLibraryDirectories>x:\Projects-devel\dacia-hg\bin\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Native</SubSystem>
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugKernel|ARM64'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<Midl />
<ClCompile>
<AdditionalOptions>/kernel /D "AMD64" %(AdditionalOptions)</AdditionalOptions>
<Optimization>Disabled</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories>include;..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<StringPooling>true</StringPooling>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ProgramDataBaseFileName>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName).pdb</ProgramDataBaseFileName>
<ForcedIncludeFiles>
</ForcedIncludeFiles>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
<Lib>
<AdditionalLibraryDirectories>x:\Projects-devel\dacia-hg\bin\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Native</SubSystem>
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories>include;..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader />
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ProgramDataBaseFileName>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName).pdb</ProgramDataBaseFileName>
<WholeProgramOptimization>false</WholeProgramOptimization>
</ClCompile>
<Lib>
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|Win32'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories>include;..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ProgramDataBaseFileName>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName).pdb</ProgramDataBaseFileName>
<ForcedIncludeFiles />
<AdditionalOptions>/kernel /D %(AdditionalOptions)</AdditionalOptions>
<WholeProgramOptimization>false</WholeProgramOptimization>
</ClCompile>
<Lib>
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalOptions>/D "AMD64" %(AdditionalOptions)</AdditionalOptions>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>false</WholeProgramOptimization>
<AdditionalIncludeDirectories>include;..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<StringPooling>true</StringPooling>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader />
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ProgramDataBaseFileName>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName).pdb</ProgramDataBaseFileName>
<CompileAs>Default</CompileAs>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
</ProjectReference>
<Lib>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
</Lib>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<Midl />
<ClCompile>
<AdditionalOptions>/D "AMD64" %(AdditionalOptions)</AdditionalOptions>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>false</WholeProgramOptimization>
<AdditionalIncludeDirectories>include;..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<StringPooling>true</StringPooling>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ProgramDataBaseFileName>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName).pdb</ProgramDataBaseFileName>
<CompileAs>Default</CompileAs>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
</ProjectReference>
<Lib>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
</Lib>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|x64'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalOptions>/kernel /D "AMD64" %(AdditionalOptions)</AdditionalOptions>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>false</WholeProgramOptimization>
<AdditionalIncludeDirectories>include;..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<StringPooling>true</StringPooling>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ProgramDataBaseFileName>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName).pdb</ProgramDataBaseFileName>
<ForcedIncludeFiles />
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
</ProjectReference>
<Lib>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<SubSystem>Native</SubSystem>
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|ARM64'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<Midl />
<ClCompile>
<AdditionalOptions>/kernel /D "AMD64" %(AdditionalOptions)</AdditionalOptions>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>false</WholeProgramOptimization>
<AdditionalIncludeDirectories>include;..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<StringPooling>true</StringPooling>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ProgramDataBaseFileName>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName).pdb</ProgramDataBaseFileName>
<ForcedIncludeFiles>
</ForcedIncludeFiles>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
</ProjectReference>
<Lib>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<SubSystem>Native</SubSystem>
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="bdformat.c" />
<ClCompile Include="bdhelpers.c" />
<ClCompile Include="crt.c" />
<ClCompile Include="bddisasm.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|ARM64'">NotUsing</PrecompiledHeader>
<ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='DebugKernel|Win32'">
</ForcedIncludeFiles>
<ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='DebugKernel|x64'">
</ForcedIncludeFiles>
<ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='DebugKernel|ARM64'">
</ForcedIncludeFiles>
<ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|Win32'">
</ForcedIncludeFiles>
<ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|x64'">
</ForcedIncludeFiles>
<ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='ReleaseKernel|ARM64'">
</ForcedIncludeFiles>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\inc\constants.h" />
<ClInclude Include="..\inc\cpuidflags.h" />
<ClInclude Include="..\inc\bddisasm.h" />
<ClInclude Include="..\inc\disasmstatus.h" />
<ClInclude Include="..\inc\disasmtypes.h" />
<ClInclude Include="..\inc\registers.h" />
<ClInclude Include="..\inc\version.h" />
<ClInclude Include="include\instructions.h" />
<ClInclude Include="include\mnemonics.h" />
<ClInclude Include="include\nd_crt.h" />
<ClInclude Include="include\prefixes.h" />
<ClInclude Include="include\tabledefs.h" />
<ClInclude Include="include\table_evex.h" />
<ClInclude Include="include\table_root.h" />
<ClInclude Include="include\table_vex.h" />
<ClInclude Include="include\table_xop.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Header Files\public">
<UniqueIdentifier>{8f31fedd-353c-4b9c-9e2d-bdb129e1e02b}</UniqueIdentifier>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
<Filter Include="Other">
<UniqueIdentifier>{5e26c505-e8f5-4e6c-9d54-f20e36b637b8}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="crt.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="bddisasm.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="bdformat.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="bdhelpers.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\instructions.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\mnemonics.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\prefixes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\table_evex.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\table_root.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\table_vex.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\table_xop.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\tabledefs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\inc\constants.h">
<Filter>Header Files\public</Filter>
</ClInclude>
<ClInclude Include="..\inc\bddisasm.h">
<Filter>Header Files\public</Filter>
</ClInclude>
<ClInclude Include="..\inc\disasmstatus.h">
<Filter>Header Files\public</Filter>
</ClInclude>
<ClInclude Include="..\inc\disasmtypes.h">
<Filter>Header Files\public</Filter>
</ClInclude>
<ClInclude Include="..\inc\registers.h">
<Filter>Header Files\public</Filter>
</ClInclude>
<ClInclude Include="..\inc\version.h">
<Filter>Header Files\public</Filter>
</ClInclude>
<ClInclude Include="..\inc\cpuidflags.h">
<Filter>Header Files\public</Filter>
</ClInclude>
<ClInclude Include="include\nd_crt.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,332 @@
/*
* Copyright (c) 2020 Bitdefender
* SPDX-License-Identifier: Apache-2.0
*/
#include "include/nd_crt.h"
#include "../inc/bddisasm.h"
//
// NdIsInstruxRipRelative
//
ND_BOOL
NdIsInstruxRipRelative(
const INSTRUX *Instrux
)
//
// Provided for backwards compatibility with existing code that uses disasm 1.0
//
{
if (ND_NULL == Instrux)
{
return ND_FALSE;
}
else
{
return Instrux->IsRipRelative;
}
}
//
// NdGetFullAccessMap
//
NDSTATUS
NdGetFullAccessMap(
const INSTRUX *Instrux,
ND_ACCESS_MAP *AccessMap
)
{
ND_UINT32 i;
const ND_OPERAND *pOp;
// pre-init
i = 0;
pOp = (const ND_OPERAND *)ND_NULL;
// validate
if (ND_NULL == Instrux)
{
return ND_STATUS_INVALID_PARAMETER;
}
if (ND_NULL == AccessMap)
{
return ND_STATUS_INVALID_PARAMETER;
}
for (i = 0; i < Instrux->OperandsCount; i++)
{
pOp = &Instrux->Operands[i];
if (ND_OP_MEM == pOp->Type)
{
if (pOp->Info.Memory.IsStack)
{
AccessMap->StackAccess |= pOp->Access.Access;
AccessMap->GprAccess[NDR_RSP] |= ND_ACCESS_READ|ND_ACCESS_WRITE;
AccessMap->SegAccess[NDR_SS] |= ND_ACCESS_READ;
}
else
{
AccessMap->MemAccess |= pOp->Access.Access;
if (pOp->Info.Memory.HasSeg)
{
AccessMap->SegAccess[pOp->Info.Memory.Seg] |= ND_ACCESS_READ;
}
if (pOp->Info.Memory.HasBase)
{
AccessMap->GprAccess[pOp->Info.Memory.Base] |= ND_ACCESS_READ;
}
if (pOp->Info.Memory.HasIndex)
{
if (pOp->Info.Memory.IsVsib)
{
AccessMap->SseAccess[pOp->Info.Memory.Index] |= ND_ACCESS_READ;
}
else
{
AccessMap->GprAccess[pOp->Info.Memory.Index] |= ND_ACCESS_READ;
}
}
}
}
else if (ND_OP_REG == pOp->Type)
{
switch (pOp->Info.Register.Type)
{
case ND_REG_GPR:
{
ND_UINT32 k;
for (k = 0; k < pOp->Info.Register.Count; k++)
{
if (pOp->Info.Register.IsHigh8)
{
AccessMap->GprAccess[pOp->Info.Register.Reg - 4 + k] |= pOp->Access.Access;
}
else
{
AccessMap->GprAccess[pOp->Info.Register.Reg + k] |= pOp->Access.Access;
}
}
}
break;
case ND_REG_SEG:
AccessMap->SegAccess[pOp->Info.Register.Reg] |= pOp->Access.Access;
break;
case ND_REG_FPU:
AccessMap->FpuAccess[pOp->Info.Register.Reg] |= pOp->Access.Access;
break;
case ND_REG_MMX:
AccessMap->MmxAccess[pOp->Info.Register.Reg] |= pOp->Access.Access;
break;
case ND_REG_SSE:
{
ND_UINT32 k;
for (k = 0; k < pOp->Info.Register.Count; k++)
{
AccessMap->SseAccess[pOp->Info.Register.Reg + k] |= pOp->Access.Access;
}
}
break;
case ND_REG_CR:
AccessMap->CrAccess[pOp->Info.Register.Reg] |= pOp->Access.Access;
break;
case ND_REG_DR:
AccessMap->DrAccess[pOp->Info.Register.Reg] |= pOp->Access.Access;
break;
case ND_REG_TR:
AccessMap->TrAccess[pOp->Info.Register.Reg] |= pOp->Access.Access;
break;
case ND_REG_BND:
AccessMap->BndAccess[pOp->Info.Register.Reg] |= pOp->Access.Access;
break;
case ND_REG_MSK:
AccessMap->MskAccess[pOp->Info.Register.Reg] |= pOp->Access.Access;
break;
case ND_REG_SYS:
AccessMap->SysAccess[pOp->Info.Register.Reg] |= pOp->Access.Access;
break;
case ND_REG_X87:
AccessMap->X87Access[pOp->Info.Register.Reg] |= pOp->Access.Access;
break;
case ND_REG_FLG:
AccessMap->FlagsAccess |= pOp->Access.Access;
break;
case ND_REG_RIP:
AccessMap->RipAccess |= pOp->Access.Access;
break;
case ND_REG_MXCSR:
AccessMap->MxcsrAccess |= pOp->Access.Access;
break;
case ND_REG_PKRU:
AccessMap->PkruAccess |= pOp->Access.Access;
break;
case ND_REG_SSP:
AccessMap->SspAccess |= pOp->Access.Access;
break;
case ND_REG_TILE:
AccessMap->TmmAccess[pOp->Info.Register.Reg] |= pOp->Access.Access;
break;
default:
break;
}
}
else if (ND_OP_BANK == Instrux->Operands[i].Type)
{
ND_UINT8 j;
// Bank registers access. This needs special handling. Note that LOADALL/LOADALLD is not supported, as
// it is too old and it's not valid since the good old 486.
if (ND_INS_FNSAVE == Instrux->Instruction)
{
for (j = 0; j < ND_MAX_FPU_REGS; j++)
{
AccessMap->FpuAccess[j] |= ND_ACCESS_READ;
}
}
else if (ND_INS_FRSTOR == Instrux->Instruction)
{
for (j = 0; j < ND_MAX_FPU_REGS; j++)
{
AccessMap->FpuAccess[j] |= ND_ACCESS_WRITE;
}
}
if ((ND_INS_XSAVE == Instrux->Instruction) || (ND_INS_XSAVEOPT == Instrux->Instruction) ||
(ND_INS_XSAVES == Instrux->Instruction) || (ND_INS_XSAVEC == Instrux->Instruction))
{
for (j = 0; j < ND_MAX_SSE_REGS; j++)
{
AccessMap->SseAccess[j] |= ND_ACCESS_READ;
}
}
else if ((ND_INS_XRSTOR == Instrux->Instruction) || (ND_INS_XRSTORS == Instrux->Instruction))
{
for (j = 0; j < ND_MAX_SSE_REGS; j++)
{
AccessMap->SseAccess[j] |= ND_ACCESS_WRITE;
}
}
}
}
return ND_STATUS_SUCCESS;
}
//
// NdGetOperandRlut
//
NDSTATUS
NdGetOperandRlut(
const INSTRUX *Instrux,
ND_OPERAND_RLUT *Rlut
)
{
if (ND_NULL == Instrux)
{
return ND_STATUS_INVALID_PARAMETER;
}
if (ND_NULL == Rlut)
{
return ND_STATUS_INVALID_PARAMETER;
}
// Initialize the RLUT.
nd_memset(Rlut, 0, sizeof(*Rlut));
for (ND_UINT8 i = 0; i < Instrux->OperandsCount; i++)
{
if (!!(Instrux->Operands[i].Access.Access & ND_ACCESS_ANY_WRITE))
{
// We only care about the first 2 destination operands.
if (Rlut->Dst1 == ND_NULL)
{
Rlut->Dst1 = (PND_OPERAND)&Instrux->Operands[i];
}
else if (Rlut->Dst2 == ND_NULL)
{
Rlut->Dst2 = (PND_OPERAND)&Instrux->Operands[i];
}
}
if (!!(Instrux->Operands[i].Access.Access & ND_ACCESS_ANY_READ))
{
// We only care about the first 4 source operands.
if (Rlut->Src1 == ND_NULL)
{
Rlut->Src1 = (PND_OPERAND)&Instrux->Operands[i];
}
else if (Rlut->Src2 == ND_NULL)
{
Rlut->Src2 = (PND_OPERAND)&Instrux->Operands[i];
}
else if (Rlut->Src3 == ND_NULL)
{
Rlut->Src3 = (PND_OPERAND)&Instrux->Operands[i];
}
else if (Rlut->Src4 == ND_NULL)
{
Rlut->Src4 = (PND_OPERAND)&Instrux->Operands[i];
}
}
if (Instrux->Operands[i].Type == ND_OP_MEM)
{
// We only care about the first 2 memory operands.
if (Rlut->Mem1 == ND_NULL)
{
Rlut->Mem1 = (PND_OPERAND)&Instrux->Operands[i];
}
else if (Rlut->Mem2 == ND_NULL)
{
Rlut->Mem2 = (PND_OPERAND)&Instrux->Operands[i];
}
if (Instrux->Operands[i].Info.Memory.IsStack)
{
Rlut->Stack = (PND_OPERAND)&Instrux->Operands[i];
}
}
if (Instrux->Operands[i].Type == ND_OP_REG && Instrux->Operands->Flags.IsDefault)
{
switch (Instrux->Operands[i].Info.Register.Type)
{
case ND_REG_FLG:
Rlut->Flags = (PND_OPERAND)&Instrux->Operands[i];
break;
case ND_REG_RIP:
Rlut->Rip = (PND_OPERAND)&Instrux->Operands[i];;
break;
case ND_REG_SEG:
if (Instrux->Operands[i].Info.Register.Reg == NDR_CS)
{
Rlut->Cs = (PND_OPERAND)&Instrux->Operands[i];
}
else if (Instrux->Operands[i].Info.Register.Reg == NDR_SS)
{
Rlut->Ss = (PND_OPERAND)&Instrux->Operands[i];
}
break;
case ND_REG_GPR:
if (Instrux->Operands[i].Info.Register.Reg < 8)
{
*(&Rlut->Rax + Instrux->Operands[i].Info.Register.Reg) = (PND_OPERAND)&Instrux->Operands[i];
}
break;
default:
break;
}
}
}
return ND_STATUS_SUCCESS;
}

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 2020 Bitdefender
* SPDX-License-Identifier: Apache-2.0
*/
#include "include/nd_crt.h"
//
// nd_strcat_s
//
char *
nd_strcat_s(
char *dst,
ND_SIZET dst_size,
const char *src
)
{
char *p;
ND_SIZET available;
p = dst;
available = dst_size;
while (available > 0 && *p != 0)
{
p++;
available--;
}
if (available == 0)
{
nd_memzero(dst, dst_size);
return (char *)ND_NULL;
}
while ((*p++ = *src++) != 0 && --available > 0);
if (available == 0)
{
nd_memzero(dst, dst_size);
return (char *)ND_NULL;
}
return dst;
}
#if !defined(BDDISASM_NO_FORMAT) && defined(BDDISASM_HAS_VSNPRINTF)
#include <stdio.h>
int nd_vsnprintf_s(char *buffer, ND_SIZET sizeOfBuffer, ND_SIZET count, const char *format, va_list argptr)
{
UNREFERENCED_PARAMETER(count);
return vsnprintf(buffer, sizeOfBuffer, format, argptr);
}
#endif // !defined(BDDISASM_NO_FORMAT) && defined(BDDISASM_HAS_VSNPRINTF)
#if defined(BDDISASM_HAS_MEMSET)
#include <string.h>
void *nd_memset(void *s, int c, ND_SIZET n)
{
return memset(s, c, n);
}
#endif // defined(BDDISASM_HAS_MEMSET)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,317 @@
/*
* Copyright (c) 2020 Bitdefender
* SPDX-License-Identifier: Apache-2.0
*/
//
// This file was auto-generated by generate_tables.py. DO NOT MODIFY!
//
#ifndef MNEMONICS_H
#define MNEMONICS_H
const char *gMnemonics[1736] =
{
"AAA", "AAD", "AADD", "AAM", "AAND", "AAS", "ADC", "ADCX", "ADD",
"ADDPD", "ADDPS", "ADDSD", "ADDSS", "ADDSUBPD", "ADDSUBPS", "ADOX",
"AESDEC", "AESDEC128KL", "AESDEC256KL", "AESDECLAST", "AESDECWIDE128KL",
"AESDECWIDE256KL", "AESENC", "AESENC128KL", "AESENC256KL", "AESENCLAST",
"AESENCWIDE128KL", "AESENCWIDE256KL", "AESIMC", "AESKEYGENASSIST",
"ALTINST", "AND", "ANDN", "ANDNPD", "ANDNPS", "ANDPD", "ANDPS",
"AOR", "ARPL", "AXOR", "BEXTR", "BLCFILL", "BLCI", "BLCIC", "BLCMSK",
"BLCS", "BLENDPD", "BLENDPS", "BLENDVPD", "BLENDVPS", "BLSFILL",
"BLSI", "BLSIC", "BLSMSK", "BLSR", "BNDCL", "BNDCN", "BNDCU",
"BNDLDX", "BNDMK", "BNDMOV", "BNDSTX", "BOUND", "BSF", "BSR",
"BSWAP", "BT", "BTC", "BTR", "BTS", "BZHI", "CALL", "CALLF",
"CBW", "CDQ", "CDQE", "CLAC", "CLC", "CLD", "CLDEMOTE", "CLEVICT0",
"CLEVICT1", "CLFLUSH", "CLFLUSHOPT", "CLGI", "CLI", "CLRSSBSY",
"CLTS", "CLUI", "CLWB", "CLZERO", "CMC", "CMOVBE", "CMOVC", "CMOVL",
"CMOVLE", "CMOVNBE", "CMOVNC", "CMOVNL", "CMOVNLE", "CMOVNO",
"CMOVNP", "CMOVNS", "CMOVNZ", "CMOVO", "CMOVP", "CMOVS", "CMOVZ",
"CMP", "CMPBEXADD", "CMPCXADD", "CMPLEXADD", "CMPLXADD", "CMPNBEXADD",
"CMPNCXADD", "CMPNLEXADD", "CMPNLXADD", "CMPNOXADD", "CMPNPXADD",
"CMPNSXADD", "CMPNZXADD", "CMPOXADD", "CMPPD", "CMPPS", "CMPPXADD",
"CMPSB", "CMPSD", "CMPSQ", "CMPSS", "CMPSW", "CMPSXADD", "CMPXCHG",
"CMPXCHG16B", "CMPXCHG8B", "CMPZXADD", "COMISD", "COMISS", "CPUID",
"CPU_READ", "CPU_WRITE", "CQO", "CRC32", "CVTDQ2PD", "CVTDQ2PS",
"CVTPD2DQ", "CVTPD2PI", "CVTPD2PS", "CVTPI2PD", "CVTPI2PS", "CVTPS2DQ",
"CVTPS2PD", "CVTPS2PI", "CVTSD2SI", "CVTSD2SS", "CVTSI2SD", "CVTSI2SS",
"CVTSS2SD", "CVTSS2SI", "CVTTPD2DQ", "CVTTPD2PI", "CVTTPS2DQ",
"CVTTPS2PI", "CVTTSD2SI", "CVTTSS2SI", "CWD", "CWDE", "DAA",
"DAS", "DEC", "DELAY", "DIV", "DIVPD", "DIVPS", "DIVSD", "DIVSS",
"DMINT", "DPPD", "DPPS", "EMMS", "ENCLS", "ENCLU", "ENCLV", "ENCODEKEY128",
"ENCODEKEY256", "ENDBR32", "ENDBR64", "ENQCMD", "ENQCMDS", "ENTER",
"ERETS", "ERETU", "EXTRACTPS", "EXTRQ", "F2XM1", "FABS", "FADD",
"FADDP", "FBLD", "FBSTP", "FCHS", "FCMOVB", "FCMOVBE", "FCMOVE",
"FCMOVNB", "FCMOVNBE", "FCMOVNE", "FCMOVNU", "FCMOVU", "FCOM",
"FCOMI", "FCOMIP", "FCOMP", "FCOMPP", "FCOS", "FDECSTP", "FDIV",
"FDIVP", "FDIVR", "FDIVRP", "FEMMS", "FFREE", "FFREEP", "FIADD",
"FICOM", "FICOMP", "FIDIV", "FIDIVR", "FILD", "FIMUL", "FINCSTP",
"FIST", "FISTP", "FISTTP", "FISUB", "FISUBR", "FLD", "FLD1",
"FLDCW", "FLDENV", "FLDL2E", "FLDL2T", "FLDLG2", "FLDLN2", "FLDPI",
"FLDZ", "FMUL", "FMULP", "FNCLEX", "FNDISI", "FNINIT", "FNOP",
"FNSAVE", "FNSTCW", "FNSTENV", "FNSTSW", "FPATAN", "FPREM", "FPREM1",
"FPTAN", "FRINEAR", "FRNDINT", "FRSTOR", "FSCALE", "FSIN", "FSINCOS",
"FSQRT", "FST", "FSTDW", "FSTP", "FSTPNCE", "FSTSG", "FSUB",
"FSUBP", "FSUBR", "FSUBRP", "FTST", "FUCOM", "FUCOMI", "FUCOMIP",
"FUCOMP", "FUCOMPP", "FXAM", "FXCH", "FXRSTOR", "FXRSTOR64",
"FXSAVE", "FXSAVE64", "FXTRACT", "FYL2X", "FYL2XP1", "GETSEC",
"GF2P8AFFINEINVQB", "GF2P8AFFINEQB", "GF2P8MULB", "HADDPD", "HADDPS",
"HLT", "HRESET", "HSUBPD", "HSUBPS", "IDIV", "IMUL", "IN", "INC",
"INCSSPD", "INCSSPQ", "INSB", "INSD", "INSERTPS", "INSERTQ",
"INSW", "INT", "INT1", "INT3", "INTO", "INVD", "INVEPT", "INVLPG",
"INVLPGA", "INVLPGB", "INVPCID", "INVVPID", "IRETD", "IRETQ",
"IRETW", "JBE", "JC", "JCXZ", "JECXZ", "JL", "JLE", "JMP", "JMPE",
"JMPF", "JNBE", "JNC", "JNL", "JNLE", "JNO", "JNP", "JNS", "JNZ",
"JO", "JP", "JRCXZ", "JS", "JZ", "KADDB", "KADDD", "KADDQ", "KADDW",
"KANDB", "KANDD", "KANDNB", "KANDND", "KANDNQ", "KANDNW", "KANDQ",
"KANDW", "KMERGE2L1H", "KMERGE2L1L", "KMOVB", "KMOVD", "KMOVQ",
"KMOVW", "KNOTB", "KNOTD", "KNOTQ", "KNOTW", "KORB", "KORD",
"KORQ", "KORTESTB", "KORTESTD", "KORTESTQ", "KORTESTW", "KORW",
"KSHIFTLB", "KSHIFTLD", "KSHIFTLQ", "KSHIFTLW", "KSHIFTRB", "KSHIFTRD",
"KSHIFTRQ", "KSHIFTRW", "KTESTB", "KTESTD", "KTESTQ", "KTESTW",
"KUNPCKBW", "KUNPCKDQ", "KUNPCKWD", "KXNORB", "KXNORD", "KXNORQ",
"KXNORW", "KXORB", "KXORD", "KXORQ", "KXORW", "LAHF", "LAR",
"LDDQU", "LDMXCSR", "LDS", "LDTILECFG", "LEA", "LEAVE", "LES",
"LFENCE", "LFS", "LGDT", "LGS", "LIDT", "LKGS", "LLDT", "LLWPCB",
"LMSW", "LOADIWKEY", "LODSB", "LODSD", "LODSQ", "LODSW", "LOOP",
"LOOPNZ", "LOOPZ", "LSL", "LSS", "LTR", "LWPINS", "LWPVAL", "LZCNT",
"MASKMOVDQU", "MASKMOVQ", "MAXPD", "MAXPS", "MAXSD", "MAXSS",
"MCOMMIT", "MFENCE", "MINPD", "MINPS", "MINSD", "MINSS", "MONITOR",
"MONITORX", "MONTMUL", "MOV", "MOVAPD", "MOVAPS", "MOVBE", "MOVD",
"MOVDDUP", "MOVDIR64B", "MOVDIRI", "MOVDQ2Q", "MOVDQA", "MOVDQU",
"MOVHLPS", "MOVHPD", "MOVHPS", "MOVLHPS", "MOVLPD", "MOVLPS",
"MOVMSKPD", "MOVMSKPS", "MOVNTDQ", "MOVNTDQA", "MOVNTI", "MOVNTPD",
"MOVNTPS", "MOVNTQ", "MOVNTSD", "MOVNTSS", "MOVQ", "MOVQ2DQ",
"MOVSB", "MOVSD", "MOVSHDUP", "MOVSLDUP", "MOVSQ", "MOVSS", "MOVSW",
"MOVSX", "MOVSXD", "MOVUPD", "MOVUPS", "MOVZX", "MPSADBW", "MUL",
"MULPD", "MULPS", "MULSD", "MULSS", "MULX", "MWAIT", "MWAITX",
"NEG", "NOP", "NOT", "OR", "ORPD", "ORPS", "OUT", "OUTSB", "OUTSD",
"OUTSW", "PABSB", "PABSD", "PABSW", "PACKSSDW", "PACKSSWB", "PACKUSDW",
"PACKUSWB", "PADDB", "PADDD", "PADDQ", "PADDSB", "PADDSW", "PADDUSB",
"PADDUSW", "PADDW", "PALIGNR", "PAND", "PANDN", "PAUSE", "PAVGB",
"PAVGUSB", "PAVGW", "PBLENDVB", "PBLENDW", "PCLMULQDQ", "PCMPEQB",
"PCMPEQD", "PCMPEQQ", "PCMPEQW", "PCMPESTRI", "PCMPESTRM", "PCMPGTB",
"PCMPGTD", "PCMPGTQ", "PCMPGTW", "PCMPISTRI", "PCMPISTRM", "PCONFIG",
"PDEP", "PEXT", "PEXTRB", "PEXTRD", "PEXTRQ", "PEXTRW", "PF2ID",
"PF2IW", "PFACC", "PFADD", "PFCMPEQ", "PFCMPGE", "PFCMPGT", "PFMAX",
"PFMIN", "PFMUL", "PFNACC", "PFPNACC", "PFRCP", "PFRCPIT1", "PFRCPIT2",
"PFRCPV", "PFRSQIT1", "PFRSQRT", "PFRSQRTV", "PFSUB", "PFSUBR",
"PHADDD", "PHADDSW", "PHADDW", "PHMINPOSUW", "PHSUBD", "PHSUBSW",
"PHSUBW", "PI2FD", "PI2FW", "PINSRB", "PINSRD", "PINSRQ", "PINSRW",
"PMADDUBSW", "PMADDWD", "PMAXSB", "PMAXSD", "PMAXSW", "PMAXUB",
"PMAXUD", "PMAXUW", "PMINSB", "PMINSD", "PMINSW", "PMINUB", "PMINUD",
"PMINUW", "PMOVMSKB", "PMOVSXBD", "PMOVSXBQ", "PMOVSXBW", "PMOVSXDQ",
"PMOVSXWD", "PMOVSXWQ", "PMOVZXBD", "PMOVZXBQ", "PMOVZXBW", "PMOVZXDQ",
"PMOVZXWD", "PMOVZXWQ", "PMULDQ", "PMULHRSW", "PMULHRW", "PMULHUW",
"PMULHW", "PMULLD", "PMULLW", "PMULUDQ", "POP", "POPA", "POPAD",
"POPCNT", "POPFD", "POPFQ", "POPFW", "POR", "PREFETCH", "PREFETCHE",
"PREFETCHIT0", "PREFETCHIT1", "PREFETCHM", "PREFETCHNTA", "PREFETCHT0",
"PREFETCHT1", "PREFETCHT2", "PREFETCHW", "PREFETCHWT1", "PSADBW",
"PSHUFB", "PSHUFD", "PSHUFHW", "PSHUFLW", "PSHUFW", "PSIGNB",
"PSIGND", "PSIGNW", "PSLLD", "PSLLDQ", "PSLLQ", "PSLLW", "PSMASH",
"PSRAD", "PSRAW", "PSRLD", "PSRLDQ", "PSRLQ", "PSRLW", "PSUBB",
"PSUBD", "PSUBQ", "PSUBSB", "PSUBSW", "PSUBUSB", "PSUBUSW", "PSUBW",
"PSWAPD", "PTEST", "PTWRITE", "PUNPCKHBW", "PUNPCKHDQ", "PUNPCKHQDQ",
"PUNPCKHWD", "PUNPCKLBW", "PUNPCKLDQ", "PUNPCKLQDQ", "PUNPCKLWD",
"PUSH", "PUSHA", "PUSHAD", "PUSHFD", "PUSHFQ", "PUSHFW", "PVALIDATE",
"PXOR", "RCL", "RCPPS", "RCPSS", "RCR", "RDFSBASE", "RDGSBASE",
"RDMSR", "RDMSRLIST", "RDPID", "RDPKRU", "RDPMC", "RDPRU", "RDRAND",
"RDSEED", "RDSHR", "RDSSPD", "RDSSPQ", "RDTSC", "RDTSCP", "RETF",
"RETN", "RMPADJUST", "RMPQUERY", "RMPUPDATE", "ROL", "ROR", "RORX",
"ROUNDPD", "ROUNDPS", "ROUNDSD", "ROUNDSS", "RSDC", "RSLDT",
"RSM", "RSQRTPS", "RSQRTSS", "RSTORSSP", "RSTS", "SAHF", "SAL",
"SALC", "SAR", "SARX", "SAVEPREVSSP", "SBB", "SCASB", "SCASD",
"SCASQ", "SCASW", "SEAMCALL", "SEAMOPS", "SEAMRET", "SENDUIPI",
"SERIALIZE", "SETBE", "SETC", "SETL", "SETLE", "SETNBE", "SETNC",
"SETNL", "SETNLE", "SETNO", "SETNP", "SETNS", "SETNZ", "SETO",
"SETP", "SETS", "SETSSBSY", "SETZ", "SFENCE", "SGDT", "SHA1MSG1",
"SHA1MSG2", "SHA1NEXTE", "SHA1RNDS4", "SHA256MSG1", "SHA256MSG2",
"SHA256RNDS2", "SHL", "SHLD", "SHLX", "SHR", "SHRD", "SHRX",
"SHUFPD", "SHUFPS", "SIDT", "SKINIT", "SLDT", "SLWPCB", "SMINT",
"SMSW", "SPFLT", "SQRTPD", "SQRTPS", "SQRTSD", "SQRTSS", "STAC",
"STC", "STD", "STGI", "STI", "STMXCSR", "STOSB", "STOSD", "STOSQ",
"STOSW", "STR", "STTILECFG", "STUI", "SUB", "SUBPD", "SUBPS",
"SUBSD", "SUBSS", "SVDC", "SVLDT", "SVTS", "SWAPGS", "SYSCALL",
"SYSENTER", "SYSEXIT", "SYSRET", "T1MSKC", "TCMMIMFP16PS", "TCMMRLFP16PS",
"TDCALL", "TDPBF16PS", "TDPBSSD", "TDPBSUD", "TDPBUSD", "TDPBUUD",
"TDPFP16PS", "TEST", "TESTUI", "TILELOADD", "TILELOADDT1", "TILERELEASE",
"TILESTORED", "TILEZERO", "TLBSYNC", "TPAUSE", "TZCNT", "TZMSK",
"UCOMISD", "UCOMISS", "UD0", "UD1", "UD2", "UIRET", "UMONITOR",
"UMWAIT", "UNPCKHPD", "UNPCKHPS", "UNPCKLPD", "UNPCKLPS", "V4FMADDPS",
"V4FMADDSS", "V4FNMADDPS", "V4FNMADDSS", "VADDPD", "VADDPH",
"VADDPS", "VADDSD", "VADDSH", "VADDSS", "VADDSUBPD", "VADDSUBPS",
"VAESDEC", "VAESDECLAST", "VAESENC", "VAESENCLAST", "VAESIMC",
"VAESKEYGENASSIST", "VALIGND", "VALIGNQ", "VANDNPD", "VANDNPS",
"VANDPD", "VANDPS", "VBCSTNEBF162PS", "VBCSTNESH2PS", "VBLENDMPD",
"VBLENDMPS", "VBLENDPD", "VBLENDPS", "VBLENDVPD", "VBLENDVPS",
"VBROADCASTF128", "VBROADCASTF32X2", "VBROADCASTF32X4", "VBROADCASTF32X8",
"VBROADCASTF64X2", "VBROADCASTF64X4", "VBROADCASTI128", "VBROADCASTI32X2",
"VBROADCASTI32X4", "VBROADCASTI32X8", "VBROADCASTI64X2", "VBROADCASTI64X4",
"VBROADCASTSD", "VBROADCASTSS", "VCMPPD", "VCMPPH", "VCMPPS",
"VCMPSD", "VCMPSH", "VCMPSS", "VCOMISD", "VCOMISH", "VCOMISS",
"VCOMPRESSPD", "VCOMPRESSPS", "VCVTDQ2PD", "VCVTDQ2PH", "VCVTDQ2PS",
"VCVTNE2PS2BF16", "VCVTNEEBF162PS", "VCVTNEEPH2PS", "VCVTNEOBF162PS",
"VCVTNEOPH2PS", "VCVTNEPS2BF16", "VCVTPD2DQ", "VCVTPD2PH", "VCVTPD2PS",
"VCVTPD2QQ", "VCVTPD2UDQ", "VCVTPD2UQQ", "VCVTPH2DQ", "VCVTPH2PD",
"VCVTPH2PS", "VCVTPH2PSX", "VCVTPH2QQ", "VCVTPH2UDQ", "VCVTPH2UQQ",
"VCVTPH2UW", "VCVTPH2W", "VCVTPS2DQ", "VCVTPS2PD", "VCVTPS2PH",
"VCVTPS2PHX", "VCVTPS2QQ", "VCVTPS2UDQ", "VCVTPS2UQQ", "VCVTQQ2PD",
"VCVTQQ2PH", "VCVTQQ2PS", "VCVTSD2SH", "VCVTSD2SI", "VCVTSD2SS",
"VCVTSD2USI", "VCVTSH2SD", "VCVTSH2SI", "VCVTSH2SS", "VCVTSH2USI",
"VCVTSI2SD", "VCVTSI2SH", "VCVTSI2SS", "VCVTSS2SD", "VCVTSS2SH",
"VCVTSS2SI", "VCVTSS2USI", "VCVTTPD2DQ", "VCVTTPD2QQ", "VCVTTPD2UDQ",
"VCVTTPD2UQQ", "VCVTTPH2DQ", "VCVTTPH2QQ", "VCVTTPH2UDQ", "VCVTTPH2UQQ",
"VCVTTPH2UW", "VCVTTPH2W", "VCVTTPS2DQ", "VCVTTPS2QQ", "VCVTTPS2UDQ",
"VCVTTPS2UQQ", "VCVTTSD2SI", "VCVTTSD2USI", "VCVTTSH2SI", "VCVTTSH2USI",
"VCVTTSS2SI", "VCVTTSS2USI", "VCVTUDQ2PD", "VCVTUDQ2PH", "VCVTUDQ2PS",
"VCVTUQQ2PD", "VCVTUQQ2PH", "VCVTUQQ2PS", "VCVTUSI2SD", "VCVTUSI2SH",
"VCVTUSI2SS", "VCVTUW2PH", "VCVTW2PH", "VDBPSADBW", "VDIVPD",
"VDIVPH", "VDIVPS", "VDIVSD", "VDIVSH", "VDIVSS", "VDPBF16PS",
"VDPPD", "VDPPS", "VERR", "VERW", "VEXP2PD", "VEXP2PS", "VEXPANDPD",
"VEXPANDPS", "VEXTRACTF128", "VEXTRACTF32X4", "VEXTRACTF32X8",
"VEXTRACTF64X2", "VEXTRACTF64X4", "VEXTRACTI128", "VEXTRACTI32X4",
"VEXTRACTI32X8", "VEXTRACTI64X2", "VEXTRACTI64X4", "VEXTRACTPS",
"VFCMADDCPH", "VFCMADDCSH", "VFCMULCPH", "VFCMULCSH", "VFIXUPIMMPD",
"VFIXUPIMMPS", "VFIXUPIMMSD", "VFIXUPIMMSS", "VFMADD132PD", "VFMADD132PH",
"VFMADD132PS", "VFMADD132SD", "VFMADD132SH", "VFMADD132SS", "VFMADD213PD",
"VFMADD213PH", "VFMADD213PS", "VFMADD213SD", "VFMADD213SH", "VFMADD213SS",
"VFMADD231PD", "VFMADD231PH", "VFMADD231PS", "VFMADD231SD", "VFMADD231SH",
"VFMADD231SS", "VFMADDCPH", "VFMADDCSH", "VFMADDPD", "VFMADDPS",
"VFMADDSD", "VFMADDSS", "VFMADDSUB132PD", "VFMADDSUB132PH", "VFMADDSUB132PS",
"VFMADDSUB213PD", "VFMADDSUB213PH", "VFMADDSUB213PS", "VFMADDSUB231PD",
"VFMADDSUB231PH", "VFMADDSUB231PS", "VFMADDSUBPD", "VFMADDSUBPS",
"VFMSUB132PD", "VFMSUB132PH", "VFMSUB132PS", "VFMSUB132SD", "VFMSUB132SH",
"VFMSUB132SS", "VFMSUB213PD", "VFMSUB213PH", "VFMSUB213PS", "VFMSUB213SD",
"VFMSUB213SH", "VFMSUB213SS", "VFMSUB231PD", "VFMSUB231PH", "VFMSUB231PS",
"VFMSUB231SD", "VFMSUB231SH", "VFMSUB231SS", "VFMSUBADD132PD",
"VFMSUBADD132PH", "VFMSUBADD132PS", "VFMSUBADD213PD", "VFMSUBADD213PH",
"VFMSUBADD213PS", "VFMSUBADD231PD", "VFMSUBADD231PH", "VFMSUBADD231PS",
"VFMSUBADDPD", "VFMSUBADDPS", "VFMSUBPD", "VFMSUBPS", "VFMSUBSD",
"VFMSUBSS", "VFMULCPH", "VFMULCSH", "VFNMADD132PD", "VFNMADD132PH",
"VFNMADD132PS", "VFNMADD132SD", "VFNMADD132SH", "VFNMADD132SS",
"VFNMADD213PD", "VFNMADD213PH", "VFNMADD213PS", "VFNMADD213SD",
"VFNMADD213SH", "VFNMADD213SS", "VFNMADD231PD", "VFNMADD231PH",
"VFNMADD231PS", "VFNMADD231SD", "VFNMADD231SH", "VFNMADD231SS",
"VFNMADDPD", "VFNMADDPS", "VFNMADDSD", "VFNMADDSS", "VFNMSUB132PD",
"VFNMSUB132PH", "VFNMSUB132PS", "VFNMSUB132SD", "VFNMSUB132SH",
"VFNMSUB132SS", "VFNMSUB213PD", "VFNMSUB213PH", "VFNMSUB213PS",
"VFNMSUB213SD", "VFNMSUB213SH", "VFNMSUB213SS", "VFNMSUB231PD",
"VFNMSUB231PH", "VFNMSUB231PS", "VFNMSUB231SD", "VFNMSUB231SH",
"VFNMSUB231SS", "VFNMSUBPD", "VFNMSUBPS", "VFNMSUBSD", "VFNMSUBSS",
"VFPCLASSPD", "VFPCLASSPH", "VFPCLASSPS", "VFPCLASSSD", "VFPCLASSSH",
"VFPCLASSSS", "VFRCZPD", "VFRCZPS", "VFRCZSD", "VFRCZSS", "VGATHERDPD",
"VGATHERDPS", "VGATHERPF0DPD", "VGATHERPF0DPS", "VGATHERPF0QPD",
"VGATHERPF0QPS", "VGATHERPF1DPD", "VGATHERPF1DPS", "VGATHERPF1QPD",
"VGATHERPF1QPS", "VGATHERQPD", "VGATHERQPS", "VGETEXPPD", "VGETEXPPH",
"VGETEXPPS", "VGETEXPSD", "VGETEXPSH", "VGETEXPSS", "VGETMANTPD",
"VGETMANTPH", "VGETMANTPS", "VGETMANTSD", "VGETMANTSH", "VGETMANTSS",
"VGF2P8AFFINEINVQB", "VGF2P8AFFINEQB", "VGF2P8MULB", "VHADDPD",
"VHADDPS", "VHSUBPD", "VHSUBPS", "VINSERTF128", "VINSERTF32X4",
"VINSERTF32X8", "VINSERTF64X2", "VINSERTF64X4", "VINSERTI128",
"VINSERTI32X4", "VINSERTI32X8", "VINSERTI64X2", "VINSERTI64X4",
"VINSERTPS", "VLDDQU", "VLDMXCSR", "VMASKMOVDQU", "VMASKMOVPD",
"VMASKMOVPS", "VMAXPD", "VMAXPH", "VMAXPS", "VMAXSD", "VMAXSH",
"VMAXSS", "VMCALL", "VMCLEAR", "VMFUNC", "VMGEXIT", "VMINPD",
"VMINPH", "VMINPS", "VMINSD", "VMINSH", "VMINSS", "VMLAUNCH",
"VMLOAD", "VMMCALL", "VMOVAPD", "VMOVAPS", "VMOVD", "VMOVDDUP",
"VMOVDQA", "VMOVDQA32", "VMOVDQA64", "VMOVDQU", "VMOVDQU16",
"VMOVDQU32", "VMOVDQU64", "VMOVDQU8", "VMOVHLPS", "VMOVHPD",
"VMOVHPS", "VMOVLHPS", "VMOVLPD", "VMOVLPS", "VMOVMSKPD", "VMOVMSKPS",
"VMOVNTDQ", "VMOVNTDQA", "VMOVNTPD", "VMOVNTPS", "VMOVQ", "VMOVSD",
"VMOVSH", "VMOVSHDUP", "VMOVSLDUP", "VMOVSS", "VMOVUPD", "VMOVUPS",
"VMOVW", "VMPSADBW", "VMPTRLD", "VMPTRST", "VMREAD", "VMRESUME",
"VMRUN", "VMSAVE", "VMULPD", "VMULPH", "VMULPS", "VMULSD", "VMULSH",
"VMULSS", "VMWRITE", "VMXOFF", "VMXON", "VORPD", "VORPS", "VP2INTERSECTD",
"VP2INTERSECTQ", "VP4DPWSSD", "VP4DPWSSDS", "VPABSB", "VPABSD",
"VPABSQ", "VPABSW", "VPACKSSDW", "VPACKSSWB", "VPACKUSDW", "VPACKUSWB",
"VPADDB", "VPADDD", "VPADDQ", "VPADDSB", "VPADDSW", "VPADDUSB",
"VPADDUSW", "VPADDW", "VPALIGNR", "VPAND", "VPANDD", "VPANDN",
"VPANDND", "VPANDNQ", "VPANDQ", "VPAVGB", "VPAVGW", "VPBLENDD",
"VPBLENDMB", "VPBLENDMD", "VPBLENDMQ", "VPBLENDMW", "VPBLENDVB",
"VPBLENDW", "VPBROADCASTB", "VPBROADCASTD", "VPBROADCASTMB2Q",
"VPBROADCASTMW2D", "VPBROADCASTQ", "VPBROADCASTW", "VPCLMULQDQ",
"VPCMOV", "VPCMPB", "VPCMPD", "VPCMPEQB", "VPCMPEQD", "VPCMPEQQ",
"VPCMPEQW", "VPCMPESTRI", "VPCMPESTRM", "VPCMPGTB", "VPCMPGTD",
"VPCMPGTQ", "VPCMPGTW", "VPCMPISTRI", "VPCMPISTRM", "VPCMPQ",
"VPCMPUB", "VPCMPUD", "VPCMPUQ", "VPCMPUW", "VPCMPW", "VPCOMB",
"VPCOMD", "VPCOMPRESSB", "VPCOMPRESSD", "VPCOMPRESSQ", "VPCOMPRESSW",
"VPCOMQ", "VPCOMUB", "VPCOMUD", "VPCOMUQ", "VPCOMUW", "VPCOMW",
"VPCONFLICTD", "VPCONFLICTQ", "VPDPBSSD", "VPDPBSSDS", "VPDPBSUD",
"VPDPBSUDS", "VPDPBUSD", "VPDPBUSDS", "VPDPBUUD", "VPDPBUUDS",
"VPDPWSSD", "VPDPWSSDS", "VPERM2F128", "VPERM2I128", "VPERMB",
"VPERMD", "VPERMI2B", "VPERMI2D", "VPERMI2PD", "VPERMI2PS", "VPERMI2Q",
"VPERMI2W", "VPERMIL2PD", "VPERMIL2PS", "VPERMILPD", "VPERMILPS",
"VPERMPD", "VPERMPS", "VPERMQ", "VPERMT2B", "VPERMT2D", "VPERMT2PD",
"VPERMT2PS", "VPERMT2Q", "VPERMT2W", "VPERMW", "VPEXPANDB", "VPEXPANDD",
"VPEXPANDQ", "VPEXPANDW", "VPEXTRB", "VPEXTRD", "VPEXTRQ", "VPEXTRW",
"VPGATHERDD", "VPGATHERDQ", "VPGATHERQD", "VPGATHERQQ", "VPHADDBD",
"VPHADDBQ", "VPHADDBW", "VPHADDD", "VPHADDDQ", "VPHADDSW", "VPHADDUBD",
"VPHADDUBQ", "VPHADDUBW", "VPHADDUDQ", "VPHADDUWD", "VPHADDUWQ",
"VPHADDW", "VPHADDWD", "VPHADDWQ", "VPHMINPOSUW", "VPHSUBBW",
"VPHSUBD", "VPHSUBDQ", "VPHSUBSW", "VPHSUBW", "VPHSUBWD", "VPINSRB",
"VPINSRD", "VPINSRQ", "VPINSRW", "VPLZCNTD", "VPLZCNTQ", "VPMACSDD",
"VPMACSDQH", "VPMACSDQL", "VPMACSSDD", "VPMACSSDQH", "VPMACSSDQL",
"VPMACSSWD", "VPMACSSWW", "VPMACSWD", "VPMACSWW", "VPMADCSSWD",
"VPMADCSWD", "VPMADD52HUQ", "VPMADD52LUQ", "VPMADDUBSW", "VPMADDWD",
"VPMASKMOVD", "VPMASKMOVQ", "VPMAXSB", "VPMAXSD", "VPMAXSQ",
"VPMAXSW", "VPMAXUB", "VPMAXUD", "VPMAXUQ", "VPMAXUW", "VPMINSB",
"VPMINSD", "VPMINSQ", "VPMINSW", "VPMINUB", "VPMINUD", "VPMINUQ",
"VPMINUW", "VPMOVB2M", "VPMOVD2M", "VPMOVDB", "VPMOVDW", "VPMOVM2B",
"VPMOVM2D", "VPMOVM2Q", "VPMOVM2W", "VPMOVMSKB", "VPMOVQ2M",
"VPMOVQB", "VPMOVQD", "VPMOVQW", "VPMOVSDB", "VPMOVSDW", "VPMOVSQB",
"VPMOVSQD", "VPMOVSQW", "VPMOVSWB", "VPMOVSXBD", "VPMOVSXBQ",
"VPMOVSXBW", "VPMOVSXDQ", "VPMOVSXWD", "VPMOVSXWQ", "VPMOVUSDB",
"VPMOVUSDW", "VPMOVUSQB", "VPMOVUSQD", "VPMOVUSQW", "VPMOVUSWB",
"VPMOVW2M", "VPMOVWB", "VPMOVZXBD", "VPMOVZXBQ", "VPMOVZXBW",
"VPMOVZXDQ", "VPMOVZXWD", "VPMOVZXWQ", "VPMULDQ", "VPMULHRSW",
"VPMULHUW", "VPMULHW", "VPMULLD", "VPMULLQ", "VPMULLW", "VPMULTISHIFTQB",
"VPMULUDQ", "VPOPCNTB", "VPOPCNTD", "VPOPCNTQ", "VPOPCNTW", "VPOR",
"VPORD", "VPORQ", "VPPERM", "VPROLD", "VPROLQ", "VPROLVD", "VPROLVQ",
"VPRORD", "VPRORQ", "VPRORVD", "VPRORVQ", "VPROTB", "VPROTD",
"VPROTQ", "VPROTW", "VPSADBW", "VPSCATTERDD", "VPSCATTERDQ",
"VPSCATTERQD", "VPSCATTERQQ", "VPSHAB", "VPSHAD", "VPSHAQ", "VPSHAW",
"VPSHLB", "VPSHLD", "VPSHLDD", "VPSHLDQ", "VPSHLDVD", "VPSHLDVQ",
"VPSHLDVW", "VPSHLDW", "VPSHLQ", "VPSHLW", "VPSHRDD", "VPSHRDQ",
"VPSHRDVD", "VPSHRDVQ", "VPSHRDVW", "VPSHRDW", "VPSHUFB", "VPSHUFBITQMB",
"VPSHUFD", "VPSHUFHW", "VPSHUFLW", "VPSIGNB", "VPSIGND", "VPSIGNW",
"VPSLLD", "VPSLLDQ", "VPSLLQ", "VPSLLVD", "VPSLLVQ", "VPSLLVW",
"VPSLLW", "VPSRAD", "VPSRAQ", "VPSRAVD", "VPSRAVQ", "VPSRAVW",
"VPSRAW", "VPSRLD", "VPSRLDQ", "VPSRLQ", "VPSRLVD", "VPSRLVQ",
"VPSRLVW", "VPSRLW", "VPSUBB", "VPSUBD", "VPSUBQ", "VPSUBSB",
"VPSUBSW", "VPSUBUSB", "VPSUBUSW", "VPSUBW", "VPTERNLOGD", "VPTERNLOGQ",
"VPTEST", "VPTESTMB", "VPTESTMD", "VPTESTMQ", "VPTESTMW", "VPTESTNMB",
"VPTESTNMD", "VPTESTNMQ", "VPTESTNMW", "VPUNPCKHBW", "VPUNPCKHDQ",
"VPUNPCKHQDQ", "VPUNPCKHWD", "VPUNPCKLBW", "VPUNPCKLDQ", "VPUNPCKLQDQ",
"VPUNPCKLWD", "VPXOR", "VPXORD", "VPXORQ", "VRANGEPD", "VRANGEPS",
"VRANGESD", "VRANGESS", "VRCP14PD", "VRCP14PS", "VRCP14SD", "VRCP14SS",
"VRCP28PD", "VRCP28PS", "VRCP28SD", "VRCP28SS", "VRCPPH", "VRCPPS",
"VRCPSH", "VRCPSS", "VREDUCEPD", "VREDUCEPH", "VREDUCEPS", "VREDUCESD",
"VREDUCESH", "VREDUCESS", "VRNDSCALEPD", "VRNDSCALEPH", "VRNDSCALEPS",
"VRNDSCALESD", "VRNDSCALESH", "VRNDSCALESS", "VROUNDPD", "VROUNDPS",
"VROUNDSD", "VROUNDSS", "VRSQRT14PD", "VRSQRT14PS", "VRSQRT14SD",
"VRSQRT14SS", "VRSQRT28PD", "VRSQRT28PS", "VRSQRT28SD", "VRSQRT28SS",
"VRSQRTPH", "VRSQRTPS", "VRSQRTSH", "VRSQRTSS", "VSCALEFPD",
"VSCALEFPH", "VSCALEFPS", "VSCALEFSD", "VSCALEFSH", "VSCALEFSS",
"VSCATTERDPD", "VSCATTERDPS", "VSCATTERPF0DPD", "VSCATTERPF0DPS",
"VSCATTERPF0QPD", "VSCATTERPF0QPS", "VSCATTERPF1DPD", "VSCATTERPF1DPS",
"VSCATTERPF1QPD", "VSCATTERPF1QPS", "VSCATTERQPD", "VSCATTERQPS",
"VSHUFF32X4", "VSHUFF64X2", "VSHUFI32X4", "VSHUFI64X2", "VSHUFPD",
"VSHUFPS", "VSQRTPD", "VSQRTPH", "VSQRTPS", "VSQRTSD", "VSQRTSH",
"VSQRTSS", "VSTMXCSR", "VSUBPD", "VSUBPH", "VSUBPS", "VSUBSD",
"VSUBSH", "VSUBSS", "VTESTPD", "VTESTPS", "VUCOMISD", "VUCOMISH",
"VUCOMISS", "VUNPCKHPD", "VUNPCKHPS", "VUNPCKLPD", "VUNPCKLPS",
"VXORPD", "VXORPS", "VZEROALL", "VZEROUPPER", "WAIT", "WBINVD",
"WBNOINVD", "WRFSBASE", "WRGSBASE", "WRMSR", "WRMSRLIST", "WRMSRNS",
"WRPKRU", "WRSHR", "WRSSD", "WRSSQ", "WRUSSD", "WRUSSQ", "XABORT",
"XADD", "XBEGIN", "XCHG", "XCRYPTCBC", "XCRYPTCFB", "XCRYPTCTR",
"XCRYPTECB", "XCRYPTOFB", "XEND", "XGETBV", "XLATB", "XOR", "XORPD",
"XORPS", "XRESLDTRK", "XRSTOR", "XRSTOR64", "XRSTORS", "XRSTORS64",
"XSAVE", "XSAVE64", "XSAVEC", "XSAVEC64", "XSAVEOPT", "XSAVEOPT64",
"XSAVES", "XSAVES64", "XSETBV", "XSHA1", "XSHA256", "XSTORE",
"XSUSLDTRK", "XTEST",
};
#endif

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2020 Bitdefender
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ND_CRT_H
#define ND_CRT_H
#include "../../inc/disasmtypes.h"
#ifndef UNREFERENCED_PARAMETER
#define UNREFERENCED_PARAMETER(P) ((void)(P))
#endif
// By default, an integrator is expected to provide nd_vsnprintf_s and nd_strcat_s.
// bddisasm needs both for NdToText, while bdshemu needs nd_vsnprintf_s for emulation tracing.
// If BDDISASM_NO_FORMAT is defined at compile time these requirements are removed. Instruction formatting will no
// longer be available in bddisasm and emulation tracing will no longer be available in bdshemu.
#ifndef BDDISASM_NO_FORMAT
#include <stdarg.h>
extern int nd_vsnprintf_s(
char *buffer,
ND_SIZET sizeOfBuffer,
ND_SIZET count,
const char *format,
va_list argptr
);
char *
nd_strcat_s(
char *dst,
ND_SIZET dst_size,
const char *src
);
#endif // !BDDISASM_NO_FORMAT
// Declared here only. Expecting it to be defined in the integrator.
extern void *nd_memset(void *s, int c, ND_SIZET n);
#define nd_memzero(Dest, Size) nd_memset((Dest), 0, (Size))
// Handy macros.
#define RET_EQ(x, y, z) if ((x) == (y)) { return (z); }
#define RET_GE(x, y, z) if ((x) >= (y)) { return (z); }
#define RET_GT(x, y, z) if ((x) > (y)) { return (z); }
#endif // ND_CRT_H

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2020 Bitdefender
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef PREFIXES_H
#define PREFIXES_H
#define ND_PREF_CODE_NONE 0
#define ND_PREF_CODE_STANDARD 1
#define ND_PREF_CODE_EX 2
#define ND_PREF_CODE_REX 3
static const ND_UINT8 gPrefixesMap[256] =
{
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, // 2
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, // 3
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 4
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 5
0, 0, 2, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, // 6
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 7
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, // 8
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // A
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // B
0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // C
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // D
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // E
1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // F
};
#endif // PREFIXES_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More