using System;
using System.IO;
using System.Linq.Expressions;
using System.Net;
using System.Reflection;
using HarmonyLib;
public static class Pacth
{
public static void MyPacth()
{ foreach (string text in Directory.GetFiles("C:\\Users\\Administrator\\Desktop\\t5\\bin\\Debug\\net5.0\\ttt", "*.dll"))
{
AppDomain.CurrentDomain.Load(File.ReadAllBytes(text));
}
foreach (MethodInfo methodInfo in AccessTools.GetDeclaredMethods(Type.GetType("Netch.Utils.WebUtil")))
{
var harmony = new Harmony(methodInfo.MetadataToken.ToString());
var mPrefix = SymbolExtensions.GetMethodInfo(() => Prefix(null));
harmony.Patch(methodInfo, new HarmonyMethod(mPrefix), new HarmonyMethod(Postfix));
}
}
private static void Postfix2(ref object __result)
{
if (__result is string){
System.IO.File.AppendAllText("vvv2.log","Postfix:"+(string)__result+"\r\n");
}
}
private static void Postfix(ref object __instance, ref object __result)
{
if (__result.GetType()==)
System.IO.File.AppendAllText("vvv2.log","Postfix result:"+__result.GetType().FullName+"\r\n");
}
private static bool Prefix(object[] __args)
{
if (__args.Length > 2)
{
if (__args[0] is HttpWebRequest)
{
File.AppendAllText("vvv2.log", "Prefix:"+((HttpWebRequest)__args[0]).RequestUri.ToString()+"\r\n");
}
if (__args[1] is string)
{
File.AppendAllText("vvv2.log","Prefix:"+ (string)__args[1]+"\r\n");
}
}
return true;
}
}
[HarmonyPatch(typeof(YourClassName))] // 替換 "YourClassName" 爲包含 DownloadStringAsyncPost 方法的類名
[HarmonyPatch("DownloadStringAsyncPost")]
public class DownloadStringAsyncPostPatch
{
[HarmonyPostfix] // 使用 HarmonyPostfix 註解來在方法執行後執行你的代碼
public static void Postfix(string __result) // 使用 Postfix 方法來接收返回值
{
Console.WriteLine("返回數據:" + __result);
}
[HarmonyPostfix] // 使用 HarmonyPostfix 註解來在方法執行後執行你的代碼
public static void Postfix(HttpWebRequest req, string json, string encoding) // 使用 Postfix 方法來接收參數
{
Console.WriteLine("請求參數 req:" + req);
Console.WriteLine("請求參數 json:" + json);
Console.WriteLine("請求參數 encoding:" + encoding);
}
}
HarmonyLib Patch
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.