C# creating buffer overflow -
i'm trying create buffer overflow c# school project:
unsafe { fixed (char* ptr_str = new char[6] {'h', 'a', 'l', 'l', 'o', ','}) { fixed (char* ptr_str2 = new char[6] {'w', 'e', 'r', 'e', 'l', 'd'}) { fixed (char* ptr_str3 = new char[6] {'!', '!', '!', '!', '!', '!'}) { (int = 0; < 8; i++) { ptr_str2[i] = 'a'; } (int = 0; < 6; i++) { this.label2.text += ptr_str[i]; this.label3.text += ptr_str2[i]; this.label4.text += ptr_str3[i]; } } } } }
i thought flood ptr_str2
, thereby overwriting chars in ptr_str
. not seem happen. execute values in ptr_str
not overwritten.
can achieving this? don't understand i'm doing wrong.
you missing fact arrays objects themselves. have object header managed reference type , private field stores array size. have overwrite first before start overwriting array elements. on 32-bit machine, you'll start overwriting first element of ptr_str2 this:
(int = 0; < 13; i++) { ptr_str[i] = 'a'; }
of course, had 13.
observe setting breakpoint on loop. debug + windows + memory + memory 1, type "ptr_str" in address box. step code see memory getting changed. you'll see ptr_str2 right after that, 4 bytes syncblk, 4 bytes method table pointer , 4 bytes array length. 12 bytes total, 6 chars.
Comments
Post a Comment