[mapguide-commits] r6364 - in trunk/Tools/Maestro: . Maestro
SignMapGuideApi SignMapGuideApi/Properties
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Sun Dec 25 05:51:36 EST 2011
Author: jng
Date: 2011-12-25 02:51:36 -0800 (Sun, 25 Dec 2011)
New Revision: 6364
Added:
trunk/Tools/Maestro/SignMapGuideApi/
trunk/Tools/Maestro/SignMapGuideApi/Program.cs
trunk/Tools/Maestro/SignMapGuideApi/Properties/
trunk/Tools/Maestro/SignMapGuideApi/Properties/AssemblyInfo.cs
trunk/Tools/Maestro/SignMapGuideApi/SignMapGuideApi.csproj
Modified:
trunk/Tools/Maestro/Maestro/Maestro_All.sln
Log:
Add a utility to assist in signing of the official MapGuide API assemblies. Original source code provided by Hans Milling.
Modified: trunk/Tools/Maestro/Maestro/Maestro_All.sln
===================================================================
--- trunk/Tools/Maestro/Maestro/Maestro_All.sln 2011-12-24 14:20:28 UTC (rev 6363)
+++ trunk/Tools/Maestro/Maestro/Maestro_All.sln 2011-12-25 10:51:36 UTC (rev 6364)
@@ -93,6 +93,8 @@
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalConfigure", "..\LocalConfigure\LocalConfigure.csproj", "{6EE16FFD-296E-42FF-B994-8902C27AA0F4}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignMapGuideApi", "..\SignMapGuideApi\SignMapGuideApi.csproj", "{D24F724A-1CBF-4EB6-A48B-92C08353C4CC}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -227,6 +229,10 @@
{6EE16FFD-296E-42FF-B994-8902C27AA0F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6EE16FFD-296E-42FF-B994-8902C27AA0F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6EE16FFD-296E-42FF-B994-8902C27AA0F4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D24F724A-1CBF-4EB6-A48B-92C08353C4CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D24F724A-1CBF-4EB6-A48B-92C08353C4CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D24F724A-1CBF-4EB6-A48B-92C08353C4CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D24F724A-1CBF-4EB6-A48B-92C08353C4CC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Property changes on: trunk/Tools/Maestro/SignMapGuideApi
___________________________________________________________________
Added: svn:ignore
+ bin
obj
Added: trunk/Tools/Maestro/SignMapGuideApi/Program.cs
===================================================================
--- trunk/Tools/Maestro/SignMapGuideApi/Program.cs (rev 0)
+++ trunk/Tools/Maestro/SignMapGuideApi/Program.cs 2011-12-25 10:51:36 UTC (rev 6364)
@@ -0,0 +1,233 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using System.Diagnostics;
+
+namespace SignMapGuideApi
+{
+ class Program
+ {
+ static string[] files = { "MapGuideDotNetApi", "OSGeo.MapGuide.Foundation", "OSGeo.MapGuide.Geometry", "OSGeo.MapGuide.MapGuideCommon", "OSGeo.MapGuide.PlatformBase", "OSGeo.MapGuide.Web" };
+ static string[] ildasm32 = { "C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\Bin\\ildasm.exe",
+ "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v6.0A\\Bin\\ildasm.exe",
+ "C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\ildasm.exe",
+ "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\ildasm.exe" };
+ static string[] ildasm64 = { "C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\Bin\\x64\\ildasm.exe",
+ "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v6.0A\\Bin\\x64\\ildasm.exe",
+ "C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\x64\\ildasm.exe",
+ "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\x64\\ildasm.exe" };
+
+ static string[] ilasm32 = { "C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\ilasm.exe", "C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\ilasm.exe" };
+ static string[] ilasm64 = { "C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\ilasm.exe", "C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\ilasm.exe" };
+
+ //TODO: Allow for custom key and infer public key token from it
+ static string _keyFile = "maestroapi.key";
+ static string _publicKeyToken = "F5 26 C4 89 29 FD A8 56";
+
+ static bool Is64BitProcess()
+ {
+ return IntPtr.Size == 8;
+ }
+
+ static string getILDASMEXE()
+ {
+ if (Is64BitProcess())
+ {
+ foreach (string f in ildasm64)
+ if (File.Exists(f))
+ return f;
+ }
+ else
+ {
+ foreach (string f in ildasm32)
+ if (File.Exists(f))
+ return f;
+ }
+ return null;
+ }
+
+ static string getILASMEXE()
+ {
+ if (Is64BitProcess())
+ {
+ foreach (string f in ilasm64)
+ if (File.Exists(f))
+ return f;
+ }
+ else
+ {
+ foreach (string f in ilasm32)
+ if (File.Exists(f))
+ return f;
+ }
+ return null;
+ }
+
+ static void backup()
+ {
+ Console.Write("Creating Backup folder...");
+ Directory.CreateDirectory("Backup");
+ Console.WriteLine("Done");
+ Console.WriteLine("Backing up original DLL files.");
+ foreach (string f in files)
+ {
+ string file = f + ".dll";
+ if (!File.Exists(file))
+ {
+ Console.WriteLine("[WARNING]: Could not find file to backup (" + file + ")");
+ continue;
+ }
+ Console.Write("Copying " + file + "...");
+ File.Copy(file, "Backup\\" + file, true);
+ Console.WriteLine("Done");
+ }
+ }
+
+ static void decompile(string decompiler)
+ {
+ foreach (string f in files)
+ {
+ string file = f + ".dll";
+ if (!File.Exists(file))
+ {
+ Console.WriteLine("[WARNING]: Could not find file to decompilation (" + file + ")");
+ continue;
+ }
+ Console.Write("Decompiling: " + file + "...");
+ Process p = Process.Start(decompiler, "/all /out=" + f + ".il " + file);
+ p.WaitForExit();
+ p.Dispose();
+ Console.WriteLine("Done");
+ }
+ }
+
+ static void cleandll()
+ {
+ foreach (string f in files)
+ {
+ string file = f + ".dll";
+ Console.Write("Deleting " + file + "...");
+ File.Delete(file);
+ Console.WriteLine("done");
+ }
+ }
+
+ static void compile(string compiler, string file)
+ {
+ if (!File.Exists(file + ".il"))
+ {
+ Console.WriteLine("[WARNING]: No IL file to compile (" + file + ".il)");
+ return;
+ }
+
+ Console.Write("Compiling: " + file + ".il...");
+ Process p = Process.Start(compiler, "/dll /key=" + _keyFile + " " + file + ".il");
+ p.WaitForExit();
+ p.Dispose();
+ Console.WriteLine("Done");
+ }
+
+ static bool assemblyLine(string line)
+ {
+ string l = line.ToLower();
+ if (l.StartsWith(".assembly extern"))
+ {
+ bool ends = false;
+ foreach (string f in files)
+ {
+ if (l.EndsWith(f.ToLower()))
+ {
+ ends = true;
+ Console.WriteLine(" Added key to section: " + l);
+ break;
+ }
+ }
+ return ends;
+ }
+ return false;
+ }
+
+ static void fixKey(string file)
+ {
+ string ilfile = file + ".il";
+ if (!File.Exists(ilfile))
+ {
+ Console.WriteLine("[WARNING]: Cannot find IL file to fix (" + ilfile + ")");
+ return;
+ }
+
+ string tempfile = file + ".temp";
+ File.Move(ilfile, tempfile); // rename file to .temp
+ System.IO.StreamReader fin = new System.IO.StreamReader(tempfile); // open file for read
+ System.IO.StreamWriter fout = new System.IO.StreamWriter(ilfile, false); // open file for write
+ string line;
+ Console.WriteLine("Fixing: " + ilfile);
+ int count = 0;
+ while ((line = fin.ReadLine()) != null) // read line by line
+ {
+ fout.WriteLine(line); // copy line to new file
+ if (assemblyLine(line)) // if line starts with .assembly extern and ends with one in file names
+ {
+ line = fin.ReadLine(); // Copy next line containing: {
+ fout.WriteLine(line);
+ fout.WriteLine(" .publickeytoken = (" + _publicKeyToken + " )"); // Write .publickeytoken line
+ }
+ count++;
+ }
+ fout.Close();
+ fin.Close();
+ }
+
+ static void cleanup()
+ {
+ Console.Write("Cleanup...");
+ foreach (string f in files)
+ {
+ if (File.Exists(f + ".temp"))
+ File.Delete(f + ".temp");
+
+ if (File.Exists(f + ".il"))
+ File.Delete(f + ".il");
+
+ if (File.Exists(f + ".res"))
+ File.Delete(f + ".res");
+ }
+ Console.WriteLine("Done");
+ }
+
+ static void Main(string[] args)
+ {
+ try
+ {
+ if (File.Exists(_keyFile))
+ {
+ Console.Write("Detecting tools...");
+ string ildasmexe = getILDASMEXE(); // Detect 32 or 64 bit versions of decompiler and compiler
+ string ilasmexe = getILASMEXE();
+ Console.WriteLine("Done");
+ Console.WriteLine("Compiler: " + ilasmexe);
+ Console.WriteLine("Decompiler: " + ildasmexe);
+ backup(); // make backup copy of dll
+ decompile(ildasmexe); // decompile dll files
+ cleandll();
+ for (int i = files.Length - 1; i >= 0; i--) // Compile the il files back to dll, fixing any missing key tokens in the references
+ {
+ fixKey(files[i]);
+ compile(ilasmexe, files[i]);
+ }
+ cleanup();
+ Console.WriteLine("All OSGeo files has been signed.");
+ }
+ else
+ {
+ Console.WriteLine("Error: The file '" + _keyFile + "' is missing. This is required to sign the DLL files.");
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Error:\r\n" + ex.ToString());
+ }
+ }
+ }
+}
Added: trunk/Tools/Maestro/SignMapGuideApi/Properties/AssemblyInfo.cs
===================================================================
--- trunk/Tools/Maestro/SignMapGuideApi/Properties/AssemblyInfo.cs (rev 0)
+++ trunk/Tools/Maestro/SignMapGuideApi/Properties/AssemblyInfo.cs 2011-12-25 10:51:36 UTC (rev 6364)
@@ -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("SignMapGuideApi")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("SignMapGuideApi")]
+[assembly: AssemblyCopyright("Copyright © 2011")]
+[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("eb96b48e-b456-4715-ae7c-b73522414bf9")]
+
+// 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")]
Added: trunk/Tools/Maestro/SignMapGuideApi/SignMapGuideApi.csproj
===================================================================
--- trunk/Tools/Maestro/SignMapGuideApi/SignMapGuideApi.csproj (rev 0)
+++ trunk/Tools/Maestro/SignMapGuideApi/SignMapGuideApi.csproj 2011-12-25 10:51:36 UTC (rev 6364)
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{D24F724A-1CBF-4EB6-A48B-92C08353C4CC}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>SignMapGuideApi</RootNamespace>
+ <AssemblyName>SignMapGuideApi</AssemblyName>
+ <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>..\SDK\bin\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>..\SDK\bin\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file
More information about the mapguide-commits
mailing list