运行时动态伪造vsprintf的va_list

本文介绍了一种通过手动构造内存布局来动态伪造vsprintf函数所需的va_list参数的方法。这种方法涉及分配内存、设置整型和字符串类型的参数,并通过va_list传递给vprintf函数进行格式化输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

运行时动态伪造vsprintf的va_list

#include <stdio.h>
int main() {
  char* m = (char*) malloc(sizeof(int)*2 + sizeof(char*)); /* prepare enough memory*/
  void* bm = m; /* copies the pointer */
  char* string = "I am a string!!"; /* an example string */

  (*(int*)m) = 10; /*puts the first value */
  m += sizeof(int); /* move forward the pointer to the next element */

  (*(char**)m) = string; /* puts the next value */
  m += sizeof(char*); /* move forward again*/

  (*(int*)m) = 20; /* puts the third element */
  m += sizeof(int); /* unneeded, but here for clarity. */

  vprintf("%d %s %d\n", bm); /* the deep magic starts here...*/
  free(bm);
}

转载于:https://www.cnblogs.com/ohmhong/p/6869937.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值