Computer Architecture and Assembly Language

Slides:



Advertisements
Similar presentations
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
Advertisements

The art of exploitation
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Object Code.
Practical Session 3 Computer Architecture and Assembly Language.
Memory Image of Running Programs Executable file on disk, running program in memory, activation record, C-style and Pascal-style parameter passing.
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.
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.
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
Position Independent Code self sufficiency of combining program.
Computer Architecture and Assembly Languages Course’s web site: Teaching Assistant: Or Peri Office Hours: Thursday 37/-108.
Practical Session 8 Computer Architecture and Assembly Language.
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 7 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Derived from "x86 Assembly Registers and the Stack" by Rodney BeedeRodney Beede x86 Assembly Registers and the Stack Nov 2009.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 22: Unconventional.
ELF binary # readelf -a foo.out ELF Header:
Practical Session 4 Computer Architecture and Assembly Language.
Assembly 08. Outline Local Labels Jump Lengths External Libraries Macros 1.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
CS429 Computer Architecture Topics Simple C program Basic structure, functions, separate files Compilation Phases, options Assembler GNU style, byte ordering,
Computer Architecture and Assembly Language
Practical Session 4. GNU Linker Links object files together Used as the last step in the compilation We will use ld to link together compiled assembly.
Practical Session 8. Position Independent Code- self sufficiency of combining program Position Independent Code (PIC) program has everything it needs.
Practical Session 4. GNU Linker Links object files together Used as the last step in the compilation We will use ld to link together compiled assembly.
NASM ASSEMBLER & COMPILE WITH GCC 어셈러브 refered to ‘PC Assembly Language’ by Paul A. Carter
ICS51 Introductory Computer Organization Accessing parameters from the stack and calling functions.
Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 4, 2010 CSCE 212Honors Computer Organization.
Practical Session 3 Computer Architecture and Assembly Language.
Practical Session 3.
Section 5: Procedures & Stacks
Practical Session 5.
Instructions for test_function
Computer Architecture and Assembly Language
Assembly language.
Static and dynamic analysis of binaries
Computer Architecture and Assembly Language
CSCE 212Honors Computer Organization
Debugging with gdb gdb is the GNU debugger on our CS machines.
Homework Reading Machine Projects Labs PAL, pp ,
Computer Architecture and Assembly Language
Writing a Useful Program With NASM
High-Level Language Interface
Computer Architecture and Assembly Language
Computer Architecture and Assembly Language
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Assembly Language Programming II: C Compiler Calling Sequences
Computer Architecture and Assembly Language
Understanding Program Address Space
EECE.3170 Microprocessor Systems Design I
Practical Session 4.
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.
CNT4704: Analysis of Computer Communication Network Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Fall 2011.
Multi-modules programming
EECE.3170 Microprocessor Systems Design I
X86 Assembly Review.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
CSC 497/583 Advanced Topics in Computer Security
CSCE 212Honors Computer Organization
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.
Computer Architecture and System Programming Laboratory
Computer Architecture and Assembly Language
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Presentation transcript:

Computer Architecture and Assembly Language Practical Session 4

Local Labels Definition valid characters in labels are: letters, numbers, _, $, #, @, ~, ., and ? first character can be: letter, _, ?, and . Local Labels Definition A label beginning with a single period (.) is treated as a local label, which means that it is associated with the previous non-local label. Example: label1: mov eax, 3 .loop: dec eax jne .loop ret label2: mov eax, 5 Each JNE instruction jumps to the closest .loop, because the two definitions of .loop are kept separate. (this is indeed label1.loop) (this is indeed label2.loop)

Assembly program with no .c file usage – sample.s section .data numeric: DD 0x12345678 string: DB 'abc' answer: DD 0 section .text global _start ;entry point (main) _start: pushad ; backup registers push dword 2 ; push argument #2 push dword 1 ; push argument #1 CALL myFunc ; call the function myFunc returnAddress: mov [answer], eax ; retrieve return value from EAX add esp, 8 ; "delete" function arguments popad mov ebx,0 ; exit program mov eax,1 int 0x80 myFunc: push ebp ; save previous value of ebp mov ebp, esp ; set ebp to point to myFunc frame mov eax, dword [ebp+8] ; get function argument #1 mov ebx, dword [ebp+12] ; get function argument #2 myFunc_code: add eax, ebx ; eax = 3 returnFrom_myFunc: mov esp, ebp ; "delete" local variables of myFunc pop ebp ; restore previous value of ebp RET ; return to the caller GNU Linker ld links together compiled assembly without using .c main file > nasm –f elf sample.s –o sample.o > ld -m elf_i386 sample.o –o sample > sample or with gdb debugger > gdb sample Command-line arguments ld(_start) vs. gcc (main) This is just like C’s main(int argc, char** argv) stack stack argv[2] argv[1] argv[0] argc &{argv[0],argv[1],argv[2],…} argc ESP ESP

Producing a listing file: > nasm -f elf sample.s -l sample.lst The first column (from the left) is the line number in the listing file The second column is the relative address of where the code will be placed in memory each section starts at relative address 0 The third column is the compiled code The forth column is the original code Labels do not create code; they are a way to tell assembler that those locations have symbolic names. 0x15 is how many bytes EIP should jump forward ‘CALL myFunc’ is compiled to opcode E8 followed by a 4-byte target address, relative to the next instruction after the call.  address of myFunc label = 0x1F  address of the next instruction after the call (i.e. ‘mov [answer], eax’) is 0xA  0x1F-0xA=0x15, and we get exactly the binary code written here ‘E815000000’ executable

Debugging with GDB guide section .data numeric: DD 0x12345678 string: DB 'abc' answer: DD 0 section .text global _start _start: pushad push dword 2 push dword 1 CALL myFunc returnAddress: mov [answer], eax add esp, 8 popad mov ebx,0 mov eax,1 int 0x80 myFunc: push ebp mov ebp, esp mov eax, dword [ebp+8] mov ebx, dword [ebp+12] myFunc_code: add eax, ebx returnFrom_myFunc: mov esp, ebp pop ebp ret - examining memory - examining data print ‘numeric’ global variable numeric into memory – little endian print ‘string’ global variable string into memory – little endian pushad 0xffffd640 – 0xffffd620= 0x20 = 32 bytes = 8 registers * 4 bytes push function’s arguments into stack CALL myFunc return address