Thông tin

Tác giả Maxime Mawait
Hạn chót Không có hạn chót
Giới hạn nộp bài Không có giới hạn
Các tag chuyên mục S3, Pointer, Level 2

Tags

Đăng nhập

[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.


Câu hỏi 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) {
Câu hỏi 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) {
Câu hỏi 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) {