Datei: NDOEnhancer/NDOEnhancer/Asm.cs
Last Commit (3c5cca3)
| 1 | // |
| 2 | // Copyright (c) 2002-2022 Mirko Matytschak |
| 3 | // (www.netdataobjects.de) |
| 4 | // |
| 5 | // Author: Mirko Matytschak |
| 6 | // |
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 11 | // conditions: |
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 14 | // of the Software. |
| 15 | // |
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | |
| 23 | using System; |
| 24 | using System.Linq; |
| 25 | using System.Diagnostics; |
| 26 | using System.IO; |
| 27 | using Microsoft.Win32; |
| 28 | using System.Globalization; |
| 29 | using System.Reflection; |
| 30 | |
| 31 | namespace NDOEnhancer |
| 32 | { |
| 33 | ····/// <summary> |
| 34 | ····/// Summary description for Asm. |
| 35 | ····/// </summary> |
| 36 | ····internal class Asm : ConsoleProcess |
| 37 | ····{ |
| 38 | ········string ilAsmPath; |
| 39 | ········MessageAdapter messages; |
| 40 | |
| 41 | ········void CheckIlAsmPath() |
| 42 | ········{ |
| 43 | ············string path; |
| 44 | ············if (System.OperatingSystem.IsLinux()) |
| 45 | ················path = Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "runtimes", "linux-x64", "native", "ilasm" ); |
| 46 | ············else if (System.OperatingSystem.IsWindows()) |
| 47 | ················path = Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "runtimes", "win-x64", "native", "ilasm.exe" ); |
| 48 | ············else |
| 49 | ················throw new Exception( "Can't determine, if NDOEnhancer is running on Windows or Linux." ); |
| 50 | |
| 51 | ············this.ilAsmPath = path; |
| 52 | ········} |
| 53 | |
| 54 | ········public Asm(MessageAdapter messages, bool verboseMode) : base(verboseMode) |
| 55 | ········{ |
| 56 | ············this.messages = messages; |
| 57 | |
| 58 | ············CheckIlAsmPath(); |
| 59 | ········} |
| 60 | |
| 61 | ········public void DoIt(string ilFileName, string dllFileName, string keyFileName, bool debug) |
| 62 | ········{ |
| 63 | ············if (!File.Exists(ilFileName)) |
| 64 | ················throw new Exception("Assembling: File not found: " + ilFileName); |
| 65 | |
| 66 | ············// Dll or Exe? |
| 67 | string libMode = "/" + Path. GetExtension( dllFileName) . Substring( 1) . ToUpper( ) ; |
| 68 | string debugMode = debug ? " /DEBUG /PDB" : string. Empty; |
| 69 | string key = keyFileName != null ? " /KEY=\"" + keyFileName + '"' : string. Empty; |
| 70 | |
| 71 | ············string parameters = |
| 72 | ················libMode |
| 73 | ················+ debugMode |
| 74 | ················+ key |
| 75 | + " /QUIET" |
| 76 | + " /NOLOGO" |
| 77 | + " /OUTFILE=\"" + dllFileName + "\"" |
| 78 | ················+ " \"" + ilFileName + "\"" ; |
| 79 | |
| 80 | ············Execute(ilAsmPath, parameters/*, Path.GetDirectoryName(dllFileName)*/); |
| 81 | ············string errorMessage = string.Empty; |
| 82 | ············if (Stderr != string.Empty) |
| 83 | ················errorMessage = Stderr; |
| 84 | ············int p = Stdout.IndexOf("Error:"); |
| 85 | ············if (p > -1) |
| 86 | ············{ |
| 87 | ················if (errorMessage != string.Empty) |
| 88 | ····················errorMessage += '\n'; |
| 89 | ················errorMessage += Stdout.Substring(p + 7); |
| 90 | ············} |
| 91 | ············if (errorMessage != string.Empty) |
| 92 | ············{ |
| 93 | ················if (errorMessage.IndexOf( "error", StringComparison.InvariantCultureIgnoreCase ) > -1) |
| 94 | ················{ |
| 95 | ····················Console.WriteLine( errorMessage ); |
| 96 | ····················throw new Exception( "ILAsm failure" ); |
| 97 | ················} |
| 98 | ················else |
| 99 | ················{ |
| 100 | ····················Console.WriteLine( errorMessage ); |
| 101 | ················} |
| 102 | ············} |
| 103 | ········} |
| 104 | ····} |
| 105 | } |
| 106 |
New Commit (dbc6a64)
| 1 | // |
| 2 | // Copyright (c) 2002-2022 Mirko Matytschak |
| 3 | // (www.netdataobjects.de) |
| 4 | // |
| 5 | // Author: Mirko Matytschak |
| 6 | // |
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 11 | // conditions: |
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 14 | // of the Software. |
| 15 | // |
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | |
| 23 | using System; |
| 24 | using System.Linq; |
| 25 | using System.Diagnostics; |
| 26 | using System.IO; |
| 27 | using Microsoft.Win32; |
| 28 | using System.Globalization; |
| 29 | using System.Reflection; |
| 30 | |
| 31 | namespace NDOEnhancer |
| 32 | { |
| 33 | ····/// <summary> |
| 34 | ····/// Summary description for Asm. |
| 35 | ····/// </summary> |
| 36 | ····internal class Asm : ConsoleProcess |
| 37 | ····{ |
| 38 | ········string ilAsmPath; |
| 39 | ········MessageAdapter messages; |
| 40 | |
| 41 | ········void CheckIlAsmPath() |
| 42 | ········{ |
| 43 | ············string path; |
| 44 | ············if (System.OperatingSystem.IsLinux()) |
| 45 | ················path = Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "runtimes", "linux-x64", "native", "ilasm" ); |
| 46 | ············else if (System.OperatingSystem.IsWindows()) |
| 47 | ················path = Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "runtimes", "win-x64", "native", "ilasm.exe" ); |
| 48 | ············else |
| 49 | ················throw new Exception( "Can't determine, if NDOEnhancer is running on Windows or Linux." ); |
| 50 | |
| 51 | ············this.ilAsmPath = path; |
| 52 | ········} |
| 53 | |
| 54 | ········public Asm(MessageAdapter messages, bool verboseMode) : base(verboseMode) |
| 55 | ········{ |
| 56 | ············this.messages = messages; |
| 57 | |
| 58 | ············CheckIlAsmPath(); |
| 59 | ········} |
| 60 | |
| 61 | ········public void DoIt(string ilFileName, string dllFileName, string keyFileName, bool debug) |
| 62 | ········{ |
| 63 | ············if (!File.Exists(ilFileName)) |
| 64 | ················throw new Exception("Assembling: File not found: " + ilFileName); |
| 65 | |
| 66 | ············// Dll or Exe? |
| 67 | string libMode = "-" + Path. GetExtension( dllFileName) . Substring( 1) . ToUpper( ) ; |
| 68 | string debugMode = debug ? " -DEBUG -PDB" : string. Empty; |
| 69 | string key = keyFileName != null ? " -KEY=\"" + keyFileName + '"' : string. Empty; |
| 70 | |
| 71 | ············string parameters = |
| 72 | ················libMode |
| 73 | ················+ debugMode |
| 74 | ················+ key |
| 75 | + " -QUIET" |
| 76 | + " -NOLOGO" |
| 77 | + " -OUTPUT=\"" + dllFileName + "\"" |
| 78 | ················+ " \"" + ilFileName + "\"" ; |
| 79 | |
| 80 | ············Execute(ilAsmPath, parameters/*, Path.GetDirectoryName(dllFileName)*/); |
| 81 | ············string errorMessage = string.Empty; |
| 82 | ············if (Stderr != string.Empty) |
| 83 | ················errorMessage = Stderr; |
| 84 | ············int p = Stdout.IndexOf("Error:"); |
| 85 | ············if (p > -1) |
| 86 | ············{ |
| 87 | ················if (errorMessage != string.Empty) |
| 88 | ····················errorMessage += '\n'; |
| 89 | ················errorMessage += Stdout.Substring(p + 7); |
| 90 | ············} |
| 91 | ············if (errorMessage != string.Empty) |
| 92 | ············{ |
| 93 | ················if (errorMessage.IndexOf( "error", StringComparison.InvariantCultureIgnoreCase ) > -1) |
| 94 | ················{ |
| 95 | ····················Console.WriteLine( errorMessage ); |
| 96 | ····················throw new Exception( "ILAsm failure" ); |
| 97 | ················} |
| 98 | ················else |
| 99 | ················{ |
| 100 | ····················Console.WriteLine( errorMessage ); |
| 101 | ················} |
| 102 | ············} |
| 103 | ········} |
| 104 | ····} |
| 105 | } |
| 106 |