小编Jer*_*ang的帖子

在printf中使用%p?

我通过以下链接在线阅读以下代码:http://www.cse.scu.edu/~tschwarz/coen152_05/Lectures/BufferOverflow.html

我对此行中%p的使用感到困惑:

 printf("Now the stack looks like:\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
Run Code Online (Sandbox Code Playgroud)

这是从这段代码中获取的:

 /*
  StackOverrun.c
  This program shows an example of how a stack-based 
  buffer overrun can be used to execute arbitrary code.  Its 
  objective is to find an input string that executes the function bar.
*/

#pragma check_stack(off)

#include <string.h>
#include <stdio.h> 

void foo(const char* input)
{
    char buf[10];

    printf("My stack looks like:\n%p\n%p\n%p\n%p\n%p\n% p\n\n");

    strcpy(buf, input);
    printf("%s\n", buf);

    printf("Now the stack looks like:\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
}

void bar(void)
{
    printf("Augh! I've been hacked!\n"); …
Run Code Online (Sandbox Code Playgroud)

c memory assembly

3
推荐指数
1
解决办法
692
查看次数

在堆栈或堆上初始化结构?

如果您在 C 中有这样的结构:

struct mystruct{
        int i;
        char c;
};
Run Code Online (Sandbox Code Playgroud)

你也是:

mystruct m;
m.i = 5;
m.c = 'i';
Run Code Online (Sandbox Code Playgroud)

您是在堆上还是在堆栈上创建结构?

c

1
推荐指数
1
解决办法
4304
查看次数

标签 统计

c ×2

assembly ×1

memory ×1