Difference between revisions of "CSC231 Homework 2"

From dftwiki3
Jump to: navigation, search
(Problem #2)
(Problem #2)
Line 52: Line 52:
 
==Problem #2==
 
==Problem #2==
  
For this problem you have to debug the executable version of a program and answer two questions.
+
For this problem you have to debug a program whose source code is so cryptic that it is (almost) impossible to recognize the instructions...
  
* You can get the executable version of the program by using this command, from your Linux account:
+
Its code is given below:
  
     cp ~thiebaut/public_html/classes/231/hw2 .
+
<code><pre>
 +
                              section .data
 +
msg db 0x61,0x20,0x6D,0x61,0x6E,0x20,0x61,0x20,0x70
 +
    db 0x6C,0x61,0x6E,0x20,0x61,0x20,0x63   
 +
msgL    equ    $-msg
 +
    db 0x68,0x61,0x72,0x61,0x63,0x74,0x65,0x72,0x20
 +
    db 0x61,0x20,0x62,0x6C,0x6F,0x67,0x21   
 +
lf  db 0x0A,0x0A
 +
     section .text
 +
    global _start
 +
_start:
 +
    db 0x90,0x90
 +
    db 0xBE
 +
    dd msg
 +
    db 0xBF,
 +
    dd lf-2
 +
    db 0xB9, 0x10, 0, 0, 0, 0x8A, 6, 0x88, 7
 +
    db 0x46, 0x81, 0xEF,1, 0, 0, 0
 +
    db 0xe2, 0xf3
 +
    db 0xA1
 +
    dd msg
 +
    db 0xBa, 0, 0, 0, 0,
 +
    db 0x8B, 0x1D
 +
    dd msg+4
 +
    db 0xF7, 0xE3
 +
    db 0x90, 0x90
 +
    db 0xb8
 +
    dd 1
 +
    db 0xbb
 +
    dd 0
 +
    db 0xcd, 0x80
  
(don't forget the dot at the end of the line!)
+
</pre></code>
  
If you are working off-campus, and you have a linux machine where the utility '''wget''' is installed, try this:
+
* Open a new file in your Linux account, and call it hw2.asm. 
 +
* Paste the code above in it.
 +
* Assemble and link it:
  
    wget http://cs.smith.edu/~thiebaut/classes/231/hw2
+
  nasm -f elf -F stabs hw2.asm
 +
  ld -o hw2 hw2.o
  
and you should get a copy of the program.
+
*Debug it!
  
Of course, you can just click on the link and get the executable!
+
    ddd hw2 &
  
* Once you're done transfering the program, debug it:
+
* Because the instructions are provided in the code as opcodes (in hex), ddd will disassemble the program for you, and will show something like this:
  
    ddd hw2 &
+
[[Image:231_hw2_ddd_Window.png | 800px ]]
  
* Because you do not have the source file, the .asm program, ddd will disassemble the beginning of the program for you, and will show something like this:
 
  
<code><pre>
 
Dump of assembler code for function _start:
 
    0x08048080 <_start+0>:  nop
 
    0x08048081 <_start+1>:  nop   
 
    0x08048082 <_start+2>:  mov    $0x80490c0,%esi
 
    0x08048087 <_start+7>:  mov    $0x80490de,%edi
 
    0x0804808c <_start+12>: mov    $0x10,%ecx
 
End of assembler dump.
 
</pre></code>
 
 
Right click on the address of the second nop, and set a '''breakpoint'''.  A little red <font color="red">STOP</font> sign should appear on this line.
 
Right click on the address of the second nop, and set a '''breakpoint'''.  A little red <font color="red">STOP</font> sign should appear on this line.
  

Revision as of 18:25, 21 September 2008

<meta name="keywords" content="computer science, assembly language, pentium, exercise, machine language, intel" /> <meta name="description" content="Dominique Thiebaut's Web Page" /> <meta name="title" content="Dominique Thiebaut -- Computer Science" /> <meta name="abstract" content="Dominique Thiebaut's Computer Science Web pages" /> <meta name="author" content="thiebaut at cs.smith.edu" /> <meta name="distribution" content="Global" /> <meta name="revisit-after" content="10 days" /> <meta name="copyright" content="(c) D. Thiebaut 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,2008" /> <meta name="robots" content="FOLLOW,INDEX" />

Back to CSC231 Main Page


Assignment #2

This assignment is due on Wednesday, Sept 24th, at 11:59 p.m. plus 1 minute.

Problem #1

Write a program that displays the following pattern using loops.

**********#
 *********##
  ********###
   *******####
    ******#####
     *****######
      ****#######
       ***########
        **#########
         *##########
        **#########
       ***########
      ****#######
     *****######
    ******#####
   *******####
  ********###
 *********##
**********#

Requirements: your program cannot contain more than 5 int 0x80 instructions!

Store your program in a file called hw2a.asm and submit it as follows:

  submit hw2 hw2a.asm

Problem #2

For this problem you have to debug a program whose source code is so cryptic that it is (almost) impossible to recognize the instructions...

Its code is given below:

                               	section	.data
msg db 0x61,0x20,0x6D,0x61,0x6E,0x20,0x61,0x20,0x70
    db 0x6C,0x61,0x6E,0x20,0x61,0x20,0x63     
msgL    equ     $-msg
    db 0x68,0x61,0x72,0x61,0x63,0x74,0x65,0x72,0x20
    db 0x61,0x20,0x62,0x6C,0x6F,0x67,0x21     
lf  db 0x0A,0x0A
    section	.text
    global	_start
_start:
    db 0x90,0x90
    db 0xBE
    dd msg
    db 0xBF,
    dd lf-2
    db 0xB9, 0x10, 0, 0, 0, 0x8A, 6, 0x88, 7
    db 0x46, 0x81, 0xEF,1, 0, 0, 0
    db 0xe2, 0xf3
    db 0xA1
    dd msg
    db 0xBa, 0, 0, 0, 0, 
    db 0x8B, 0x1D
    dd msg+4
    db 0xF7, 0xE3
    db 0x90, 0x90
    db 0xb8
    dd 1
    db 0xbb
    dd 0
    db 0xcd, 0x80

  • Open a new file in your Linux account, and call it hw2.asm.
  • Paste the code above in it.
  • Assemble and link it:
 nasm -f elf -F stabs hw2.asm
 ld -o hw2 hw2.o
  • Debug it!
   ddd hw2 &
  • Because the instructions are provided in the code as opcodes (in hex), ddd will disassemble the program for you, and will show something like this:

231 hw2 ddd Window.png


Right click on the address of the second nop, and set a breakpoint. A little red STOP sign should appear on this line.

  • Then run the program by clicking on the Run button of the floating toolbar (or by pressing F2).
  • Then it's a matter of clicking Stepi and gather the information you need to answer the questions below.

Question 1

What string of characters is contained in the array that occupies the first 31 bytes of data memory when the processor has reached the 3rd NOP instruction of the program?

Question 2

What hexadecimal values are stored in the registers eax, ebx, ecx, and edx when the processor has reached the 3rd NOP instruction of the program?

Write your answers in a file called hw2.txt and submit your file as follows:

  submit hw2 hw2.txt