Disassembly תרגול 7 ניתוח קוד.

Slides:



Advertisements
Similar presentations
Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 7, 2012 CSCE 212Honors Computer Organization.
Advertisements

1 Homework / Exam Turn in mp2 at start of class today Reading –PAL, pp 3-6, Exam #1 next class –Open Book / Open Notes –NO calculators or other.
Pipeline Enhancements for the Y86 Architecture
Randal E. Bryant Carnegie Mellon University CS:APP2e CS:APP Chapter 4 Computer Architecture SequentialImplementation CS:APP Chapter 4 Computer Architecture.
Lecture Notes from Randal E. Bryant, CMU CS:APP Chapter 4 Computer Architecture Instruction Set Architecture CS:APP Chapter 4 Computer Architecture Instruction.
Disassembly תרגול 9 ניתוח קוד. How to - Disassembly of code Compilation of code:  gcc code.c  We get the file: a.out Disassembly:  objdump -d a.out.
Instruction Set Architecture CSC 333. – 2 – Instruction Set Architecture Assembly Language View Processor state Registers, memory, … Instructions addl,
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Computer ArchitectureFall 2008 © Sep 3 rd, 2008 Majd F. Sakr CS-447– Computer Architecture.
Randal E. Bryant CS:APP Chapter 4 Computer Architecture SequentialImplementation CS:APP Chapter 4 Computer Architecture SequentialImplementation Slides.
Computer Organization Chapter 4
Y86 Processor State Program Registers
CS:APP2e CS:APP Chapter 4 Computer Architecture Instruction Set Architecture.
Processor Architecture: The Y86 Instruction Set Architecture
Randal E. Bryant adapted by Jason Fritts CS:APP2e CS:APP Chapter 4 Computer Architecture Instruction Set Architecture CS:APP Chapter 4 Computer Architecture.
EECS 354 Network Security Reverse Engineering. Introduction Preventing Reverse Engineering Reversing High Level Languages Reversing an ELF Executable.
Chapter 4: Processor Architecture How does the hardware execute the instructions? We’ll see by studying an example system  Based on simple instruction.
Randal E. Bryant Carnegie Mellon University CS:APP CS:APP Chapter 4 Computer Architecture SequentialImplementation CS:APP Chapter 4 Computer Architecture.
Randal E. Bryant adapted by Jason Fritts CS:APP2e CS:APP Chapter 4 Computer Architecture SequentialImplementation CS:APP Chapter 4 Computer Architecture.
Datapath Design I Topics Sequential instruction execution cycle Instruction mapping to hardware Instruction decoding Systems I.
Based on slides by Patrice Belleville CPSC 121: Models of Computation Unit 10: A Working Computer.
1 Carnegie Mellon Assembly and Bomb Lab : Introduction to Computer Systems Recitation 4, Sept. 17, 2012.
1 Sequential CPU Implementation. 2 Outline Logic design Organizing Processing into Stages SEQ timing Suggested Reading 4.2,4.3.1 ~
1 Processor Architecture. Coverage Our Approach –Work through designs for particular instruction set Y86---a simplified version of the Intel IA32 (a.k.a.
Chapter 4: Processor Architecture
Computer Architecture
1 SEQ CPU Implementation. 2 Outline SEQ Implementation Suggested Reading 4.3.1,
Sequential CPU Implementation Implementation. – 2 – Processor Suggested Reading - Chap 4.3.
1 Seoul National University Sequential Implementation.
Precept 7: Introduction to IA-32 Assembly Language Programming
CPSC 121: Models of Computation
Lecture 3 Translation.
CPSC 121: Models of Computation
Data in Memory variables have multiple attributes symbolic name
Lecture 13 Y86-64: SEQ – sequential implementation
Module 10: A Working Computer
Debugging with gdb gdb is the GNU debugger on our CS machines.
Computer Architecture
Homework In-line Assembly Code Machine Language
Computer Architecture
Recitation 2 – 2/4/01 Outline Machine Model
Assembly Language Programming V: In-line Assembly Code
Machine-Level Programming II: Arithmetic & Control
Sequential Implementation
Chapter 3 Machine-Level Representation of Programs
Ch. 2 Two’s Complement Boolean vs. Logical Floating Point
Machine-Level Programming 1 Introduction
Computer Architecture adapted by Jason Fritts then by David Ferry
asum.ys A Y86 Programming Example
Y86 Processor State Program Registers
Instructor: David Ferry
Processor Architecture: The Y86-64 Instruction Set Architecture
Instruction Decoding Optional icode ifun valC Instruction Format
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Assembly Language Programming II: C Compiler Calling Sequences
Processor Architecture: The Y86-64 Instruction Set Architecture
Machine-Level Representation of Programs III
Sequential CPU Implementation
Recap: Performance Comparison
Machine-Level Programming: Introduction
Chapter 3 Machine-Level Representation of Programs
Chapter 4 Processor Architecture
Machine-Level Programming I: Basics Comp 21000: Introduction to Computer Organization & Systems Instructor: John Barr * Modified slides from the book.
02/02/10 20:53 Assembly Questions תרגול 12 1.
Sequential CPU Implementation
Computer Architecture I: Outline and Instruction Set Architecture
CS-447– Computer Architecture M,W 10-11:20am Lecture 5 Instruction Set Architecture Sep 12th, 2007 Majd F. Sakr
Debugging.
Credits and Disclaimers
Sequential Design תרגול 10.
Presentation transcript:

Disassembly תרגול 7 ניתוח קוד

How to - Disassembly of code Compilation of code: gcc code.c We get the file: a.out Disassembly: objdump -d a.out We get an assembly-like code that represents the c code appeared in file code.c Objdump –t a.out This will print out the symbol table of the file. The symbol table includes the names of all functions and global variables in the file, the names of all the functions being called by the file, and their addresses.

Basic: Many times when we work with an executive file we are interested in the code behind it. We can use the disassembly option or the debugger option in order to analyze the executive file, and understand what it does. Sometimes we want to use both options. Disassembly enable us to get an assembly-like file that represent the activity of the executive file.

Important aspects In disassembly we only get the code of the functions in the files and functions that were used by the files. We don’t get the code of the system’s functions (printf, scanf…). We don’t get the values of global constants or strings. Many times there are optimizations or nops added by the compiler – which make it harder to understand. For example, nop xchg %cx, %cx

An example While using disassember there are many global general functions added (init, start) usually we don’t care about them. Show disass.asm

Y86 Instruction Set Byte 1 2 3 4 5 nop addl 6 subl 1 andl 2 xorl 3 1 2 3 4 5 nop addl 6 subl 1 andl 2 xorl 3 halt 1 rrmovl rA, rB 2 rA rB irmovl V, rB 3 8 rB V rmmovl rA, D(rB) 4 rA rB D jmp 7 jle 1 jl 2 je 3 jne 4 jge 5 jg 6 mrmovl D(rB), rA 5 rA rB D OPl rA, rB 6 fn rA rB jXX Dest 7 fn Dest call Dest 8 Dest ret 9 pushl rA A rA 8 popl rA B rA 8

main:

hello: Address 0x08048520 does not appear in the disassembly code we can see. What does that tell us? How can we find out what is its value?

hello: Function “puts” is a simplified version of the printf() function. It doesn’t have all printf formats and it always put the newline character in the end of its strings.

main:

even: What kind of a loop is it?

main: Cleaning up the stack!

The C code: