파이썬 특정 문자열 카운팅
언어/python2017. 9. 24. 10:39
sTarget = """
WORD Magic;
BYTE MajorLinkerVersion;
BYTE MinorLinkerVersion;
DWORD SizeOfCode;
DWORD SizeOfInitializedData;
DWORD SizeOfUninitializedData;
DWORD AddressOfEntryPoint;
DWORD BaseOfCode;
DWORD BaseOfData;
DWORD ImageBase;
DWORD SectionAlignment;
DWORD FileAlignment;
WORD MajorOperatingSystemVersion;
WORD MinorOperatingSystemVersion;
WORD MajorImageVersion;
WORD MinorImageVersion;
WORD MajorSubsystemVersion;
WORD MinorSubsystemVersion;
DWORD Win32VersionValue;
DWORD SizeOfImage;
DWORD SizeOfHeaders;
DWORD CheckSum;
WORD Subsystem;
WORD DllCharacteristics;
DWORD SizeOfStackReserve;
DWORD SizeOfStackCommit;
DWORD SizeOfHeapReserve;
DWORD SizeOfHeapCommit;
DWORD LoaderFlags;
DWORD NumberOfRvaAndSizes;
"""
sTarget = sTarget.replace('\n', '')
sTarget = sTarget.replace(';', ' ')
resultList = sTarget.split(' ')
print (resultList)
byte_data = 0 # size => 1byte (char)
word_data = 0 # size => 2byte (short)
dword_data = 0 # size => 4byte (int)
TotalSize = 0
nList = [128] # empty list
if 'byte'.upper() in resultList:
byte_data = resultList.count('byte'.upper()) * 1
nList.append(byte_data)
if 'word'.upper() in resultList:
word_data = resultList.count('word'.upper()) * 2
nList.append(word_data)
if 'dword'.upper() in resultList:
dword_data = resultList.count('dword'.upper()) * 4
nList.append(dword_data)
print (nList)
for i in nList:
TotalSize += i
print (hex(TotalSize))
'언어 > python' 카테고리의 다른 글
python turtle 슈퍼 그랑죠 피닉스 ㅋㅋㅋㅋㅋ 나도 오타쿠 인가 ㅋㅋ (0) | 2017.10.01 |
---|---|
수정 중인 코드 (0) | 2017.09.24 |
BigData + graph (0) | 2017.09.21 |
base64 encoding (0) | 2017.09.16 |
문제5 (0) | 2017.08.30 |