1. Trang chủ
  2. » Giáo Dục - Đào Tạo

072 string representation kho tài liệu training

11 17 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 11
Dung lượng 588,88 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

String representation Assembly language programming... Objectives  We will learn how to represent text strings inside our assembly code...  We call this kind of representation a string

Trang 1

String representation

Assembly language programming

Trang 2

Objectives

 We will learn how to represent text strings inside our assembly code

Trang 3

Representing text

 How to express “Hello world” using ASCII?

 We call this kind of representation a string of bytes, or

just a string

 How can we know the size of the string?

48 65 6c 6c 6f 20 77 6f 72 6c 64

Trang 4

Schools of strings

 Two basic schools of indicating the size of a string:

Length prefix (Pascal style):

 Write the size of the string on the first byte

 ‘Hello’ is represented as:

Null terminated (C style):

 The string ends (terminates) with the Null character (0)

 ‘Hello’ is represented as:

 There are some more representation systems (Linked list, ropes etc.)

05 48 65 6c 6c 6f

48 65 6c 6c 6f 00

Trang 5

Schools of strings (Cont.)

Length prefix Null termination

Pros • Length can be calculated quickly • The size of string is virtually

unlimited

Cons • Size of string is limited (If the

length prefix is small)

• Takes longer time to calculate length

• Security issues: Strings can have no ending

Trang 6

Schools of strings (Cont.)

In this course we will work with Null terminated strings

 Windows API functions expect null terminated strings

 There are special assembly instructions to deal with null terminated objects

48 65 6c 6c 6f 00

Trang 7

Declaring strings

 The following declarations are equivalent:

section '.data' data readable writeable

; Declare strings:

str1 db 'Hello world',0 str2 db "Hello world",0

str3 db 48h,65h,6ch,6ch,6fh,20h,77h,6fh,72h,6ch,64h,0

str4 db 'Hell'

db 'o world',0

str5 db 'Hello',20h,'world',0

Trang 8

New line

 Example:

 Different representations:

 In Windows, a new line is marked by 0xd,0xa

 In Linux, a new line is marked by 0xa

 Historic note:

 CR (Carriage Return): 0xd

 Return to beginning of current line

 LF (Line Feed): 0xa

 Advance the paper one line forward

Walking in realms of brightness Passing the wall of above

Down into the soul

New lines

LF

CR

Trang 9

Declaring strings with newline

 Example:

section '.data' data readable writeable

; Declare strings with more than one line:

song db 'Walking in the realms of brightness',13,10

db 'Passing the wall of above',0dh,0ah

db 'Down into the soul',0

lines db 'First line',0dh,0ah,'second line',0

Trang 10

Summary

 There are two basic ways to indicate the size of a

string:

 Length prefix (Pascal style)

 Null termination (C style)

Strings are declared using the db data syntax

 New line is represented as:

 0xd,0xa in windows

 0xa in linux

Trang 11

Exercise

 Assemble the given asm source file

 Open the output using a hex editor

 Identify the strings inside the output file

Ngày đăng: 17/11/2019, 08:21