Skip to content

Commit a8b23ea

Browse files
image loading correction
1 parent 02dbafe commit a8b23ea

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

content/post/binary-bomb-phase-6.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -150,146 +150,146 @@ Let's go through the assembly step-by-step and map it to the C code:
150150
- We see a call to the function 'read_six_numbers'. Add a breakpoint on the call instruction if you want to explore the function.
151151
- The function `read_six_numbers` will take `rcx`, `rdx` as arguments. `rdx` is set with the address of `rbp+48h`. The user input values will be set from the address starting at `rdx`, and hence `rbp+48h` will have the input values.
152152

153-
![read_six_numbers](../../images/sscanf%20numbers.png)
154-
![breakpoint on read_six_numbers](../../images/sscanf%20breakpoint.png)
153+
![read_six_numbers](./images/sscanf%20numbers.png)
154+
![breakpoint on read_six_numbers](./images/sscanf%20breakpoint.png)
155155

156156
- Add breakpoint to check the output of read six numbers. It can be seen that even if the input contains more than 6 digits, the output is 6, so it could mean that first 6 digits would be considered.
157157

158-
![read_six_numbers input](../../images/read%20six%20numbers.png)
159-
![output of read_six_numbers](../../images/read%20six%20numbers%20output.png)
158+
![read_six_numbers input](./images/read%20six%20numbers.png)
159+
![output of read_six_numbers](./images/read%20six%20numbers%20output.png)
160160

161161
- After the call to read_six_numbers, a variable `rbp+0c4h` (let's call this as variable `a`) is set to 0 and there is jump statement.
162162

163163
- The jump statement takes the control to the compare function. This function checks if the value of the variable is greater than or equal to 6.
164164

165-
![compare length of user input](../../images/jump1.png)
165+
![compare length of user input](./images/jump1.png)
166166

167167
- If the value is greater than equal to 6, the jump statement is executed and takes the control to a different location which is outside the loop. This seems like the false condition for a loop.
168168

169-
![jump for wrong loop condition](../../images/a%20loop%20wrong%20condition%20jump%20loc.png)
169+
![jump for wrong loop condition](./images/a%20loop%20wrong%20condition%20jump%20loc.png)
170170

171171
- But, if the value of `a` is less than 6, the jump does not take place and flow continues after the jump statement.
172172

173-
![first loop](../../images/first%20loop%20condition.png)
173+
![first loop](./images/first%20loop%20condition.png)
174174

175175
- `rbp+48h` had the user input values. The value of variable `a` is being used as an array index (let's call the array as `inp`).
176176
The value of array at index *a* `inp[a]` is compared with 1.
177177
If the value turns out to be less than 1, the explode_bomb is function being called with jump statement.
178178

179-
![first loop condition 1](../../images/func%201%20condition%201.png)
179+
![first loop condition 1](./images/func%201%20condition%201.png)
180180

181181
- If the value is more than 1, then again the `inp[a]` is being compared with 6. If the value is greater than 6, the jump statement is not executed and explode_bomb function will be called.
182182
**So, the value of `inp[a]` should be in range of 1 and 6.**
183183

184-
![first loop condition 2](../../images/func%201%20condition%202.png)
184+
![first loop condition 2](./images/func%201%20condition%202.png)
185185

186186
- If the value of `a` is in [1,6], then a new variable `rbp+0e4h` (let's call it variable `b`) is assigned the value `a+1`.
187187
- The jump statement takes to condition statement, where the value of `b` is compared with 6. If the value is greater than or equal to 6, the jump statment again takes control to the increment operation of variable `a`.
188188

189189
- If the value of `b` is less than 6, then there is a comparison between `inp[a]` and `inp[b]`.
190190

191-
![array values comparison](../../images/func%201%20array%20values%20cmp.png)
191+
![array values comparison](./images/func%201%20array%20values%20cmp.png)
192192

193193
- If the values are equal, the jump statement is not taken, and explode_bomb function is called. If the values are not equal, the jump statement takes the control to increment of variable `b` and back to the loop condition of comparison of value `b` with 6.
194194

195-
![array values not equal jump](../../images/func%201%20array%20values%20not%20equal%20jump.png)
196-
![b value increment](../../images/func%201%20array%20values%20not%20equal%20jump.png)
195+
![array values not equal jump](./images/func%201%20array%20values%20not%20equal%20jump.png)
196+
![b value increment](./images/func%201%20array%20values%20not%20equal%20jump.png)
197197

198198
- Now, if we go back and look around the read_six_numbers function, there is an instruction related to node. Address of this node is saved to `rbp+8`.
199199

200-
![node instruction](../../images/node%20instruction.png)
200+
![node instruction](./images/node%20instruction.png)
201201

202202
- If we try to print the value at address, we could see that it contains a different address as well. We can print that too, and find a pattern.
203203

204-
![node address1](../../images/node%20address1.png)
205-
![node address1](../../images/node%20address2.png)
206-
![node address1](../../images/node%20address3.png)
204+
![node address1](./images/node%20address1.png)
205+
![node address1](./images/node%20address2.png)
206+
![node address1](./images/node%20address3.png)
207207

208208
- This shows a Linked List structure where each node has a value and reference the next node address. The last node with the address *b108f000* seems to be the last node, as it doesn't point to another address.
209209

210210
- When the condition of main loop became false, the just statement took the control to outside the loop where the value of `a` is set to 0 and then jump statement takes to another condition where `a` is compared with 6. This seems to be the start of another main loop.
211211

212-
![a compared against 6 again](../../images/a%20ge%206%20condition%202.png)
212+
![a compared against 6 again](./images/a%20ge%206%20condition%202.png)
213213

214214
- If the value of `a` again is greater than or equal to 6, the control passes to a different location.
215215

216216
- If the value of `a` is less than 6, `rbp+8` which contains the address of first linked list node, is passed to `rbp+28h`. The value of `b` is set to 1.
217217
Let's call the node at `rbp+8` as `head`, and `rbp+28h` as `curr` (current).
218218

219-
![second loop](../../images/second%20loop%20inside.png)
219+
![second loop](./images/second%20loop%20inside.png)
220220

221221
- The value of `b` is compared with the value of array at index `a`. If value of `b` is less, the value of `curr` is set to `curr->next` (the next node). For each node, the value at the address is the node value, then there is index, and then the address to next node. So, the <node address> + 8, gives the address of next node.
222222

223-
![second loop first condition](../../images/second%20loop%20condition%201.png)
224-
![second loop node iteration](../../images/second%20loop%20node%20iteration.png)
223+
![second loop first condition](./images/second%20loop%20condition%201.png)
224+
![second loop node iteration](./images/second%20loop%20node%20iteration.png)
225225

226226
- The value of `b` is increased by 1 and agin the comparison starts, so it means the comparison of `b` with value of array at index `a` was a loop condition (nested loop) and here the loop ends.
227227

228-
![second loop b increment](../../images/second%20loop%20b%20increment.png)
228+
![second loop b increment](./images/second%20loop%20b%20increment.png)
229229

230230
- If the value of `b` when compared with value of array at `a` was greater, then the jump would pass the control outside the inner loop. `rbp+78h` contained the address of the start of the node of linked list. From this address, an array is taken (let's call it `narr`), whose value at index *a* `narr[a]` is set with the value of `curr` node.
231231

232-
![second loop outside inner loop](../../images/second%20loop%20outside%20inner%20loop.png)
232+
![second loop outside inner loop](./images/second%20loop%20outside%20inner%20loop.png)
233233

234234
- Jump instruction takes the control to iteration where the value of `a` is incremented by 1, and again the condition is checked, which means the loop ends.
235235

236-
![second loop iteration](../../images/second%20loop%20iteration.png)
236+
![second loop iteration](./images/second%20loop%20iteration.png)
237237

238238
- If the value of `a` becomes greater than or equal to 6, then the loop condition breaks and control passes outside the loop.
239239
The address at `rbp+78h` (`narr[0]` node array) is being set to `rbp+8` (`head` node). The address from `rbp+8` (`head`) is being set to `rbp+28h` (`curr` node).
240240

241-
![second loop linked list address 1](../../images/second%20loop%201.png)
241+
![second loop linked list address 1](./images/second%20loop%201.png)
242242

243243
- We can check the value of `rbp+78` (`narr`) has address of different nodes of the linked list.
244244

245-
![second loop linked list address 1](../../images/second%20loop%20nodes%20address.png)
245+
![second loop linked list address 1](./images/second%20loop%20nodes%20address.png)
246246

247247
- We can break at the line where `rbp+28h` (`curr`)is assigned and check the value. It has the starting node address of linked list.
248248

249-
![rbp 28h starting address](../../images/rbp%2028h%20starting%20address.png)
249+
![rbp 28h starting address](./images/rbp%2028h%20starting%20address.png)
250250

251251
- So, this indicates something like `head = narr[0]; curr = head;`
252252

253253
- The value of `a` is set to 1, and jump takes the control to a comparison statement which again compares the value of `a` with 6. This could be the start of another loop.
254254

255-
![third loop start](../../images/third%20loop%20start.png)
255+
![third loop start](./images/third%20loop%20start.png)
256256

257257
- If the value of `a` is greater than or equal to 6, the jump statement takes the control to a different location.
258258

259259
- If the value of `a` is less, the loop starts/continues.
260260
The `curr` node (`rbp+28h`) next element is set to the node at index `a` of the node array `narr` (`curr->next = narr[a]`). Then `curr` node is again set to `curr->next`.
261261

262-
![third loop inside](../../images/third%20loop%20inside.png)
262+
![third loop inside](./images/third%20loop%20inside.png)
263263

264264
- The jump instruction takes the control to iteration where the value of `a` is increased by 1. After the iteration again there is the comparison statement of `a` which is the loop condition, so the loop ends.
265265

266-
![third loop iteration](../../images/third%20loop%20iteration.png)
266+
![third loop iteration](./images/third%20loop%20iteration.png)
267267

268268
- If the value of `a` becomes more than or equal to 6, the loop breaks and control moves out of loop.
269269
The `curr` node next address is set to 0, which indicates to NULL. It means that the `curr` node does not point to any other node.
270270
- Then the `curr` node is pointed to the `head` node. Value of `a` is set to 0.
271271

272-
![after third loop](../../images/after%20third%20loop.png)
272+
![after third loop](./images/after%20third%20loop.png)
273273

274274
- The jump statement then takes the control to the comparison instruction. If the value of `a` is greater than or equal to 5, jump statement takes the control to another location.
275275

276-
![fourth loop condition](../../images/fourth%20loop%20condition.png)
276+
![fourth loop condition](./images/fourth%20loop%20condition.png)
277277

278278
- If the value of `a` is less than 5, comparison happens between values of `curr` and `curr->next`. If `curr` value is less than `curr->next` value, the `explode_bomb` function is being called.
279279

280-
![fourth loop true condition](../../images/fourth%20loop%20condition%20true.png)
280+
![fourth loop true condition](./images/fourth%20loop%20condition%20true.png)
281281

282282
- If the value of `curr` is equal to or greater than value of `curr->next`, then `curr` node is set to `curr->next` node.
283283

284-
![curr curr next condition](../../images/curr%20curr%20next%20condition.png)
284+
![curr curr next condition](./images/curr%20curr%20next%20condition.png)
285285

286286
- The jump statement takes the control to iteration where the value of `a` is increased by 1. The loop condition comes again, which means that the loop ends.
287287

288-
![fourth loop iteration](../../images/fourth%20loop%20iteration.png)
288+
![fourth loop iteration](./images/fourth%20loop%20iteration.png)
289289

290290
- If the value of `a` is greater than or equal to 5, the control passes outside the loop.
291291

292-
![after fourth loop](../../images/after%20fourth%20loop.png)
292+
![after fourth loop](./images/after%20fourth%20loop.png)
293293

294294
The program ends here.
295295

0 commit comments

Comments
 (0)