运行时动态伪造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);
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-28
  • 2021-06-20
  • 2021-09-09
  • 2021-06-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2021-04-03
  • 2021-05-19
  • 2022-12-23
  • 2021-12-04
相关资源
相似解决方案