Skip to content

Commit

Permalink
Opcode extraction improvement by @jemik
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Roth committed Nov 15, 2016
1 parent f9a5b82 commit 7df70c3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions yarGen.py
Expand Up @@ -260,9 +260,19 @@ def extract_opcodes(filePath):
print "[-] Extracting OpCodes: %s" % filePath

pe = pefile.PE(filePath)
name = ""
ep = pe.OPTIONAL_HEADER.AddressOfEntryPoint
pos = 0
for sec in pe.sections:
if (ep >= sec.VirtualAddress) and \
(ep < (sec.VirtualAddress + sec.Misc_VirtualSize)):
name = sec.Name.replace('\x00', '')
break
else:
pos += 1

for section in pe.sections:
if section.Name.rstrip("\x00") == '.text':
if section.Name.rstrip("\x00") == name:
text = section.get_data()
# Split text into subs
text_parts = re.split("[\x00]{3,}", text)
Expand All @@ -272,7 +282,7 @@ def extract_opcodes(filePath):
continue
opcodes.append(text_part[:16].encode('hex'))

except Exception,e:
except Exception, e:
if args.debug:
traceback.print_exc()
pass
Expand Down Expand Up @@ -1537,7 +1547,7 @@ def print_welcome():
print " "
print " Yara Rule Generator"
print " by Florian Roth"
print " October 2016"
print " November 2016"
print " Version 0.16.2"
print " "
print "###############################################################################"
Expand Down

0 comments on commit 7df70c3

Please sign in to comment.