我有一個C#DLL與成員類似以下內容:如何用Mono.Cecil重新拋出一個ILAsm拋出?
public void DoStuff(int i) {
try {
something.InnerDoStuff(i);
}
catch (Exception ex) {
throw ex;
}
}
我想出如何讓throw opcode:用rethrow opcode
Add-Type -Path 'c:\Program Files\ILSpy2\Mono.Cecil.dll'
Add-Type -Path 'c:\Program Files\ILSpy2\Mono.Cecil.pdb.dll'
$dll = 'c:\Program Files\ZippySoft\Something\foo.dll'
$assemblyDefinition = [Mono.Cecil.AssemblyDefinition]::ReadAssembly($dll);
$doThingsIlAsm = (
(
$assemblyDefinition.MainModule.Types `
| where { $_.Name -eq 'DoerOfThings' } `
| select -first 1 *
).Methods | where { $_.Name -eq 'DoStuff' }
).Body.Instructions
$throwOp = ($doThingsIlAsm | where {
$_.OpCode.Name -eq 'throw'
})
我的問題是如何更換拋操作碼?
您的標題問如何「替換」的操作碼,但你問只是如何「搞定」了。你對哪些感興趣? – latkin