Skip to content

Instantly share code, notes, and snippets.

@DanBrink91
Last active August 29, 2015 14:05
Show Gist options
  • Save DanBrink91/0c15cbc39296ea4c2f07 to your computer and use it in GitHub Desktop.
Save DanBrink91/0c15cbc39296ea4c2f07 to your computer and use it in GitHub Desktop.
messing with the stack
#include <stdio.h>
#include <stdlib.h>
// Global / Static aren't in the stack!
unsigned long stack_top;
unsigned int* location;
int main()
{
int X = 72, Y = 30;
int i;
// Get location of stack
asm volatile ("movl %%esp, %0" : "=r" (stack_top));
// Convert to address and skip ahead
location = (int*)stack_top + 5;
printf("Stack Location is %x\n", (unsigned int)location);
// Print stack stuff and more...
for(i = 0; i < 10; i++)
{
printf("%d:\t%d\n", i, *(location + i));
}
// Change value of our local variable!
location[2] = 3;
printf("Y is %d\n", Y);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment