Casting map causes crash

05/13/2021 01:26 ozuromo#1
I created .exe with a map in it like this:
Code:
typedef std::map<const char*, DWORD> tmap;
tmap myMap;
myMap.insert(std::make_pair("One", 0xFFFFF));
myMap.insert(std::make_pair("Two", 0xEEEEE));
std::cout << std::hex << &myMap << std::endl;
Then, I created a .dll like this:
Code:
typedef std::map<const char*, DWORD> tmap;
tmap myMap = *(tmap*)(Output of &myMap);
But somehow, when I inject this dll the program insta crashes. Why?
05/16/2021 19:42 elmarcia#2
Quote:
Originally Posted by ozuromo View Post
I created .exe with a map in it like this:
Code:
typedef std::map<const char*, DWORD> tmap;
tmap myMap;
myMap.insert(std::make_pair("One", 0xFFFFF));
myMap.insert(std::make_pair("Two", 0xEEEEE));
std::cout << std::hex << &myMap << std::endl;
Then, I created a .dll like this:
Code:
typedef std::map<const char*, DWORD> tmap;
tmap myMap = *(tmap*)(Output of &myMap);
But somehow, when I inject this dll the program insta crashes. Why?
Are you pausing your program execution after line ?:
std::cout << std::hex << &myMap << std::endl;

if not memory will be released and casting will point to invalid pointer