This commit is contained in:
Bluzume 2020-08-01 23:36:57 +12:00 committed by GitHub
parent 11508797bf
commit 0ed6baaee5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 674 additions and 0 deletions

25
CpUpES2-Decrypt.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CpUpES2-Decrypt", "CpUpES2-Decrypt\CpUpES2-Decrypt.csproj", "{82E64B8F-936A-4880-B2EF-29F826635D16}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{82E64B8F-936A-4880-B2EF-29F826635D16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{82E64B8F-936A-4880-B2EF-29F826635D16}.Debug|Any CPU.Build.0 = Debug|Any CPU
{82E64B8F-936A-4880-B2EF-29F826635D16}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82E64B8F-936A-4880-B2EF-29F826635D16}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6FB3887A-8432-439F-9F38-02631DC24297}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\ILMerge.3.0.41\build\ILMerge.props" Condition="Exists('..\packages\ILMerge.3.0.41\build\ILMerge.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{82E64B8F-936A-4880-B2EF-29F826635D16}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>CpUpES2_Decrypt</RootNamespace>
<AssemblyName>CpUpES2-Decrypt</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.6.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
<HintPath>..\packages\BouncyCastle.1.8.6.1\lib\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\ILMerge.3.0.41\build\ILMerge.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\ILMerge.3.0.41\build\ILMerge.props'))" />
</Target>
</Project>

125
CpUpES2-Decrypt/Program.cs Normal file
View File

@ -0,0 +1,125 @@
using Org.BouncyCastle.Crypto.Encodings;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Math;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace CpUpES2_Decrypt
{
class Program
{
public static byte[] Aes_128_Decrypt(byte[] message, byte[] Key, byte[] Iv)
{
Aes aes = new AesManaged();
aes.Key = Key;
aes.IV = Iv;
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.None;
ICryptoTransform cipher;
cipher = aes.CreateDecryptor();
return cipher.TransformFinalBlock(message, 0, message.Length);
}
static int Main(string[] args)
{
RsaKeyParameters Rsa_Public_Key = new RsaKeyParameters(false, new BigInteger("A7CCAE0F501188527BF3DACCA3E231C8D8701E7B91927390701DE5E7A96327DAD87167A8F01368ADDFE490E325A290533697058FBA775766698010AFD8FD7A3FFD265E0A52FE04928BCE8B4302F4C70FFAC3C9397FD24B106271E57BDA20D2D702298F6F990ECF9B0FE04FF6CCEE170B555304232012D78E6019DAB29763829E6AF5ADA802204FA551631179CBFE6164732662E8576741949BB136456C11DE355F487211D230267DC05E699A2652AD5C6D74B0568326F4F2F5B86AD956E94404D3A65928F4EA2189567CE9989911B04808517F4C76A8B25DF1D6ABBE8595C469BFD7E870C4F00A89610C2C9B79F625A42CA2B4C6B8D37E62CE9EC61A856FD32F", 16), new BigInteger("10001", 16));
if(args.Length < 1)
{
Console.WriteLine("Usage: CpUpES2Decrypt.exe <UpdaterES2.CpUp File>");
return 2;
}
else if(File.Exists(args[0]))
{
// Parse Header
FileStream fs = File.OpenRead(args[0]);
BinaryReader bfs = new BinaryReader(fs);
UInt32 Magic = bfs.ReadUInt32();
UInt32 Version = bfs.ReadUInt32();
UInt64 Reserved = bfs.ReadUInt64();
UInt32 Type = bfs.ReadUInt32();
UInt32 FullSize = bfs.ReadUInt32();
UInt32 StartAddress = bfs.ReadUInt32();
UInt32 ExtractedSize = bfs.ReadUInt32();
if (Magic == 0x43705570) //CpUp
{
Console.WriteLine("CpUp Magic: 0x" + Magic.ToString("X"));
Console.WriteLine("CpUp Version: 0x" + Version.ToString("X"));
Console.WriteLine("CpUp Reserved Space: 0x" + Reserved.ToString("X"));
Console.WriteLine("CpUp Type: 0x" + Type.ToString("X"));
Console.WriteLine("CpUp Size: 0x" + FullSize.ToString("X"));
Console.WriteLine("CpUp Start Address: 0x" + StartAddress.ToString("X"));
Console.WriteLine("CpUp Extracted Size: 0x" + ExtractedSize.ToString("X"));
Console.WriteLine("\n\nRSA Decrypting Key Information...");
// Dervie AES Key
Pkcs1Encoding pkcs1Encoding = new Pkcs1Encoding(new RsaEngine());
pkcs1Encoding.Init(false, Rsa_Public_Key);
pkcs1Encoding.GetInputBlockSize();
fs.Seek(-0x100, SeekOrigin.End);
Byte[] HeaderData = new Byte[0x100];
fs.Read(HeaderData, 0x00, 0x100);
Byte[] HeaderDecrypted = pkcs1Encoding.ProcessBlock(HeaderData, 0, 0x100);
Byte[] Iv = new Byte[0x10];
Byte[] Key = new Byte[0x10];
Byte[] Sha1Hash = new Byte[0x14];
Array.ConstrainedCopy(HeaderDecrypted, 0x0, Iv, 0x0, 0x10);
Array.ConstrainedCopy(HeaderDecrypted, 0x10, Key, 0x0, 0x10);
Array.ConstrainedCopy(HeaderDecrypted, 0x20, Sha1Hash, 0x0, 0x14);
Console.WriteLine("CpUp Key: " + BitConverter.ToString(Key));
Console.WriteLine("CpUp Iv: " + BitConverter.ToString(Iv));
Console.WriteLine("CpUp Sha1: " + BitConverter.ToString(Sha1Hash));
Console.WriteLine("\n\nAES Decrytping CpUp File...");
// Decrypt Update
fs.Seek(StartAddress, SeekOrigin.Begin);
Byte[] UpdateData = new Byte[(FullSize - StartAddress) - 0x100];
fs.Read(UpdateData, 0x00, UpdateData.Length);
Byte[] UpdateDecrypted = Aes_128_Decrypt(UpdateData, Key, Iv);
fs.Close();
String FileName = Path.ChangeExtension(args[0], "tar.gz");
fs = File.OpenWrite(FileName);
fs.Write(UpdateDecrypted, 0x00, (Int32)ExtractedSize);
fs.Close();
Console.WriteLine("Decrypted file saved to: " + FileName);
ConsoleColor PrevColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\n\nBlessed Be!");
Console.ForegroundColor = PrevColor;
return 0;
}
else
{
Console.WriteLine("Invalid CPUP! (Magic = 0x" + Magic.ToString("X")+")");
return 1;
}
}
else
{
Console.WriteLine("File not Found: " + args[0]);
return 4;
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CpUpES2-Decrypt")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CpUpES2-Decrypt")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("82e64b8f-936a-4880-b2ef-29f826635d16")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BouncyCastle" version="1.8.6.1" targetFramework="net472" />
<package id="ILMerge" version="3.0.41" targetFramework="net472" />
</packages>

Binary file not shown.

30
packages/BouncyCastle.1.8.6.1/README.md vendored Normal file
View File

@ -0,0 +1,30 @@
# The Bouncy Castle Crypto Package For C Sharp
The Bouncy Castle Crypto package is a C\# implementation of cryptographic algorithms and protocols, it was developed by the Legion of the Bouncy Castle, a registered Australian Charity, with a little help! The Legion, and the latest goings on with this package, can be found at [http://www.bouncycastle.org](http://www.bouncycastle.org). In addition to providing basic cryptography algorithms, the package also provides support for CMS, TSP, X.509 certificate generation and a variety of other standards such as OpenPGP.
The Legion also gratefully acknowledges the contributions made to this package by others (see [here](http://www.bouncycastle.org/csharp/contributors.html) for the current list). If you would like to contribute to our efforts please feel free to get in touch with us or visit our [donations page](https://www.bouncycastle.org/donate), sponsor some specific work, or purchase a support contract through [Crypto Workshop](http://www.cryptoworkshop.com).
Except where otherwise stated, this software is distributed under a license based on the MIT X Consortium license. To view the license, [see here](http://www.bouncycastle.org/licence.html). The OpenPGP library also includes a modified BZIP2 library which is licensed under the [Apache Software License, Version 2.0](http://www.apache.org/licenses/).
**Note**: this source tree is not the FIPS version of the APIs - if you are interested in our FIPS version please contact us directly at [office@bouncycastle.org](mailto:office@bouncycastle.org).
## Mailing Lists
For those who are interested, there are 2 mailing lists for participation in this project. To subscribe use the links below and include the word subscribe in the message body. (To unsubscribe, replace **subscribe** with **unsubscribe** in the message body)
* [announce-crypto-csharp-request@bouncycastle.org](mailto:announce-crypto-csharp-request@bouncycastle.org)
This mailing list is for new release announcements only, general subscribers cannot post to it.
* [dev-crypto-csharp-request@bouncycastle.org](mailto:dev-crypto-csharp-request@bouncycastle.org)
This mailing list is for discussion of development of the package. This includes bugs, comments, requests for enhancements, questions about use or operation.
**NOTE:**You need to be subscribed to send mail to the above mailing list.
## Feedback
If you want to provide feedback directly to the members of **The Legion** then please use [feedback-crypto@bouncycastle.org](mailto:feedback-crypto@bouncycastle.org), if you want to help this project survive please consider [donating](https://www.bouncycastle.org/donate).
For bug reporting/requests you can report issues here on github, via feedback-crypto if required, and we also have a [Jira issue tracker](http://www.bouncycastle.org/jira). We will accept pull requests based on this repository as well.
## Finally
Enjoy!

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ILMergeConsolePath>$(MSBuildThisFileDirectory)..\tools\net452\ILMerge.exe</ILMergeConsolePath>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,374 @@
# ILMerge
Michael Barnett<br/>
Research in Software Engineering (RiSE)<br/>
Microsoft Research<br/>
Copyright &copy; Microsoft Corporation. All rights reserved.
# 1. Introduction
This document describes the ILMerge utility which merges multiple .NET assemblies into a single assembly. However, some .NET assemblies may not be able to be merged because they may contain features such as unmanaged code. I would highly recommend using peverify (the .NET Framework SDK tool) on the output of ILMerge to guarantee that the output is verifiable and will load in the .NET runtime.
ILMerge is packaged as a console application. But all of its functionality is also accessible programmatically. Note that Visual Studio **does** allow one to add an executable as a reference, so you can write a client that uses ILMerge as a library.
ILMerge takes a set of _input assemblies_ and merges them into one _target assembly_. The first assembly in the list of input assemblies is the _primary assembly_. When the primary assembly is an executable, then the target assembly is created as an executable with the same entry point as the primary assembly. Also, if the primary assembly has a strong name, and a .snk file is provided, then the target assembly is re-signed with the specified key so that it also has a strong name.
Note that anything that depended upon any of the names of the input assemblies, e.g., configuration files, must be updated to refer instead to the name of the target assembly.
Any Win32 Resources in the primary assembly are copied over into the target assembly.
There are many options that control the behavior of ILMerge. These are described in the next section.
# 2. Public Interface
The public interface for ILMerge is defined in the ILMerging namespace as the class ILMerge.
```csharp
namespace ILMerging
{
public class ILMerge { }
}
```
To use this class programmatically, just create an instance using the default (nullary) constructor. There are several properties and methods which are used to affect the behavior of the merging. The method `Merge()` is called to actually perform the merging.
## 2.1 AllowDuplicateType
```csharp
public void AllowDuplicateType(string typeName);
```
The normal behavior of ILMerge is to not allow there to be more than one public type with the same name. If such a duplicate is found, then an exception is thrown. However, ILMerge can just rename the type so that it no longer causes a conflict. For private types, this is not a problem since no outside client can see it anyway, so ILMerge just does the renaming by default. For public types, it is not often a useful feature to have it renamed. However, there are situations where it is needed. In particular, for obfuscated assemblies, it seems that the obfuscator defines an attribute and creates an assembly-level attribute for the obfuscated assembly using that attribute. This would mean that obfuscated assemblies cannot be merged.
So this option allows the user to either allow all public types to be renamed when they are duplicates, or to specify it for arbitrary type names. On the command line, there can be as many options as desired, if followed by a colon and a type name, otherwise just specify it alone with no colon (and type name) to allow all duplicates.
When used through the API, an argument of &quot;null&quot; means to allow all public types to be renamed.
**Default:** no duplicates of public types allowed
**Command line option:** `[/allowDup[:typeName]]*`
## 2.2 AllowMultipleAssemblyLevelAttributes
```csharp
public bool AllowMultipleAssemblyLevelAttributes { get; set; }
```
When this is set before calling Merge, then if the CopyAttributes property (Section 2.7) is also set, any assembly-level attributes names that have the same type are copied over into the target directory as long as the definition of the attribute type specifies that &quot;AllowMultiple&quot; is true.
**Default:** `false`
**Command line option:** `/allowMultiple`
## 2.3 AllowWildCards
```csharp
public bool AllowWildCards { get; set; }
```
When this is set before calling Merge, any wild cards in file names are expanded and all matching files will be used as input. Note that because the wild card matching is done by a call to Directory.GetFiles, it does not allow the characters &quot;..&quot; to appear in a file name. So if you want to specify a relative path containing &quot;..&quot; to move up a directory, you will have to use it with the &quot;/lib&quot; option (Section 2.20). That option does allow the use of &quot;..&quot; to move up directories.
**Default:** `false`
**Command line option:** `/wildcards`
## 2.4 AllowZeroPeKind
```csharp
public bool AllowZeroPeKind { get; set; }
```
When this is set before calling Merge, then if an assembly&#39;s PeKind flag (this is the value of the field listed as .corflags in the Manifest) is zero it will be treated as if it was ILonly. This can be used to allow C++ assemblies to be merged; it does not appear that the C++ compiler writes the value as ILonly. However, if such an assembly has any non-IL features, then they will probably not be copied over into the target assembly correctly. So please use this option with caution.
**Default:** `false`
**Command line option:** `/zeroPeKind`
## 2.5 AttributeFile
```csharp
public string AttributeFile { get; set; }
```
If this is set before calling Merge, then it specifies the path and filename to an _atttribute assembly_, an assembly that will be used to get all of the assembly-level attributes such as Culture, Version, etc. It will also be used to get the Win32 Resources from. It is mutually exclusive with the CopyAttributes property (Section 2.7). When it is not specified, then the Win32 Resources from the primary assembly are copied over into the target assembly. If it is not a full path, then the current directory is used.
**Default:** `null`
**Command line option:** `/attr:filename`
## 2.6 Closed
```csharp
public bool Closed { get; set; }
```
When this is set before calling Merge, then the &quot;transitive closure&quot; of the input assemblies is computed and added to the list of input assemblies. An assembly is considered part of the transitive closure if it is referenced, either directly or indirectly, from one of the originally specified input assemblies and it has an external reference to one of the input assemblies, or one of the assemblies that has such a reference. Complicated, but that is life...
**Default:** `false`
**Command line option:** `/closed`
## 2.7 CopyAttributes
```csharp
public bool CopyAttributes { get; set; }
```
When this is set before calling Merge, then the assembly level attributes of each input assembly are copied over into the target assembly. Any duplicate attribute overwrites a previously copied attribute. If you want to allow duplicates (for those attributes whose type specifies &quot;AllowMultiple&quot; in their definition), then you can also set the AllowMultipleAssemblyLevelAttributes (Section 2.2). The input assemblies are processed in the order they are specified. This option is mutually exclusive with specifying an attribute assembly, i.e., the property AttributeFile (Section 2.5). When an attribute assembly is specified, then no assembly-level attributes are copied over from the input assemblies.
**Default:** `false`
**Command line option:** `/copyattrs`
## 2.8 DebugInfo
```csharp
public bool DebugInfo { get; set; }
```
When this is set to true, ILMerge creates a .pdb file for the output assembly and merges into it any .pdb files found for input assemblies. If you do not want a .pdb file created for the output assembly, either set this property to false or else specify the /ndebug option at the command line.
**Default:** `true`
**Command line option:** `/ndebug`
## 2.9 DelaySign
```csharp
public bool DelaySign { get; set; }
```
When this is set before calling Merge, then the target assembly will be delay signed. This can be set only in conjunction with the `/keyfile` option (Section 2.13).
**Default:** `false`
## 2.10 ExcludeFile
```csharp
public string ExcludeFile { get; set; }
```
This property is used only in conjunction with the Internalize property (Section 2.12). When this is set before calling Merge, it indicates the path and filename that will be used to identify types that are not to have their visibility modified. If Internalize is true, but ExcludeFile is &quot;&quot;, then all types in any assembly other than the primary assembly are made non-public. Setting this property implicitly sets Internalize to true.
The contents of the file should be one regular expression per line. The syntax is that defined in the .NET namespace System.Text.RegularExpressions for regular expressions. The regular expressions are matched against each type&#39;s full name, e.g., &quot;System.Collections.IList&quot;. If the match fails, it is tried again with the assembly name (surrounded by square brackets) prepended to the type name. Thus, the pattern &quot;\\[A\\].\\\*&quot; excludes all types in assembly A from being made non-public. (The backslashes are required because the string is treated as a regular expression.) The pattern &quot;N.T&quot; will match all types named T in the namespace named N no matter what assembly they are defined in.
It is important to note that the regular expressions are _not_ anchored to the beginning of the string; if this is desired, use the appropriate regular expression operator characters to do so.
**Default:** &quot;&quot;
**Command line option:** `/internalize[:excludeFile]`
## 2.11 FileAlignment
```csharp
public int FileAlignment { get; set; }
```
This controls the file alignment used for the target assembly. The setter sets the value to the largest power of two that is no larger than the supplied argument, and is at least 512.
**Default:** `512`
**Command line option:** `/align:n`
## 2.12 Internalize
```csharp
public bool Internalize { get; set; }
```
This controls whether types in assemblies _other than_ the primary assembly have their visibility modified. When it is true, then all non-exempt types that are visible outside of their assembly have their visibility modified so that they are not visible from outside of the merged assembly. A type is exempt if its _full name_ matches a line from the ExcludeFile (Section 2.10) using the .NET regular expression engine.
**Default:** `false`
**Command line option:** `/internalize[:excludeFile]`
## 2.13 KeyFile
```csharp
public string KeyFile { get; set; }
```
When this is set before calling Merge, it specifies the path and filename to a .snk file. The target assembly will be signed with its contents and will then have a strong name. It can be used with the DelaySign property (Section 2.9) to have the target assembly delay signed. This can be done even if the primary assembly was fully signed.
**Default:** `null`
**Command line option:** `/keyfile:filename`
## 2.14 Log
```csharp
public bool Log { get; set; }
```
When this is set before calling Merge, then log messages are written. It is used in conjunction with the LogFile property. If Log is true, but LogFile is null, then log messages are written to Console.Out. To specify this behavior on the command line, the option &quot;/log&quot; can be given without a log file.
**Default:** `false`
**Command line option:** `/log[:logfile]`
## 2.15 LogFile
```csharp
public string LogFile { get; set; }
```
When this is set before calling Merge, it indicates the path and filename that log messages are written to. If Log is true, but LogFile is null, then log messages are written to Console.Out.
**Default:** `null`
**Command line option:** `/log[:logfile]`
## 2.16 Merge
```csharp
public void Merge();
```
Once all desired options are set, this method performs the actual merging.
## 2.17 OutputFile
```csharp
public string OutputFile { get; set; }
```
This must be set before calling Merge. It specifies the path and filename that the target assembly will be written to.
**Default:** `null`
**Command line option:** `/out:filename`
## 2.18 PublicKeyTokens
```csharp
public bool PublicKeyTokens { get; set; }
```
This must be set before calling Merge. It indicates whether external assembly references in the manifest of the target assembly will use full public keys (false) or public key tokens (true).
**Default:** `true`
**Command line option:** `/useFullPublicKeyForReferences`
## 2.19 SetInputAssemblies
```csharp
public void SetInputAssemblies(string[] assems);
```
When used programmatically, each element of the array should contain the path and filename of an input assembly. The first element of the array is considered to be the primary assembly.
## 2.20 SetSearchDirectories
```csharp
public void SetSearchDirectories(string[] dirs);
```
If specified, this sets the directories to be used to search for input assemblies. When used programmatically, each element of the array should contain a directory name. When specified on the command line, use a separate &quot;/lib&quot; option for each directory.
**Command line option:** `/lib:directory`
## 2.21 SetTargetPlatform
```csharp
public void SetTargetPlatform(string platform, string dir);
```
This method sets the .NET Framework for the target assembly to be the one specified by platform. Valid strings for the first argument are `v1`, `v1.1`, `v2`, and `v4`;. The `v` is case insensitive and is also optional. This way ILMerge can be used to &quot;cross-compile&quot;, i.e., it can run in one version of the framework and generate the target assembly so it will run under a different assembly. The second argument is the directory in which `mscorlib.dll` is to be found.
**Command line option:** `/targetplatform:version,platformdirectory`
## 2.22 StrongNameLost
```csharp
public bool StrongNameLost { get; }
```
Once merging is complete, this property is true if and only if the primary assembly had a strong name, but the target assembly does not. This can occur when an .snk file is not specified, or if something goes wrong trying to read its contents.
## 2.23 TargetKind
```csharp
public ILMerge.Kind { get; set; }
```
This controls whether the target assembly is created as a library, a console application or as a Windows application. When it is not specified, then the target assembly will be the same kind as that of the primary assembly. (In that case, the file extensions found on the specified target assembly and the primary assembly must match.) When it is specified, then the file extension of the target assembly must match the specification.
The possible values are `ILMerge.Kind.{Dll, Exe, WinExe}`
**Default:** `ILMerge.Kind.SameAsPrimaryAssembly`
**Command line option:** `/target:(library|exe|winexe)`
## 2.24 UnionMerge
```csharp
public bool { get; set; }
```
When this is true, then types with the same name are all merged into a single type in the target assembly. The single type is the union of all of the individual types in the input assemblies: it contains all of the members from each of the corresponding types in the input assemblies. It cannot be specified at the same time as `/allowDup`.
**Default:** `false`
**Command line option:** `/union`
## 2.25 Version
```csharp
public System.Version Version { get; set; }
```
When this has a non-null value, then the target assembly will be given its value as the version number of the assembly. When specified on the command line, the version is read in as a string and should look like &quot;6.2.1.3&quot; (but without the quote marks). The version must be a valid assembly version as defined by the attribute AssemblyVersion in the System.Reflection namespace.
**Default:** `null`
**Command line option:** `/ver:version`
## 2.26 XmlDocumentation
```csharp
public bool XmlDocumentation { get; set; }
```
This property controls whether XML documentation files are merged to produce an XML documentation file for the target assembly.
**Default:** `false`
**Command line option:** `/xmldocs`
# 3 Command Line Usage
The full command line for ILMerge is:
```
ilmerge [/lib:directory]* [/log[:filename]] [/keyfile:filename [/delaysign]] [/internalize[:filename]]
[/t[arget]:(library|exe|winexe)] [/closed] [/ndebug] [/ver:version] [/copyattrs [/allowMultiple]]
[/xmldocs] [/attr:filename] ([/targetplatform:<version>[,<platformdir>]]|v1|v1.1|v2|v4)
[/useFullPublicKeyForReferences] [/zeroPeKind] [/wildcards] [/allowDup[:typename]]*
[/allowDuplicateResources] [/union] [/align:n]
/out:filename <primary assembly> [<other assemblies>...]
```
All options that take arguments can use either `:` or `=` as a separator. Options can be in any order, but all of the options must precede the list of input assemblies.
# 4 Troubleshooting
## 4.1 Input assembly not merged in correctly
A common problem is that after merging some assemblies, you get an error message stating that an input assembly was not merged in correctly because it is still listed as an external reference in the merged assembly. The most common cause of this problem is that one of the input assemblies, B, has an external reference to the incorrectly merged assembly, A, and also an external reference to another assembly, C, that itself has an external reference to A. Suppose the reference to C is to a method that takes an argument whose type is defined in A. Then the type signature of the method call to the method in C still refers to the type from A even in the merged assembly. After all, ILMerge cannot go and modify the assembly C so that it now depends on the type as it is defined in the output assembly after it has been merged!
The solution is to use the closed option (Section 2.6) to have ILMerge compute the transitive closure of the input assemblies to prevent this kind of &quot;dangling reference&quot;. In the example, that would result in all three assemblies A, B, and C, being merged. There is no way to merge just A and B without there still being an external reference to A.
## 4.2 Merged assembly causes a runtime error (not present in the unmerged assemblies)
The most frequent cause of problems when executing the target assembly is that ILMerge has no way to merge resources. Therefore resources are just copied over from the input assemblies into the target assembly. If these resources encode references to types defined in the input assemblies, then at runtime your program may fail because the type returned from the resource does not match the type as it is defined in the target assembly. You may even see a message that &quot;type &#39;T&#39; cannot be converted to type &#39;T&#39;&quot;. This looks confusing because the messages do not show the assembly that each type is defined in. The actual error is that one type is defined in the input assembly while the other is defined in the target assembly.
I do not know of any way to have ILMerge do the right thing in such cases. There is no general way to decode resources and change any type references they contain.
# 5 Dependencies
ILMerge is a stand-alone assembly dependent only on the v4.0 .NET Framework. (It actually uses two other assemblies: the assembly that makes up CCI itself, `System.Compiler.dll`, and `AssemblyResolver.dll`, which provides a small component for finding and loading assemblies when requested by the CCI Reader. But those assemblies have been merged into ILMerge using ILMerge before it is distributed.)
# 6 Acknowledgements
Without [Herman Venter](https://github.com/hermanventer), this tool could not have been written. Not only because it completely depends on CCI to provide the underlying functionality for reading, transforming, and writing IL, but because of all of his help and support.

Binary file not shown.

Binary file not shown.