Problem
This problem comes from pwn.college: Assembly Crash Course ⤴.
We will now set some values in memory dynamically before each run. On each run, the values will change. This means you will need to do some type of formulaic operation with registers. We will tell you which registers are set beforehand and where you should put the result. In most cases, it’s
rax.In this level, you will be working with memory. This will require you to read or write to things stored linearly in memory. If you are confused, go look at the linear addressing module in ‘ike. You may also be asked to dereference things, possibly multiple times, to things we dynamically put in memory for your use.
Please perform the following:
- Place the value stored at
0x404000intorax.- Increment the value stored at the address
0x404000by0x1337.Make sure the value in
raxis the original value stored at0x404000and make sure that[0x404000]now has the incremented value.
Solution
.intel_syntax noprefix
.global _start
_start:
mov rax, [0x404000]
add qword ptr [0x404000], 0x1337
Note:
Writing add [0x404000], 0x1337 wasn’t sufficient and the compiler output: Error: ambiguous operand size for 'add'.
The problem is that the compiler doesn’t know how many bytes to read from memory, so it doesn’t know what to add to 0x1337.
We need to explicitly state how much of the memory location read. Here, we specify qword ptr, which means “use all 8 bytes from memory.”