给出下面的示例源代码,有人可以使用反汇编程序查看 _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/