You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

385 lines
14 KiB

Change core system to improve performance and facilitate multi TV info sources. Change migrate core objects TVShow and TVEpisode and everywhere that these objects affect. Add message to logs and disable ui backlog buttons when no media provider has active and/or scheduled searching enabled. Change views for py3 compat. Change set default runtime of 5 mins if none is given for layout Day by Day. Add OpenSubtitles authentication support to config/Subtitles/Subtitles Plugin. Add "Enforce media hash match" to config/Subtitles Plugin/Opensubtitles for accurate subs if enabled, but if disabled, search failures will fallback to use less reliable subtitle results. Add Apprise 0.8.0 (6aa52c3). Add hachoir_py3 3.0a6 (5b9e05a). Add sgmllib3k 1.0.0 Update soupsieve 1.9.1 (24859cc) to soupsieve_py2 1.9.5 (6a38398) Add soupsieve_py3 2.0.0.dev (69194a2). Add Tornado_py3 Web Server 6.0.3 (ff985fe). Add xmlrpclib_to 0.1.1 (c37db9e). Remove ancient Growl lib 0.1 Remove xmltodict library. Change requirements.txt for Cheetah3 to minimum 3.2.4 Change update sabToSickBeard. Change update autoProcessTV. Change remove Twitter notifier. Update NZBGet Process Media extension, SickGear-NG 1.7 → 2.4 Update Kodi addon 1.0.3 → 1.0.4 Update ADBA for py3. Update Beautiful Soup 4.8.0 (r526) to 4.8.1 (r531). Update Send2Trash 1.3.0 (a568370) to 1.5.0 (66afce7). Update soupsieve 1.9.1 (24859cc) to 1.9.5 (6a38398). Change use GNTP (Growl Notification Transport Protocol) from Apprise. Change add multi host support to Growl notifier. Fix Growl notifier when using empty password. Change update links for Growl notifications. Change deprecate confg/Notifications/Growl password field as these are now stored with host setting. Fix prevent infinite memoryError from a particular jpg data structure. Change subliminal for py3. Change enzyme for py3. Change browser_ua for py3. Change feedparser for py3 (sgmlib is no longer available on py3 as standardlib so added ext lib) Fix Guessit. Fix parse_xml for py3. Fix name parser with multi eps for py3. Fix tvdb_api fixes for py3 (search show). Fix config/media process to only display "pattern is invalid" qtip on "Episode naming" tab if the associated field is actually visible. Also, if the field becomes hidden due to a setting change, hide any previously displayed qtip. Note for Javascript::getelementbyid (or $('tag[id="<name>"')) is required when an id is being searched in the dom due to ":" used in a shows id name. Change download anidb xml files to main cache folder and use adba lib folder as a last resort. Change create get anidb show groups as centralised helper func and consolidate dupe code. Change move anidb related functions to newly renamed anime.py (from blacklistandwhitelist.py). Change str encode hex no longer exits in py3, use codecs.encode(...) instead. Change fix b64decode on py3 returns bytestrings. Change use binary read when downloading log file via browser to prevent any encoding issues. Change add case insensitive ordering to anime black/whitelist. Fix anime groups list not excluding whitelisted stuff. Change add Windows utf8 fix ... see: ytdl-org/youtube-dl#820 Change if no qualities are wanted, exit manual search thread. Fix keepalive for py3 process media. Change add a once a month update of tvinfo show mappings to the daily updater. Change autocorrect ids of new shows by updating from -8 to 31 days of the airdate of episode one. Add next run time to Manage/Show Tasks/Daily show update. Change when fetching imdb data, if imdb id is an episode id then try to find and use real show id. Change delete diskcache db in imdbpie when value error (due to change in Python version). Change during startup, cleanup any _cleaner.pyc/o to prevent issues when switching python versions. Add .pyc cleaner if python version is switched. Change replace deprecated gettz_db_metadata() and gettz. Change rebrand "SickGear PostProcessing script" to "SickGear Process Media extension". Change improve setup guide to use the NZBGet version to minimise displayed text based on version. Change NZBGet versions prior to v17 now told to upgrade as those version are no longer supported - code has actually exit on start up for some time but docs were outdated. Change comment out code and unused option sg_base_path. Change supported Python version 2.7.9-2.7.18 inclusive expanded to 3.7.1-3.8.1 inclusive. Change pidfile creation under Linux 0o644. Make logger accept lists to output continuously using the log_lock instead of split up by other processes. Fix long path issues with Windows process media.
6 years ago
"""
Nintendo DS .nds game file parser
File format references:
- http://www.bottledlight.com/ds/index.php/FileFormats/NDSFormat
- http://imrannazar.com/The-Smallest-NDS-File
- http://darkfader.net/ds/files/ndstool.cpp
- http://crackerscrap.com/docs/dsromstructure.html
- http://nocash.emubase.de/gbatek.htm
"""
from hachoir_py3.parser import Parser
from hachoir_py3.field import (UInt8, UInt16, UInt32, UInt64, String, RawBytes, SubFile, FieldSet, NullBits, Bit, Bits, Bytes,
SeekableFieldSet, RootSeekableFieldSet)
from hachoir_py3.core.text_handler import textHandler, hexadecimal
from hachoir_py3.core.endian import LITTLE_ENDIAN
"""
CRC16 Calculation
Modified from:
http://www.mail-archive.com/python-list@python.org/msg47844.html
Original License:
crc16.py by Bryan G. Olson, 2005
This module is free software and may be used and
distributed under the same terms as Python itself.
"""
class CRC16:
_table = None
def _initTable(self):
from array import array
# CRC-16 poly: p(x) = x**16 + x**15 + x**2 + 1
# top bit implicit, reflected
poly = 0xa001
CRC16._table = array('H')
for byte in range(256):
crc = 0
for bit in range(8):
if (byte ^ crc) & 1:
crc = (crc >> 1) ^ poly
else:
crc >>= 1
byte >>= 1
CRC16._table.append(crc)
def checksum(self, string, value):
if CRC16._table is None:
self._initTable()
for ch in string:
value = self._table[ord(ch) ^ (value & 0xff)] ^ (value >> 8)
return value
class Crc16(UInt16):
"16 bit field for calculating and comparing CRC-16 of specified string"
def __init__(self, parent, name, targetBytes):
UInt16.__init__(self, parent, name)
self.targetBytes = targetBytes
def createDescription(self):
crc = CRC16().checksum(self.targetBytes, 0xffff)
if crc == self.value:
return "matches CRC of %d bytes" % len(self.targetBytes)
else:
return "mismatch (calculated CRC %d for %d bytes)" % (crc, len(self.targetBytes))
class FileNameDirTable(FieldSet):
static_size = (4 + 2 + 2) * 8
def createFields(self):
yield UInt32(self, "entry_start")
yield UInt16(self, "entry_file_id")
yield UInt16(self, "parent_id")
def createDescription(self):
return "first file id: %d; parent directory id: %d (%d)" % (self["entry_file_id"].value, self["parent_id"].value, self["parent_id"].value & 0xFFF)
class FileNameEntry(FieldSet):
def createFields(self):
yield Bits(self, "name_len", 7)
yield Bit(self, "is_directory")
yield String(self, "name", self["name_len"].value)
if self["is_directory"].value:
yield UInt16(self, "dir_id")
def createDescription(self):
s = ""
if self["is_directory"].value:
s = "[D] "
return s + self["name"].value
class Directory(FieldSet):
def createFields(self):
while True:
fne = FileNameEntry(self, "entry[]")
if fne["name_len"].value == 0:
yield UInt8(self, "end_marker")
break
yield fne
class FileNameTable(SeekableFieldSet):
def createFields(self):
self.startOffset = self.absolute_address // 8
# parent_id of first FileNameDirTable contains number of directories:
dt = FileNameDirTable(self, "dir_table[]")
numDirs = dt["parent_id"].value
yield dt
for i in range(1, numDirs):
yield FileNameDirTable(self, "dir_table[]")
for i in range(0, numDirs):
dt = self["dir_table[%d]" % i]
offset = self.startOffset + dt["entry_start"].value
self.seekByte(offset, relative=False)
yield Directory(self, "directory[]")
class FATFileEntry(FieldSet):
static_size = 2 * 4 * 8
def createFields(self):
yield UInt32(self, "start")
yield UInt32(self, "end")
def createDescription(self):
return "start: %d; size: %d" % (self["start"].value, self["end"].value - self["start"].value)
class FATContent(FieldSet):
def createFields(self):
num_entries = self.parent["header"]["fat_size"].value // 8
for i in range(0, num_entries):
yield FATFileEntry(self, "entry[]")
class BannerTile(FieldSet):
static_size = 32 * 8
def createFields(self):
for y in range(8):
for x in range(8):
yield Bits(self, "pixel[%d,%d]" % (x, y), 4)
class BannerIcon(FieldSet):
static_size = 16 * 32 * 8
def createFields(self):
for y in range(4):
for x in range(4):
yield BannerTile(self, "tile[%d,%d]" % (x, y))
class NdsColor(FieldSet):
static_size = 16
def createFields(self):
yield Bits(self, "red", 5)
yield Bits(self, "green", 5)
yield Bits(self, "blue", 5)
yield NullBits(self, "pad", 1)
def createDescription(self):
return "#%02x%02x%02x" % (self["red"].value << 3, self["green"].value << 3, self["blue"].value << 3)
class Banner(FieldSet):
static_size = 2112 * 8
def createFields(self):
yield UInt16(self, "version")
# CRC of this structure, excluding first 32 bytes:
yield Crc16(self, "crc", self.stream.readBytes(self.absolute_address + (32 * 8), (2112 - 32)))
yield RawBytes(self, "reserved", 28)
yield BannerIcon(self, "icon_data")
for i in range(0, 16):
yield NdsColor(self, "palette_color[]")
yield String(self, "title_jp", 256, charset="UTF-16-LE", truncate="\0")
yield String(self, "title_en", 256, charset="UTF-16-LE", truncate="\0")
yield String(self, "title_fr", 256, charset="UTF-16-LE", truncate="\0")
yield String(self, "title_de", 256, charset="UTF-16-LE", truncate="\0")
yield String(self, "title_it", 256, charset="UTF-16-LE", truncate="\0")
yield String(self, "title_es", 256, charset="UTF-16-LE", truncate="\0")
class Overlay(FieldSet):
static_size = 8 * 4 * 8
def createFields(self):
yield UInt32(self, "id")
yield textHandler(UInt32(self, "ram_address"), hexadecimal)
yield UInt32(self, "ram_size")
yield UInt32(self, "bss_size")
yield textHandler(UInt32(self, "init_start_address"), hexadecimal)
yield textHandler(UInt32(self, "init_end_address"), hexadecimal)
yield UInt32(self, "file_id")
yield RawBytes(self, "reserved[]", 4)
def createDescription(self):
return "file #%d, %d (+%d) bytes to 0x%08x" % (
self["file_id"].value, self["ram_size"].value, self["bss_size"].value, self["ram_address"].value)
class SecureArea(FieldSet):
static_size = 2048 * 8
def createFields(self):
yield textHandler(UInt64(self, "id"), hexadecimal)
if self["id"].value == 0xe7ffdeffe7ffdeff: # indicates that secure area is decrypted
yield Bytes(self, "fixed[]", 6) # always \xff\xde\xff\xe7\xff\xde
yield Crc16(self, "header_crc16", self.stream.readBytes(self.absolute_address + (16 * 8), 2048 - 16))
yield RawBytes(self, "unknown[]", 2048 - 16 - 2)
yield Bytes(self, "fixed[]", 2) # always \0\0
else:
yield RawBytes(self, "encrypted[]", 2048 - 8)
class DeviceSize(UInt8):
def createDescription(self):
return "%d Mbit" % ((2**(20 + self.value)) // (1024 * 1024))
class Header(FieldSet):
def createFields(self):
yield String(self, "game_title", 12, truncate="\0")
yield String(self, "game_code", 4)
yield String(self, "maker_code", 2)
yield UInt8(self, "unit_code")
yield UInt8(self, "device_code")
yield DeviceSize(self, "card_size")
yield String(self, "card_info", 9)
yield UInt8(self, "rom_version")
yield Bits(self, "unknown_flags[]", 2)
yield Bit(self, "autostart_flag")
yield Bits(self, "unknown_flags[]", 5)
yield UInt32(self, "arm9_source", "ARM9 ROM offset")
yield textHandler(UInt32(self, "arm9_execute_addr", "ARM9 entry address"), hexadecimal)
yield textHandler(UInt32(self, "arm9_copy_to_addr", "ARM9 RAM address"), hexadecimal)
yield UInt32(self, "arm9_bin_size", "ARM9 code size")
yield UInt32(self, "arm7_source", "ARM7 ROM offset")
yield textHandler(UInt32(self, "arm7_execute_addr", "ARM7 entry address"), hexadecimal)
yield textHandler(UInt32(self, "arm7_copy_to_addr", "ARM7 RAM address"), hexadecimal)
yield UInt32(self, "arm7_bin_size", "ARM7 code size")
yield UInt32(self, "filename_table_offset")
yield UInt32(self, "filename_table_size")
yield UInt32(self, "fat_offset")
yield UInt32(self, "fat_size")
yield UInt32(self, "arm9_overlay_src")
yield UInt32(self, "arm9_overlay_size")
yield UInt32(self, "arm7_overlay_src")
yield UInt32(self, "arm7_overlay_size")
yield textHandler(UInt32(self, "ctl_read_flags"), hexadecimal)
yield textHandler(UInt32(self, "ctl_init_flags"), hexadecimal)
yield UInt32(self, "banner_offset")
yield Crc16(self, "secure_crc16", self.stream.readBytes(0x4000 * 8, 0x4000))
yield UInt16(self, "rom_timeout")
yield UInt32(self, "arm9_unk_addr")
yield UInt32(self, "arm7_unk_addr")
yield UInt64(self, "unenc_mode_magic")
yield UInt32(self, "rom_size")
yield UInt32(self, "header_size")
yield RawBytes(self, "unknown[]", 36)
yield String(self, "passme_autoboot_detect", 4)
yield RawBytes(self, "unknown[]", 16)
yield RawBytes(self, "gba_logo", 156)
yield Crc16(self, "logo_crc16", self.stream.readBytes(0xc0 * 8, 156))
yield Crc16(self, "header_crc16", self.stream.readBytes(0, 350))
yield UInt32(self, "debug_rom_offset")
yield UInt32(self, "debug_size")
yield textHandler(UInt32(self, "debug_ram_address"), hexadecimal)
class NdsFile(Parser, RootSeekableFieldSet):
PARSER_TAGS = {
"id": "nds_file",
"category": "program",
"file_ext": ("nds",),
"mime": ("application/octet-stream",),
"min_size": 352 * 8, # just a minimal header
"description": "Nintendo DS game file",
}
endian = LITTLE_ENDIAN
def validate(self):
try:
header = self["header"]
except Exception:
return False
return (self.stream.readBytes(0, 1) != b"\0"
and (header["device_code"].value & 7) == 0
and header["header_size"].value >= 352
and header["card_size"].value < 15 # arbitrary limit at 32Gbit
and header["arm9_bin_size"].value > 0 and header["arm9_bin_size"].value <= 0x3bfe00
and header["arm7_bin_size"].value > 0 and header["arm7_bin_size"].value <= 0x3bfe00
and header["arm9_source"].value + header["arm9_bin_size"].value < self._size
and header["arm7_source"].value + header["arm7_bin_size"].value < self._size
and header["arm9_execute_addr"].value >= 0x02000000 and header["arm9_execute_addr"].value <= 0x023bfe00
and header["arm9_copy_to_addr"].value >= 0x02000000 and header["arm9_copy_to_addr"].value <= 0x023bfe00
and header["arm7_execute_addr"].value >= 0x02000000 and header["arm7_execute_addr"].value <= 0x03807e00
and header["arm7_copy_to_addr"].value >= 0x02000000 and header["arm7_copy_to_addr"].value <= 0x03807e00
)
def createFields(self):
# Header
yield Header(self, "header")
# Secure Area
if self["header"]["arm9_source"].value >= 0x4000 and self["header"]["arm9_source"].value < 0x8000:
secStart = self["header"]["arm9_source"].value & 0xfffff000
self.seekByte(secStart, relative=False)
yield SecureArea(self, "secure_area", size=0x8000 - secStart)
# ARM9 binary
self.seekByte(self["header"]["arm9_source"].value, relative=False)
yield RawBytes(self, "arm9_bin", self["header"]["arm9_bin_size"].value)
# ARM7 binary
self.seekByte(self["header"]["arm7_source"].value, relative=False)
yield RawBytes(self, "arm7_bin", self["header"]["arm7_bin_size"].value)
# File Name Table
if self["header"]["filename_table_size"].value > 0:
self.seekByte(
self["header"]["filename_table_offset"].value, relative=False)
yield FileNameTable(self, "filename_table", size=self["header"]["filename_table_size"].value * 8)
# FAT
if self["header"]["fat_size"].value > 0:
self.seekByte(self["header"]["fat_offset"].value, relative=False)
yield FATContent(self, "fat_content", size=self["header"]["fat_size"].value * 8)
# banner
if self["header"]["banner_offset"].value > 0:
self.seekByte(
self["header"]["banner_offset"].value, relative=False)
yield Banner(self, "banner")
# ARM9 overlays
if self["header"]["arm9_overlay_src"].value > 0:
self.seekByte(
self["header"]["arm9_overlay_src"].value, relative=False)
numOvls = self["header"]["arm9_overlay_size"].value // (8 * 4)
for i in range(numOvls):
yield Overlay(self, "arm9_overlay[]")
# files
if self["header"]["fat_size"].value > 0:
for field in self["fat_content"]:
if field["end"].value > field["start"].value:
self.seekByte(field["start"].value, relative=False)
yield SubFile(self, "file[]", field["end"].value - field["start"].value)