Giter Site home page Giter Site logo

alx-tools / hack-the-virtual-memory Goto Github PK

View Code? Open in Web Editor NEW
305.0 28.0 85.0 199 KB

This is a series of small articles / tutorials based around virtual memory. The goal is to learn some CS basics, but in a different and more practical way.

Home Page: https://www.holbertonschool.com

C 59.62% Python 40.38%
proc-filesystem virtual-memory

hack-the-virtual-memory's Introduction

Hack the Virtual Memory

hack the virtual memory

This is a series of small articles / tutorials based around virtual memory. The goal is to learn some CS basics, but in a different and more practical way.

TOC

00. C strings & /proc

For this first piece, we'll use /proc to find and modify variables (in this example, an ASCII string) contained inside the virtual memory of a running process, and learn some cool things along the way.

Status: Published

01. Python bytes

For this second piece, we'll do almost the same thing, but instead we will access the virtual memory of a running Python 3 script. It is not as straightfoward. Let's take this as an excuse to look at some Python 3 internals!

Status: Published

02. What's where in the virtual memory

Let's try to guess where things are in the virtual memory.

Status: Published

03. malloc, the heap and the program break

In this fourth chapter we will look at the heap and how malloc works in order to answer some of the questions we ended with at the end of the previous chapter.

Status: Published

04. The stack, registers and assembly code

Status: In progress

hack-the-virtual-memory's People

Contributors

aax13 avatar jbarbier avatar namodawn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hack-the-virtual-memory's Issues

Can I ask a question

I run 00. C strings & the proc filesystem success.
But I add some code to print pid of current process, then failed.
Then I move the code, it success again. I don't know why.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+ #include <unistd.h>
+ #include <sys/types.h>

/**
 * main - uses strdup to create a new string, and prints the
 * address of the new duplcated string
 *
 * Return: EXIT_FAILURE if malloc failed. Otherwise EXIT_SUCCESS
 */
int main(void)
{
	char *s;
+       pid_t pid = getpid();
+       printf("pid: %lun", pid);
	s = strdup("Holberton");

	if (s == NULL)
	{
		fprintf(stderr, "Can't allocate mem with malloc\n");
		return (EXIT_FAILURE);
	}
	printf("%p\n", (void *)s);
	return (EXIT_SUCCESS);
}
gcc main.c -o holberton 
./holbeton
./read_write_heap.py ${PID}  "Holberton" "hello,world" ## still output Holberton
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+ #include <unistd.h>
+ #include <sys/types.h>

/**
 * main - uses strdup to create a new string, and prints the
 * address of the new duplcated string
 *
 * Return: EXIT_FAILURE if malloc failed. Otherwise EXIT_SUCCESS
 */
int main(void)
{
	char *s;
	s = strdup("Holberton");
+       pid_t pid = getpid();
+       printf("pid: %lun", pid);

	if (s == NULL)
	{
		fprintf(stderr, "Can't allocate mem with malloc\n");
		return (EXIT_FAILURE);
	}
	printf("%p\n", (void *)s);
	return (EXIT_SUCCESS);
}
gcc main.c -o holberton 
./holbeton
./read_write_heap.py ${PID}  "Holberton" "hello,world" ## output Holberton changed to hello,world

I don't understand why.

cmd error

In this article: 04. The Stack, registers and assembly code

Follow cmd error.
objdump without target file.

    holberton$ gcc 0-main.c
    holberton$ objdump -d -j .text -M intel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.