コード例 #1
0
ファイル: disasm.py プロジェクト: topin89/codimension
def getBufferDisassembled(content, encoding, path, optimization):
    """Disassembles a memory buffer"""
    tempSrcFile = makeTempFile(suffix='.py')
    tempPycFile = makeTempFile(suffix='.pyc')

    try:
        saveToFile(tempSrcFile, content, allowException=True, enc=encoding)
        py_compile.compile(tempSrcFile,
                           tempPycFile,
                           path,
                           doraise=True,
                           optimize=optimization)
    except Exception as exc:
        safeUnlink(tempSrcFile)
        safeUnlink(tempPycFile)
        raise

    try:
        result = getCompiledfileDisassembled(tempPycFile, path, optimization,
                                             True)
    except:
        safeUnlink(tempSrcFile)
        safeUnlink(tempPycFile)
        raise

    safeUnlink(tempSrcFile)
    safeUnlink(tempPycFile)
    if path:
        return result.replace('file "' + path + '",',
                              'unsaved buffer "' + path + '",')
    return result
コード例 #2
0
def getBufferBinary(content, encoding, path, optimization):
    """Provides the binary pyc content"""
    tempSrcFile = makeTempFile(suffix='.py')
    tempPycFile = makeTempFile(suffix='.pyc')

    try:
        saveToFile(tempSrcFile, content, allowException=True, enc=encoding)
        py_compile.compile(tempSrcFile,
                           tempPycFile,
                           path,
                           doraise=True,
                           optimize=optimization)
    except Exception:
        safeUnlink(tempSrcFile)
        safeUnlink(tempPycFile)
        raise

    try:
        props, content = getCompiledfileBinary(tempPycFile, path, optimization,
                                               True)
    except:
        safeUnlink(tempSrcFile)
        safeUnlink(tempPycFile)
        raise

    safeUnlink(tempSrcFile)
    safeUnlink(tempPycFile)
    return props, content
コード例 #3
0
ファイル: disasm.py プロジェクト: topin89/codimension
def getFileDisassembled(path, optimization):
    """Dsassembles a file"""
    if not os.path.exists(path):
        raise Exception("Cannot find " + path + " to disassemble")
    if not os.access(path, os.R_OK):
        raise Exception("No read permissions for " + path)

    tempPycFile = makeTempFile(suffix='.pyc')
    try:
        py_compile.compile(path,
                           tempPycFile,
                           doraise=True,
                           optimize=optimization)
    except Exception as exc:
        safeUnlink(tempPycFile)
        raise Exception("Cannot disassemble file " + path + ': ' + str(exc))

    try:
        result = getCompiledfileDisassembled(tempPycFile, path, optimization)
    except:
        safeUnlink(tempPycFile)
        raise

    safeUnlink(tempPycFile)
    return result
コード例 #4
0
def getFileBinary(path, optimization):
    """Provides the binary pyc content"""
    if not os.path.exists(path):
        raise Exception("Cannot find " + path + " to provide binary")
    if not os.access(path, os.R_OK):
        raise Exception("No read permissions for " + path)

    tempPycFile = makeTempFile(suffix='.pyc')
    try:
        py_compile.compile(path,
                           tempPycFile,
                           doraise=True,
                           optimize=optimization)
    except Exception as exc:
        safeUnlink(tempPycFile)
        raise Exception("Cannot provide binary for file " + path + ': ' +
                        str(exc))

    try:
        props, content = getCompiledfileBinary(tempPycFile, path, optimization)
    except:
        safeUnlink(tempPycFile)
        raise

    safeUnlink(tempPycFile)
    return props, content
コード例 #5
0
def getGraphFromDescriptionData(content):
    """Runs dot and then parses and builds normalized graph"""
    tempFileName = makeTempFile()
    saveToFile(tempFileName, content)

    try:
        graph = getGraphFromDescrptionFile(tempFileName)
    finally:
        os.unlink(tempFileName)
    return graph