Example #1
0
File: cs.py Project: CptFrazz/cs
if __name__ == '__main__':
    parser = OptionParser()
    parser.add_option('-H', '--hashes', dest='hashes', action='store_true', default=False, help='print the actual hashes')
    parser.add_option('', '--verify-hashes', dest='verify_hashes', action='store_true', default=False, help='and verify them')
    parser.add_option('-c', '--certs', dest='certs', default=None, help='save the certificates blob (DER-encoded PKCS#7) to a file')
    options, args = parser.parse_args()
    filename = args[0]

    should_print = not options.verify_hashes

    if not options.hashes:
        macho_cs.Hashes_ = construct.OnDemand(macho_cs.Hashes_)

    f = open(filename, 'rb')
    odata = construct_try(lambda: macho.InputFile.parse_stream(f)).data
    try:
        data = odata.FatArch[0].MachO
    except:
        data = odata

    def do_blob(sblob):
        if should_print:
            print sblob
        if options.certs:
            try:
                for blob in sblob.data.BlobIndex:
                    if blob.blob.magic == 'CSMAGIC_BLOBWRAPPER':
                        open(options.certs, 'wb').write(blob.blob.data.data.value)
                        break
            except:
Example #2
0
File: elf32.py Project: CptFrazz/cs
    ),
    
    # program header table
    Rename("program_table",
        Pointer(lambda ctx: ctx.ph_offset,
            Array(lambda ctx: ctx.ph_count,
                elf_program_header
            )
        )
    ),
    
    # section table
    Rename("sections", 
        Pointer(lambda ctx: ctx.sh_offset,
            Array(lambda ctx: ctx.sh_count,
                elf_section_header
            )
        )
    ),
)


if __name__ == "__main__":
    import sys
    from construct_try import construct_try
    obj = construct_try(lambda: elf_file.parse_stream(open(sys.argv[1], "rb")))
    print obj
    #[s.data.value for s in obj.sections if s.data is not None]
    #print obj

Example #3
0
    UInt16("strtab_section_index"),

    # calculate the string table data offset (pointer arithmetics)
    # ugh... anyway, we need it in order to read the section names, later on
    Pointer(
        lambda ctx: ctx.sh_offset + ctx.strtab_section_index * ctx.
        sh_entry_size + (24 if sixtyfour_bit else 16),
        UInt32("strtab_data_offset"),
    ),

    # program header table
    Rename(
        "program_table",
        Pointer(lambda ctx: ctx.ph_offset,
                Array(lambda ctx: ctx.ph_count, elf_program_header))),

    # section table
    Rename(
        "sections",
        Pointer(lambda ctx: ctx.sh_offset,
                Array(lambda ctx: ctx.sh_count, elf_section_header))),
)

if __name__ == "__main__":
    import sys
    from construct_try import construct_try
    obj = construct_try(lambda: elf_file.parse_stream(open(sys.argv[1], "rb")))
    print obj
    #[s.data.value for s in obj.sections if s.data is not None]
    #print obj
Example #4
0
File: cs.py Project: wangtielei/cs
                      dest='hashes',
                      action='store_true',
                      default=False,
                      help='print the actual hashes')
    parser.add_option(
        '-c',
        '--certs',
        dest='certs',
        default=None,
        help='save the certificates blob (DER-encoded PKCS#7) to a file')
    options, args = parser.parse_args()
    filename = args[0]

    if not options.hashes:
        macho_cs.Hashes_ = construct.Struct('Hashes')

    f = open(filename, 'rb')
    data = construct_try(lambda: macho.MachOOrFat.parse_stream(f))
    for cmd in data.data.commands:
        if cmd.cmd == 'LC_CODE_SIGNATURE':
            print cmd
            if options.certs:
                try:
                    for blob in cmd.data.blob.data.BlobIndex:
                        if blob.blob.magic == 'CSMAGIC_BLOBWRAPPER':
                            open(options.certs,
                                 'wb').write(blob.blob.data.data.value)
                            break
                except:
                    pass
Example #5
0
File: cs.py Project: xtxwy/cs
    parser.add_option(
        '-c',
        '--certs',
        dest='certs',
        default=None,
        help='save the certificates blob (DER-encoded PKCS#7) to a file')
    options, args = parser.parse_args()
    filename = args[0]

    should_print = not options.verify_hashes

    if not options.hashes:
        macho_cs.Hashes_ = construct.OnDemand(macho_cs.Hashes_)

    f = open(filename, 'rb')
    odata = construct_try(lambda: macho.InputFile.parse_stream(f)).data
    try:
        data = odata.FatArch[0].MachO
    except:
        data = odata

    def do_blob(sblob):
        if should_print:
            print sblob
        if options.certs:
            try:
                for blob in sblob.data.BlobIndex:
                    if blob.blob.magic == 'CSMAGIC_BLOBWRAPPER':
                        open(options.certs,
                             'wb').write(blob.blob.data.data.value)
                        break
Example #6
0
File: cs.py Project: ieswxia/cs
import sys, os, re
from optparse import OptionParser
import macho, macho_cs
import construct
from construct_try import construct_try

if __name__ == '__main__':
    parser = OptionParser()
    parser.add_option('-H', '--hashes', dest='hashes', action='store_true', default=False, help='print the actual hashes')
    parser.add_option('-c', '--certs', dest='certs', default=None, help='save the certificates blob (DER-encoded PKCS#7) to a file')
    options, args = parser.parse_args()
    filename = args[0]

    if not options.hashes:
        macho_cs.Hashes_ = construct.Struct('Hashes')

    f = open(filename, 'rb')
    data = construct_try(lambda: macho.MachOOrFat.parse_stream(f))
    for cmd in data.data.commands:
        if cmd.cmd == 'LC_CODE_SIGNATURE':
            print cmd
            if options.certs:
                try:
                    for blob in cmd.data.blob.data.BlobIndex:
                        if blob.blob.magic == 'CSMAGIC_BLOBWRAPPER':
                            open(options.certs, 'wb').write(blob.blob.data.data.value)
                            break
                except:
                    pass