简体   繁体   English

C#如何反编译yield-return枚举器

[英]C# how to decompile yield-return enumerators

I am trying to decompile some C# code that uses IEnumerators with yield-return, but no decompiler bothers to rename the variables to valid C# names. 我试图反编译一些使用带有yield-return的IEnumerators的C#代码,但没有反编译器将变量重命名为有效的C#名称。 I have tried ILSpy, JustDecompile, dotPeek and Reflector with no success. 我试过ILSpy,JustDecompile,dotPeek和Reflector但都没有成功。

Decompiled example so far: 到目前为止的反编译示例:

private IEnumerator _WaitForSecondsThenStop(float startToFadeTime, float fadeOutLength)
{
    AudioObject.<_WaitForSecondsThenStop>c__Iterator0 <_WaitForSecondsThenStop>c__Iterator = new AudioObject.<_WaitForSecondsThenStop>c__Iterator0();
    <_WaitForSecondsThenStop>c__Iterator.startToFadeTime = startToFadeTime;
    <_WaitForSecondsThenStop>c__Iterator.fadeOutLength = fadeOutLength;
    <_WaitForSecondsThenStop>c__Iterator.<$>startToFadeTime = startToFadeTime;
    <_WaitForSecondsThenStop>c__Iterator.<$>fadeOutLength = fadeOutLength;
    <_WaitForSecondsThenStop>c__Iterator.<>f__this = this;
    return <_WaitForSecondsThenStop>c__Iterator;
}

ILSpy is supposedly able to decompile enumerators properly, however it doesn't work for me. 据推测,ILSpy 能够正确地反编译枚举器,但它对我不起作用。 Somewhere I've read it might be caused by some optimizations of the code that make it impossible for ILSpy to recognize the patters, so it may be caused by that. 我读过的地方可能是由于代码的一些优化导致ILSpy无法识别模式,因此可能是由此造成的。

However, what I want to ask is this: Is there a C# decompiler that will rename all the field, variables and classes to valid C# names? 但是,我想问的是:是否有一个C#反编译器将所有字段,变量和类重命名为有效的C#名称? I'm fine with the state automaton madness, as long as it compiles as a proper C# code. 我对状态自动机疯狂很好,只要它编译为正确的C#代码。

I ended up changing the names with these 4 regexes: 我最终改变了这4个正则表达式的名称:

Pattern               Replacement       What it fixes
<(\w+)>c__Iterator    Iter_$1           <_WaitForSecondsThenStop>c__Iterator
<(\w+)>_              _L_$1_            <form>__2
<\$?>                 _S_               <$>startToFadeTime
\$(\w+)               _SS_$1            $current

EDIT: after some inspection, it still doesn't quite cover everything, I'll update the table once I fix it. 编辑:经过一番检查后,它仍然没有完全覆盖所有内容,我会在修复后更新表格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM