H
@Matthias G., Mechanics, merano:
ASLR kann man in in visual cpp 2010 mit der Linkeroption /DYNAMICBASE:NO und mit /FIXED abschalten.
Trotzdem tritt der Fehler bei Windows 7 Professional, 64 Bit, Service Pack 1
noch auf.
Hier der Programmcode
Prozess 1:
--------------
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <new>
#include <sys/stat.h>
#include "..\..\include\classA.h"
#include <new>
int main()
{
DWORD lastError (0);
HANDLE mapFileHdl (CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_EXECUTE_READWRITE, // read/write/execute access
0, // maximum object size
sizeof A1, // maximum object size
mappingFileName)); // name of mapping object
if (mapFileHdl == NULL)
{
lastError = GetLastError();
printf("CreateFileMapping(...) war nicht erfolgreich, GetLastError() = (%d).\n", lastError);
return 1;
}
# ifdef FIXEDMAPPING
void (*pBuffer) (MapViewOfFileEx (mapFileHdl, FILE_MAP_ALL_ACCESS,
0, 0, 0, (void *)GLOBMEMBASEADDRESSE));
# else
void (*pBuffer) (MapViewOfFile (mapFileHdl, FILE_MAP_ALL_ACCESS,
0, 0, 0));
# endif
if (pBuffer == NULL)
{
lastError = GetLastError();
printf("MapViewOfFile(...) war nicht erfolgreich, GetLastError() = (%d).\n", lastError);
CloseHandle(mapFileHdl);
return 1;
}
A1 a1;
A0 (*pA00)(&a1);
pA00->SetId(1);
memset (pBuffer, 0x99, sizeof (A1));
*(void **) pBuffer = 0L;
A0 (*pA0) (new (pBuffer) A1(&a1));
pA0->SetId(-1);
__int64 id (pA0->GetId());
A1 xx,yy,zz;
int c (_getch());
UnmapViewOfFile(pBuffer);
CloseHandle(mapFileHdl);
return 0;
}
Prozess 2:
--------------
#include <windows.h>
#include <stdio.h>
#include "..\..\include\classA.h"
int main()
{
DWORD lastError(0);
HANDLE mapFileHdl (OpenFileMapping(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
mappingFileName)); // name of mapping object
if (mapFileHdl == NULL)
{
lastError = GetLastError();
printf("OpenFileMapping(...) war nicht erfolgreich, GetLastError() = (%d).\n", lastError);
return 1;
}
# ifdef FIXEDMAPPING
void (*pBuffer) (MapViewOfFileEx (mapFileHdl, FILE_MAP_ALL_ACCESS,
0, 0, 0, (void *)GLOBMEMBASEADDRESSE));
# else
void (*pBuffer) (MapViewOfFile (mapFileHdl, FILE_MAP_ALL_ACCESS,
0, 0, 0));
# endif
if (pBuffer == NULL)
{
lastError = GetLastError();
printf("MapViewOfFile(...) war nicht erfolgreich, GetLastError() = (%d).\n", lastError);
CloseHandle(mapFileHdl);
return 1;
}
A0 (*pA0) ((A0 (pBuffer));
__int64 id0 (pA0->GetId());
UnmapViewOfFile(pBuffer);
CloseHandle(mappingFileName);
return 0;
gemeinsames Includefile classA.h:
------------------------
//#define FIXEDMAPPING
#define GLOBMEMBASEADDRESSE 0x52000000
char mappingFileName[]=("mappingFileName");
class A0
{
public:
A0() {}
virtual __int64 GetId() = 0;
virtual void SetId(__int64 i) = 0;
};
class A1 : public A0
{
private:
__int64 i;
public:
A1()
:A0(),
i(0)
{
};
A1(A1 *pa)
:A0(),
i(pa->i)
{
};
A1(A1 &ra)
:A0(),
i(ra.i)
{
};
void SetId(__int64 id)
{
i = id;
}
__int64 GetId()
{
return i;
}
};