在其它怎看到一个让静态变量可以多次初始化的例子,也看明白了,就有一点想不通,程序代码应该是在代码段上的是不可写的,可下面的程序为什么没有修改其属性就可以直接修改,附代码如下:
void Test(int initVal)
{
static int i = initVal;
cout<<sizeof(i)<<endl;
} int FindAddress() {  unsigned char *addr = (unsigned char *)&Test;  // There is only one instruction in Test: jmp realAddr  if (*addr == 0xe9) 
{
addr = addr + *(int *)(addr + 1) + 5;
} // Look forward at most 100 bytes for instruction "and eax 1" 
for (int i = 0; i < 64; i++) 
{
#ifdef WIN32 
if (memcmp(addr + i, "\x83\xe0\x01", 3) == 0) 

return *(int *)(addr + i - 4); 

#else 
if (addr[i+0] == 0x80 && addr[i+1] == 0x3d && addr[i+6] == 0x00) 

return *(int *)(addr + i + 2); 

#endif 

return 0; } 
int main()
{
cout <<"before modify: "<<endl; 
Test(0);
Test(100); 
try 
{
int flagAddress = FindAddress(); 
if (flagAddress) 
{
cout << "After modify: " << endl; 
*reinterpret_cast <int *>(flagAddress) = 0;  //Here :flagAddress是一个代码段的地址,为什么可以直接修改??
Test(1000);

else 
{
cout << "Can not find the flag address" << endl; 


catch (...) 
{
cout << "There is some bug in program" << endl; 
}  return 0;
}