ITSC203 Lab3b
ITSC203 Lab3b
EVALUATION:
1 Problem 1 15
2 Problem 2 30
TOTAL MARK 45
Background Reading
Read chapters 6–10 in How to Think Like a Computer Scientist: Learning with Python,
available at www.greenteapress.com/thinkpython/thinkCSpy.pdf.
https://docs.python.org/3.8/
Important Information
YOU MUST PRESENT IMAGES OF YOUR CODE BEING EXECUTED. DO NOT
SUBMIT YOUR ANSWERS IN THE DOCUMENT. CREATE A BLANK DOCUMENT
AND SUBMIT YOUR ANSWERS THERE.
2. Comments on lines where you used some unique computation that might be tricky to
comprehend a month later.
list1 = [x for x in range(20) if x % 4 == 1] # Using list comprehension to ….
3|Page
HINT: Modules you may want to investigate (datetime, pathlib, os and glob)
The PE file is made up of Headers and Section. The headers contain data about the sections
and the sections contain information and instructions required to tell the CPU what to do and the
data to apply those actions to. Stated differently sections contain data and instructions and
headers tell the system where to find the appropriate section.
5|Page
Requirements
For this problem you will likely need the following modules:
1. datetime
2. sys
3. struct
4. prettytable
5. pefile
Copy the file expandpe.zip, from D2L, to your work directory for Lab3. Unzip the file and
confirm that there are .exe and .dll files in this directory.
Links to resources:
https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#file-headers
https://en.wikipedia.org/wiki/Portable_Executable
https://en.wikipedia.org/wiki/Portable_Executable#Use_on_other_operating_systems
https://whatis.techtarget.com/definition/binary-file#:~:text=A%20binary%20file%20is
%20a,certain%20place%20within%20the%20file.
https://en.wikipedia.org/wiki/Binary_file
To get started, you will create a variable that will represent an object of type PE. That PE object
will allow for the parsing of the file named Kyjrgz41.exe. Once the parsing is complete you will
proceed to extra meaningful information from the file.
6|Page
Instructions
1. Using Image1 as a reference, you will perform the following actions:
a. Import the PE class from the pefile module
Image 1: The image below shows the output using the ipython. You will write your code to
a text editor. The image is provided to show how you can start the process.
b. Create an instance variable of type PE, named mype22. This variable is associated
with the filename ‘Kyjrgz41.exe’
This variable, mype22, allows us to access the different components of the
PE file
c. The first header in the file is called the MS DOS Header and it contains:
variables with the “e_” prefix followed by an attribute name eg (magic,
lfanew)
information that is now obsolete and offers no real insight according to
Microsoft documentation.
2 pieces of information that modern systems use to identify the file type and
the new PE header
i. a signature, also known as the magic number.
ii. the PE header offset – the location of where the PE Header begins
Complete the following tasks to extract the specific content from the
file:
1. print(type(mype22.DOS_HEADER), '\n', mype22.DOS_HEADER)
a. What is a pefile.Structure?
b. Notice the two columns of numbers of the left side of the output. What do the 2
columns of number represent in the output?
c. What are the offsets of the magic number and the offset to the PE Header?
i. The values are located in the DOS_HEADER
d. How many bytes does the DOS_HEADER use?
2. Save the value of the magic as dosMagic
a. Do not process a file if the DOS Signature is not MZ
7|Page
8. Now that you have complete the analysis for one file you will automate the analysis of
the other files in the directory using the same process. And then generate a table similar
to the one shown on the following page.
Questions:
1. What is the significance of the Entry point of an executable file? 2pts
2. What is the significance of the Magic number? In other words what is it used for? 1pt
4. Is the PE file format the only file format for executables? Name 1 other file format for
5. Non-executable files like PDFs are considered binary files because like the PE file
format they have a specific structure that tells the Reader how to process the file. Are
they any other types of binary files like the PDF file? Name 5 file types and example
programs that can open them? Also list if python modules are available to parse these