Your answers go below each question.
Q1: print saves rdi on the stack before calling len and restores it after len returns. How is rdi used in len, and why does print save it to the stack?
Copyright By PowCoder代写 加微信 powcoder
Q2: The calling convention defines rbx, rbp, and r12-r15 as callee-saved registers, but print doesn’t save any of them. Does this violate the calling convention? If so, how? If not, why not?
Q3: _start uses rbx to track the argument count. Suppose we used rax instead. Would that work under the calling convention rules? If yes, explain why. If not, what would we need to change in _start to make this work (without modifying print or len)?
Q4: List the five top entries on the stack at the point when the cmp instruction inside len is executed for the first time. For each entry, list the byte offset relative to rsp, what the value there represents, and the address of the instruction that wrote this value to the stack.
Q5: xor rdi, rdi has an equivalent mov instruction. Why do you think xor rdi, rdi might be preferable?
When answering questions about code, make sure your answer succinctly describes the in English or as a high-level mathematical expression. Answers that merely transcribe the code into English (e.g., “next, it adds register rax to register rdi”) will receive no credit.
Your answers go below each question.
Q1: There are four call instructions in the first sixty bytes following the label _start. Each checks something about the input argument. What does each of them check, in the order they appear in the program?
Q2: The code is broken into several smaller functions. (For this task, we will define functions as targets of call instructions.) Reverse-engineer those functions. For each function show below (a) the address, (b) what the function expects as the argument(s) and in which register(s), and (c) what the function computes.
Q3. Provide an example input that results in the hackme code assigned to you displaying “YOU WIN!”