c# - Why does this code work without the unsafe keyword? -
In itself, it is shown that you do not need "unsafe" keywords to read and write bites directly You can declare the following types of any .NET object example:
[Layout layout (layout kick)] Stretch memory entry {[Field Offset (0)] Public Object Object; [Field Offset (0)] Public Topbytes Bytes; } Class topbits {public byte b; Public byte b1; Public byte b2; Public byte b3; Public byte b4; Public byte b5; Public byte b6; Public byte b7; Public byte b8; Public byte b9; Public byte b10; Public byte B11; Public byte b12; Public byte b13; Public byte b14; Public byte b15; } And then you can do things like changing an "irreversible" string The following code prints "bar" on my machine:
string foo = "Foo"; MemoryAccess mem = New MemoryAccess (); Mem.Object = foo; Mem.Bytes.b8 = (byte) 'b'; Mem.Bytes.b10 = (byte) 'A'; Mem.Bytes.b12 = (byte) 'r'; Console.WriteLine (foo); You can also trigger by corrupting the object references from the same technology.
Question: I thought that the keyword (in the pure managed C # code) was necessary, things like this why it is not necessary here? Does this mean that the purely managed "safe" code is not at all safe?
Okay, this is bad ... the danger of using a union. It can work, but this is not a great idea - I think I compare it with reflection (where you can work most). I would be interested to see if it works in the environment of a limited reach - if so, it can represent a big problem ...
I used to say "full trust" The flag, and runtime rejects it:
Could not load the 'MemoryAccess' type from the assembly 'ConsoleApplication4, version = 1.0.0.0, culture = neutral, publickenToken = tap' because Overlapping object offsets and checking the assembly I need it.
And to keep this flag, you already need high confidence - so you can already do more dirty work. Strings are a little different, because they are not normal. Net objects - but there are other examples of ways to make changes - though the "association" approach is an interesting one, though. In another Haimi manner (with sufficient confidence):
string origin = "abc", copy = orig; Type (string), typef (straight), typef (string), typef (string), typef (string), fault (origin, new object) ["DEFT", 3}); Console.WriteLine (copy); // Note, we did not touch "Copy", so we have changed the same reference to
Comments
Post a Comment