[S3] Pointer arithmetic

A hacker wanted to challenge you and encrypted your hard drive. To unlock your drive, he gave you a function get_key(int a, char b, int c) which returns the decryption key if the correct parameters are given.

He then hid the parameters a, b and c in memory, and gave you a pointer from which you can retrieve these parameters.


Question 1: First argument

You found a hint from the hacker, telling the first parameter is located at the 12th byte after ptr. An int is guaranteed to be 4 bytes long.

Write the body of the function first which returns the integer at that position in memory.

int first(void *ptr) {
Question 2: Second argument

The second parameter is a char located 6 bytes after ptr.

Write the body of the function second which returns the char at that position in memory.

char second(void *ptr) {
Question 3: Third argument

The third parameter is an int located 45 bytes after ptr.

Write the body of the function third which returns the int at that position in memory.

int third(void *ptr) {

Information

Author(s) Maxime Mawait
Deadline No deadline
Submission limit No limitation
Category Tags Pointer, S3

Tags

Sign in