Assembly and Bomb Lab 15-213: Introduction to Computer Systems Recitation 4: Monday, Sept. 16, 2013 Marjorie Carlson Section A.

Slides:



Advertisements
Similar presentations
Assembly Language – 1.
Advertisements

Fabián E. Bustamante, Spring 2007 Machine-Level Programming II: Control Flow Today Condition codes Control flow structures Next time Procedures.
Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 7, 2012 CSCE 212Honors Computer Organization.
%rax %eax %rbx %ebx %rdx %edx %rcx %ecx %rsi %esi %rdi %edi %rbp %ebp %rsp %esp %r8 %r8d %r9 %r9d %r11 %r11d %r10 %r10d %r12 %r12d %r13 %r13d.
Introduction to Information Security מרצים : Dr. Eran Tromer: Prof. Avishai Wool: מתרגלים : Itamar Gilad
Utilizing the GDB debugger to analyze programs Background and application.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
Flow Control Instructions
Memory & Storage Architecture Seoul National University Computer Architecture “ Bomb Lab Hints” 2nd semester, 2014 Modified version : The original.
Recitation 2: Assembly & gdb Andrew Faulring Section A 16 September 2002.
Recitation: Bomb Lab June 5, 2015 Dipayan Bhattacharya.
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Introduction to Information Security מרצים : Dr. Eran Tromer: Prof. Avishai Wool: מתרגלים : Itamar Gilad
Carnegie Mellon 1 Representing Data : Introduction to Computer Systems Recitation 3: Monday, Sept. 9 th, 2013 Marjorie Carlson Section A.
Carnegie Mellon Recitation: Bomb Lab 21 Sep 2015 Monil Shah, Shelton D’Souza.
1 ICS 51 Introductory Computer Organization Fall 2009.
Carnegie Mellon 1 Odds and Ends Intro to x86-64 Memory Layout.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
1 Carnegie Mellon Assembly and Bomb Lab : Introduction to Computer Systems Recitation 4, Sept. 17, 2012.
Reminder Bomb lab is due tomorrow! Attack lab is released tomorrow!!
CSE 351 x86 Calling Conventions, Control Flow, & Lab 2 April 23, 2015.
Carnegie Mellon 1 Midterm Review : Introduction to Computer Systems Recitation 8: Monday, Oct. 14, 2013 Marjorie Carlson Section A.
Jumps, Loops and Branching. Unconditional Jumps Transfer the control flow of the program to a specified instruction, other than the next instruction in.
OUTLINE 2 Pre-requisite Bomb! Pre-requisite Bomb! 3.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Introduction to Computer Systems Topics: Assembly Stack discipline Structs/alignment Caching CS 213 S ’12 rec8.pdf “The Class That Gives CMU Its.
CPSC 121: Models of Computation
Practical Session 3.
Instruction Set Architecture
Credits and Disclaimers
Recitation 5: Attack Lab
Computer Architecture and Assembly Language
Credits and Disclaimers
Recitation: Bomb Lab _______________ 18 Sep 2017.
More GDB, Intro to x86 Calling Conventions, Control Flow, & Lab 2
Homework Reading Labs PAL, pp
Recitation: Attack Lab
Debugging with gdb gdb is the GNU debugger on our CS machines.
Recitation: Bomb Lab _______________ 06 Feb 2017.
Aaron Miller David Cohen Spring 2011
Assembly Language Programming Part 2
Recitation 2 – 2/4/01 Outline Machine Model
Introduction to Computer Systems
Recitation: Attack Lab
Computer Architecture “Bomb Lab Hints”
Computer Architecture adapted by Jason Fritts then by David Ferry
x86-64 Programming II CSE 351 Autumn 2017
Computer Architecture and Assembly Language
Y86 Processor State Program Registers
Recitation: Attack Lab
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Fundamentals of Computer Organisation & Architecture
Practical Session 4.
Homework Reading Machine Projects Labs PAL, pp
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
X86 Assembly Review.
Carnegie Mellon Ithaca College
CS201- Lecture 8 IA32 Flow Control
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
Credits and Disclaimers
Credits and Disclaimers
Credits and Disclaimers
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Recitation: Bomb Lab Your TAs September 16th 2019.
By Hugues Leger / Intro to GDB debugger By Hugues Leger / 11/16/2019.
Presentation transcript:

Assembly and Bomb Lab 15-213: Introduction to Computer Systems Recitation 4: Monday, Sept. 16, 2013 Marjorie Carlson Section A

Agenda Overview of Bomb Lab Assembly Refresher Intro to GDB Unix Refresher Bomb Lab Demo

Bomb Lab Oh no! Dr. Evil has written an evil program that will “explode” the Shark machines! The program is in phases, each of which reads in input – something like a password – from standard input. If your input is correct, you go on to the next phase. If not, the bomb explodes. The program prints “BOOM!!!” and terminates, and you lose half a point. (Your score is updated automatically – you don’t have to upload anything to Autolab.)

Bomb Lab We give you: Partial source code, in which Dr. Evil mocks you The executable file itself You can’t read the C source code. So how can you figure out what the program does? From the binary executable!

Agenda Overview of Bomb Lab Assembly Refresher Intro to GDB Unix Refresher Bomb Lab Demo

x86-64 Integer Registers %rax %r8 %rbx %r9 %rcx %r10 %rdx %r11 %rsi return %eax arg 5 %r8d %rbx %ebx %r9 arg 6 %r9d %rcx %r10 arg 4 %ecx %r10d %rdx %edx %r11 arg 3 %r11d %rsi %r12 arg 2 %esi %r12d %rdi arg 1 %edi %r13 %r13d %rsp %esp %r14 %r14d %rbp %ebp %r15 %r15d

Assembly: Operands Data type Syntax Examples Notes Immediate values (constant integers) Start with $ $0x0 $-15213 Don’t forget 0x means hex! Registers Start with % %esi %rax Can represent a value or an address Memory locations Parentheses around a register, or addressing mode – D(Rb,Ri,S) (%esi) 0x8(%rax) (%rax, %rsi, 4) Parentheses dereference. If %esi stores an address, (%esi) is the value at that address.

Assembly: Some Common Operations Instruction Effect mov %rdi, %rax rax = rdi add %rdi, %rax rax = rax + rdi sub %rdi, %rax rax = rax - rdi lea (%rdi, %rsi, 2), %rax rax = rdi + (2 * rsi) (doesn’t dereference) call foo Calls function “foo” push %eax Pushes eax onto the stack pop %eax Pops a value off the stack and into eax ret Returns to the return address (i.e., the next line in the calling function) nop Does nothing! You may see suffixes on the end: b, w, l, q Specify operand is 1, 2, 4, 8 bytes

Assembly: Comparisons and Jumps Remember from class that Assembly uses comparisons and jumps (gotos) to execute various conditionals and loops. cmp b, a sets the same flags as computing a – b. test b, a sets the same flags as computing a & b. These are usually followed by a conditional jump instruction that relies on the results. Watch out for operand order: cmpl %eax, %edx if %edx > %eax, jg 401095 jump to 401095

Assembly: Comparisons and Jumps Instruction Effect jmp Always jump ja Jump if above (unsigned >) je/jz Jump if =/0 jae Jump if above or equal jne/jnz Jump if ≠/0 jb Jump if below (unsigned <) jg Jump if > jbe Jump if below or equal jge Jump if >= js Jump if negative jl Jump if < jns Jump if nonnegative jle Jump if <=

Assembly: Comparisons and Jumps cmp $0x42, %edi je 400d3b if ____________, jump to 400d3b cmp %esi, %edx jle 400e71 if_____________, jump to 400e71 test %rdi, %rdi jne 400e87 if ____________, jump to 400e87 edi == 66 edx <= esi %rdi != 0

Agenda Overview of Bomb Lab Assembly Refresher Intro to GDB Unix Refresher Bomb Lab Demo

Your Defusing Toolkit objdump –t bomb prints the symbol table strings bomb prints all printable strings objdump –d bomb prints the Assembly gdb bomb shows you the executable file in Assembly and lets you step through it line by line, peeking into the registers and stack as you go All the GDB commands you need are in http://csapp.cs.cmu.edu/public/docs/gdbnotes-x86-64.pdf

GDB: Stepping Through Code break <location> sets a breakpoint. Location can be a function name or an address. Pro tip: you have to reset your break points when you restart GDB! run / run <filename> runs the program up till the next breakpoint. Pro tip: instead of typing in your inputs each time, you can put them in a text file, one per line, and run that. disassemble (or disas – but not dis!!!) shows you the current function, with an arrow to the next line. step / stepi / nexti step executes one C statement – it doesn’t work for us. stepi steps to the next line of Assembly. nexti does the same but doesn’t stop in function calls. stepi <n> or nexti <n> steps through n lines.

GDB: Examining Data info registers print $<register> prints the (hex) contents of every register. print $<register> prints the contents of a register. Note the $ – not a %. Use /x or /d, to specify hex or decimal: print /d $rax. x $<register> / x 0x<address> prints what the register points to (or what’s at the given address). By default, prints one word (a “word” here is 4 bytes). However, in addition to specifying format (now including /s, string), you can specify how many objects of what size to print, in the format x /[num][size][format], for example: x /4wd $rsp

One Last Hint: sscanf The bomb frequently calls sscanf to read in formatted arguments. If you’re not familiar with the formatting used by printf, now’s the time! Example: %s %x %s represents an input of a string, hex number, and string. This could be handy in figuring out what kinds of arguments a phase is expecting. man sscanf!

Resources Assignment writeup GDB cheat sheet: http://csapp.cs.cmu.edu/public/docs/gdbnotes-x86-64.pdf. CS:APP Chapter 3 If you’re stuck, check the course FAQ: http://www.cs.cmu.edu/~213/faq.html If that doesn’t help, email us: 15-213-staff@cs.cmu.edu Office hours: Sun-Thu, 5:30-8:30 pm, in Wean 5207 Peer tutoring: Tue 8:30-11, Mudge Reading Room Note: if you Google Assembly instructions, make sure what you find is in AT&T syntax, not Intel. (The operands are reversed.)

Agenda Overview of Bomb Lab Assembly Refresher Intro to GDB Unix Refresher Bomb Lab Demo

Unix Refresher At the very least, you should be comfortable with: man to read manual pages cd to change directories ls to list contents of the current directory ls –l to list contents with extra info, including permission bits scp to send files between your computer and the Shark machines ssh to log into the Shark machines tar to tar (-cvf) and untar (-xvf) things (-z for optional gzip) chmod to change permission bits if necessary flags (e.g. –R to apply a command recursively to a folder) Helpful hints: Tab autocompletes. An up arrow scrolls up through your last few commands.

Agenda Overview of Bomb Lab Assembly Refresher Intro to GDB Unix Refresher Bomb Lab Demo