def createPictures(): print "Reading file" raw = dparse.readFile("onion3.hex") print "Parsing" dHex = dparse.txtToHex(raw) dInt = dparse.hexToInt(dHex) dBin = dparse.intToBin(dInt) print "Searching" start = dstats.searchForBytes(dBin, dparse.intToBin(dparse.hexToInt(["FF", "D8", "FF"]))) end = dstats.searchForBytes(dBin, dparse.intToBin(dparse.hexToInt(["FF", "D9"]))) + 2 print "Separating: " + str(start) + ", " + str(end) iBin = dBin[start:end] iInt = dparse.binToInt(iBin) iAsc = dparse.intToAsc(iInt) print "Writing" outFile = open("../pics/2out0.jpg", "w") outFile.write(iAsc) outFile.close() remains = dBin[end:] remains = dmanip.flipOrder(remains) rAsc = dparse.intToAsc(dparse.binToInt(remains)) with open("../pics/2out1.jpg", "w") as f: f.write(rAsc)
def flipBits(b): ret = [] i = dparse.binToInt(b) for byte in i: ret.append(xor([byte], [255])[0]) return dparse.intToBin(ret)
def createPictures(): print "Reading file" raw = dparse.readFile("onion2.hex") print "Parsing" dHex = dparse.txtToHex(raw) dInt = dparse.hexToInt(dHex) dBin = dparse.intToBin(dInt) print "Flipping" dBinFlipped = dmanip.flipBits(dBin) for i in range(3): if i == 2: dBinFlipped = dmanip.flipOrder(dBinFlipped) print "Searching" start = dstats.searchForBytes(dBinFlipped, dparse.intToBin(dparse.hexToInt(['FF', 'D8']))) end = dstats.searchForBytes(dBinFlipped, dparse.intToBin(dparse.hexToInt(['FF', 'D9']))) + 2 print "Separating: " + str(start) + ", " + str(end) iBin = dBinFlipped[start : end] print dBinFlipped[:5] print dBinFlipped[-5:] print "---" print iBin[:5] print iBin[-5:] print "---" dBinFlipped = dBinFlipped[end:] # Cut off beginning of file for next iteration iInt = dparse.binToInt(iBin) iAsc = dparse.intToAsc(iInt) print "Writing" outFile = open("../pics/out" + str(i) + ".jpg", 'w') outFile.write(iAsc) outFile.close() print "Done"
def extMagNum(h): print "Creating flipped data" i = dparse.hexToInt(h) b = dparse.intToBin(i) bFlip = dmanip.flipBits(b) bRev = dmanip.flipBinOrder(b) bRevFlip = dmanip.flipBits(bRev) hFlip = dparse.intToHex(dparse.binToInt(bFlip)) hRev = dparse.intToHex(dparse.binToInt(bRev)) hRevFlip = dparse.intToHex(dparse.binToInt(bRevFlip)) print "> Searching normal" magNumSearch(h) print "> Searching flipped bits" magNumSearch(hFlip) print "> Searching reversed order" magNumSearch(hRev) print "> Searching flipped bits and reversed order" magNumSearch(hRevFlip)