Datei: NDOEnhancer/NDOEnhancer/Dasm.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.IO;
26 using System.Diagnostics;
27 using Microsoft.Win32;
28 using System.Reflection;
29
30 namespace NDOEnhancer
31 {
32 ····/// <summary>
33 ····/// Summary description for Dasm.
34 ····/// </summary>
35 ····internal class Dasm
36 ····{
37 ········string ilDasmPath = string.Empty;
38 ········MessageAdapter messages;
39 ········bool verboseMode;
40
41 ········void CheckILDasmPath()
42 ········{
43 ············string path;
44 ············if (System.OperatingSystem.IsLinux())
45 ················path = Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "runtimes", "linux-x64", "native", "ildasm" );
46 ············else if (System.OperatingSystem.IsWindows())
47 ················path = Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "runtimes", "win-x64", "native", "ildasm.exe" );
48 ············else
49 ················throw new Exception( "Can't determine, if NDOEnhancer is running on Windows or Linux." );
50
51 ············this.ilDasmPath = path;
52 ········}
53
54 ········public Dasm(MessageAdapter messages, bool verboseMode)
55 ········{
56 ············this.messages = messages;
57 ············this.verboseMode = verboseMode;
58
59 ············CheckILDasmPath();
60
61 ········}
62
63 ········public void DoIt(string dllName, string ilName)
64 ········{
65 ············if (verboseMode)
66 ················messages.WriteLine("Disassembling: " + dllName + "->" + ilName);
67
68 ············ProcessStartInfo psi = new ProcessStartInfo( ilDasmPath,
69 " /LINENUM"
70 #if !NETCOREAPP2_0 && !NET6_0_OR_GREATER
71 + " /NOBAR"
72 #endif
73 + " /UNICODE "
74 ················+ '"' + dllName + '"'
75 + @" /OUT=""" + ilName + '"') ;
76 ············psi.CreateNoWindow·········· = true;
77 ············psi.UseShellExecute·········· = false;
78 ············psi.WorkingDirectory······ = Path.GetDirectoryName(dllName);
79 ············psi.RedirectStandardError··= true;
80
81 ············System.Diagnostics.Process proc = System.Diagnostics.Process.Start( psi );
82 ············proc.WaitForExit();
83 ············string stderr = proc.StandardError.ReadToEnd();
84
85 ············if ( 0 < stderr.Length )
86 ············{
87 ················if (stderr.IndexOf("ERROR") > -1)
88 ····················throw new Exception(stderr);
89 ············}
90 ········}
91 ····}
92 }
93
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.IO;
26 using System.Diagnostics;
27 using Microsoft.Win32;
28 using System.Reflection;
29
30 namespace NDOEnhancer
31 {
32 ····/// <summary>
33 ····/// Summary description for Dasm.
34 ····/// </summary>
35 ····internal class Dasm
36 ····{
37 ········string ilDasmPath = string.Empty;
38 ········MessageAdapter messages;
39 ········bool verboseMode;
40
41 ········void CheckILDasmPath()
42 ········{
43 ············string path;
44 ············if (System.OperatingSystem.IsLinux())
45 ················path = Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "runtimes", "linux-x64", "native", "ildasm" );
46 ············else if (System.OperatingSystem.IsWindows())
47 ················path = Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "runtimes", "win-x64", "native", "ildasm.exe" );
48 ············else
49 ················throw new Exception( "Can't determine, if NDOEnhancer is running on Windows or Linux." );
50
51 ············this.ilDasmPath = path;
52 ········}
53
54 ········public Dasm(MessageAdapter messages, bool verboseMode)
55 ········{
56 ············this.messages = messages;
57 ············this.verboseMode = verboseMode;
58
59 ············CheckILDasmPath();
60
61 ········}
62
63 ········public void DoIt(string dllName, string ilName)
64 ········{
65 ············if (verboseMode)
66 ················messages.WriteLine("Disassembling: " + dllName + "->" + ilName);
67
68 ············ProcessStartInfo psi = new ProcessStartInfo( ilDasmPath,
69 " -LINENUM"
70 #if !NETCOREAPP2_0 && !NET6_0_OR_GREATER
71 + " -NOBAR"
72 #endif
73 + " -UNICODE "
74 ················+ '"' + dllName + '"'
75 + @" -OUT=""" + ilName + '"') ;
76 ············psi.CreateNoWindow·········· = true;
77 ············psi.UseShellExecute·········· = false;
78 ············psi.WorkingDirectory······ = Path.GetDirectoryName(dllName);
79 ············psi.RedirectStandardError··= true;
80
81 ············System.Diagnostics.Process proc = System.Diagnostics.Process.Start( psi );
82 ············proc.WaitForExit();
83 ············string stderr = proc.StandardError.ReadToEnd();
84
85 ············if ( 0 < stderr.Length )
86 ············{
87 ················if (stderr.IndexOf("ERROR") > -1)
88 ····················throw new Exception(stderr);
89 ············}
90 ········}
91 ····}
92 }
93