鉴于下面的示例源代码,是否有人可以看到_secret
使用反汇编程序的价值?我没有看到通过 Reflector 获得价值的方法,但我并没有经常使用它。假设代码没有以任何方式混淆。
class Foo
{
private string _secret = @"all your base are belong to us";
public void Foo()
{
...
}
}
谢谢!
鉴于下面的示例源代码,是否有人可以看到_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"; }
Foo
在方法中的反射器中可见.ctor
。
您还可以在ildasm
(随 Microsoft Visual Studio 提供)中查看此信息Foo::.ctor : void
:
.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
最后,如果有人知道你的类型的名称和你的私有字段的名称,你可以这样获取值:
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
当然,我总是可以看到你所有的私人领域
var fields = typeof(Foo).GetFields(
BindingFlags.Instance | BindingFlags.NonPublic
);
是的,有可能。硬编码的值将出现在 IL 中,并且可以通过任何 .NET 反汇编程序查看。由于这是一个字段,因此可以在 Reflector 的构造函数中查看其从字面量初始化的内容。