这是一个示例,显示了此溢出如何为您提供帮助。假设您无权访问私有成员(例如 pwd),因此 printf 将帮助您查看此变量的内容
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
struct SecureLogin{
SecureLogin(const char * login_)
{
strcpy(login,login_);
strcpy(pwd,"ijk");//the user does not see this part of the source code as it is in a DLL
}
char login[8];
private:
char pwd[8];
};
int main() {
// your code goes here
SecureLogin log("abc");
printf("Pwd = %s\n",(&log.login[0])+8);
// Pass a string address which is the base address of the login
// field, but add 8 bytes, which skips onto the pwd field (we know
// login is 8 bytes)
return 0;
}
输出:
密码 = ijk