Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
dude719 committed Nov 3, 2016
1 parent 17e326c commit f6de109
Show file tree
Hide file tree
Showing 111 changed files with 40,500 additions and 0 deletions.
39 changes: 39 additions & 0 deletions UefiApplication/UefiApplication.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{79D78FD5-8F41-442F-944E-81774DC9DF39}</ProjectGuid>
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(SolutionDir)\bootkit.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
<ItemDefinitionGroup>
<Link>
<AdditionalDependencies>UefiApplicationEntryPoint.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>EFI Application</SubSystem>
</Link>
<PostBuildEvent>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy /Y "$(TargetDir)$(TargetName).efi" "G:\efi\boot\bootx64.efi"</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy /Y "$(TargetDir)$(TargetName).efi" "G:\efi\boot\bootx64.efi"</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\edk2\EdkCompatibilityPkg\Foundation\Efi\Protocol\SimpleFileSystem\SimpleFileSystem.c" />
<ClCompile Include="imageldr.c" />
<ClCompile Include="main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="imageldr.h" />
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions UefiApplication/UefiApplication.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="imageldr.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="main.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\edk2\EdkCompatibilityPkg\Foundation\Efi\Protocol\SimpleFileSystem\SimpleFileSystem.c">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="src">
<UniqueIdentifier>{ec1e3a7f-36df-44fc-bc0a-f8c440f0ca09}</UniqueIdentifier>
</Filter>
<Filter Include="include">
<UniqueIdentifier>{8d73de3e-b0e4-4e27-85bd-0f93f438fbaf}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="imageldr.h">
<Filter>include</Filter>
</ClInclude>
</ItemGroup>
</Project>
23 changes: 23 additions & 0 deletions UefiApplication/imageldr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "imageldr.h"

#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/LoadedImage.h>

EFI_STATUS ImageLoad( IN EFI_HANDLE ParentHandle, IN EFI_DEVICE_PATH* DevicePath, OUT EFI_HANDLE* ImageHandle )
{
EFI_STATUS status = EFI_NOT_FOUND;
// Load image in memory
status = gBS->LoadImage( TRUE, ParentHandle, DevicePath, NULL, 0, ImageHandle );
if (status != EFI_SUCCESS)
{
Print( L"[!] LoadImage error = %X\r\n", status );
}

return status;
}

EFI_STATUS ImageStart( IN EFI_HANDLE ImageHandle )
{
return gBS->StartImage( ImageHandle, (UINTN *)NULL, (CHAR16 **)NULL );
}
7 changes: 7 additions & 0 deletions UefiApplication/imageldr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <Protocol/DevicePath.h>

EFI_STATUS ImageLoad( IN EFI_HANDLE ParentHandle, IN EFI_DEVICE_PATH* DevicePath, OUT EFI_HANDLE* ImageHandle );

EFI_STATUS ImageStart( IN EFI_HANDLE ImageHandle );
147 changes: 147 additions & 0 deletions UefiApplication/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
//
// Basic UEFI Libraries
//
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>

//
// Boot and Runtime Services
//
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/DevicePathLib.h>

//
// Protocols
//
#include <Protocol/SimpleFileSystem.h>

//
// Custom Driver Protocol
//
#include "../UefiDriver/drvproto.h"
EFI_GUID gEfiSampleDriverProtocolGuid = EFI_RUNTIME_DRIVER_PROTOCOL_GUID;

//
// My includes
//
#include "imageldr.h"

//
// Globals
//

// We run on any UEFI Specification
extern CONST UINT32 _gUefiDriverRevision = 0;
// Our name
CHAR8 *gEfiCallerBaseName = "UefiApplication";
// Windows Boot Manager x64 image path
static CHAR16 *gRuntimeDriverImagePath = L"\\EFI\\Boot\\rtdriver.efi";

//
// Try to find gWindowsBootX64ImagePath by browsing each device
//
EFI_STATUS LocateFile( IN CHAR16* ImagePath, OUT EFI_DEVICE_PATH** DevicePath )
{
EFI_FILE_IO_INTERFACE *ioDevice;
EFI_FILE_HANDLE handleRoots, bootFile;
EFI_HANDLE* handleArray;
UINTN nbHandles, i;
EFI_STATUS efistatus;

*DevicePath = (EFI_DEVICE_PATH *)NULL;
efistatus = gBS->LocateHandleBuffer( ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &nbHandles, &handleArray );
if (EFI_ERROR( efistatus ))
return efistatus;

Print( L"\r\nNumber of UEFI Filesystem Devices: %d\r\n", nbHandles );

for (i = 0; i < nbHandles; i++)
{
efistatus = gBS->HandleProtocol( handleArray[i], &gEfiSimpleFileSystemProtocolGuid, &ioDevice );
if (efistatus != EFI_SUCCESS)
continue;

efistatus = ioDevice->OpenVolume( ioDevice, &handleRoots );
if (EFI_ERROR( efistatus ))
continue;

efistatus = handleRoots->Open( handleRoots, &bootFile, ImagePath, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY );
if (!EFI_ERROR( efistatus ))
{
handleRoots->Close( bootFile );
*DevicePath = FileDevicePath( handleArray[i], ImagePath );
Print( L"\r\nFound file at \'%s\'\r\n", ConvertDevicePathToText( *DevicePath, TRUE, TRUE ) );
break;
}
}

return efistatus;
}

EFI_STATUS EFIAPI UefiMain( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE* SystemTable )
{
EFI_STATUS efiStatus;
EFI_RUNTIME_DRIVER_PROTOCOL* RuntimeProtocol;
EFI_DEVICE_PATH* RuntimeDriverDevicePath = NULL;
EFI_HANDLE RuntimeDriverHandle = NULL;

//
// Print stuff out
//
Print( L"Hello World! My handle is %lx and System Table is at %p\n", ImageHandle, SystemTable );

//
// Locate the runtime driver
//
efiStatus = LocateFile( gRuntimeDriverImagePath, &RuntimeDriverDevicePath );
if (EFI_ERROR( efiStatus ))
goto Exit;

//
// Load Runtime Driver into memory
//
efiStatus = ImageLoad( ImageHandle, RuntimeDriverDevicePath, &RuntimeDriverHandle );
if (EFI_ERROR( efiStatus ))
goto Exit;

//
// Transfer executon to the Runtime Driver
//
efiStatus = ImageStart( RuntimeDriverHandle );
if (EFI_ERROR( efiStatus ))
goto Exit;

//
// Check if the runtime driver is loaded
//
efiStatus = gBS->LocateProtocol( &gEfiSampleDriverProtocolGuid, NULL, &RuntimeProtocol );
if (EFI_ERROR( efiStatus ))
goto Exit;

//
// Print the value and exit
//
Print( L"Runtime driver is loaded: %lx\n", RuntimeProtocol->Value );
efiStatus = EFI_SUCCESS;

Exit:
if (efiStatus != EFI_SUCCESS)
{
ErrorPrint( L"UEFI Runtime Driver Loader failed with status: %lx\r\n", efiStatus );
}

return efiStatus;
}



EFI_STATUS EFIAPI UefiUnload( IN EFI_HANDLE ImageHandle )
{
//
// This code should be compiled out and never called
//
ASSERT( FALSE );
}
78 changes: 78 additions & 0 deletions UefiDriver/UefiDriver.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{DF325AB7-67A6-473E-93FF-16955AFBC063}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<PlatformToolset>v140</PlatformToolset>
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(SolutionDir)\bootkit.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>$(EDK_PATH)\MdePkg\Include;$(EDK_PATH)\MdePkg\Include\X64;$(IncludePath)</IncludePath>
</PropertyGroup>
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
</ImportGroup>
<ItemDefinitionGroup>
<Link>
<AdditionalDependencies>UefiDriverEntryPoint.lib;BaseCryptLib.lib;IntrinsicLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem Condition="'$(Configuration)|$(Platform)'=='Release|x64'">EFI Runtime</SubSystem>
</Link>
<PostBuildEvent>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy /Y "$(TargetDir)$(TargetName).efi" "G:\efi\boot\rtdriver.efi"</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy /Y "$(TargetDir)$(TargetName).efi" "G:\efi\boot\rtdriver.efi"</Message>
</PostBuildEvent>
<ClCompile>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">__UD_STANDALONE__;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4706;4055;4054</DisableSpecificWarnings>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\edk2\EdkCompatibilityPkg\Foundation\Efi\Protocol\SimpleFileSystem\SimpleFileSystem.c" />
<ClCompile Include="drvname.c" />
<ClCompile Include="drvpnp.c" />
<ClCompile Include="drvmain.c" />
<ClCompile Include="imageldr.c" />
<ClCompile Include="pe.c" />
<ClCompile Include="udis86\libudis86\decode.c" />
<ClCompile Include="udis86\libudis86\itab.c" />
<ClCompile Include="udis86\libudis86\syn-att.c" />
<ClCompile Include="udis86\libudis86\syn-intel.c" />
<ClCompile Include="udis86\libudis86\syn.c" />
<ClCompile Include="udis86\libudis86\udis86.c" />
<ClCompile Include="utils.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="drv.h" />
<ClInclude Include="drvproto.h" />
<ClInclude Include="imageldr.h" />
<ClInclude Include="pe.h" />
<ClInclude Include="pestructs.h" />
<ClInclude Include="udis86\libudis86\decode.h" />
<ClInclude Include="udis86\libudis86\extern.h" />
<ClInclude Include="udis86\libudis86\itab.h" />
<ClInclude Include="udis86\libudis86\syn.h" />
<ClInclude Include="udis86\libudis86\types.h" />
<ClInclude Include="udis86\libudis86\udint.h" />
<ClInclude Include="udis86\udis86.h" />
<ClInclude Include="utils.h" />
</ItemGroup>
<ItemGroup>
<MASM Include="hook.asm" />
</ItemGroup>
</Project>
Loading

0 comments on commit f6de109

Please sign in to comment.