pe 세미 프로젝트
언어/python2017. 11. 5. 14:55
# -*- coding: utf-8 -*-
# PE 자동화
# 작성자 : 김준현
# ================================
from openpyxl import load_workbook
import pe_1_dos_header
import pe_2_NT_header
import pe_3_section_header
import PE_4_OPTIONAL_HEADER
import PE_5_FILE_HEADER
import pprint
# ================================
class Stu_PE:
def __init__(self): # 생성자
self.targetFile = ""
self.wb = load_workbook('C:\\Users\\sleep\\Desktop\\a.xlsx')
def m_target_file_write(self):
#self.targetFile = input("file directory : ")
self.targetFile = "C:\\Users\\sleep\\Desktop\\s.exe"
# DOS_HEADER
def m_dos_header(self):
dosHeader_file = pe_1_dos_header.make_dos_header(self.targetFile)
ws = self.wb.create_sheet(title="pe_dos_header")
Indx = 1
for k,v in dosHeader_file.items(): # e_cp
In_alphabet = 66
#print (k, type(v)) # , dictionary
s = chr(65) + str(Indx)
print (s)
ws[s] = k
for k1 in v.keys():
s = chr(In_alphabet) + str(Indx)
print (s)
ws[s] = v[k1]
In_alphabet +=1
Indx += 1
#self.wb.save('C:\\Users\\sleep\\Desktop\\a.xlsx')
# NT_HEADER => Signatue
def m_nt_header(self):
tmp_main_ntHeader_file = pe_2_NT_header.make_nt_header(self.targetFile)
ws = self.wb.create_sheet(title="pe_nt_header")
Indx = 1
for k, v in tmp_main_ntHeader_file.items(): # e_cp
In_alphabet = 66
# print (k, type(v)) # , dictionary
s = chr(65) + str(Indx)
print(s)
ws[s] = k
for k1 in v.keys():
s = chr(In_alphabet) + str(Indx)
print(s)
ws[s] = v[k1]
In_alphabet += 1
Indx += 1
#self.wb.save('C:\\Users\\sleep\\Desktop\\a.xlsx')
# NT_HEADER => FILE_HEADER
def m_file_header(self):
tmp_main_fileHeader_file = PE_5_FILE_HEADER.make_file_header(self.targetFile)
ws = self.wb.create_sheet(title="pe_file_header")
Indx = 1
for k, v in tmp_main_fileHeader_file.items(): # e_cp
In_alphabet = 66
# print (k, type(v)) # , dictionary
s = chr(65) + str(Indx)
print(s)
ws[s] = k
for k1 in v.keys():
s = chr(In_alphabet) + str(Indx)
print(s)
ws[s] = v[k1]
In_alphabet += 1
Indx += 1
#self.wb.save('C:\\Users\\sleep\\Desktop\\a.xlsx')
# NT_HEADER => OPTIONAL_HEADER
def m_optional_header(self):
tmp_main_optionalHeader_file = PE_4_OPTIONAL_HEADER.make_optional_header(self.targetFile)
ws = self.wb.create_sheet(title="pe_optional_header")
Indx = 1
for k, v in tmp_main_optionalHeader_file.items(): # e_cp
In_alphabet = 66
s = chr(65) + str(Indx)
ws[s] = k
for k1 in v.keys():
s = chr(In_alphabet) + str(Indx)
print(s)
ws[s] = v[k1]
In_alphabet += 1
Indx += 1
# SECTION_HEADER
def m_section_header(self):
tmp_main_sectionHeader_file = pe_3_section_header.make_section_header(self.targetFile)
tmp_main_sectionHeader_file = tmp_main_sectionHeader_file
print (type(tmp_main_sectionHeader_file))
ws = self.wb.create_sheet(title="pe_section_header")
#self.wb.save('C:\\Users\\sleep\\Desktop\\a.xlsx')
def __del__(self):
self.wb.save('C:\\Users\\sleep\\Desktop\\a.xlsx')
def main():
# C:\\Users\\sleep\\Desktop\\s.exe
my_pe_str = Stu_PE()
my_pe_str.m_target_file_write()
#my_pe_str.m_section_header()
my_pe_str.m_dos_header() # <- DOS_HEADER
my_pe_str.m_nt_header() # <- NT_HEADER
my_pe_str.m_file_header() # <- FILE_HEADER
my_pe_str.m_optional_header() # <- OPTIONAL_HEADER
#self.wb.save('C:\\Users\\sleep\\Desktop\\a.xlsx')
if __name__ == "__main__":
main()
======================================================================
#def main():
#
# #print (pe.DOS_HEADER)
#
# #print (hex(pe.DOS_HEADER.e_magic)) # 0x5a4d
# for i in pe.DOS_HEADER:
# print (i)
# if __name__ == "__main__":
# main()
# ================================
import pefile
import re
# ================================
def make_dos_header(target_file):
pe = pefile.PE(target_file)
pe = pe.DOS_HEADER
pe = pe.dump_dict() # type of dictionary
pe_key = pe.keys()
#print (type(pe_key)) # <class 'dict_keys'>
pe_value= pe.values()
pe_key = list(pe_key)[1:]
pe_value = list(pe_value)[1:]
pe_dict = dict() # type of dictionary
for i in zip(pe_key, pe_value):
if type(i[1]['Value']) == int :
i[1]['Value'] = hex(i[1]['Value'])
i[1]['FileOffset'] = hex(i[1]['FileOffset'])
pe_dict[i[0]] = i[1]
return pe_dict
==========================================================================
# def main():
# pe = pefile.PE('C:\\Users\\sleep\\Desktop\\s.exe')
# print (pe.NT_HEADERS)
#
# if __name__ == "__main__":
# main()
import pefile
def make_nt_header(target_file):
pe = pefile.PE(target_file)
pe = pe.NT_HEADERS
pe = pe.dump_dict() # type of dictionary
pe_key = pe.keys()
# print (type(pe_key)) # <class 'dict_keys'>
pe_value = pe.values()
pe_key = list(pe_key)[1:]
pe_value = list(pe_value)[1:]
pe_dict = dict() # type of dictionary
for i in zip(pe_key, pe_value):
if type(i[1]['Value']) == int:
i[1]['Value'] = hex(i[1]['Value'])
i[1]['FileOffset'] = hex(i[1]['FileOffset'])
pe_dict[i[0]] = i[1]
return pe_dict
==========================================================================
# def main():
# pe = pefile.PE('C:\\Users\\sleep\\Desktop\\s.exe')
# print (pe.OPTIONAL_HEADER)
# if __name__ == "__main__":
# main()
import pefile
def make_optional_header(target_file):
pe = pefile.PE(target_file)
pe = pe.OPTIONAL_HEADER
pe = pe.dump_dict() # type of dictionary
pe_key = pe.keys()
# print (type(pe_key)) # <class 'dict_keys'>
pe_value = pe.values()
pe_key = list(pe_key)[1:]
pe_value = list(pe_value)[1:]
pe_dict = dict() # type of dictionary
for i in zip(pe_key, pe_value):
if type(i[1]['Value']) == int:
i[1]['Value'] = hex(i[1]['Value'])
i[1]['FileOffset'] = hex(i[1]['FileOffset'])
pe_dict[i[0]] = i[1]
return pe_dict
# def main():
# pe = pefile.PE('C:\\Users\\sleep\\Desktop\\s.exe')
# print (pe.FILE_HEADER)
# S = pe.FILE_HEADER.dump_dict()
#
# for i in S.items():
# print (i)
# if __name__ == "__main__":
# main()
import pefile
def make_file_header(target_file):
pe = pefile.PE(target_file)
pe = pe.FILE_HEADER
pe = pe.dump_dict()
pe_key = pe.keys()
# print (type(pe_key)) # <class 'dict_keys'>
pe_value = pe.values()
pe_key = list(pe_key)[1:]
pe_value = list(pe_value)[1:]
pe_dict = dict() # type of dictionary
for i in zip(pe_key, pe_value):
if type(i[1]['Value']) == int:
i[1]['Value'] = hex(i[1]['Value'])
i[1]['FileOffset'] = hex(i[1]['FileOffset'])
pe_dict[i[0]] = i[1]
return pe_dict
'언어 > python' 카테고리의 다른 글
회사에서 사용할 자동화 툴 ( excel + python) (0) | 2017.11.22 |
---|---|
stu (0) | 2017.11.19 |
pe구조 => 엑셀 [파이썬] (0) | 2017.10.29 |
python base 64 (0) | 2017.10.28 |
엘라스틱 서치 :: 파이썬 (0) | 2017.10.27 |