You've already forked linux-packaging-mono
Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
22
external/ikdasm/Program.cs
vendored
22
external/ikdasm/Program.cs
vendored
@@ -36,6 +36,7 @@ namespace Ildasm
|
||||
{
|
||||
string outputFile = null;
|
||||
string inputFile = null;
|
||||
MetadataTableIndex? tableToDump = null;
|
||||
var compatLevel = CompatLevel.None;
|
||||
var flags = Flags.None;
|
||||
|
||||
@@ -44,7 +45,10 @@ namespace Ildasm
|
||||
|
||||
var p = new OptionSet () {
|
||||
{ "help", v => printUsage = true },
|
||||
{ "out", v => outputFile = v }
|
||||
{ "out", v => outputFile = v },
|
||||
{ "assembly", v =>tableToDump = MetadataTableIndex.Assembly },
|
||||
{ "assemblyref", v =>tableToDump = MetadataTableIndex.AssemblyRef },
|
||||
{ "moduleref", v =>tableToDump = MetadataTableIndex.ModuleRef },
|
||||
};
|
||||
args = p.Parse (args).ToArray ();
|
||||
if (printUsage) {
|
||||
@@ -117,6 +121,22 @@ namespace Ildasm
|
||||
PrintUsage();
|
||||
return 1;
|
||||
}
|
||||
if (tableToDump.HasValue)
|
||||
{
|
||||
var tableDumper = new TableDumper(inputFile);
|
||||
if (outputFile != null)
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter(outputFile, false))
|
||||
{
|
||||
tableDumper.DumpTable(sw, tableToDump.Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tableDumper.DumpTable(Console.Out, tableToDump.Value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
var disassembler = new Disassembler(inputFile, outputFile, compatLevel, flags);
|
||||
if (outputFile != null)
|
||||
{
|
||||
|
||||
142
external/ikdasm/TableDumper.cs
vendored
Normal file
142
external/ikdasm/TableDumper.cs
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
//
|
||||
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using IKVM.Reflection;
|
||||
|
||||
namespace Ildasm
|
||||
{
|
||||
enum MetadataTableIndex {
|
||||
ModuleRef = 0x1a,
|
||||
Assembly = 0x20,
|
||||
AssemblyRef = 0x23,
|
||||
}
|
||||
|
||||
class TableDumper
|
||||
{
|
||||
Universe universe;
|
||||
Assembly assembly;
|
||||
Module module;
|
||||
|
||||
public TableDumper (string inputFile) {
|
||||
universe = new Universe (UniverseOptions.None);
|
||||
|
||||
var raw = universe.OpenRawModule (System.IO.File.OpenRead (inputFile), System.IO.Path.GetTempPath () + "/Dummy");
|
||||
if (raw.IsManifestModule)
|
||||
{
|
||||
assembly = universe.LoadAssembly (raw);
|
||||
module = assembly.ManifestModule;
|
||||
}
|
||||
else
|
||||
{
|
||||
var ab = universe.DefineDynamicAssembly (new AssemblyName ("<ModuleContainer>"), IKVM.Reflection.Emit.AssemblyBuilderAccess.ReflectionOnly);
|
||||
assembly = ab;
|
||||
module = ab.__AddModule (raw);
|
||||
}
|
||||
}
|
||||
|
||||
public void DumpTable (TextWriter w, MetadataTableIndex tableIndex) {
|
||||
switch (tableIndex) {
|
||||
case MetadataTableIndex.Assembly:
|
||||
DumpAssemblyTable (w);
|
||||
break;
|
||||
case MetadataTableIndex.AssemblyRef:
|
||||
DumpAssemblyRefTable (w);
|
||||
break;
|
||||
case MetadataTableIndex.ModuleRef:
|
||||
DumpModuleRefTable (w);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
}
|
||||
|
||||
void HexDump (TextWriter w, byte[] bytes, int len) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if ((i % 16) == 0)
|
||||
w.Write (String.Format ("\n0x{0:x08}: ", i));
|
||||
w.Write (String.Format ("{0:X02} ", bytes [i]));
|
||||
}
|
||||
}
|
||||
|
||||
void DumpAssemblyTable (TextWriter w) {
|
||||
var t = module.AssemblyTable;
|
||||
w.WriteLine ("Assembly Table");
|
||||
foreach (var r in t.records) {
|
||||
w.WriteLine (String.Format ("Name: {0}", module.GetString (r.Name)));
|
||||
w.WriteLine (String.Format ("Hash Algoritm: 0x{0:x08}", r.HashAlgId));
|
||||
w.WriteLine (String.Format ("Version: {0}.{1}.{2}.{3}", r.MajorVersion, r.MinorVersion, r.BuildNumber, r.RevisionNumber));
|
||||
w.WriteLine (String.Format ("Flags: 0x{0:x08}", r.Flags));
|
||||
w.WriteLine (String.Format ("PublicKey: BlobPtr (0x{0:x08})", r.PublicKey));
|
||||
|
||||
var blob = module.GetBlob (r.PublicKey);
|
||||
if (blob.Length == 0) {
|
||||
w.WriteLine ("\tZero sized public key");
|
||||
} else {
|
||||
w.Write ("\tDump:");
|
||||
byte[] bytes = blob.ReadBytes (blob.Length);
|
||||
HexDump (w, bytes, bytes.Length);
|
||||
w.WriteLine ();
|
||||
}
|
||||
w.WriteLine (String.Format ("Culture: {0}", module.GetString (r.Culture)));
|
||||
w.WriteLine ();
|
||||
}
|
||||
}
|
||||
|
||||
void DumpAssemblyRefTable (TextWriter w) {
|
||||
var t = module.AssemblyRef;
|
||||
w.WriteLine ("AssemblyRef Table");
|
||||
int rowIndex = 1;
|
||||
foreach (var r in t.records) {
|
||||
w.WriteLine (String.Format ("{0}: Version={1}.{2}.{3}.{4}", rowIndex, r.MajorVersion, r.MinorVersion, r.BuildNumber, r.RevisionNumber));
|
||||
w.WriteLine (String.Format ("\tName={0}", module.GetString (r.Name)));
|
||||
w.WriteLine (String.Format ("\tFlags=0x{0:x08}", r.Flags));
|
||||
var blob = module.GetBlob (r.PublicKeyOrToken);
|
||||
if (blob.Length == 0) {
|
||||
w.WriteLine ("\tZero sized public key");
|
||||
} else {
|
||||
w.Write ("\tPublic Key:");
|
||||
byte[] bytes = blob.ReadBytes (blob.Length);
|
||||
HexDump (w, bytes, bytes.Length);
|
||||
w.WriteLine ();
|
||||
}
|
||||
w.WriteLine ();
|
||||
rowIndex ++;
|
||||
}
|
||||
}
|
||||
|
||||
void DumpModuleRefTable (TextWriter w) {
|
||||
var t = module.ModuleRef;
|
||||
w.WriteLine ("ModuleRef Table (1.." + t.RowCount + ")");
|
||||
int rowIndex = 1;
|
||||
foreach (var r in t.records) {
|
||||
w.WriteLine (String.Format ("{0}: {1}", rowIndex, module.GetString (r)));
|
||||
rowIndex ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user