Skip to content

Commit

Permalink
Further improvement of detection of encrypted RAR files.
Browse files Browse the repository at this point in the history
  • Loading branch information
shypike committed Nov 16, 2011
1 parent cab42a4 commit eda7642
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
15 changes: 8 additions & 7 deletions sabnzbd/assembler.py
Expand Up @@ -40,7 +40,7 @@
from sabnzbd.postproc import PostProcessor
import sabnzbd.downloader
from sabnzbd.utils.rarfile import RarFile, is_rarfile
from sabnzbd.encoding import latin1
from sabnzbd.encoding import latin1, unicoder


#------------------------------------------------------------------------------
Expand Down Expand Up @@ -269,12 +269,13 @@ def ParseFilePacket(f, header):
return nothing


def is_cloaked(names):
def is_cloaked(path, names):
""" Return True if this is likely to be a cloaked encrypted post """
fname = unicoder(os.path.split(path)[1]).lower()
for name in names:
name = name.lower()
if name.endswith('.rar') or 'password' in name:
return len(names) < 3
name = unicoder(name.lower())
if fname == name or 'password' in name:
return True
return False


Expand All @@ -283,8 +284,8 @@ def check_encrypted_rar(nzo, filepath):
encrypted = False
if not nzo.password and cfg.pause_on_pwrar() and is_rarfile(filepath):
try:
zf = RarFile(filepath)
encrypted = zf.encrypted or is_cloaked(zf.namelist())
zf = RarFile(filepath, all_names=True)
encrypted = zf.encrypted or is_cloaked(filepath, zf.namelist())
if encrypted and int(nzo.encrypted) < 2:
nzo.encrypted = 1
else:
Expand Down
6 changes: 4 additions & 2 deletions sabnzbd/utils/rarfile.py
Expand Up @@ -124,9 +124,11 @@ def isdir(self):

class RarFile:
'''Rar archive handling.'''
def __init__(self, rarfile, mode="r", charset='cp850', info_callback=None):
def __init__(self, rarfile, mode="r", charset='cp850', info_callback=None, all_names=False):
# 'all_names' = show names of 'split' files too
self.rarfile = rarfile
self.charset = charset
self.all_names = all_names

self.info_list = []
self.is_solid = 0
Expand Down Expand Up @@ -215,7 +217,7 @@ def _process_entry(self, item):
# RAR_BLOCK_NEWSUB has files too: CMT, RR
if item.type == RAR_BLOCK_FILE:
# use only first part
if (item.flags & RAR_FILE_SPLIT_BEFORE) == 0:
if self.all_names or (item.flags & RAR_FILE_SPLIT_BEFORE) == 0:
# Always use Unix separators
item.filename = item.filename.replace('\\', '/')
item.unicode_filename = item.unicode_filename.replace(u'\\', u'/')
Expand Down

0 comments on commit eda7642

Please sign in to comment.