示例#1
0
    filename = "temp%s.txt" % os.getpid()
    f = open(filename, "wt")

    f.write("// Add a * in front of the bytes you want to ignore\n")
    f.write("// this file will be deleted at the end of the procedure\n\n")
    f.write("\n".join(("// %s:%s" % (i[0].ljust(hlen), i[1]) for i in r)))
    f.close()

    #hiew.MessageWaitOpen()
    os.system(filename)
    #hiew.MessageWaitClose()

    f = open(filename, "rt")
    r = f.readlines()
    f.close()

    f = open(filename, "wt")
    for i in r:
        f.write(i)
    f.write("\n")
    f.write(templatize(seq_to_snippets(code_to_seq(r))))
    f.close()

    #TODO: make portable hiew.MessageWaitOpen()
    os.system(filename)
    #hiew.MessageWaitClose()

    #hiew.Window.FromString("Success", "Operation successfull! deleting temp file...")
    os.remove(filename)

示例#2
0
#  0F, B7, F7                  //movzx esi,di
#  8D, 45, C0                  //lea eax,[ebp-0x40]
#  53                          //push ebx
#  50                          //push eax
#  C7, 45, FC,*05,*40,*00, 80  //mov dword [ebp-0x4],0x80004005
#  89, 7D, F8                  //mov [ebp-0x8],edi
#  03                          //add eax,[eax]


# into this:
# if (
#      (*(UINT32*)&buffer[i + 00]             == 0x8DF7B70F) &&
#      (*(UINT32*)&buffer[i + 04]             == 0x5053C045) &&
#     ((*(UINT32*)&buffer[i + 08] & 0xFFFFFF) == 0xFC45C7) &&
#      (*(UINT32*)&buffer[i + 0e]             == 0xF87D8980) &&
#      (*(UINT8*)&buffer[i + 12]              == 0x03)
#     )
#     {




if __name__=='__main__':
    import sys
    from utils import templatize, seq_to_snippets, code_to_seq
    f = open(sys.argv[1], "rt")
    r = f.readlines()
    f.close()

    print templatize(seq_to_snippets(code_to_seq(r)))
示例#3
0
        consec += 1
        if CONSEC_LIMIT > 0 and consec > CONSEC_LIMIT:
            limit = i + 1 - ZERO_LIMIT
            break

seq = seq[:limit + 1]
a1 = a1[:limit + 1]
a2 = a2[:limit + 1]

print "// automated comparison and test-generation of :"
print "// file %s\n// %s" % (f1, " ".join(["%02X" % ord(i) for i in d1[:limit]]))
print "// file %s\n// %s" % (f2, " ".join(["%02X" % ord(i) for i in d2[:limit]]))
print

from utils import get_disassembly

a1 = get_disassembly("".join(chr(int(i, 16)) for i in a1))
a2 = get_disassembly("".join(chr(int(i, 16)) for i in a2))

hlen = max(len(i[0]) for i in a1) + 1
a1 = ["// %s:%s" % (i[0].ljust(hlen), i[1]) for i in a1]
a2 = ["// %s:%s" % (i[0].ljust(hlen), i[1]) for i in a2]

if len(a1) == len(a2):
    for i,j in enumerate(a1):
        print getwildstring(j, a2[i])
else:
    print "different length"

print templatize(seq_to_snippets(seq))
示例#4
0
            limit = i + 1 - ZERO_LIMIT
            break

seq = seq[:limit + 1]
a1 = a1[:limit + 1]
a2 = a2[:limit + 1]

print "// automated comparison and test-generation of :"
print "// file %s\n// %s" % (f1, " ".join(
    ["%02X" % ord(i) for i in d1[:limit]]))
print "// file %s\n// %s" % (f2, " ".join(
    ["%02X" % ord(i) for i in d2[:limit]]))
print

from utils import get_disassembly

a1 = get_disassembly("".join(chr(int(i, 16)) for i in a1))
a2 = get_disassembly("".join(chr(int(i, 16)) for i in a2))

hlen = max(len(i[0]) for i in a1) + 1
a1 = ["// %s:%s" % (i[0].ljust(hlen), i[1]) for i in a1]
a2 = ["// %s:%s" % (i[0].ljust(hlen), i[1]) for i in a2]

if len(a1) == len(a2):
    for i, j in enumerate(a1):
        print getwildstring(j, a2[i])
else:
    print "different length"

print templatize(seq_to_snippets(seq))
示例#5
0
# this program generates a C test from a sequence of bytes with ignored entries

# It will turn this:

#  0F, B7, F7                  //movzx esi,di
#  8D, 45, C0                  //lea eax,[ebp-0x40]
#  53                          //push ebx
#  50                          //push eax
#  C7, 45, FC,*05,*40,*00, 80  //mov dword [ebp-0x4],0x80004005
#  89, 7D, F8                  //mov [ebp-0x8],edi
#  03                          //add eax,[eax]

# into this:
# if (
#      (*(UINT32*)&buffer[i + 00]             == 0x8DF7B70F) &&
#      (*(UINT32*)&buffer[i + 04]             == 0x5053C045) &&
#     ((*(UINT32*)&buffer[i + 08] & 0xFFFFFF) == 0xFC45C7) &&
#      (*(UINT32*)&buffer[i + 0e]             == 0xF87D8980) &&
#      (*(UINT8*)&buffer[i + 12]              == 0x03)
#     )
#     {

if __name__ == '__main__':
    import sys
    from utils import templatize, seq_to_snippets, code_to_seq
    f = open(sys.argv[1], "rt")
    r = f.readlines()
    f.close()

    print templatize(seq_to_snippets(code_to_seq(r)))