I
Ioannis Vranos
Here is a similar code to one that I saw in a video on the web:
#include <cstdio>
#include <cstring>
void somefunc(const char *input)
{
using namespace std;
char buf[5];
// Displays the stack
printf("Stack looks like:\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
//Buffer overflow
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 somefunc2()
{
printf("somefunc2()\n");
}
int main(int argc, char *argv[])
{
using namespace std;
printf("Address of somefunc = %p\n", somefunc);
printf("Address of somefunc2 = %p\n", somefunc2);
somefunc(argv[1]);
}
So, can we be sure that we can display the contents of the stack in this way?
#include <cstdio>
#include <cstring>
void somefunc(const char *input)
{
using namespace std;
char buf[5];
// Displays the stack
printf("Stack looks like:\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
//Buffer overflow
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 somefunc2()
{
printf("somefunc2()\n");
}
int main(int argc, char *argv[])
{
using namespace std;
printf("Address of somefunc = %p\n", somefunc);
printf("Address of somefunc2 = %p\n", somefunc2);
somefunc(argv[1]);
}
So, can we be sure that we can display the contents of the stack in this way?