// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
using System;
using System.IO;
using System.Reflection;
using System.Collections;
+using System.Security.Cryptography;
+using Mono.Security;
namespace Mono.ILASM {
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
DriverMain driver = new DriverMain (args);
- try {
if (!driver.Run ()) {
Console.WriteLine ();
Console.WriteLine ("***** FAILURE *****");
return 1;
}
- } catch (Exception e) {
- Console.WriteLine (e);
- Console.WriteLine ("Error while compiling.");
- return 1;
- }
Console.WriteLine ("Operation completed successfully");
return 0;
}
private bool show_method_ref = false;
private bool show_parser = false;
private bool scan_only = false;
+ private bool debugging_info = false;
private CodeGen codegen;
+ private bool keycontainer = false;
+ private string keyname;
public DriverMain (string[] args)
{
public bool Run ()
{
- try {
if (il_file_list.Count == 0)
Usage ();
if (output_file == null)
output_file = CreateOutputFile ();
- codegen = new CodeGen (output_file, target == Target.Dll, true, report);
+ codegen = new CodeGen (output_file, target == Target.Dll, true, debugging_info, report);
foreach (string file_path in il_file_list)
ProcessFile (file_path);
if (scan_only)
if (report.ErrorCount > 0)
return false;
codegen.Write ();
+
+ try {
+ if (keyname != null) {
+ Console.WriteLine ("Signing assembly with the specified strongname keypair");
+ return Sign (output_file);
+ }
} catch {
return false;
}
return true;
}
+ private bool Sign (string filename)
+ {
+ // note: if the file cannot be signed (no public key in it) then
+ // we do not show an error, or a warning, if the key file doesn't
+ // exists
+ StrongName sn = null;
+ if (keycontainer) {
+ CspParameters csp = new CspParameters ();
+ csp.KeyContainerName = keyname;
+ RSACryptoServiceProvider rsa = new RSACryptoServiceProvider (csp);
+ sn = new StrongName (rsa);
+ } else {
+ byte[] data = null;
+ using (FileStream fs = File.OpenRead (keyname)) {
+ data = new byte [fs.Length];
+ fs.Read (data, 0, data.Length);
+ fs.Close ();
+ }
+ sn = new StrongName (data);
+ }
+ return sn.Sign (filename);
+ }
+
private void ProcessFile (string file_path)
{
if (!File.Exists (file_path)) {
}
ILParser parser = new ILParser (codegen, scanner);
+ codegen.BeginSourceFile (file_path);
try {
if (show_parser)
parser.yyparse (new ScannerAdapter (scanner),
} catch {
Console.WriteLine ("Error at: " + scanner.Reader.Location);
throw;
- }
+ } finally {
+ codegen.EndSourceFile ();
+ }
}
public void ShowToken (object sender, NewTokenEventArgs args)
case "quiet":
quiet = true;
break;
+ case "debug":
+ case "deb":
+ if (str[0] != '-')
+ break;
+ debugging_info = true;
+ break;
// Stubs to stay commandline compatible with MS
case "listing":
case "nologo":
- case "debug":
case "clock":
case "error":
case "subsystem":
case "flags":
case "alignment":
case "base":
- case "key":
case "resource":
break;
+ case "key":
+ if (command_arg.Length > 0)
+ keycontainer = (command_arg [0] == '@');
+ if (keycontainer)
+ keyname = command_arg.Substring (1);
+ else
+ keyname = command_arg;
+ break;
case "scan_only":
scan_only = true;
break;
" /output:file_name Specifies output file.\n" +
" /exe Compile to executable.\n" +
" /dll Compile to library.\n" +
+ " /debug Include debug information.\n" +
+ " /key:keyfile Strongname using the specified key file\n" +
+ " /key:@container Strongname using the specified key container\n" +
"Options can be of the form -option or /option\n");
Environment.Exit (1);
}