.net - 是否可以使用像 Reflector 这样的反汇编器查看成员变量的硬编码值?

标签 .net reflector disassembly

给出下面的示例源代码,有人可以使用反汇编程序查看 _secret 的值吗?我没有看到通过 Reflector 获取值的方法,但我用得不多。假设代码没有以任何方式混淆。

class Foo
{
    private string _secret = @"all your base are belong to us";

    public void Foo()
    {
        ...
    }
}

谢谢!

最佳答案

它在 Reflector 的构造函数中可见。

class Foo { private string _secret = @"all your base are belong to us"; }

转化为有构造函数

public Foo() { this._secret = "all your base are belong to us"; }

在方法 .ctor 中的 Foo 下的 Reflector 中可见。

您还可以在 Foo::.ctor : void 中的 ildasm(Microsoft Visual Studio 附带)中看到此信息:

.method public hidebysig specialname rtspecialname instance void .ctor() cil managed {
    // Code size       19 (0x13)
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  ldstr      "all your base are belong to us"
    IL_0006:  stfld      string Playground.Foo::_secret
    IL_000b:  ldarg.0
    IL_000c:  call       instance void [mscorlib]System.Object::.ctor()
    IL_0011:  nop
    IL_0012:  ret
} // end of method Foo::.ctor

最后,如果有人知道你的类型名称和你的私有(private)字段名称,你可以获得这样的值:

object o = typeof(Foo).GetField(
    "_secret",
    BindingFlags.Instance | BindingFlags.NonPublic
).GetValue(f);
Console.WriteLine(o); // writes "all your base are belong to us" to the console

当然,我总能看到你所有的私有(private)领域

var fields = typeof(Foo).GetFields(
    BindingFlags.Instance | BindingFlags.NonPublic
);

关于.net - 是否可以使用像 Reflector 这样的反汇编器查看成员变量的硬编码值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1562174/

相关文章:

macos - 完全分解可执行二进制文件

android - 防止/使修补二进制程序集变得困难

c# - 如何确定全局键盘钩子(Hook)是否已断开连接?

.net - 在 Reflector 中打开 XNA Xbox 360 程序集

c# - 委托(delegate)的构造函数和成员函数在哪里定义?

c# - 检查 C# 代码混淆的效率

c# - .NET 中的对象布局结构使用反汇编程序

.net - WPF 为 Silverlight/Windows Phone 7 设计自定义 UI 组件

c# - 使用正则表达式 C# 替换 Unicode(泰米尔语)字符串

c# - 不允许使用默认参数说明符