Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<LangVersion>preview</LangVersion>
<LangVersion Condition="'$(MSBuildProjectExtension)' == '.vbproj'">latest</LangVersion>
<Deterministic>true</Deterministic>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions eng/Analyzers.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<PropertyGroup>
<CodeAnalysisRuleset>$(MSBuildThisFileDirectory)CodeAnalysis.ruleset</CodeAnalysisRuleset>
<!-- Disable analyzers in sourcebuild -->
<EnableAnalyzers Condition="'$(DotNetBuildFromSource)' == 'true'">false</EnableAnalyzers>
<RunAnalyzers Condition="'$(DotNetBuildFromSource)' == 'true'">false</RunAnalyzers>
</PropertyGroup>
<ItemGroup Condition="'$(EnableAnalyzers)' == 'true'">
<ItemGroup Condition="'$(RunAnalyzers)' != 'false'">
<PackageReference Include="Microsoft.DotNet.CodeAnalysis" Version="$(MicrosoftDotNetCodeAnalysisVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.0-rc2.20458.2" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164" PrivateAssets="all" />
Expand Down
2 changes: 1 addition & 1 deletion eng/referenceAssemblies.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AdditionalBuildTargetFrameworks Condition="!$(BuildTargetFramework.StartsWith('netcoreapp2.0'))">$(AdditionalBuildTargetFrameworks);netstandard2.1</AdditionalBuildTargetFrameworks>

<!-- Reference assemblies are special and don't initialize fields or have empty finalizers, etc. -->
<EnableAnalyzers>false</EnableAnalyzers>
<RunAnalyzers>false</RunAnalyzers>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@

<SkipCommonResourcesIncludes>true</SkipCommonResourcesIncludes>
<DocumentationFile>$(OutputPath)$(MSBuildProjectName).xml</DocumentationFile>
<EnableAnalyzers>true</EnableAnalyzers>
</PropertyGroup>

<!-- Platform specific properties -->
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/src/tools/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<PropertyGroup>
<IsShipping>false</IsShipping>
<SignAssembly>false</SignAssembly>
<RunAnalyzers>false</RunAnalyzers>
</PropertyGroup>
</Project>
5 changes: 5 additions & 0 deletions src/coreclr/tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@
<CLRTestBuildAllTargets></CLRTestBuildAllTargets>
</PropertyGroup>

<!-- Language settings -->
<PropertyGroup>
<RunAnalyzers>false</RunAnalyzers>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions src/coreclr/tests/dir.sdkbuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<EnableDefaultItems>false</EnableDefaultItems>
<Platform>AnyCPU</Platform>
<NoWarn>$(NoWarn),618,SYSLIB0012</NoWarn>

<!-- [ARCADE REMOVE] This line should be removed we use the Arcade Sdk. -->
<DeterministicSourcePaths>false</DeterministicSourcePaths>
Expand Down
5 changes: 0 additions & 5 deletions src/installer/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@

</PropertyGroup>

<!-- Set up handling of build warnings -->
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<TargetsWindows>false</TargetsWindows>
<TargetsOSX>false</TargetsOSX>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
namespace Microsoft.NET.HostModel.AppHost
{
/// <summary>
/// The application host executable cannot be customized because adding resources requires
/// The application host executable cannot be customized because adding resources requires
/// that the build be performed on Windows (excluding Nano Server).
/// </summary>
public class AppHostCustomizationUnsupportedOSException : AppHostUpdateException
{
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public enum MachOFormatError
SignBlobNotLast, // Signature blob must be at the very end of the file
SignDoesntFollowSymtab, // Signature blob must immediately follow the Symtab
MemoryMapAccessFault, // Error reading the memory-mapped apphost
InvalidUTF8 // UTF8 decoding failed
InvalidUTF8 // UTF8 decoding failed
}

/// <summary>
/// The MachO application host executable cannot be customized because
/// The MachO application host executable cannot be customized because
/// it was not in the expected format
/// </summary>
public class AppHostMachOFormatException : AppHostUpdateException
Expand All @@ -39,4 +39,3 @@ public AppHostMachOFormatException(MachOFormatError error)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
namespace Microsoft.NET.HostModel.AppHost
{
/// <summary>
/// Unable to use the input file as application host executable because it's not a
/// Unable to use the input file as application host executable because it's not a
/// Windows executable for the CUI (Console) subsystem.
/// </summary>
public class AppHostNotCUIException : AppHostUpdateException
{
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
namespace Microsoft.NET.HostModel.AppHost
{
/// <summary>
/// Unable to use the input file as an application host executable
/// Unable to use the input file as an application host executable
/// because it's not a Windows PE file
/// </summary>
public class AppHostNotPEFileException : AppHostUpdateException
{
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
namespace Microsoft.NET.HostModel.AppHost
{
/// <summary>
/// An instance of this exception is thrown when an AppHost binary update
/// An instance of this exception is thrown when an AppHost binary update
/// fails due to known user errors.
/// </summary>
public class AppHostUpdateException : Exception
{
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ public AppNameTooLongException(string name)

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ private static unsafe void Pad0(byte[] searchPattern, byte[] patternToReplace, b
}

public static unsafe void SearchAndReplace(
string filePath,
byte[] searchPattern,
string filePath,
byte[] searchPattern,
byte[] patternToReplace,
bool pad0s = true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ internal static class ElfUtils
// The Linux Headers are copied from elf.h

#pragma warning disable 0649
struct ElfHeader
private struct ElfHeader
{
byte EI_MAG0;
byte EI_MAG1;
byte EI_MAG2;
byte EI_MAG3;
private byte EI_MAG0;
private byte EI_MAG1;
private byte EI_MAG2;
private byte EI_MAG3;

public bool IsValid()
{
Expand Down Expand Up @@ -49,4 +49,3 @@ public static bool IsElfImage(string filePath)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static void SetAsBundle(
long bundleHeaderOffset)
{
byte[] bundleHeaderPlaceholder = {
// 8 bytes represent the bundle header-offset
// 8 bytes represent the bundle header-offset
// Zero for non-bundle apphosts (default).
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 32 bytes represent the bundle signature: SHA-256 for ".net core bundle"
Expand Down Expand Up @@ -206,7 +206,7 @@ void FindBundleHeader()
throw new PlaceHolderNotFoundInAppHostException(bundleSignature);
}

headerOffset = accessor.ReadInt64(position - sizeof(Int64));
headerOffset = accessor.ReadInt64(position - sizeof(long));
}
}
}
Expand Down
53 changes: 26 additions & 27 deletions src/installer/managed/Microsoft.NET.HostModel/AppHost/MachOUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ namespace Microsoft.NET.HostModel.AppHost
{
internal static class MachOUtils
{
// The MachO Headers are copied from
// The MachO Headers are copied from
// https://opensource.apple.com/source/cctools/cctools-870/include/mach-o/loader.h
//
// The data fields and enumerations match the structure definitions in the above file,
// and hence do not conform to C# CoreFx naming style.

enum Magic : uint
private enum Magic : uint
{
MH_MAGIC = 0xfeedface,
MH_CIGAM = 0xcefaedfe,
MH_MAGIC_64 = 0xfeedfacf,
MH_CIGAM_64 = 0xcffaedfe
}

enum FileType : uint
private enum FileType : uint
{
MH_EXECUTE = 0x2
}

#pragma warning disable 0649
struct MachHeader
private struct MachHeader
{
public Magic magic;
public int cputype;
Expand Down Expand Up @@ -63,30 +63,30 @@ public bool IsValid()
}
}

enum Command : uint
private enum Command : uint
{
LC_SYMTAB = 0x2,
LC_SEGMENT_64 = 0x19,
LC_CODE_SIGNATURE = 0x1d,
}

struct LoadCommand
private struct LoadCommand
{
public Command cmd;
public uint cmdsize;
}

// The linkedit_data_command contains the offsets and sizes of a blob
// of data in the __LINKEDIT segment (including LC_CODE_SIGNATURE).
struct LinkEditDataCommand
// of data in the __LINKEDIT segment (including LC_CODE_SIGNATURE).
private struct LinkEditDataCommand
{
public Command cmd;
public uint cmdsize;
public uint dataoff;
public uint datasize;
}

struct SymtabCommand
private struct SymtabCommand
{
public uint cmd;
public uint cmdsize;
Expand All @@ -96,7 +96,7 @@ struct SymtabCommand
public uint strsize;
};

unsafe struct SegmentCommand64
private unsafe struct SegmentCommand64
{
public Command cmd;
public uint cmdsize;
Expand Down Expand Up @@ -159,47 +159,47 @@ public static bool IsMachOImage(string filePath)
/// <summary>
/// This Method is a utility to remove the code-signature (if any)
/// from a MachO AppHost binary.
///
///
/// The tool assumes the following layout of the executable:
///
///
/// * MachoHeader (64-bit, executable, not swapped integers)
/// * LoadCommands
/// LC_SEGMENT_64 (__PAGEZERO)
/// LC_SEGMENT_64 (__TEXT)
/// LC_SEGMENT_64 (__DATA)
/// LC_SEGMENT_64 (__LINKEDIT)
/// ...
/// LC_SYMTAB
/// LC_SYMTAB
/// ...
/// LC_CODE_SIGNATURE (last)
///
///
/// * ... Different Segments ...
///
///
/// * The __LINKEDIT Segment (last)
/// * ... Different sections ...
/// * SYMTAB
/// * ... Different sections ...
/// * SYMTAB
/// * (Some alignment bytes)
/// * The Code-signature
///
///
/// In order to remove the signature, the method:
/// - Removes (zeros out) the LC_CODE_SIGNATURE command
/// - Adjusts the size and count of the load commands in the header
/// - Truncates the size of the __LINKEDIT segment to the end of SYMTAB
/// - Truncates the apphost file to the end of the __LINKEDIT segment
///
///
/// </summary>
/// <param name="filePath">Path to the AppHost</param>
/// <returns>
/// True if
/// - The input is a MachO binary, and
/// - It is a signed binary, and
/// True if
/// - The input is a MachO binary, and
/// - It is a signed binary, and
/// - The signature was successfully removed
/// False otherwise
/// False otherwise
/// </returns>
/// <exception cref="AppHostMachOFormatException">
/// The input is a MachO file, but doesn't match the expect format of the AppHost.
/// </exception>
unsafe public static bool RemoveSignature(string filePath)
public static unsafe bool RemoveSignature(string filePath)
{
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite))
{
Expand Down Expand Up @@ -278,7 +278,7 @@ unsafe public static bool RemoveSignature(string filePath)
Verify(symtab->symoff > linkEdit->fileoff, MachOFormatError.SymtabNotInLinkEdit);
Verify(signature->dataoff > linkEdit->fileoff, MachOFormatError.SignNotInLinkEdit);

// The signature blob immediately follows the symtab blob,
// The signature blob immediately follows the symtab blob,
// except for a few bytes of padding.
Verify(signature->dataoff >= symtabEnd && signature->dataoff - symtabEnd < 32, MachOFormatError.SignBlobNotLast);

Expand All @@ -294,7 +294,7 @@ unsafe public static bool RemoveSignature(string filePath)
linkEdit->filesize -= signatureSize;

// codesign --remove-signature doesn't reset the vmsize.
// Setting the vmsize here makes the output bin-equal with the original
// Setting the vmsize here makes the output bin-equal with the original
// unsigned apphost (and not bin-equal with a signed-unsigned-apphost).
linkEdit->vmsize = linkEdit->filesize;
}
Expand All @@ -321,4 +321,3 @@ unsafe public static bool RemoveSignature(string filePath)
}
}
}

Loading