mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
- Created a unit test to verify that the LARGEADDRESSAWARE flag is set on mRemoteNG.exe
- Created configurations for the unit test project to support the PORTABLE compilation symbol. This is required for the unit test to work correctly.
This commit is contained in:
67
mRemoteNGTests/BinaryFileTests.cs
Normal file
67
mRemoteNGTests/BinaryFileTests.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using NUnit.Framework;
|
||||
using System.IO;
|
||||
|
||||
namespace mRemoteNGTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class BinaryFileTests
|
||||
{
|
||||
[Test]
|
||||
public void LargeAddressAwareFlagIsSet()
|
||||
{
|
||||
var exePath = GetTargetPath();
|
||||
Assert.That(IsLargeAware(exePath), Is.True);
|
||||
}
|
||||
|
||||
static string GetTargetPath()
|
||||
{
|
||||
string debugOrRelease = "";
|
||||
string normalOrPortable = "";
|
||||
#if DEBUG
|
||||
debugOrRelease = "Debug";
|
||||
#else
|
||||
debugOrRelease = "Release";
|
||||
#endif
|
||||
#if PORTABLE
|
||||
normalOrPortable = " Portable";
|
||||
#else
|
||||
normalOrPortable = "";
|
||||
#endif
|
||||
string path = string.Format(".\\mRemoteV1\\bin\\{0}{1}\\mRemoteNG.exe", debugOrRelease, normalOrPortable);
|
||||
return path;
|
||||
}
|
||||
|
||||
static bool IsLargeAware(string file)
|
||||
{
|
||||
using (var fs = File.OpenRead(file))
|
||||
{
|
||||
return IsLargeAware(fs);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Checks if the stream is a MZ header and if it is large address aware
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream to check, make sure its at the start of the MZ header</param>
|
||||
/// <exception cref=""></exception>
|
||||
/// <returns></returns>
|
||||
static bool IsLargeAware(Stream stream)
|
||||
{
|
||||
const int IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x20;
|
||||
|
||||
var br = new BinaryReader(stream);
|
||||
|
||||
if (br.ReadInt16() != 0x5A4D) //No MZ Header
|
||||
return false;
|
||||
|
||||
br.BaseStream.Position = 0x3C;
|
||||
var peloc = br.ReadInt32(); //Get the PE header location.
|
||||
|
||||
br.BaseStream.Position = peloc;
|
||||
if (br.ReadInt32() != 0x4550) //No PE header
|
||||
return false;
|
||||
|
||||
br.BaseStream.Position += 0x12;
|
||||
return (br.ReadInt16() & IMAGE_FILE_LARGE_ADDRESS_AWARE) == IMAGE_FILE_LARGE_ADDRESS_AWARE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,24 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug Portable|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug Portable\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;PORTABLE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release Portable|x86'">
|
||||
<OutputPath>bin\x86\Release Portable\</OutputPath>
|
||||
<DefineConstants>TRACE;PORTABLE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
@@ -75,6 +93,7 @@
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="App\LoggerTests.cs" />
|
||||
<Compile Include="BinaryFileTests.cs" />
|
||||
<Compile Include="Connection\ConnectionInfoInheritanceTests.cs" />
|
||||
<Compile Include="ListViewTester.cs" />
|
||||
<Compile Include="Config\Connections\SqlConnectionUpdateCheckerTests.cs" />
|
||||
|
||||
@@ -42,15 +42,15 @@ Global
|
||||
{4934A491-40BC-4E5B-9166-EA1169A220F6}.Release|x86.Build.0 = Release|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Debug Portable|Any CPU.ActiveCfg = Release|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Debug Portable|Any CPU.Build.0 = Release|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Debug Portable|x86.ActiveCfg = Debug|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Debug Portable|x86.Build.0 = Debug|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Debug Portable|x86.ActiveCfg = Debug Portable|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Debug Portable|x86.Build.0 = Debug Portable|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Debug|x86.Build.0 = Debug|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Release Portable|Any CPU.ActiveCfg = Release|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Release Portable|Any CPU.Build.0 = Release|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Release Portable|x86.ActiveCfg = Release|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Release Portable|x86.Build.0 = Release|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Release Portable|x86.ActiveCfg = Release Portable|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Release Portable|x86.Build.0 = Release Portable|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Release|Any CPU.ActiveCfg = Release|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Release|x86.ActiveCfg = Release|x86
|
||||
{1453B37F-8621-499E-B0B2-6091F76DC0BB}.Release|x86.Build.0 = Release|x86
|
||||
|
||||
Reference in New Issue
Block a user