[user:Backdoor] ls
main.cpp
[user:Backdoor] cat main.cpp
/// @file main.cpp
/// @brief
/// @author EastonWoo
/// 0.01
/// @date 2012-12-24
#include <stdio.h>
#define DEBUG_BACKDOOR //后门宏
typedef struct s_hello
{
int aa;
char bb;
int cc;
}s_hello;
class CTest
{
public:
CTest()
{
m_a = 1;
m_s.aa = 10;
m_s.bb = 20;
m_s.cc = 30;
}
#ifdef DEBUG_BACKDOOR
friend bool getValue(CTest &disk, int index, void** output, int &size); //友元函数
typedef enum e_value
{
E_M_A,
E_M_S,
}e_value;
#endif
private:
int m_a;
s_hello m_s;
};
#ifdef DEBUG_BACKDOOR
bool getValue(CTest &disk, int index, void** output, int &size) //获取私有成员变量
{
switch(index)
{
case CTest::E_M_A:
*output = (void*)&disk.m_a;
size = sizeof(disk.m_a);
break;
case CTest::E_M_S:
*output = (void*)&disk.m_s;
size = sizeof(disk.m_s);
break;
default:
return false;
break;
}
return true;
}
#endif
int main()
{
CTest hd;
int *pA = NULL;
int size = 0;
getValue(hd,CTest::E_M_A,(void**)&pA,size);
printf("*pA = %d, size = %d\n",*pA,size);
s_hello* my_hello;
int my_size = 0;
getValue(hd,CTest::E_M_S,(void**)&my_hello,my_size);
printf("*pA = %d, size = %d\n",my_hello->aa,my_size);
return 0;
}
[user:Backdoor]
二.编译运行:
[user:Backdoor] g++ -g main.cpp
[user:Backdoor] ls
a.out* main.cpp
[user:Backdoor] ./a.out
*pA = 1, size = 4
*pA = 10, size = 12 //成功获取.可作为后门调试
[user:Backdoor]