Displaying Memory/Files

Slides:



Advertisements
Similar presentations
Recursive Descent Technique CMSC 331. UMBC 2 The Header /* This program matches the following A -> B { '|' B } B -> C { '&' C } C -> D { '^' D } D ->
Advertisements

C Functions. What are they? In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive.
C Language.
Linux kernel internals Introduction to process descriptors.
Recitation 4 Outline Buffer overflow –Practical skills for Lab 3 Code optimization –Strength reduction –Common sub-expression –Loop unrolling Reminders.
Buffer Overflow Prabhaker Mateti Wright State University.
Smashing the Stack for Fun and Profit
CSC469 Tutorial2 Inline assembly, cycle counters, Gnuplot, LaTeX
Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.
Bit Field.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
C Intro.
Programming In C++ Spring Semester 2013 Lecture 8 Programming In C++, Lecture 8 By Umer Rana.
Union, bitfield, typedef, enum union nama_u{ }; union nama_u{ struct nama_s byte; }; enum{ }; Tipedef var BYTE.
CS 4284 Systems Capstone Godmar Back Linking and Loading.
An IP-header’s TOS field On setting and inspecting the ‘Type-of-Service’ field for outgoing or incoming datagrams.
Flow Diagram: Push flags, CS, IP Pop IP,CS,flags Push AX,BX,CX,DX,ES,DS,SI,DI,BP POP BP,DI,SI,DS,ES,DX,CX,BX,AX.
C Programming - Lecture 3 File handling in C - opening and closing. Reading from and writing to files. Special file streams stdin, stdout & stderr. How.
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
Linux Memory Management High-Level versus Low-Level.
Scientific Visualization Using imagery to aid humans in understanding a complicated phenomenon.
Non-blocking I/O int flags; int fd; /* file descripter */ void main() { fd = open(“myfile.txt”, R_ONLY); if ((flags = fcntl(fd, F_GETFL, 0)) < 0) /* first.
Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common.
Lecture 16 CIS 208 Friday March 18 th, Last bit on structs, I swear Structs in Debugger It’s your friend.
C Course Lecture 4 This lecture we'll talk about: Multi-dimensional arrays. Pointer arithmetic. Pointers to structures. Multi-file programming. What is.
Recursion Examples Fundamentals of CS Case 1: Code /* Recursion: Case 1 */ #include void count (int index); main () { count (0); getchar(); } void count.
CS 3204 Operating Systems Godmar Back Lecture 11.
Assembly Questions תרגול 12.
1 Homework HW5 due today Review a lot of things about allocation of storage that may not have been clear when we covered them in our initial pass Introduction.
Agenda Attack Lab C Exercises C Conventions C Debugging
TPFDF Keylists in ISOC Paul Stuyvesant. Agenda The traditional approach - Assembler The traditional approach - ISOC Using parameters in ISOC Overview.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2013 CMPE-013/L Unions and Bitfields Gabriel Hugh Elkaim Spring 2013.
What is exactly Exploit writing?  Writing a piece of code which is capable of exploit the vulnerability in the target software.
Generic lists Vassilis Athitsos. Problems With Textbook Interface? Suppose that we fix the first problem, and we can have multiple stacks. Can we have.
COMPSCI 210 Semester Tutorial 8 – C programming language.
Data Types Always data types will decide which type of information we are storing into variables In C programming language we are having 3 types of basic.
LOOPING IN C. What would be the output of the following program main( ) { int j ; while ( j
Inline Assembly 井民全. Accessing C or C++ Data in __asm Blocks An __asm block can refer to any symbols Including variable name Ex: __asm mov eax, var Store.
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Institute of Radio Physics and Electronics and Indian GNU/Linux Users Group Kolkata.
Instruction Set Architecture
Homework / Exam Return and Review Exam #1 Reading Machine Projects
Assembly Language Programming IV: shift, struct, recursion
Embedded Systems Programming Examples and Comparison
1st prog! Q: Read a char – from a keyboard & display it at the beginning of the next line! ====== A.
CSCE 212Honors Computer Organization
Chapter7 Structure & C++
CS 5204 Operating Systems Linking and Loading Godmar Back.
High-Level Language Interface
CSCI206 - Computer Organization & Programming
Heterogeneous Data Structures & Alignment
By: Syed Shahrukh Haider
DATA HANDLING.
פרטים נוספים בסילבוס של הקורס
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
FUNCTIONS& FUNCTIONS OVERLOADING
CS 4284 Systems Capstone Linking and Loading Godmar Back.
Discussions on HW2 Objectives
Govt. Polytechnic,Dhangar
Lecture 2 SCOPE – Local and Global variables
EECE.2160 ECE Application Programming
Lecture 1. Program Surgery
Discussions on HW2 Objectives
EECE.2160 ECE Application Programming
C Miscellaneous Programs Prabhat Kumar Padhy
02/02/10 20:53 Assembly Questions תרגול 12 1.
CSCE 212Honors Computer Organization
EECE.2160 ECE Application Programming
Introduction to C CS 3410.
The ‘asm’ construct An introduction to the GNU C/C++ compiler’s obscure syntax for doing inline assembly language.
Presentation transcript:

Displaying Memory/Files What every systems programmer needs to know how to do

An often-needed capability When we want to look at memory-contents or see what’s been saved in an arbitrary file We need to write code for a memory-dump So often, It’s probably worth memorizing!

Here’s the basic loop in C unsigned char *cp; // where the data starts int n; // number of bytes of data for (i = 0; i < n; i += 16) { if ( (i % 16) == 0 ) printf( “\n%a: “, cp+i ); for (j = 0; j < 16; j++) { if ( i+j < n ) printf( “%02X “, cp[i+j] ); else printf( “ “ ); } char ch = ( i+j < n ) ? cp[i+j] | 0x20; if (( ch < 0x20 )||( ch > 0x7E )) ch = ‘.’; printf( “%c”, ch ); }

Exercise: let’s see our stack Write a program to ‘dump’ its user-stack We can use inline assembly to get ESP int main( void ) { unsigned char *cp; asm(“ movl %%esp, %0 “ : “=n” (cp) ); int nbytes = 0xC0000000 – (int)cp; /* then code to dump stack goes here */

Compare with ‘mm_struct’ Header-file ‘/usr/src/linux/include/linux/sched.h’ Defines the type ‘struct mm_struct’ Includes some fields describing user stack