示例#1
0
文件: ir.py 项目: frankdeath/hx-tools
 def analyze(self):
     # "RIFF"
     #!self.riffTag = util.getBytes(self.data, 0, 4)
     # riffSize = dataSize - 8
     #!self.riffSize = util.getInt(self.data, 4)
     # "WAVE"
     #!self.waveTag = util.getBytes(self.data, 8, 4)
     # "fmt "
     #!self.fmtChunk = util.getBytes(self.data, 12, 4)
     # size of the format section
     self.fmtChunkSize = util.getInt(self.data, 16)
     # "data"
     #!self.dataChunk = util.getBytes(self.data, 20+self.fmtChunkSize, 4)
     # size of the data section
     self.dataChunkSize = util.getInt(self.data, 24 + self.fmtChunkSize)
     # "LIST"
     #!self.listTag = util.getBytes(self.data, 28+self.fmtChunkSize+self.dataChunkSize, 4)
     # size of list section (includes iname)
     #!self.listSize = util.getInt(self.data, 32+self.fmtChunkSize+self.dataChunkSize)
     # "INFO"
     #!self.infoTag = util.getBytes(self.data, 36+self.fmtChunkSize+self.dataChunkSize, 4)
     # "INAM"
     #!self.inamTag = util.getBytes(self.data, 40+self.fmtChunkSize+self.dataChunkSize, 4)
     # size of iname section
     self.inamSize = util.getInt(
         self.data, 44 + self.fmtChunkSize + self.dataChunkSize)
     # Name of impulse response
     self.name = util.getBytes(self.data,
                               48 + self.fmtChunkSize + self.dataChunkSize,
                               self.inamSize)
     # Remove the trailing null byte when converting to a string
     self.nameStr = self.name.decode('utf-8')[:-1]
示例#2
0
    def analyzeFooter(self):
        #
        self.name = util.getBytes(self.footer, 0, util.sectionNameSize)

        #
        for i in range(util.sectionNameSize, self.footerSize, util.intSize):
            self.footerValues.append(util.getInt(self.footer, i))

        #
        self.sectionOffset = self.footerValues[0]
        self.compressedSize = self.footerValues[2]
        self.compressed = (self.footerValues[4] > 0)
        self.uncompressedSize = self.footerValues[5]
示例#3
0
    def __init__(self, data, footerSectionOffset, footerSectionSize):
        ## raw data from the footer
        self.footer = util.getBytes(data, footerSectionOffset,
                                    footerSectionSize)
        self.footerSize = len(self.footer)
        self.footerOffset = footerSectionOffset
        ## parsed data from the footer
        self.name = None
        self.footerValues = []
        # 1st 32-bit (LE) int
        self.sectionOffset = None
        # 3rd 32-bit (LE) int
        self.compressedSize = None
        # 5th 32-bit (LE) int
        self.compressed = None
        # 6th 32-bit (LE) int
        self.uncompressedSize = None

        self.analyzeFooter()

        ## raw data from the section
        self.rawData = util.getBytes(data, self.sectionOffset,
                                     self.compressedSize)
        self.rawDataSize = len(self.rawData)
        ## parsed data from the section
        self.data = None
        self.dataSize = None
        #
        self.ir = None
        self.jsonGlobal = None
        self.deviceInfo = None
        self.description = None
        self.setList = None
        self.setListName = None

        self.decompress()

        self.analyze()
示例#4
0
#!/usr/bin/env python

from collections import defaultdict

from util import getBytes

for line in open('challenge8.txt'):
	line = line.strip()
	bytes = getBytes(line)
	# print bytes

	blocks = defaultdict(int)
	for i in range(0, len(bytes), 16):
		block = tuple(bytes[i:i+16])
		blocks[block] += 1
	
	sortedBlocks = sorted(blocks.iteritems(), key=lambda (block, count): count, reverse=True)

	block, count = sortedBlocks[0]
	# Duplicate blocks means that plaintext was repeated
	if count > 1:
		print line
		print bytes
		for block, count in sortedBlocks:
			print count, block


示例#5
0
#!/usr/bin/env python

from util import getBytes
from ascii import scoreBytes

maxScore = None
for line in open('challenge4.txt'):
    line = line.strip()
    bytes = getBytes(line)

    for key in range(256):
        xored = [byte ^ key for byte in bytes]
        score = scoreBytes(xored)
        if maxScore < score:
            maxScore = score
            maxKey = key
            maxBytes = xored

print maxScore
print maxKey
print maxBytes

string = ''.join(map(chr, maxBytes))
print string
示例#6
0
    elif char < 'A':
        return 0
    elif char <= 'Z':
        return 1
    elif char < 'a':
        return 0
    elif char <= 'z':
        return 1
    elif char <= '~':
        return 0
    else:
        return -1


input = '1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736'
bytes = getBytes(input)
print bytes

maxScore = None
for key in range(256):
    xored = [byte ^ key for byte in bytes]
    score = scoreBytes(xored)
    if maxScore < score:
        maxScore = score
        maxKey = key
        maxBytes = xored

print maxScore
print maxKey
print maxBytes
示例#7
0
		return 1
	elif char < 'A':
		return 0
	elif char <= 'Z':
		return 1
	elif char < 'a':
		return 0
	elif char <= 'z':
		return 1
	elif char <= '~':
		return 0
	else:
		return -1

input = '1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736'
bytes = getBytes(input)
print bytes

maxScore = None
for key in range(256):
	xored = [byte ^ key for byte in bytes]
	score = scoreBytes(xored)
	if maxScore < score:
		maxScore = score
		maxKey = key
		maxBytes = xored

print maxScore
print maxKey
print maxBytes