Skip to content

Commit

Permalink
Update and enable NGEN fix for Linux / macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ade committed May 11, 2020
1 parent ee5ea0f commit 785eaf3
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 43 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
24 changes: 24 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build",
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
2 changes: 1 addition & 1 deletion MonoMod.Common
82 changes: 40 additions & 42 deletions MonoMod.UnitTest/RuntimeDetour/DetourExtTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,61 +78,59 @@ public void TestDetoursExt() {
// This was provided by a Harmony user.
// TextWriter's methods (including all overrides) were unable to be hooked on some runtimes.
// FIXME: .NET 5 introduces similar behavior for macOS and Linux, but RD isn't ready for that. See DetourRuntimeNETPlatform for more info.
if (PlatformHelper.Is(Platform.Windows)) {
#if true
using (MemoryStream ms = new MemoryStream()) {

using (StreamWriter writer = new StreamWriter(ms, Encoding.UTF8, 1024, true)) {
// In case anyone needs to debug this mess anytime in the future ever again:
/*
MethodBase m = typeof(StreamWriter).GetMethod("Write", new Type[] { typeof(string) });
Console.WriteLine($"meth: 0x{(long) m?.MethodHandle.Value:X16}");
Console.WriteLine($"getf: 0x{(long) m?.MethodHandle.GetFunctionPointer():X16}");
Console.WriteLine($"fptr: 0x{(long) m?.GetLdftnPointer():X16}");
Console.WriteLine($"nats: 0x{(long) m?.GetNativeStart():X16}");
*/

using (MemoryStream ms = new MemoryStream()) {

using (StreamWriter writer = new StreamWriter(ms, Encoding.UTF8, 1024, true)) {
// In case anyone needs to debug this mess anytime in the future ever again:
/*/
MethodBase m = typeof(StreamWriter).GetMethod("Write", new Type[] { typeof(string) });
Console.WriteLine($"meth: 0x{(long) m?.MethodHandle.Value:X16}");
Console.WriteLine($"getf: 0x{(long) m?.MethodHandle.GetFunctionPointer():X16}");
Console.WriteLine($"fptr: 0x{(long) m?.GetLdftnPointer():X16}");
Console.WriteLine($"nats: 0x{(long) m?.GetNativeStart():X16}");
/**/

// Debugger.Break();
writer.Write("A");

using (Hook h = new Hook(
typeof(StreamWriter).GetMethod("Write", new Type[] { typeof(string) }),
new Action<Action<StreamWriter, string>, StreamWriter, string>((orig, self, value) => {
orig(self, "-");
})
)) {
// Debugger.Break();
writer.Write("A");

using (Hook h = new Hook(
typeof(StreamWriter).GetMethod("Write", new Type[] { typeof(string) }),
new Action<Action<StreamWriter, string>, StreamWriter, string>((orig, self, value) => {
orig(self, "-");
})
)) {
// Debugger.Break();
writer.Write("B");
}

writer.Write("C");
writer.Write("B");
}

ms.Seek(0, SeekOrigin.Begin);
writer.Write("C");
}

using (StreamReader reader = new StreamReader(ms, Encoding.UTF8, false, 1024, true)) {
Assert.Equal("A-C", reader.ReadToEnd());
}
ms.Seek(0, SeekOrigin.Begin);

using (StreamReader reader = new StreamReader(ms, Encoding.UTF8, false, 1024, true)) {
Assert.Equal("A-C", reader.ReadToEnd());
}

}
#endif

#if NETFRAMEWORK && true
Assert.Equal("A", new SqlCommand("A").CommandText);

using (Hook h = new Hook(
typeof(SqlCommand).GetConstructor(new Type[] { typeof(string) }),
new Action<Action<SqlCommand, string>, SqlCommand, string>((orig, self, value) => {
orig(self, "-");
})
)) {
Assert.Equal("-", new SqlCommand("B").CommandText);
}
Assert.Equal("A", new SqlCommand("A").CommandText);

Assert.Equal("C", new SqlCommand("C").CommandText);
using (Hook h = new Hook(
typeof(SqlCommand).GetConstructor(new Type[] { typeof(string) }),
new Action<Action<SqlCommand, string>, SqlCommand, string>((orig, self, value) => {
orig(self, "-");
})
)) {
Assert.Equal("-", new SqlCommand("B").CommandText);
}

Assert.Equal("C", new SqlCommand("C").CommandText);
#endif

}
}
}

Expand Down

0 comments on commit 785eaf3

Please sign in to comment.