示例#1
0
文件: mcusw.py 项目: mirror4/phosher
def main():
    userOptions = OptionParser()
    userOptions.add_option(
        "-p",
        "--patches",
        dest="patchesFile",
        type="string",
        help="Python scriptin that defines global var PATCHES. The file would be executed!",
    )
    userOptions.add_option(
        "-i",
        "--input",
        dest="inputFile",
        type="string",
        help="Input MCUSW file. It is also possible to set a global INPUT_FILE var in the PATCHES file",
    )
    userOptions.add_option(
        "-o",
        "--output",
        dest="outputFile",
        type="string",
        help="Output file. If not set the output file is dervid from the input file name",
    )
    userOptions.add_option(
        "-d", "--plain", dest="dumpPlain", action="store_true", help="Save the plain (deobfuscated) data to file"
    )
    userOptions.add_option("-u", "--plainDst", dest="dumpDest", type="string", help="Where to dump plain data to")
    userOptions.add_option("-v", "--verbose", dest="isVerbose", action="store_true", help="Set verbose output on")
    userOptions.add_option(
        "-z", "--dontFixChecksum", dest="dontFixChecksum", action="store_true", help="Don't fix the plain checksum"
    )
    userOptions.set_defaults(
        inputFile=None, outputFile=None, isVerbose=False, dumpDest=None, dumpPlain=False, dontFixChecksum=False
    )
    (options, args) = userOptions.parse_args(sys.argv[1:])
    patchesFile = options.patchesFile
    inputFile = options.inputFile
    outputFile = options.outputFile
    isDumpPlain = options.dumpPlain
    dumpDest = options.dumpDest
    isVerbose = options.isVerbose
    dontFixChecksum = options.dontFixChecksum
    PATCHES, patchesDefines = loadPatchesFromFile(patchesFile, userOptions, isVerbose)
    inputFile = cmdLineInputFile(patchesDefines, inputFile, userOptions)
    outputFile = cmdLineOutputFile(patchesDefines, outputFile, inputFile)
    nokiaFile = NokiaFile(inputFile, isVerbose=isVerbose)
    plain = nokiaFile.plain
    plainAddr = nokiaFile.address

    if None != patchesFile:
        plain = patchMcusw(plainAddr, plain, nokiaFile, PATCHES, isVerbose)
        nokiaFile.plain = plain
    if False == dontFixChecksum:
        plain = fixChecksum(plainAddr, plain, nokiaFile, isVerbose)
        nokiaFile.plain = plain
    if isDumpPlain:
        dumpDest = cmdLineDumpDestFile(patchesDefines, dumpDest, outputFile, plainAddr)
        file(dumpDest, "wb").write(plain)
    mcuData = nokiaFile.encode()
    file(outputFile, "wb").write(mcuData)
示例#2
0
文件: image.py 项目: mirror4/phosher
def main():
    userOptions = OptionParser()
    userOptions.add_option("-p", "--patches",   dest="patchesFile", type="string", help="Python scriptin that defines global var PATCHES. The file would be executed!")
    userOptions.add_option("-i", "--input",     dest="inputFile",   type="string", help="Input Image file. It is also possible to set a global INPUT_FILE var in the PATCHES file")
    userOptions.add_option("-o", "--output",    dest="outputFile",  type="string", help="Output file. If not set the output file is dervid from the input file name")
    userOptions.add_option("-d", "--dump",      dest="isDump",      action="store_true", help="Dump files in image to disk")
    userOptions.add_option("-u", "--dumpDest",  dest="dumpDest",    type="string", help="Where to dump files from image")
    userOptions.add_option("-c", "--createIma", dest="createIma",   action="store_true", help="Create FAT16 image file")
    userOptions.add_option("-w", "--imageName", dest="imageName",   type="string", help="Destination FAT16 image file")
    userOptions.add_option("-l", "--list",      dest="listFiles",   action="store_true", help="Display list of all files in image as tree")
    userOptions.add_option("-v", "--verbose",   dest="isVerbose",   action="store_true", help="Set verbose output on")
    userOptions.set_defaults(inputFile=None, outputFile=None, isVerbose=False)
    (options, args) = userOptions.parse_args(sys.argv[1:])
    patchesFile = options.patchesFile
    inputFile   = options.inputFile
    outputFile  = options.outputFile
    isDump      = options.isDump
    dumpDest    = options.dumpDest
    createIma   = options.createIma
    imageName   = options.imageName
    listFiles   = options.listFiles
    isVerbose   = options.isVerbose
    PATCHES, patchesDefines = loadPatchesFromFile(patchesFile, userOptions, isVerbose, globs=patcher)
    inputFile = cmdLineInputFile(patchesDefines, inputFile, userOptions)
    outputFile = cmdLineOutputFile(patchesDefines, outputFile, inputFile)
    if None == dumpDest:
        writeOutput = False
    else:
        writeOutput = True
    if "DUMP_DEST" not in patchesDefines and None == dumpDest:
        dumpDest = inputFile + '_DUMP'
    elif "DUMP_DEST"   in patchesDefines and None == dumpDest:
        dumpDest = patchesDefines["DUMP_DEST"]
    if "IMAGE_FILE" not in patchesDefines and None == imageName:
        imageName = inputFile + '.ima'
    elif "IMAGE_FILE"   in patchesDefines and None == imageName:
        imageName = IMAGE_FILE
    nokiaFile = NokiaFile(inputFile, isVerbose=isVerbose)
    imageData = nokiaFile.plain

    fat16 = parseFAT16(imageData, isVerbose=isVerbose)

    if None != patchesFile:
        writeOutput = True
        fat16Patcher = patcher.Fat16Patcher(fat16)
        fat16Patcher.patch(PATCHES)
    if isDump:
        fat16.dumpTree(dumpDest)
    if createIma:
        imageData = fat16.makeNoPadding()
        file(imageName, 'wb').write(imageData)
    if listFiles:
        print fat16.displayTree()
    if writeOutput:
        nokiaFile.plain = fat16.make()
        file(outputFile, 'wb').write(nokiaFile.encode())
示例#3
0
def main():
    userOptions = OptionParser()
    userOptions.add_option("-i",
                           "--input",
                           dest="inputFile",
                           type="string",
                           help="Input file")
    userOptions.add_option("-o",
                           "--output",
                           dest="outputFile",
                           type="string",
                           help="Where to save plain data")
    userOptions.add_option("-v",
                           "--verbose",
                           dest="isVerbose",
                           action="store_true",
                           help="Set verbose output on")
    userOptions.set_defaults(inputFile=None, outputFile=None, isVerbose=False)
    (options, args) = userOptions.parse_args(sys.argv[1:])
    inputFile = options.inputFile
    outputFile = options.outputFile
    isVerbose = options.isVerbose
    inputFile = cmdLineInputFile({}, inputFile, userOptions)
    outputFile = cmdLineOutputFile({}, outputFile, inputFile)

    data = file(inputFile, 'rb').read()
    if len(data) < 0x100:
        raise Exception("Input file too short to be a NokiaFile")

    nokiaFile = NokiaFile(data, isVerbose=isVerbose)

    if None != outputFile:
        file(outputFile, 'wb').write(nokiaFile.plain)
示例#4
0
文件: ppm.py 项目: mirror4/phosher
def main():
    userOptions = OptionParser()
    userOptions.add_option("-p", "--patches",   dest="patchesFile", type="string", help="Python scriptin that defines global var PATCHES. The file would be executed!")
    userOptions.add_option("-i", "--input",     dest="inputFile",   type="string", help="Input Image file. It is also possible to set a global INPUT_FILE var in the PATCHES file")
    userOptions.add_option("-o", "--output",    dest="outputFile",  type="string", help="Output file. If not set the output file is dervid from the input file name")
    userOptions.add_option("-d", "--dumpAni",   dest="isDumpAnimations", action="store_true", help="Should dump animations")
    userOptions.add_option("-f", "--dumpDest",  dest="dumpOutputDir", type="string", help="Where to dump the animation files")
    userOptions.add_option("-t", "--text",      dest="isText",      action="store_true", help="Output readable version of the PPM")
    userOptions.add_option("-v", "--verbose",   dest="isVerbose",   action="store_true", help="Set verbose output on")
    userOptions.set_defaults(inputFile=None, outputFile=None, isVerbose=False, isText=False, isDumpAnimations=False, dumpDest=None)
    (options, args) = userOptions.parse_args(sys.argv[1:])
    patchesFile = options.patchesFile
    inputFile   = options.inputFile
    outputFile  = options.outputFile
    isDumpAnimations = options.isDumpAnimations
    dumpDest    = options.dumpDest
    isText      = options.isText
    isVerbose   = options.isVerbose

    PATCHES, patchesDefines = loadPatchesFromFile(patchesFile, userOptions, isVerbose)
    inputFile = cmdLineInputFile(patchesDefines, inputFile, userOptions)
    outputFile = cmdLineOutputFile(patchesDefines, outputFile, inputFile)

    nokiaFile = NokiaFile(inputFile, isVerbose=isVerbose)
    ppmData = nokiaFile.plain

    ppm = PPM(ppmData, isVerbose=isVerbose)
    if None != patchesFile:
        ppm.patch(PATCHES)
    if None != isDumpAnimations:
        if None == dumpDest:
            dumpDest = inputFile + '.animations'
        ppm.dumpAnimationsToDisk(dumpDest)
    if isText:
        file(outputFile, 'wb').write(ppm.toText())
    else:
        nokiaFile.plain = ppm.toBinary()
        file(outputFile, 'wb').write(nokiaFile.encode())
示例#5
0
文件: mcusw.py 项目: mirror4/phosher
def main():
    userOptions = OptionParser()
    userOptions.add_option(
        "-p",
        "--patches",
        dest="patchesFile",
        type="string",
        help=
        "Python scriptin that defines global var PATCHES. The file would be executed!"
    )
    userOptions.add_option(
        "-i",
        "--input",
        dest="inputFile",
        type="string",
        help=
        "Input MCUSW file. It is also possible to set a global INPUT_FILE var in the PATCHES file"
    )
    userOptions.add_option(
        "-o",
        "--output",
        dest="outputFile",
        type="string",
        help=
        "Output file. If not set the output file is dervid from the input file name"
    )
    userOptions.add_option("-d",
                           "--plain",
                           dest="dumpPlain",
                           action="store_true",
                           help="Save the plain (deobfuscated) data to file")
    userOptions.add_option("-u",
                           "--plainDst",
                           dest="dumpDest",
                           type="string",
                           help="Where to dump plain data to")
    userOptions.add_option("-v",
                           "--verbose",
                           dest="isVerbose",
                           action="store_true",
                           help="Set verbose output on")
    userOptions.add_option("-z",
                           "--dontFixChecksum",
                           dest="dontFixChecksum",
                           action="store_true",
                           help="Don't fix the plain checksum")
    userOptions.set_defaults(inputFile=None,
                             outputFile=None,
                             isVerbose=False,
                             dumpDest=None,
                             dumpPlain=False,
                             dontFixChecksum=False)
    (options, args) = userOptions.parse_args(sys.argv[1:])
    patchesFile = options.patchesFile
    inputFile = options.inputFile
    outputFile = options.outputFile
    isDumpPlain = options.dumpPlain
    dumpDest = options.dumpDest
    isVerbose = options.isVerbose
    dontFixChecksum = options.dontFixChecksum
    PATCHES, patchesDefines = loadPatchesFromFile(patchesFile, userOptions,
                                                  isVerbose)
    inputFile = cmdLineInputFile(patchesDefines, inputFile, userOptions)
    outputFile = cmdLineOutputFile(patchesDefines, outputFile, inputFile)
    nokiaFile = NokiaFile(inputFile, isVerbose=isVerbose)
    plain = nokiaFile.plain
    plainAddr = nokiaFile.address

    if None != patchesFile:
        plain = patchMcusw(plainAddr, plain, nokiaFile, PATCHES, isVerbose)
        nokiaFile.plain = plain
    if False == dontFixChecksum:
        plain = fixChecksum(plainAddr, plain, nokiaFile, isVerbose)
        nokiaFile.plain = plain
    if isDumpPlain:
        dumpDest = cmdLineDumpDestFile(patchesDefines, dumpDest, outputFile,
                                       plainAddr)
        file(dumpDest, 'wb').write(plain)
    mcuData = nokiaFile.encode()
    file(outputFile, 'wb').write(mcuData)