diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..1ff0c42
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,63 @@
+###############################################################################
+# Set default behavior to automatically normalize line endings.
+###############################################################################
+* text=auto
+
+###############################################################################
+# Set default behavior for command prompt diff.
+#
+# This is need for earlier builds of msysgit that does not have it on by
+# default for csharp files.
+# Note: This is only used by command line
+###############################################################################
+#*.cs diff=csharp
+
+###############################################################################
+# Set the merge driver for project and solution files
+#
+# Merging from the command prompt will add diff markers to the files if there
+# are conflicts (Merging from VS is not affected by the settings below, in VS
+# the diff markers are never inserted). Diff markers may cause the following
+# file extensions to fail to load in VS. An alternative would be to treat
+# these files as binary and thus will always conflict and require user
+# intervention with every merge. To do so, just uncomment the entries below
+###############################################################################
+#*.sln merge=binary
+#*.csproj merge=binary
+#*.vbproj merge=binary
+#*.vcxproj merge=binary
+#*.vcproj merge=binary
+#*.dbproj merge=binary
+#*.fsproj merge=binary
+#*.lsproj merge=binary
+#*.wixproj merge=binary
+#*.modelproj merge=binary
+#*.sqlproj merge=binary
+#*.wwaproj merge=binary
+
+###############################################################################
+# behavior for image files
+#
+# image files are treated as binary by default.
+###############################################################################
+#*.jpg binary
+#*.png binary
+#*.gif binary
+
+###############################################################################
+# diff behavior for common document formats
+#
+# Convert binary document formats to text before diffing them. This feature
+# is only available from the command line. Turn it on by uncommenting the
+# entries below.
+###############################################################################
+#*.doc diff=astextplain
+#*.DOC diff=astextplain
+#*.docx diff=astextplain
+#*.DOCX diff=astextplain
+#*.dot diff=astextplain
+#*.DOT diff=astextplain
+#*.pdf diff=astextplain
+#*.PDF diff=astextplain
+#*.rtf diff=astextplain
+#*.RTF diff=astextplain
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..302db74
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,366 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Ww][Ii][Nn]32/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Oo]ut/
+[Ll]og/
+[Ll]ogs/
+
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUnit
+*.VisualState.xml
+TestResult.xml
+nunit-*.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# ASP.NET Scaffolding
+ScaffoldingReadMe.txt
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Coverlet is a free, cross platform Code Coverage Tool
+coverage*.json
+coverage*.xml
+coverage*.info
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# NuGet Symbol Packages
+*.snupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+# Ionide (cross platform F# VS Code tools) working folder
+.ionide/
+
+# Fody - auto-generated XML schema
+FodyWeavers.xsd
+
+Drive/NvVars
+Drive/EFI/BOOT/BOOTX64.efi
\ No newline at end of file
diff --git a/BootTo.NET.sln b/BootTo.NET.sln
new file mode 100644
index 0000000..58c344f
--- /dev/null
+++ b/BootTo.NET.sln
@@ -0,0 +1,40 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.2.32526.322
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{86AF0AE0-BF6E-4532-8E9E-7F6D8B7DE644}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "解决方案项", "解决方案项", "{F53AC2EB-6875-4964-AA83-915BB7862F1B}"
+ ProjectSection(SolutionItems) = preProject
+ Run.bat = Run.bat
+ EndProjectSection
+EndProject
+Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "CoreLib", "CoreLib\CoreLib.shproj", "{09702D3B-0A10-4653-9C75-12989E41B246}"
+EndProject
+Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "uefi-cs", "uefi-cs\uefi-cs.shproj", "{03406847-825A-4359-8159-E1769BEE543F}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {86AF0AE0-BF6E-4532-8E9E-7F6D8B7DE644}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {86AF0AE0-BF6E-4532-8E9E-7F6D8B7DE644}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {86AF0AE0-BF6E-4532-8E9E-7F6D8B7DE644}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {86AF0AE0-BF6E-4532-8E9E-7F6D8B7DE644}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {18B9E75A-70E1-49A9-9624-1DB382AB2720}
+ EndGlobalSection
+ GlobalSection(SharedMSBuildProjectFiles) = preSolution
+ uefi-cs\uefi-cs.projitems*{03406847-825a-4359-8159-e1769bee543f}*SharedItemsImports = 13
+ CoreLib\CoreLib.projitems*{09702d3b-0a10-4653-9c75-12989e41b246}*SharedItemsImports = 13
+ CoreLib\CoreLib.projitems*{86af0ae0-bf6e-4532-8e9e-7f6d8b7de644}*SharedItemsImports = 5
+ uefi-cs\uefi-cs.projitems*{86af0ae0-bf6e-4532-8e9e-7f6d8b7de644}*SharedItemsImports = 5
+ EndGlobalSection
+EndGlobal
diff --git a/ConsoleApp1/ConsoleApp1.csproj b/ConsoleApp1/ConsoleApp1.csproj
new file mode 100644
index 0000000..c7891a3
--- /dev/null
+++ b/ConsoleApp1/ConsoleApp1.csproj
@@ -0,0 +1,53 @@
+
+
+
+ Exe
+ net6.0
+ true
+
+ true
+ true
+ v4.0.30319
+ false
+ false
+
+ ConsoleApp1
+ EfiMain
+
+ EFI_APPLICATION
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ConsoleApp1/Program.cs b/ConsoleApp1/Program.cs
new file mode 100644
index 0000000..abcd112
--- /dev/null
+++ b/ConsoleApp1/Program.cs
@@ -0,0 +1,101 @@
+global using static efi;
+using System;
+using System.IO;
+using System.Net.Sockets;
+
+unsafe class Program
+{
+ static void Main() { }
+
+ //QEMU corrupts BOOTX64.efi, which is probably why it doesn't work on real hardware, please notice!
+ //If you want to running this on real hardware, please press ctrl+b to rebuild this repo and copy
+ //files from Disk folder to your usb drive, of course you have to format your usb drive to fat32 and
+ //use GUID partition table first
+ [System.Runtime.RuntimeExport("EfiMain")]
+ static EFI_STATUS EfiMain(EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE* systemTable)
+ {
+ InitializeLib(imageHandle, systemTable);
+
+ //Disable watchdog timer
+ gBS->SetWatchdogTimer(0, 0, 0, null);
+
+ Console.Clear();
+ Console.WriteLine("Hello world from \"BootTo.NET project\"!");
+
+#if false
+ #region File Test
+ byte[] buffer = File.ReadAllBytes("Test.txt");
+ Console.Write("Content of Test.txt is: ");
+ for(int i = 0; i < buffer.Length; i++)
+ {
+ Console.Write((char)buffer[i]);
+ }
+ #endregion
+#endif
+
+#if true
+ #region GOP Test
+ EFI_GRAPHICS_OUTPUT_PROTOCOL* gop;
+ gBS->LocateProtocol(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, null, (void**)&gop);
+ uint numModes = gop->Mode->MaxMode;
+ ulong sizeofMode = 0;
+ for (uint u = 0; u < numModes; u++)
+ {
+ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION* modeinfo;
+ gop->QueryMode(gop, u, &sizeofMode, &modeinfo);
+ Console.Write("GOP Mode ");
+ Console.Write(Convert.ToString(u, 10));
+ Console.Write(":");
+ Console.Write(Convert.ToString(modeinfo->HorizontalResolution, 10));
+ Console.Write("x");
+ Console.WriteLine(Convert.ToString(modeinfo->VerticalResolution, 10));
+ }
+ //gop->SetMode(gop,7);
+ Console.WriteLine("Press any key to continue...");
+ Console.ReadKey();
+ Console.Clear();
+ uint* fb = (uint*)gop->Mode->FrameBufferBase.Value;
+ for (uint w = 0; w < gop->Mode->Info->HorizontalResolution; w++)
+ {
+ for (uint h = 0; h < gop->Mode->Info->VerticalResolution; h++)
+ {
+ fb[h * gop->Mode->Info->HorizontalResolution + w] = 0xFFFF0000;
+ }
+ }
+ Console.WriteLine("The background should be red when you see this message");
+ #endregion
+#endif
+
+#if false
+ #region Socket Test
+ EFI_IPv4_ADDRESS address = new EFI_IPv4_ADDRESS();
+ address.Addr[0] = 192;
+ address.Addr[1] = 168;
+ address.Addr[2] = 137;
+ address.Addr[3] = 1;
+
+ Socket socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
+ socket.Connect(address, 54188);
+ socket.Send(GetBytes("Hello world from BootTo.NET project!"));
+ Console.WriteLine("Try receive 64bytes from server");
+ byte[] buffer = new byte[64];
+ socket.Receive(buffer);
+ Console.Write("Buffer received: ");
+ for(int i = 0; i < buffer.Length; i++)
+ {
+ Console.Write((char)buffer[i]);
+ }
+ socket.Close();
+ #endregion
+#endif
+
+ for (; ; );
+ }
+
+ public static byte[] GetBytes(string s)
+ {
+ byte[] buffer = new byte[s.Length];
+ for (int i = 0; i < s.Length; i++) buffer[i] = (byte)s[i];
+ return buffer;
+ }
+}
diff --git a/ConsoleApp1/Properties/launchSettings.json b/ConsoleApp1/Properties/launchSettings.json
new file mode 100644
index 0000000..4578564
--- /dev/null
+++ b/ConsoleApp1/Properties/launchSettings.json
@@ -0,0 +1,10 @@
+{
+ "profiles": {
+ "Run.bat": {
+ "commandName": "Executable",
+ "executablePath": "cmd.exe",
+ "commandLineArgs": "/c Run.bat",
+ "workingDirectory": "../"
+ }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp1/System/Net/Sockets/ProtocolType.cs b/ConsoleApp1/System/Net/Sockets/ProtocolType.cs
new file mode 100644
index 0000000..456464c
--- /dev/null
+++ b/ConsoleApp1/System/Net/Sockets/ProtocolType.cs
@@ -0,0 +1,31 @@
+namespace System.Net.Sockets
+{
+ public enum ProtocolType
+ {
+ Unknown = -1,
+ IP = 0,
+ IPv6HopByHopOptions = 0,
+ Unspecified = 0,
+ Icmp = 1,
+ Igmp = 2,
+ Ggp = 3,
+ IPv4 = 4,
+ Tcp = 6,
+ Pup = 12,
+ Udp = 17,
+ Idp = 22,
+ IPv6 = 41,
+ IPv6RoutingHeader = 43,
+ IPv6FragmentHeader = 44,
+ IPSecEncapsulatingSecurityPayload = 50,
+ IPSecAuthenticationHeader = 51,
+ IcmpV6 = 58,
+ IPv6NoNextHeader = 59,
+ IPv6DestinationOptions = 60,
+ ND = 77,
+ Raw = 255,
+ Ipx = 1000,
+ Spx = 1256,
+ SpxII = 1257
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp1/System/Net/Sockets/Socket.cs b/ConsoleApp1/System/Net/Sockets/Socket.cs
new file mode 100644
index 0000000..fe1ad61
--- /dev/null
+++ b/ConsoleApp1/System/Net/Sockets/Socket.cs
@@ -0,0 +1,227 @@
+using static efi;
+using System.Runtime.InteropServices;
+
+namespace System.Net.Sockets
+{
+ public unsafe class Socket
+ {
+ EFI_TCP4* tcp;
+ EFI_TCP4_RECEIVE_DATA receiveData;
+ EFI_TCP4_TRANSMIT_DATA transmitData;
+ EFI_TCP4_IO_TOKEN receiveToken;
+ EFI_TCP4_IO_TOKEN transmitToken;
+ EFI_TCP4_CONFIG_DATA configuration;
+ bool receiveDone;
+ bool transmitDone;
+
+ public Socket(SocketType socketType, ProtocolType protocolType)
+ {
+ if (socketType != SocketType.Stream || protocolType != ProtocolType.Tcp)
+ {
+ Console.WriteLine("Unsupported socket type!");
+ for (; ; );
+ }
+ }
+
+ public void Connect(EFI_IPv4_ADDRESS address, ushort port)
+ {
+ EFI_STATUS sts = EFI_SUCCESS;
+
+ configuration = new EFI_TCP4_CONFIG_DATA();
+ configuration.TimeToLive = 188;
+ configuration.AccessPoint.UseDefaultAddress = true;
+
+ configuration.AccessPoint.ActiveFlag = true;
+ configuration.AccessPoint.RemotePort = port;
+ configuration.AccessPoint.RemoteAddress = address;
+
+ ulong numdevices;
+ EFI_HANDLE* devices;
+
+ sts = gBS->LocateHandleBuffer(
+ EFI_LOCATE_SEARCH_TYPE.ByProtocol,
+ EFI_TCP4_SERVICE_BINDING_PROTOCOL,
+ null,
+ &numdevices,
+ &devices
+ );
+
+ if(sts == EFI_NOT_FOUND)
+ {
+ Console.WriteLine("Your UEFI firmware does not support TCP!");
+ Console.WriteLine("Make sure you have \"Network Stack\" enabled on your BIOS!");
+ for (; ; );
+ }
+
+ EFI_HANDLE dev = devices[0];
+
+ EFI_SERVICE_BINDING* bs;
+
+ gBS->OpenProtocol(
+ dev,
+ EFI_TCP4_SERVICE_BINDING_PROTOCOL,
+ (void**)&bs,
+ gImageHandle,
+ default,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+
+ EFI_HANDLE tcphandle;
+
+ bs->CreateChild(bs, &tcphandle);
+
+ fixed (EFI_TCP4** pcli = &tcp)
+ gBS->OpenProtocol(
+ tcphandle,
+ EFI_TCP4_PROTOCOL,
+ (void**)pcli,
+ gImageHandle,
+ default,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+
+ receiveData = new EFI_TCP4_RECEIVE_DATA();
+ transmitData = new EFI_TCP4_TRANSMIT_DATA();
+ receiveToken = new EFI_TCP4_IO_TOKEN();
+ transmitToken = new EFI_TCP4_IO_TOKEN();
+
+ receiveData.FragmentCount = 1;
+
+ fixed (EFI_TCP4_RECEIVE_DATA* prx = &receiveData)
+ receiveToken.Packet_RxData = prx;
+
+ transmitData.FragmentCount = 1;
+ transmitData.Push = true;
+ fixed (EFI_TCP4_TRANSMIT_DATA* ptx = &transmitData)
+ transmitToken.Packet_TxData = ptx;
+
+ fixed (EFI_TCP4_CONFIG_DATA* pcfg = &configuration)
+ sts = tcp->Configure(tcp, pcfg);
+
+ EFI_IP4_MODE_DATA mode = new EFI_IP4_MODE_DATA();
+
+ if (sts == EFI_NO_MAPPING)
+ {
+ Console.WriteLine("Trying to get an IP from DHCP server...");
+
+ do
+ {
+ tcp->GetModeData(tcp, null, null, &mode, null, null);
+ } while (!mode.IsConfigured);
+ fixed (EFI_TCP4_CONFIG_DATA* pcfg = &configuration)
+ tcp->Configure(tcp, pcfg);
+
+ Console.Write("Your IP is: ");
+ Console.Write(Convert.ToString(mode.ConfigData.StationAddress.Addr[0], 10));
+ Console.Write('.');
+ Console.Write(Convert.ToString(mode.ConfigData.StationAddress.Addr[1], 10));
+ Console.Write('.');
+ Console.Write(Convert.ToString(mode.ConfigData.StationAddress.Addr[2], 10));
+ Console.Write('.');
+ Console.Write(Convert.ToString(mode.ConfigData.StationAddress.Addr[3], 10));
+ Console.WriteLine();
+ }
+
+ EFI_TCP4_CONNECTION_TOKEN conn;
+
+ fixed (bool* preceiveDone = &receiveDone)
+ fixed (EFI_TCP4_IO_TOKEN* preceiveToken = &receiveToken)
+ gBS->CreateEvent(
+ EVT_NOTIFY_SIGNAL,
+ TPL_NOTIFY,
+ &OnEvent,
+ preceiveDone,
+ &preceiveToken->CompletionToken.Event
+ );
+
+ fixed (bool* ptransmitDone = &transmitDone)
+ fixed (EFI_TCP4_IO_TOKEN* ptransmitToken = &transmitToken)
+ gBS->CreateEvent(
+ EVT_NOTIFY_SIGNAL,
+ TPL_NOTIFY,
+ &OnEvent,
+ ptransmitDone,
+ &ptransmitToken->CompletionToken.Event
+ );
+
+ bool isConnected = false;
+
+ gBS->CreateEvent(
+ EVT_NOTIFY_SIGNAL,
+ TPL_NOTIFY,
+ &OnEvent,
+ &isConnected,
+ &conn.CompletionToken.Event
+ );
+
+ tcp->Connect(tcp, &conn);
+
+ while (!isConnected) ;
+
+ gBS->CloseEvent(conn.CompletionToken.Event);
+ }
+
+ public void Send(byte[] buffer)
+ {
+ transmitDone = false;
+
+ transmitData.DataLength = (uint)buffer.Length;
+ transmitData.FragmentCount = 1;
+ transmitData.FragmentTable.FragmentLength = (uint)buffer.Length;
+ fixed (byte* pbuf = buffer)
+ transmitData.FragmentTable.FragmentBuffer = pbuf;
+
+ fixed (EFI_TCP4_IO_TOKEN* ptransmitToken = &transmitToken)
+ tcp->Transmit(tcp, ptransmitToken);
+
+ while (!transmitDone) ;
+ }
+
+ public int Receive(byte[] buffer)
+ {
+ receiveDone = false;
+
+ receiveData.DataLength = (uint)buffer.Length;
+ receiveData.FragmentTable.FragmentLength = (uint)buffer.Length;
+ fixed (byte* pbuf = buffer)
+ receiveData.FragmentTable.FragmentBuffer = pbuf;
+
+ fixed (EFI_TCP4_IO_TOKEN* preceiveToken = &receiveToken)
+ tcp->Receive(tcp, preceiveToken);
+
+ while (!receiveDone) tcp->Poll(tcp);
+
+ return (int)receiveData.FragmentTable.FragmentLength;
+ }
+
+ [UnmanagedCallersOnly]
+ public static void OnEvent(EFI_EVENT e, void* ctx)
+ {
+ if (ctx != null)
+ {
+ *(bool*)ctx = true;
+ }
+ }
+
+ internal void Close()
+ {
+ bool isClosed = false;
+ EFI_TCP4_CLOSE_TOKEN closeToken;
+ gBS->CreateEvent(
+ EVT_NOTIFY_SIGNAL,
+ TPL_NOTIFY,
+ &OnEvent,
+ &isClosed,
+ &closeToken.CompletionToken.Event
+ );
+
+ tcp->Close(tcp, &closeToken);
+
+ while (!isClosed) ;
+
+ gBS->CloseEvent(receiveToken.CompletionToken.Event);
+ gBS->CloseEvent(transmitToken.CompletionToken.Event);
+ gBS->CloseEvent(closeToken.CompletionToken.Event);
+ }
+ }
+}
diff --git a/ConsoleApp1/System/Net/Sockets/SocketType.cs b/ConsoleApp1/System/Net/Sockets/SocketType.cs
new file mode 100644
index 0000000..b7d86ab
--- /dev/null
+++ b/ConsoleApp1/System/Net/Sockets/SocketType.cs
@@ -0,0 +1,12 @@
+namespace System.Net.Sockets
+{
+ public enum SocketType
+ {
+ Unknown = -1,
+ Stream = 1,
+ Dgram = 2,
+ Raw = 3,
+ Rdm = 4,
+ Seqpacket = 5
+ }
+}
diff --git a/ConsoleApp1/efi.cs b/ConsoleApp1/efi.cs
new file mode 100644
index 0000000..0e8a7b6
--- /dev/null
+++ b/ConsoleApp1/efi.cs
@@ -0,0 +1,240 @@
+using Internal.Runtime.CompilerHelpers;
+using System;
+using System.Runtime;
+
+public unsafe partial class efi
+{
+ static IntPtr _ST;
+ static IntPtr _BS;
+ static IntPtr _RT;
+
+ public static EFI_SYSTEM_TABLE* gST => (EFI_SYSTEM_TABLE*)_ST;
+ public static EFI_BOOT_SERVICES* gBS => (EFI_BOOT_SERVICES*)_BS;
+ public static EFI_RUNTIME_SERVICES* gRT => (EFI_RUNTIME_SERVICES*)_RT;
+
+ public static EFI_HANDLE gImageHandle;
+
+ public static void InitializeLib(EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE* systemTable)
+ {
+ efi._ST = (IntPtr)systemTable;
+ efi._BS = (IntPtr)systemTable->BootServices;
+ efi._RT = (IntPtr)systemTable->RuntimeServices;
+ efi.gImageHandle = imageHandle;
+
+ InitializeGuid();
+
+ EFI_LOADED_IMAGE_PROTOCOL* loadedimage = null;
+ gBS->HandleProtocol(gImageHandle, EFI_LOADED_IMAGE_PROTOCOL_GUID, (void**)&loadedimage);
+ long ImageBase = (long)loadedimage->ImageBase;
+ DOSHeader* doshdr = (DOSHeader*)ImageBase;
+ NtHeaders64* nthdr = (NtHeaders64*)(ImageBase + doshdr->e_lfanew);
+ SectionHeader* sections = ((SectionHeader*)(ImageBase + doshdr->e_lfanew + sizeof(NtHeaders64)));
+ IntPtr moduleSec = IntPtr.Zero;
+ for (int i = 0; i < nthdr->FileHeader.NumberOfSections; i++)
+ {
+ if (*(ulong*)sections[i].Name == 0x73656C75646F6D2E) moduleSec = (IntPtr)(ImageBase + sections[i].VirtualAddress);
+ }
+ StartupCodeHelpers.InitializeModules(moduleSec);
+ }
+
+ public static EFI_GUID EFI_GLOBAL_VARIABLE;
+ public static EFI_GUID MPS_TABLE_GUID;
+ public static EFI_GUID ACPI_TABLE_GUID;
+ public static EFI_GUID ACPI_20_TABLE_GUID;
+ public static EFI_GUID SMBIOS_TABLE_GUID;
+ public static EFI_GUID SMBIOS3_TABLE_GUID;
+ public static EFI_GUID SAL_SYSTEM_TABLE_GUID;
+ public static EFI_GUID EFI_DTB_TABLE_GUID;
+ public static EFI_GUID EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID;
+ public static EFI_GUID EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID;
+ public static EFI_GUID EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID;
+ public static EFI_GUID EFI_DEBUG_IMAGE_INFO_TABLE_GUID;
+ public static EFI_GUID EFI_DEBUG_SUPPORT_PROTOCOL_GUID;
+ public static EFI_GUID UNKNOWN_DEVICE_GUID;
+ public static EFI_GUID EFI_PC_ANSI_GUID;
+ public static EFI_GUID EFI_VT_100_GUID;
+ public static EFI_GUID EFI_VT_100_PLUS_GUID;
+ public static EFI_GUID EFI_VT_UTF8_GUID;
+ public static EFI_GUID EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID;
+ public static EFI_GUID EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID;
+ public static EFI_GUID EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID;
+ public static EFI_GUID EFI_PART_TYPE_UNUSED_GUID;
+ public static EFI_GUID EFI_PART_TYPE_EFI_SYSTEM_PART_GUID;
+ public static EFI_GUID EFI_PART_TYPE_LEGACY_MBR_GUID;
+ public static EFI_GUID EFI_IP4_SERVICE_BINDING_PROTOCOL;
+ public static EFI_GUID EFI_IP4_PROTOCOL;
+ public static EFI_GUID EFI_IP6_SERVICE_BINDING_PROTOCOL;
+ public static EFI_GUID EFI_IP6_PROTOCOL;
+ public static EFI_GUID EFI_SIMPLE_NETWORK_PROTOCOL_GUID;
+ public static EFI_GUID EFI_PCI_IO_PROTOCOL_GUID;
+ public static EFI_GUID EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID;
+ public static EFI_GUID EFI_SIMPLE_POINTER_PROTOCOL_GUID;
+ public static EFI_GUID EFI_ABSOLUTE_POINTER_PROTOCOL_GUID;
+ public static EFI_GUID EFI_FPSWA_PROTOCOL_GUID;
+ public static EFI_GUID EFI_DEVICE_PATH_PROTOCOL_GUID;
+ public static EFI_GUID EFI_BLOCK_IO_PROTOCOL_GUID;
+ public static EFI_GUID EFI_BLOCK_IO2_PROTOCOL_GUID;
+ public static EFI_GUID EFI_DISK_IO_PROTOCOL_GUID;
+ public static EFI_GUID EFI_DISK_IO2_PROTOCOL_GUID;
+ public static EFI_GUID EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
+ public static EFI_GUID EFI_FILE_INFO_ID;
+ public static EFI_GUID EFI_FILE_SYSTEM_INFO_ID;
+ public static EFI_GUID EFI_FILE_SYSTEM_VOLUME_LABEL_ID;
+ public static EFI_GUID EFI_LOAD_FILE_PROTOCOL_GUID;
+ public static EFI_GUID EFI_DEVICE_IO_PROTOCOL_GUID;
+ public static EFI_GUID EFI_UNICODE_COLLATION_PROTOCOL_GUID;
+ public static EFI_GUID EFI_HASH_PROTOCOL_GUID;
+ public static EFI_GUID EFI_HASH_ALGORITHM_SHA1_GUID;
+ public static EFI_GUID EFI_HASH_ALGORITHM_SHA224_GUID;
+ public static EFI_GUID EFI_HASH_ALGORITHM_SHA256_GUID;
+ public static EFI_GUID EFI_HASH_ALGORITHM_SHA384_GUID;
+ public static EFI_GUID EFI_HASH_ALGORITHM_SHA512_GUID;
+ public static EFI_GUID EFI_HASH_ALGORITHM_MD5_GUID;
+ public static EFI_GUID EFI_HASH_ALGORITHM_SHA1_NOPAD_GUID;
+ public static EFI_GUID EFI_HASH_ALGORITHM_SHA256_NOPAD_GUID;
+ public static EFI_GUID EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
+ public static EFI_GUID EFI_EDID_DISCOVERED_PROTOCOL_GUID;
+ public static EFI_GUID EFI_EDID_ACTIVE_PROTOCOL_GUID;
+ public static EFI_GUID EFI_EDID_OVERRIDE_PROTOCOL_GUID;
+ public static EFI_GUID EFI_DRIVER_BINDING_PROTOCOL_GUID;
+ public static EFI_GUID EFI_COMPONENT_NAME_PROTOCOL_GUID;
+ public static EFI_GUID EFI_COMPONENT_NAME2_PROTOCOL_GUID;
+ public static EFI_GUID EFI_LOADED_IMAGE_PROTOCOL_GUID;
+ public static EFI_GUID EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID;
+ public static EFI_GUID EFI_RNG_PROTOCOL_GUID;
+ public static EFI_GUID EFI_RNG_ALGORITHM_SP800_90_HASH_256_GUID;
+ public static EFI_GUID EFI_RNG_ALGORITHM_SP800_90_HMAC_256_GUID;
+ public static EFI_GUID EFI_RNG_ALGORITHM_SP800_90_CTR_256_GUID;
+ public static EFI_GUID EFI_RNG_ALGORITHM_X9_31_3DES_GUID;
+ public static EFI_GUID EFI_RNG_ALGORITHM_X9_31_AES_GUID;
+ public static EFI_GUID EFI_RNG_ALGORITHM_RAW;
+ public static EFI_GUID EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL_GUID;
+ public static EFI_GUID EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL_GUID;
+ public static EFI_GUID EFI_DRIVER_FAMILY_OVERRIDE_PROTOCOL_GUID;
+ public static EFI_GUID EFI_EBC_INTERPRETER_PROTOCOL_GUID;
+ public static EFI_GUID EFI_PXE_BASE_CODE_PROTOCOL_GUID;
+ public static EFI_GUID EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_GUID;
+ public static EFI_GUID EFI_SERIAL_IO_PROTOCOL_GUID;
+ public static EFI_GUID EFI_SHELL_PROTOCOL_GUID;
+ public static EFI_GUID EFI_SHELL_PARAMETERS_PROTOCOL_GUID;
+ public static EFI_GUID EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL_GUID;
+ public static EFI_GUID EFI_TCP4_SERVICE_BINDING_PROTOCOL;
+ public static EFI_GUID EFI_TCP4_PROTOCOL;
+ public static EFI_GUID EFI_TCP6_SERVICE_BINDING_PROTOCOL;
+ public static EFI_GUID EFI_TCP6_PROTOCOL;
+ public static EFI_GUID EFI_UDP4_SERVICE_BINDING_PROTOCOL;
+ public static EFI_GUID EFI_UDP4_PROTOCOL;
+ public static EFI_GUID EFI_UDP6_SERVICE_BINDING_PROTOCOL;
+ public static EFI_GUID EFI_UDP6_PROTOCOL;
+ public static EFI_GUID EFI_UI_INTERFACE_PROTOCOL_GUID;
+ public static EFI_GUID EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID;
+ public static EFI_GUID SHELL_INTERFACE_PROTOCOL_GUID;
+
+ public static void InitializeGuid()
+ {
+ EFI_GLOBAL_VARIABLE = new EFI_GUID(0x8BE4DF61, 0x93CA, 0x11d2, 0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C);
+ MPS_TABLE_GUID = new EFI_GUID(0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d);
+ ACPI_TABLE_GUID = new EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d);
+ ACPI_20_TABLE_GUID = new EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81);
+ SMBIOS_TABLE_GUID = new EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d);
+ SMBIOS3_TABLE_GUID = new EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94);
+ SAL_SYSTEM_TABLE_GUID = new EFI_GUID(0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d);
+ EFI_DTB_TABLE_GUID = new EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0);
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID = new EFI_GUID(0x387477c2, 0x69c7, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+ EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID = new EFI_GUID(0x387477c1, 0x69c7, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+ EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID = new EFI_GUID(0xdd9e7534, 0x7762, 0x4698, 0x8c, 0x14, 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa);
+ EFI_DEBUG_IMAGE_INFO_TABLE_GUID = new EFI_GUID(0x49152e77, 0x1ada, 0x4764, 0xb7, 0xa2, 0x7a, 0xfe, 0xfe, 0xd9, 0x5e, 0x8b);
+ EFI_DEBUG_SUPPORT_PROTOCOL_GUID = new EFI_GUID(0x2755590c, 0x6f3c, 0x42fa, 0x9e, 0xa4, 0xa3, 0xba, 0x54, 0x3c, 0xda, 0x25);
+ UNKNOWN_DEVICE_GUID = new EFI_GUID(0xcf31fac5, 0xc24e, 0x11d2, 0x85, 0xf3, 0x0, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b);
+ EFI_PC_ANSI_GUID = new EFI_GUID(0xe0c14753, 0xf9be, 0x11d2, 0x9a, 0x0c, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d);
+ EFI_VT_100_GUID = new EFI_GUID(0xdfa66065, 0xb419, 0x11d3, 0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d);
+ EFI_VT_100_PLUS_GUID = new EFI_GUID(0x7baec70b, 0x57e0, 0x4c76, 0x8e, 0x87, 0x2f, 0x9e, 0x28, 0x08, 0x83, 0x43);
+ EFI_VT_UTF8_GUID = new EFI_GUID(0xad15a0d6, 0x8bec, 0x4acf, 0xa0, 0x73, 0xd0, 0x1d, 0xe7, 0x7e, 0x2d, 0x88);
+ EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID = new EFI_GUID(0x8b843e20, 0x8132, 0x4852, 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c);
+ EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID = new EFI_GUID(0x5c99a21, 0xc70f, 0x4ad2, 0x8a, 0x5f, 0x35, 0xdf, 0x33, 0x43, 0xf5, 0x1e);
+ EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID = new EFI_GUID(0x379be4e, 0xd706, 0x437d, 0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4);
+ EFI_PART_TYPE_UNUSED_GUID = new EFI_GUID(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+ EFI_PART_TYPE_EFI_SYSTEM_PART_GUID = new EFI_GUID(0xc12a7328, 0xf81f, 0x11d2, 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b);
+ EFI_PART_TYPE_LEGACY_MBR_GUID = new EFI_GUID(0x024dee41, 0x33e7, 0x11d3, 0x9d, 0x69, 0x00, 0x08, 0xc7, 0x81, 0xf3, 0x9f);
+ EFI_IP4_SERVICE_BINDING_PROTOCOL = new EFI_GUID(0xc51711e7, 0xb4bf, 0x404a, 0xbf, 0xb8, 0x0a, 0x04, 0x8e, 0xf1, 0xff, 0xe4);
+ EFI_IP4_PROTOCOL = new EFI_GUID(0x41d94cd2, 0x35b6, 0x455a, 0x82, 0x58, 0xd4, 0xe5, 0x13, 0x34, 0xaa, 0xdd);
+ EFI_IP6_SERVICE_BINDING_PROTOCOL = new EFI_GUID(0xec835dd3, 0xfe0f, 0x617b, 0xa6, 0x21, 0xb3, 0x50, 0xc3, 0xe1, 0x33, 0x88);
+ EFI_IP6_PROTOCOL = new EFI_GUID(0x2c8759d5, 0x5c2d, 0x66ef, 0x92, 0x5f, 0xb6, 0x6c, 0x10, 0x19, 0x57, 0xe2);
+ EFI_SIMPLE_NETWORK_PROTOCOL_GUID = new EFI_GUID(0xA19832B9, 0xAC25, 0x11D3, 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D);
+ EFI_PCI_IO_PROTOCOL_GUID = new EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a);
+ EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID = new EFI_GUID(0x2f707ebb, 0x4a1a, 0x11d4, 0x9a, 0x38, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d);
+ EFI_SIMPLE_POINTER_PROTOCOL_GUID = new EFI_GUID(0x31878c87, 0xb75, 0x11d5, 0x9a, 0x4f, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d);
+ EFI_ABSOLUTE_POINTER_PROTOCOL_GUID = new EFI_GUID(0x8D59D32B, 0xC655, 0x4AE9, 0x9B, 0x15, 0xF2, 0x59, 0x04, 0x99, 0x2A, 0x43);
+ EFI_FPSWA_PROTOCOL_GUID = new EFI_GUID(0xc41b6531, 0x97b9, 0x11d3, 0x9a, 0x29, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d);
+ EFI_DEVICE_PATH_PROTOCOL_GUID = new EFI_GUID(0x9576e91, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+ EFI_BLOCK_IO_PROTOCOL_GUID = new EFI_GUID(0x964e5b21, 0x6459, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+ EFI_BLOCK_IO2_PROTOCOL_GUID = new EFI_GUID(0xa77b2472, 0xe282, 0x4e9f, 0xa2, 0x45, 0xc2, 0xc0, 0xe2, 0x7b, 0xbc, 0xc1);
+ EFI_DISK_IO_PROTOCOL_GUID = new EFI_GUID(0xce345171, 0xba0b, 0x11d2, 0x8e, 0x4f, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+ EFI_DISK_IO2_PROTOCOL_GUID = new EFI_GUID(0x151c8eae, 0x7f2c, 0x472c, 0x9e, 0x54, 0x98, 0x28, 0x19, 0x4f, 0x6a, 0x88);
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID = new EFI_GUID(0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+ EFI_FILE_INFO_ID = new EFI_GUID(0x9576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+ EFI_FILE_SYSTEM_INFO_ID = new EFI_GUID(0x9576e93, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+ EFI_FILE_SYSTEM_VOLUME_LABEL_ID = new EFI_GUID(0xDB47D7D3, 0xFE81, 0x11d3, 0x9A, 0x35, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D);
+ EFI_LOAD_FILE_PROTOCOL_GUID = new EFI_GUID(0x56EC3091, 0x954C, 0x11d2, 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B);
+ EFI_DEVICE_IO_PROTOCOL_GUID = new EFI_GUID(0xaf6ac311, 0x84c3, 0x11d2, 0x8e, 0x3c, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+ EFI_UNICODE_COLLATION_PROTOCOL_GUID = new EFI_GUID(0x1d85cd7f, 0xf43d, 0x11d2, 0x9a, 0xc, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d);
+ EFI_HASH_PROTOCOL_GUID = new EFI_GUID(0xC5184932, 0xDBA5, 0x46DB, 0xA5, 0xBA, 0xCC, 0x0B, 0xDA, 0x9C, 0x14, 0x35);
+ EFI_HASH_ALGORITHM_SHA1_GUID = new EFI_GUID(0x2AE9D80F, 0x3FB2, 0x4095, 0xB7, 0xB1, 0xE9, 0x31, 0x57, 0xB9, 0x46, 0xB6);
+ EFI_HASH_ALGORITHM_SHA224_GUID = new EFI_GUID(0x8DF01A06, 0x9BD5, 0x4BF7, 0xB0, 0x21, 0xDB, 0x4F, 0xD9, 0xCC, 0xF4, 0x5B);
+ EFI_HASH_ALGORITHM_SHA256_GUID = new EFI_GUID(0x51AA59DE, 0xFDF2, 0x4EA3, 0xBC, 0x63, 0x87, 0x5F, 0xB7, 0x84, 0x2E, 0xE9);
+ EFI_HASH_ALGORITHM_SHA384_GUID = new EFI_GUID(0xEFA96432, 0xDE33, 0x4DD2, 0xAE, 0xE6, 0x32, 0x8C, 0x33, 0xDF, 0x77, 0x7A);
+ EFI_HASH_ALGORITHM_SHA512_GUID = new EFI_GUID(0xCAA4381E, 0x750C, 0x4770, 0xB8, 0x70, 0x7A, 0x23, 0xB4, 0xE4, 0x21, 0x30);
+ EFI_HASH_ALGORITHM_MD5_GUID = new EFI_GUID(0x0AF7C79C, 0x65B5, 0x4319, 0xB0, 0xAE, 0x44, 0xEC, 0x48, 0x4E, 0x4A, 0xD7);
+ EFI_HASH_ALGORITHM_SHA1_NOPAD_GUID = new EFI_GUID(0x24C5DC2F, 0x53E2, 0x40CA, 0x9E, 0xD6, 0xA5, 0xD9, 0xA4, 0x9F, 0x46, 0x3B);
+ EFI_HASH_ALGORITHM_SHA256_NOPAD_GUID = new EFI_GUID(0x8628752A, 0x6CB7, 0x4814, 0x96, 0xFC, 0x24, 0xA8, 0x15, 0xAC, 0x22, 0x26);
+ EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID = new EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a);
+ EFI_EDID_DISCOVERED_PROTOCOL_GUID = new EFI_GUID(0x1C0C34F6, 0xD380, 0x41FA, 0xA0, 0x49, 0x8a, 0xD0, 0x6C, 0x1A, 0x66, 0xAA);
+ EFI_EDID_ACTIVE_PROTOCOL_GUID = new EFI_GUID(0xBD8C1056, 0x9F36, 0x44EC, 0x92, 0xA8, 0xA6, 0x33, 0x7F, 0x81, 0x79, 0x86);
+ EFI_EDID_OVERRIDE_PROTOCOL_GUID = new EFI_GUID(0x48ECB431, 0xFB72, 0x45C0, 0xA9, 0x22, 0xF4, 0x58, 0xFE, 0x04, 0x0B, 0xD5);
+ EFI_DRIVER_BINDING_PROTOCOL_GUID = new EFI_GUID(0x18A031AB, 0xB443, 0x4D1A, 0xA5, 0xC0, 0x0C, 0x09, 0x26, 0x1E, 0x9F, 0x71);
+ EFI_COMPONENT_NAME_PROTOCOL_GUID = new EFI_GUID(0x107A772C, 0xD5E1, 0x11D4, 0x9A, 0x46, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D);
+ EFI_COMPONENT_NAME2_PROTOCOL_GUID = new EFI_GUID(0x6A7A5CFF, 0xE8D9, 0x4F70, 0xBA, 0xDA, 0x75, 0xAB, 0x30, 0x25, 0xCE, 0x14);
+ EFI_LOADED_IMAGE_PROTOCOL_GUID = new EFI_GUID(0x5B1B31A1, 0x9562, 0x11d2, 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B);
+ EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID = new EFI_GUID(0xbc62157e, 0x3e33, 0x4fec, 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf);
+ EFI_RNG_PROTOCOL_GUID = new EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44);
+ EFI_RNG_ALGORITHM_SP800_90_HASH_256_GUID = new EFI_GUID(0xa7af67cb, 0x603b, 0x4d42, 0xba, 0x21, 0x70, 0xbf, 0xb6, 0x29, 0x3f, 0x96);
+ EFI_RNG_ALGORITHM_SP800_90_HMAC_256_GUID = new EFI_GUID(0xc5149b43, 0xae85, 0x4f53, 0x99, 0x82, 0xb9, 0x43, 0x35, 0xd3, 0xa9, 0xe7);
+ EFI_RNG_ALGORITHM_SP800_90_CTR_256_GUID = new EFI_GUID(0x44f0de6e, 0x4d8c, 0x4045, 0xa8, 0xc7, 0x4d, 0xd1, 0x68, 0x85, 0x6b, 0x9e);
+ EFI_RNG_ALGORITHM_X9_31_3DES_GUID = new EFI_GUID(0x63c4785a, 0xca34, 0x4012, 0xa3, 0xc8, 0x0b, 0x6a, 0x32, 0x4f, 0x55, 0x46);
+ EFI_RNG_ALGORITHM_X9_31_AES_GUID = new EFI_GUID(0xacd03321, 0x777e, 0x4d3d, 0xb1, 0xc8, 0x20, 0xcf, 0xd8, 0x88, 0x20, 0xc9);
+ EFI_RNG_ALGORITHM_RAW = new EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61);
+ EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL_GUID = new EFI_GUID(0x6b30c738, 0xa391, 0x11d4, 0x9a, 0x3b, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d);
+ EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL_GUID = new EFI_GUID(0x3bc1b285, 0x8a15, 0x4a82, 0xaa, 0xbf, 0x4d, 0x7d, 0x13, 0xfb, 0x32, 0x65);
+ EFI_DRIVER_FAMILY_OVERRIDE_PROTOCOL_GUID = new EFI_GUID(0xb1ee129e, 0xda36, 0x4181, 0x91, 0xf8, 0x04, 0xa4, 0x92, 0x37, 0x66, 0xa7);
+ EFI_EBC_INTERPRETER_PROTOCOL_GUID = new EFI_GUID(0x13ac6dd1, 0x73d0, 0x11d4, 0xb0, 0x6b, 0x00, 0xaa, 0x00, 0xbd, 0x6d, 0xe7);
+ EFI_PXE_BASE_CODE_PROTOCOL_GUID = new EFI_GUID(0x03c4e603, 0xac28, 0x11d3, 0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d);
+ EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_GUID = new EFI_GUID(0x245dca21, 0xfb7b, 0x11d3, 0x8f, 0x01, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+ EFI_SERIAL_IO_PROTOCOL_GUID = new EFI_GUID(0xBB25CF6F, 0xF1D4, 0x11D2, 0x9A, 0x0C, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0xFD);
+ EFI_SHELL_PROTOCOL_GUID = new EFI_GUID(0x6302d008, 0x7f9b, 0x4f30, 0x87, 0xac, 0x60, 0xc9, 0xfe, 0xf5, 0xda, 0x4e);
+ EFI_SHELL_PARAMETERS_PROTOCOL_GUID = new EFI_GUID(0x752f3136, 0x4e16, 0x4fdc, 0xa2, 0x2a, 0xe5, 0xf4, 0x68, 0x12, 0xf4, 0xca);
+ EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL_GUID = new EFI_GUID(0x3c7200e9, 0x005f, 0x4ea4, 0x87, 0xde, 0xa3, 0xdf, 0xac, 0x8a, 0x27, 0xc3);
+ EFI_TCP4_SERVICE_BINDING_PROTOCOL = new EFI_GUID(0x00720665, 0x67eb, 0x4a99, 0xba, 0xf7, 0xd3, 0xc3, 0x3a, 0x1c, 0x7c, 0xc9);
+ EFI_TCP4_PROTOCOL = new EFI_GUID(0x65530bc7, 0xa359, 0x410f, 0xb0, 0x10, 0x5a, 0xad, 0xc7, 0xec, 0x2b, 0x62);
+ EFI_TCP6_SERVICE_BINDING_PROTOCOL = new EFI_GUID(0xec20eb79, 0x6c1a, 0x4664, 0x9a, 0xd, 0xd2, 0xe4, 0xcc, 0x16, 0xd6, 0x64);
+ EFI_TCP6_PROTOCOL = new EFI_GUID(0x46e44855, 0xbd60, 0x4ab7, 0xab, 0xd, 0xa6, 0x79, 0xb9, 0x44, 0x7d, 0x77);
+ EFI_UDP4_SERVICE_BINDING_PROTOCOL = new EFI_GUID(0x83f01464, 0x99bd, 0x45e5, 0xb3, 0x83, 0xaf, 0x63, 0x05, 0xd8, 0xe9, 0xe6);
+ EFI_UDP4_PROTOCOL = new EFI_GUID(0x3ad9df29, 0x4501, 0x478d, 0xb1, 0xf8, 0x7f, 0x7f, 0xe7, 0x0e, 0x50, 0xf3);
+ EFI_UDP6_SERVICE_BINDING_PROTOCOL = new EFI_GUID(0x66ed4721, 0x3c98, 0x4d3e, 0x81, 0xe3, 0xd0, 0x3d, 0xd3, 0x9a, 0x72, 0x54);
+ EFI_UDP6_PROTOCOL = new EFI_GUID(0x4f948815, 0xb4b9, 0x43cb, 0x8a, 0x33, 0x90, 0xe0, 0x60, 0xb3, 0x49, 0x55);
+ EFI_UI_INTERFACE_PROTOCOL_GUID = new EFI_GUID(0x32dd7981, 0x2d27, 0x11d4, 0xbc, 0x8b, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81);
+ EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID = new EFI_GUID(0xE18541CD, 0xF755, 0x4f73, 0x92, 0x8D, 0x64, 0x3C, 0x8A, 0x79, 0xB2, 0x29);
+ SHELL_INTERFACE_PROTOCOL_GUID = new EFI_GUID(0x47c7b223, 0xc42a, 0x11d2, 0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+ }
+
+ [RuntimeExport("memset")]
+ public static unsafe void memset(byte* ptr, byte c, ulong count)
+ {
+ gBS->SetMem(ptr, count, c);
+ }
+
+ [RuntimeExport("memcpy")]
+ public static unsafe void memcpy(byte* dst, byte* src, ulong count)
+ {
+ gBS->CopyMem(dst, src, count);
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp1/pe.cs b/ConsoleApp1/pe.cs
new file mode 100644
index 0000000..8eeb353
--- /dev/null
+++ b/ConsoleApp1/pe.cs
@@ -0,0 +1,151 @@
+
+
+using System.Runtime.InteropServices;
+
+[StructLayout(LayoutKind.Sequential)]
+public struct DataDirectory
+{
+ public uint VirtualAddress;
+ public uint Size;
+}
+
+public enum DllCharacteristicsType : ushort
+{
+ RES_0 = 0x0001,
+ RES_1 = 0x0002,
+ RES_2 = 0x0004,
+ RES_3 = 0x0008,
+ DynamicBase = 0x0040,
+ ForceIntegrity = 0x0080,
+ NxCompat = 0x0100,
+ NoIsolation = 0x0200,
+ NoSEH = 0x0400,
+ NoBind = 0x0800,
+ RES_4 = 0x1000,
+ WDMDriver = 0x2000,
+ TerminalServerName = 0x8000
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public unsafe struct DOSHeader
+{
+ public ushort e_magic; // Magic number
+ public ushort e_cblp; // Bytes on last page of file
+ public ushort e_cp; // Pages in file
+ public ushort e_crlc; // Relocations
+ public ushort e_cparhdr; // Size of header in paragraphs
+ public ushort e_minalloc; // Minimum extra paragraphs needed
+ public ushort e_maxalloc; // Maximum extra paragraphs needed
+ public ushort e_ss; // Initial (relative) SS value
+ public ushort e_sp; // Initial SP value
+ public ushort e_csum; // Checksum
+ public ushort e_ip; // Initial IP value
+ public ushort e_cs; // Initial (relative) CS value
+ public ushort e_lfarlc; // File address of relocation table
+ public ushort e_ovno; // Overlay number
+ public fixed ushort e_res1[4]; // Reserved words
+ public ushort e_oemid; // OEM identifier (for e_oeminfo)
+ public ushort e_oeminfo; // OEM information; e_oemid specific
+ public fixed ushort e_res2[10]; // Reserved words
+ public int e_lfanew; // File address of new exe header
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct FileHeader
+{
+ public ushort Machine;
+ public ushort NumberOfSections;
+ public uint TimeDateStamp;
+ public uint PointerToSymbolTable;
+ public uint NumberOfSymbols;
+ public ushort SizeOfOptionalHeader;
+ public ushort Characteristics;
+}
+
+[StructLayout(LayoutKind.Sequential, Pack = 1)]
+public struct NtHeaders64
+{
+ public uint Signature;
+ public FileHeader FileHeader;
+ public OptionalHeaders64 OptionalHeader;
+}
+
+[StructLayout(LayoutKind.Sequential, Pack = 1)]
+public struct OptionalHeaders64
+{
+ public ushort Magic;
+ public byte MajorLinkerVersion;
+ public byte MinorLinkerVersion;
+ public uint SizeOfCode;
+ public uint SizeOfInitializedData;
+ public uint SizeOfUninitializedData;
+ public uint AddressOfEntryPoint;
+ public uint BaseOfCode;
+ public ulong ImageBase;
+ public uint SectionAlignment;
+ public uint FileAlignment;
+ public ushort MajorOperatingSystemVersion;
+ public ushort MinorOperatingSystemVersion;
+ public ushort MajorImageVersion;
+ public ushort MinorImageVersion;
+ public ushort MajorSubsystemVersion;
+ public ushort MinorSubsystemVersion;
+ public uint Win32VersionValue;
+ public uint SizeOfImage;
+ public uint SizeOfHeaders;
+ public uint CheckSum;
+ public SubSystemType Subsystem;
+ public DllCharacteristicsType DllCharacteristics;
+ public ulong SizeOfStackReserve;
+ public ulong SizeOfStackCommit;
+ public ulong SizeOfHeapReserve;
+ public ulong SizeOfHeapCommit;
+ public uint LoaderFlags;
+ public uint NumberOfRvaAndSizes;
+ public DataDirectory ExportTable;
+ public DataDirectory ImportTable;
+ public DataDirectory ResourceTable;
+ public DataDirectory ExceptionTable;
+ public DataDirectory CertificateTable;
+ public DataDirectory BaseRelocationTable;
+ public DataDirectory Debug;
+ public DataDirectory Architecture;
+ public DataDirectory GlobalPtr;
+ public DataDirectory TLSTable;
+ public DataDirectory LoadConfigTable;
+ public DataDirectory BoundImport;
+ public DataDirectory IAT;
+ public DataDirectory DelayImportDescriptor;
+ public DataDirectory CLRRuntimeHeader;
+ public DataDirectory Reserved;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public unsafe struct SectionHeader
+{
+ public fixed byte Name[8];
+ public uint PhysicalAddress_VirtualSize;
+ public uint VirtualAddress;
+ public uint SizeOfRawData;
+ public uint PointerToRawData;
+ public uint PointerToRelocations;
+ public uint PointerToLineNumbers;
+ public ushort NumberOfRelocations;
+ public ushort NumberOfLineNumbers;
+ public uint Characteristics;
+}
+
+public enum SubSystemType : ushort
+{
+ Unknown = 0,
+ Native = 1,
+ WindowsGUI = 2,
+ WindowsCUI = 3,
+ PosixCUI = 7,
+ WindowsCEGui = 9,
+ EfiApplication = 10,
+ EfiBootServiceDriver = 11,
+ EfiRuntimeDriver = 12,
+ EfiRom = 13,
+ Xbox = 14
+}
\ No newline at end of file
diff --git a/CoreLib/CoreLib.projitems b/CoreLib/CoreLib.projitems
new file mode 100644
index 0000000..2fbcd5f
--- /dev/null
+++ b/CoreLib/CoreLib.projitems
@@ -0,0 +1,68 @@
+
+
+
+ $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
+ true
+ 09702d3b-0a10-4653-9c75-12989e41b246
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CoreLib/CoreLib.shproj b/CoreLib/CoreLib.shproj
new file mode 100644
index 0000000..f6ca566
--- /dev/null
+++ b/CoreLib/CoreLib.shproj
@@ -0,0 +1,13 @@
+
+
+
+ 09702d3b-0a10-4653-9c75-12989e41b246
+ 14.0
+
+
+
+
+
+
+
+
diff --git a/CoreLib/Internal/Runtime/CompilerHelpers/StartupCodeHelpers.cs b/CoreLib/Internal/Runtime/CompilerHelpers/StartupCodeHelpers.cs
new file mode 100644
index 0000000..5febd69
--- /dev/null
+++ b/CoreLib/Internal/Runtime/CompilerHelpers/StartupCodeHelpers.cs
@@ -0,0 +1,170 @@
+using Internal.Runtime.CompilerServices;
+using System;
+using System.Runtime;
+
+namespace Internal.Runtime.CompilerHelpers
+{
+ // A class that the compiler looks for that has helpers to initialize the
+ // process. The compiler can gracefully handle the helpers not being present,
+ // but the class itself being absent is unhandled. Let's add an empty class.
+ unsafe class StartupCodeHelpers
+ {
+ // A couple symbols the generated code will need we park them in this class
+ // for no particular reason. These aid in transitioning to/from managed code.
+ // Since we don't have a GC, the transition is a no-op.
+ [RuntimeExport("RhpReversePInvoke")]
+ static void RhpReversePInvoke(IntPtr frame) { }
+ [RuntimeExport("RhpReversePInvokeReturn")]
+ static void RhpReversePInvokeReturn(IntPtr frame) { }
+ [RuntimeExport("RhpPInvoke")]
+ static void RhpPInvoke(IntPtr frame) { }
+ [RuntimeExport("RhpPInvokeReturn")]
+ static void RhpPInvokeReturn(IntPtr frame) { }
+
+ [RuntimeExport("RhpFallbackFailFast")]
+ static void RhpFallbackFailFast() { while (true) ; }
+
+ [RuntimeExport("RhpAssignRef")]
+ static unsafe void RhpAssignRef(void** address, void* obj) => *address = obj;
+
+ [RuntimeExport("RhpByRefAssignRef")]
+ static unsafe void RhpByRefAssignRef(void** address, void* obj) => *address = obj;
+
+ [RuntimeExport("RhpCheckedAssignRef")]
+ static unsafe void RhpCheckedAssignRef(void** address, void* obj) => *address = obj;
+
+ [RuntimeExport("RhpStelemRef")]
+ static unsafe void RhpStelemRef(Array array, int index, object obj)
+ {
+ fixed (int* n = &array._numComponents)
+ {
+ var ptr = (byte*)n;
+ ptr += sizeof(void*);
+ ptr += index * array.m_pEEType->ComponentSize;
+ var pp = (IntPtr*)ptr;
+ *pp = Unsafe.As