设为首页 加入收藏

TOP

C++友元函数获取成员变量(作为调试后门程序)
2014-11-24 07:37:36 来源: 作者: 【 】 浏览:1
Tags:函数 获取 成员 变量 作为 调试 后门 程序

一.源码例子:


[user:Backdoor] ls
main.cpp
[user:Backdoor] cat main.cpp
/// @file main.cpp
/// @brief
/// @author EastonWoo
/// 0.01
/// @date 2012-12-24


#include


#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]


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇S3C2440 地址分配硬件连接及其启.. 下一篇TX2440 裸跑实验-跑马灯(ADS1.2编..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·PostgreSQL 索引 - (2025-12-25 22:20:43)
·MySQL Node.js 连接 (2025-12-25 22:20:41)
·SQL 撤销索引、表以 (2025-12-25 22:20:38)
·Linux系统简介 (2025-12-25 21:55:25)
·Linux安装MySQL过程 (2025-12-25 21:55:22)