Difference between revisions of "CSC231 Lab 2 2015"
(Created page with "--~~~~ ---- <br /> =Reverse Engineering= <br /> Recreate the original assembly program whose hexdump is shown below. You should call your program '''lab2.asm'''. <br /> <sou...") |
|||
Line 6: | Line 6: | ||
<br /> | <br /> | ||
Recreate the original assembly program whose hexdump is shown below. You should call your program '''lab2.asm'''. | Recreate the original assembly program whose hexdump is shown below. You should call your program '''lab2.asm'''. | ||
+ | In the process, answer the following questions: | ||
+ | * what is the name of the original assembly program? | ||
+ | * how many string variables does it contain? | ||
+ | * what are the names of the strings? | ||
+ | * what are the names of the constants? | ||
+ | * what is the original program's output? | ||
+ | |||
<br /> | <br /> | ||
<source lang="text"> | <source lang="text"> | ||
00000000 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 |.ELF............| | 00000000 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 |.ELF............| | ||
00000010 02 00 03 00 01 00 00 00 80 80 04 08 34 00 00 00 |............4...| | 00000010 02 00 03 00 01 00 00 00 80 80 04 08 34 00 00 00 |............4...| | ||
− | 00000020 | + | 00000020 18 01 00 00 00 00 00 00 34 00 20 00 02 00 28 00 |........4. ...(.| |
00000030 06 00 03 00 01 00 00 00 00 00 00 00 00 80 04 08 |................| | 00000030 06 00 03 00 01 00 00 00 00 00 00 00 00 80 04 08 |................| | ||
− | 00000040 00 80 04 08 | + | 00000040 00 80 04 08 b8 00 00 00 b8 00 00 00 05 00 00 00 |................| |
− | 00000050 00 10 00 00 01 00 00 00 | + | 00000050 00 10 00 00 01 00 00 00 b8 00 00 00 b8 90 04 08 |................| |
− | 00000060 | + | 00000060 b8 90 04 08 36 00 00 00 36 00 00 00 06 00 00 00 |....6...6.......| |
00000070 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| | 00000070 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| | ||
− | 00000080 b8 04 00 00 00 bb 01 00 00 00 ba | + | 00000080 b8 04 00 00 00 bb 01 00 00 00 ba 0c 00 00 00 b9 |................| |
− | 00000090 | + | 00000090 ce 90 04 08 cd 80 b8 04 00 00 00 bb 01 00 00 00 |................| |
− | 000000a0 cd 80 00 00 | + | 000000a0 ba 16 00 00 00 b9 b8 90 04 08 cd 80 b8 01 00 00 |................| |
− | 000000b0 | + | 000000b0 00 bb 00 00 00 00 cd 80 69 74 20 73 69 6d 70 6c |........it simpl| |
− | 000000c0 | + | 000000c0 65 2c 20 53 6d 69 74 68 69 65 73 21 0a 0a 4b 49 |e, Smithies!..KI| |
− | 000000d0 | + | 000000d0 53 53 3a 20 4b 65 65 70 20 20 59 6f 75 20 67 6f |SS: Keep You go| |
− | 000000e0 00 | + | 000000e0 74 20 69 74 21 0a 4e 6f 20 77 61 79 21 0a 00 2e |t it!.No way!...| |
− | 000000f0 00 | + | 000000f0 73 79 6d 74 61 62 00 2e 73 74 72 74 61 62 00 2e |symtab..strtab..| |
− | + | 00000100 73 68 73 74 72 74 61 62 00 2e 74 65 78 74 00 2e |shstrtab..text..| | |
− | + | 00000110 64 61 74 61 00 00 00 00 00 00 00 00 00 00 00 00 |data............| | |
− | + | 00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| | |
− | + | 00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| | |
− | + | 00000140 1b 00 00 00 01 00 00 00 06 00 00 00 80 80 04 08 |................| | |
− | + | 00000150 80 00 00 00 38 00 00 00 00 00 00 00 00 00 00 00 |....8...........| | |
− | + | 00000160 10 00 00 00 00 00 00 00 21 00 00 00 01 00 00 00 |........!.......| | |
− | + | 00000170 03 00 00 00 b8 90 04 08 b8 00 00 00 36 00 00 00 |............6...| | |
− | + | 00000180 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 |................| | |
− | + | 00000190 11 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 |................| | |
− | + | 000001a0 ee 00 00 00 27 00 00 00 00 00 00 00 00 00 00 00 |....'...........| | |
− | + | 000001b0 01 00 00 00 00 00 00 00 01 00 00 00 02 00 00 00 |................| | |
− | + | 000001c0 00 00 00 00 00 00 00 00 08 02 00 00 30 01 00 00 |............0...| | |
− | + | 000001d0 05 00 00 00 0f 00 00 00 04 00 00 00 10 00 00 00 |................| | |
− | + | 000001e0 09 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 |................| | |
− | + | 000001f0 38 03 00 00 6c 00 00 00 00 00 00 00 00 00 00 00 |8...l...........| | |
− | + | 00000200 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| | |
− | + | 00000210 00 00 00 00 00 00 00 00 00 00 00 00 80 80 04 08 |................| | |
− | + | 00000220 00 00 00 00 03 00 01 00 00 00 00 00 b8 90 04 08 |................| | |
− | + | 00000230 00 00 00 00 03 00 02 00 01 00 00 00 00 00 00 00 |................| | |
− | + | 00000240 00 00 00 00 04 00 f1 ff 15 00 00 00 01 00 00 00 |................| | |
− | + | 00000250 00 00 00 00 00 00 f1 ff 1a 00 00 00 04 00 00 00 |................| | |
− | + | 00000260 00 00 00 00 00 00 f1 ff 20 00 00 00 01 00 00 00 |........ .......| | |
− | + | 00000270 00 00 00 00 00 00 f1 ff 27 00 00 00 b8 90 04 08 |........'.......| | |
− | + | 00000280 00 00 00 00 00 00 02 00 2c 00 00 00 16 00 00 00 |........,.......| | |
− | + | 00000290 00 00 00 00 00 00 f1 ff 32 00 00 00 ce 90 04 08 |........2.......| | |
− | + | 000002a0 00 00 00 00 00 00 02 00 37 00 00 00 0c 00 00 00 |........7.......| | |
− | + | 000002b0 00 00 00 00 00 00 f1 ff 3d 00 00 00 da 90 04 08 |........=.......| | |
− | + | 000002c0 00 00 00 00 00 00 02 00 42 00 00 00 0c 00 00 00 |........B.......| | |
+ | 000002d0 00 00 00 00 00 00 f1 ff 48 00 00 00 e6 90 04 08 |........H.......| | ||
+ | 000002e0 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 |................| | ||
+ | 000002f0 00 00 00 00 04 00 f1 ff 4d 00 00 00 80 80 04 08 |........M.......| | ||
+ | 00000300 00 00 00 00 10 00 01 00 54 00 00 00 ee 90 04 08 |........T.......| | ||
+ | 00000310 00 00 00 00 10 00 02 00 60 00 00 00 ee 90 04 08 |........`.......| | ||
+ | 00000320 00 00 00 00 10 00 02 00 67 00 00 00 f0 90 04 08 |........g.......| | ||
+ | 00000330 00 00 00 00 10 00 02 00 00 72 65 76 65 72 73 65 |.........reverse| | ||
+ | 00000340 45 6e 67 69 6e 65 65 72 2e 61 73 6d 00 45 58 49 |Engineer.asm.EXI| | ||
+ | 00000350 54 00 57 52 49 54 45 00 53 54 44 4f 55 54 00 6d |T.WRITE.STDOUT.m| | ||
+ | 00000360 73 67 31 00 4d 53 47 31 4c 00 6d 73 67 32 00 4d |sg1.MSG1L.msg2.M| | ||
+ | 00000370 53 47 32 4c 00 6d 73 67 33 00 4d 53 47 33 4c 00 |SG2L.msg3.MSG3L.| | ||
+ | 00000380 6d 73 67 34 00 5f 73 74 61 72 74 00 5f 5f 62 73 |msg4._start.__bs| | ||
+ | 00000390 73 5f 73 74 61 72 74 00 5f 65 64 61 74 61 00 5f |s_start._edata._| | ||
+ | 000003a0 65 6e 64 00 |end.| | ||
+ | 000003a4 | ||
</source> | </source> | ||
<br /> | <br /> | ||
Line 58: | Line 80: | ||
<br /> | <br /> | ||
<br /> | <br /> | ||
+ | <onlydft> | ||
+ | =Original Program= | ||
+ | <br /> | ||
+ | ==Assembly== | ||
+ | <br /> | ||
+ | <source lang="asm"> | ||
+ | ;;; reverseEngineering.asm | ||
+ | ;;; D. Thiebaut | ||
+ | ;;; | ||
+ | ;;; a description of the program | ||
+ | ;;; | ||
+ | ;;; to assemble and run: | ||
+ | ;;; | ||
+ | ;;; nasm -f elf -F stabs reverseEngineering.asm | ||
+ | ;;; ld -o reverseEngineering reverseEngineering.o | ||
+ | ;;; ./reverseEngineering | ||
+ | ;;; | ||
+ | ;;; ------------------------------------------------------------------- | ||
+ | |||
+ | |||
+ | |||
+ | EXIT equ 1 | ||
+ | WRITE equ 4 | ||
+ | STDOUT equ 1 | ||
+ | |||
+ | ;; ------------------------------------------------------------ | ||
+ | ;; data areas | ||
+ | ;; ------------------------------------------------------------ | ||
+ | |||
+ | section .data | ||
+ | msg1 db "it simple, Smithies!", 10, 10 | ||
+ | MSG1L equ $-msg1 | ||
+ | msg2 db "KISS: Keep " | ||
+ | MSG2L equ $-msg2 | ||
+ | msg3 db "You got it!", 10 | ||
+ | MSG3L equ $-msg3 | ||
+ | msg4 db "No way!", 10 | ||
+ | |||
+ | ;; ------------------------------------------------------------ | ||
+ | ;; code area | ||
+ | ;; ------------------------------------------------------------ | ||
+ | |||
+ | section .text | ||
+ | global _start | ||
+ | |||
+ | _start: | ||
+ | mov eax, 4 | ||
+ | mov ebx, 1 | ||
+ | mov edx, MSG2L | ||
+ | mov ecx, msg2 | ||
+ | int 0x80 | ||
+ | |||
+ | mov eax, 4 | ||
+ | mov ebx, 1 | ||
+ | mov edx, MSG1L | ||
+ | mov ecx, msg1 | ||
+ | int 0x80 | ||
+ | |||
+ | ;; exit() | ||
+ | |||
+ | mov eax,EXIT | ||
+ | mov ebx,0 | ||
+ | int 0x80 ; final system call | ||
+ | </source> | ||
+ | <br /> | ||
+ | ==Listing== | ||
+ | <br /> | ||
+ | <source lang="text"> | ||
+ | |||
+ | 1 ;;; reverseEngineering.asm | ||
+ | 2 ;;; D. Thiebaut | ||
+ | 3 ;;; | ||
+ | 4 ;;; a description of the program | ||
+ | 5 ;;; | ||
+ | 6 ;;; to assemble and run: | ||
+ | 7 ;;; | ||
+ | 8 ;;; nasm -f elf -F stabs reverseEngineering.asm | ||
+ | 9 ;;; ld -o reverseEngineering reverseEngineering.o | ||
+ | 10 ;;; ./reverseEngineering | ||
+ | 11 ;;; | ||
+ | 12 ;;; ------------------------------------------------------------------- | ||
+ | 13 | ||
+ | 14 | ||
+ | 15 | ||
+ | 16 EXIT equ 1 | ||
+ | 17 WRITE equ 4 | ||
+ | 18 STDOUT equ 1 | ||
+ | 19 | ||
+ | 20 ;; ------------------------------------------------------------ | ||
+ | 21 ;; data areas | ||
+ | 22 ;; ------------------------------------------------------------ | ||
+ | 23 | ||
+ | 24 section .data | ||
+ | 25 00000000 69742073696D706C65- msg1 db "it simple, Smithies!", 10, 10 | ||
+ | 26 00000009 2C20536D6974686965- | ||
+ | 27 00000012 73210A0A | ||
+ | 28 MSG1L equ $-msg1 | ||
+ | 29 00000016 4B4953533A204B6565- msg2 db "KISS: Keep " | ||
+ | 30 0000001F 702020 | ||
+ | 31 MSG2L equ $-msg2 | ||
+ | 32 00000022 596F7520676F742069- msg3 db "You got it!", 10 | ||
+ | 33 0000002B 74210A | ||
+ | 34 MSG3L equ $-msg3 | ||
+ | 35 0000002E 4E6F20776179210A msg4 db "No way!", 10 | ||
+ | 36 | ||
+ | 37 ;; ------------------------------------------------------------ | ||
+ | 38 ;; code area | ||
+ | 39 ;; ------------------------------------------------------------ | ||
+ | 40 | ||
+ | 41 section .text | ||
+ | 42 global _start | ||
+ | 43 | ||
+ | 44 _start: | ||
+ | 45 00000000 B804000000 mov eax, 4 | ||
+ | 46 00000005 BB01000000 mov ebx, 1 | ||
+ | 47 0000000A BA0C000000 mov edx, MSG2L | ||
+ | 48 0000000F B9[16000000] mov ecx, msg2 | ||
+ | 49 00000014 CD80 int 0x80 | ||
+ | 50 | ||
+ | 51 00000016 B804000000 mov eax, 4 | ||
+ | 52 0000001B BB01000000 mov ebx, 1 | ||
+ | 53 00000020 BA16000000 mov edx, MSG1L | ||
+ | 54 00000025 B9[00000000] mov ecx, msg1 | ||
+ | 55 0000002A CD80 int 0x80 | ||
+ | 56 | ||
+ | 57 ;; exit() | ||
+ | 58 | ||
+ | 59 0000002C B801000000 mov eax,EXIT | ||
+ | 60 00000031 BB00000000 mov ebx,0 | ||
+ | 61 00000036 CD80 int 0x80 ; final system call | ||
+ | |||
+ | |||
+ | </source> | ||
+ | </onlydft> | ||
<br /> | <br /> | ||
<br /> | <br /> |
Revision as of 07:15, 21 September 2015
--D. Thiebaut (talk) 07:15, 21 September 2015 (EDT)
Reverse Engineering
Recreate the original assembly program whose hexdump is shown below. You should call your program lab2.asm.
In the process, answer the following questions:
- what is the name of the original assembly program?
- how many string variables does it contain?
- what are the names of the strings?
- what are the names of the constants?
- what is the original program's output?
00000000 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 |.ELF............|
00000010 02 00 03 00 01 00 00 00 80 80 04 08 34 00 00 00 |............4...|
00000020 18 01 00 00 00 00 00 00 34 00 20 00 02 00 28 00 |........4. ...(.|
00000030 06 00 03 00 01 00 00 00 00 00 00 00 00 80 04 08 |................|
00000040 00 80 04 08 b8 00 00 00 b8 00 00 00 05 00 00 00 |................|
00000050 00 10 00 00 01 00 00 00 b8 00 00 00 b8 90 04 08 |................|
00000060 b8 90 04 08 36 00 00 00 36 00 00 00 06 00 00 00 |....6...6.......|
00000070 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000080 b8 04 00 00 00 bb 01 00 00 00 ba 0c 00 00 00 b9 |................|
00000090 ce 90 04 08 cd 80 b8 04 00 00 00 bb 01 00 00 00 |................|
000000a0 ba 16 00 00 00 b9 b8 90 04 08 cd 80 b8 01 00 00 |................|
000000b0 00 bb 00 00 00 00 cd 80 69 74 20 73 69 6d 70 6c |........it simpl|
000000c0 65 2c 20 53 6d 69 74 68 69 65 73 21 0a 0a 4b 49 |e, Smithies!..KI|
000000d0 53 53 3a 20 4b 65 65 70 20 20 59 6f 75 20 67 6f |SS: Keep You go|
000000e0 74 20 69 74 21 0a 4e 6f 20 77 61 79 21 0a 00 2e |t it!.No way!...|
000000f0 73 79 6d 74 61 62 00 2e 73 74 72 74 61 62 00 2e |symtab..strtab..|
00000100 73 68 73 74 72 74 61 62 00 2e 74 65 78 74 00 2e |shstrtab..text..|
00000110 64 61 74 61 00 00 00 00 00 00 00 00 00 00 00 00 |data............|
00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000140 1b 00 00 00 01 00 00 00 06 00 00 00 80 80 04 08 |................|
00000150 80 00 00 00 38 00 00 00 00 00 00 00 00 00 00 00 |....8...........|
00000160 10 00 00 00 00 00 00 00 21 00 00 00 01 00 00 00 |........!.......|
00000170 03 00 00 00 b8 90 04 08 b8 00 00 00 36 00 00 00 |............6...|
00000180 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 |................|
00000190 11 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 |................|
000001a0 ee 00 00 00 27 00 00 00 00 00 00 00 00 00 00 00 |....'...........|
000001b0 01 00 00 00 00 00 00 00 01 00 00 00 02 00 00 00 |................|
000001c0 00 00 00 00 00 00 00 00 08 02 00 00 30 01 00 00 |............0...|
000001d0 05 00 00 00 0f 00 00 00 04 00 00 00 10 00 00 00 |................|
000001e0 09 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 |................|
000001f0 38 03 00 00 6c 00 00 00 00 00 00 00 00 00 00 00 |8...l...........|
00000200 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000210 00 00 00 00 00 00 00 00 00 00 00 00 80 80 04 08 |................|
00000220 00 00 00 00 03 00 01 00 00 00 00 00 b8 90 04 08 |................|
00000230 00 00 00 00 03 00 02 00 01 00 00 00 00 00 00 00 |................|
00000240 00 00 00 00 04 00 f1 ff 15 00 00 00 01 00 00 00 |................|
00000250 00 00 00 00 00 00 f1 ff 1a 00 00 00 04 00 00 00 |................|
00000260 00 00 00 00 00 00 f1 ff 20 00 00 00 01 00 00 00 |........ .......|
00000270 00 00 00 00 00 00 f1 ff 27 00 00 00 b8 90 04 08 |........'.......|
00000280 00 00 00 00 00 00 02 00 2c 00 00 00 16 00 00 00 |........,.......|
00000290 00 00 00 00 00 00 f1 ff 32 00 00 00 ce 90 04 08 |........2.......|
000002a0 00 00 00 00 00 00 02 00 37 00 00 00 0c 00 00 00 |........7.......|
000002b0 00 00 00 00 00 00 f1 ff 3d 00 00 00 da 90 04 08 |........=.......|
000002c0 00 00 00 00 00 00 02 00 42 00 00 00 0c 00 00 00 |........B.......|
000002d0 00 00 00 00 00 00 f1 ff 48 00 00 00 e6 90 04 08 |........H.......|
000002e0 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 |................|
000002f0 00 00 00 00 04 00 f1 ff 4d 00 00 00 80 80 04 08 |........M.......|
00000300 00 00 00 00 10 00 01 00 54 00 00 00 ee 90 04 08 |........T.......|
00000310 00 00 00 00 10 00 02 00 60 00 00 00 ee 90 04 08 |........`.......|
00000320 00 00 00 00 10 00 02 00 67 00 00 00 f0 90 04 08 |........g.......|
00000330 00 00 00 00 10 00 02 00 00 72 65 76 65 72 73 65 |.........reverse|
00000340 45 6e 67 69 6e 65 65 72 2e 61 73 6d 00 45 58 49 |Engineer.asm.EXI|
00000350 54 00 57 52 49 54 45 00 53 54 44 4f 55 54 00 6d |T.WRITE.STDOUT.m|
00000360 73 67 31 00 4d 53 47 31 4c 00 6d 73 67 32 00 4d |sg1.MSG1L.msg2.M|
00000370 53 47 32 4c 00 6d 73 67 33 00 4d 53 47 33 4c 00 |SG2L.msg3.MSG3L.|
00000380 6d 73 67 34 00 5f 73 74 61 72 74 00 5f 5f 62 73 |msg4._start.__bs|
00000390 73 5f 73 74 61 72 74 00 5f 65 64 61 74 61 00 5f |s_start._edata._|
000003a0 65 6e 64 00 |end.|
000003a4