PrpAnalysis


This is a program that goes through a binary file and finds likely encodings for various elements. It’s basically a binary format solver… needless to say, sitting with a hex editor ends up being simpler than automation 90% of the time. Still, this is a fairly interesting program. It dates back to 2008.

import struct
fname = raw_input("file:")

def readFloatAll(fname):
    ##first pass offset 0
    datafile = open(fname)
    floatList1 = []
    while 1:
        try:
            data, = struct.unpack("<f",datafile.read(4))
            floatList1.append(data)
        except:
            print "end of file"
            datafile.close()
            break
    ##second pass offset 1
    datafile = open(fname)
    struct.unpack("<b",datafile.read(1))
    floatList2 = []
    while 1:
        try:
            data, = struct.unpack("<f",datafile.read(4))
            floatList2.append(data)
        except:
            print "end of file"
            datafile.close()
            break
    ##third pass offset 2
    datafile = open(fname)
    struct.unpack("<b",datafile.read(1))
    struct.unpack("<b",datafile.read(1))
    floatList3 = []
    while 1:
        try:
            data, = struct.unpack("<f",datafile.read(4))
            floatList3.append(data)
        except:
            print "end of file"
            datafile.close()
            break
    ##final pass offset 3
    datafile = open(fname)
    struct.unpack("<b",datafile.read(1))
    struct.unpack("<b",datafile.read(1))
    struct.unpack("<b",datafile.read(1))
    floatList4 = []
    while 1:
        try:
            data, = struct.unpack("<f",datafile.read(4))
            floatList4.append(data)
        except:
            print "end of file"
            datafile.close()
            break
    return (floatList1,floatList2,floatList3,floatList4)
#struct.calcsize()
def calcOffs(offset):
    if offset == 0:
        return 0
    if offset == 1:
        return 00
    if offset == 2:
        return 0000
    if offset == 3:
        return 000000
def lenFloat(strFloat):
    decimalsplit = strFloat.split('.')
    length = len(decimalsplit[1])
    return length

def floatParser(list):
    likelyFloats = []
    list1, list2, list3, list4 = list
    counter = 0
    for i in list1[1:]: #just get some kind of number
        templist = []
        templist.append(lenFloat(str(list1[counter])))
        templist.append(lenFloat(str(list2[counter])))
        templist.append(lenFloat(str(list3[counter])))
        templist.append(lenFloat(str(list4[counter])))
        templist.sort()
        score = templist[0]
        if score == lenFloat(str(list1[counter])):
            score = (score,list1[counter],1)
        if score == lenFloat(str(list2[counter])):
            score = (score,list2[counter],2)
        if score == lenFloat(str(list3[counter])):
            score = (score,list3[counter],3)
        if score == lenFloat(str(list4[counter])):
            score = (score,list4[counter],4)
        else:
            score = (score,0,0)

        objscore,numVal,index = score
        spacerRaw = calcOffs(index)

        print spacerRaw
        if spacerRaw != 0:
            likelyFloats.append(spacerRaw)
            likelyFloats.append(numVal)
        if spacerRaw == 0:
            likelyFloats.append(numVal)
        counter += 1
    print likelyFloats

readf = readFloatAll(fname)
floatParser(readf)

raw_input()

Posted in: Code by nsundin
Copyright © 2011-2025 Programmatic Verse · RSS Feed
Built on Skeleton
Powerered by Wordpress