Access denied!
Warning: Cannot modify header information - headers already sent by (output started at /homepages/19/d27199060/htdocs/typo3/fileadmin/j-asm/download.php:4) in /homepages/19/d27199060/htdocs/typo3/fileadmin/j-asm/download.php on line 9
#! /usr/bin/env python #
from hashlib import md5
from sys import (stdout, exit)
from pprint import pprint
from struct import pack, unpack

from ctypes import (c_uint8, c_uint16, c_uint32, c_uint64, c_char_p, c_char,
    c_size_t, cast, pointer, POINTER, Structure, memmove, addressof, sizeof)

class CRC32():
    table = []    
    def reverse(self,b):
        val = 0
        for bit in range(32):
            if ((b & (1 << bit)) != 0):
                val = val | (1 << (31 - bit))
        return val
        
    def __init__(self):
        val = 0
        for ent in range(256):
            val = self.reverse(ent)
            
            for i in range(8):
                if ((val & 0x80000000) != 0):
                    val = (val << 1) ^ 0x04c11db7
                else:
                    val = val << 1
            self.table.append(self.reverse(val))
    def calc(self,data):
        crc = 0xFFFFFFFF
        l = len(data)
        for i in range(l):
            ti = (crc&0xFF) ^ ord(data[i])
            crc = (crc >> 8) ^ self.table[ti]
        return crc ^ 0xFFFFFFFF
def checksum16(s,chksumpos):
    if len(s) & 1:
        s = s + "\x00"
    sum = 0
    cnt = 0
    while len(s):
        if not cnt == chksumpos:
            sum += unpack("= 0:
            ret += " of parent\n   Parent: " + bb[self.pnr].showinfo()
        return "\n"+ret
def highbit8(b):
    for i in range(0,7):
        if b<>i)
    return 0

def threeStoL(b):
    return ord(b[2])<<16 | ord(b[1])<<8 | ord(b[0])
def LtoThreeS(l):
    return pack(">8)&0xFF, (l>>16)&0xFF)


class PESECTIONHEADER(Structure):
    _fields_ = [('Name', c_char*8),
                ('VirtualSize', c_uint32),
                ('VirtualAddress', c_uint32),
                ('SizeOfRawData', c_uint32),
                ('PointerToRawData', c_uint32),
                ('PointerToRelocations', c_uint32),
                ('PointerToLinenumbers', c_uint32),
                ('NumberOfRelocations', c_uint16),
                ('NumberOfLinenumbers', c_uint16),
                ('Characteristics', c_uint32),]

    def __init__(self,data):
        memmove(addressof(self), data, sizeof(PESECTIONHEADER))
    def isCodeSection(self):
        return ((self.Characteristics & 0x00000020) == 0x20)
    def isInitedDataSection(self):
        return ((self.Characteristics & 0x00000040) == 0x40)
    def isUninitedDataSection(self):
        return (self.Characteristics & 0x00000080) == 0x80
    def isShared(self):
        return (self.Characteristics & 0x10000000) > 0
    def isExecutable(self):
        return (self.Characteristics & 0x20000000) > 0
    def isReadable(self):
        return (self.Characteristics & 0x40000000) > 0
    def isWritable(self):
        return (self.Characteristics & 0x80000000) > 0
class MZHDR(Structure):
    _fields_ = [('MZ', c_uint16),
                ('junk0', c_uint16),
                ('junk1', c_uint32),
                ('junk2', c_uint32),
                ('junk3', c_uint32),
                ('junk4', c_uint32),
                ('junk5', c_uint32),
                ('junk6', c_uint32),
                ('junk7', c_uint32),
                ('junk8', c_uint32),
                ('junk9', c_uint32),
                ('junkA', c_uint32),
                ('junkB', c_uint32),
                ('junkC', c_uint32),
                ('junkD', c_uint32),
                ('junkE', c_uint32),
                ('Offset', c_uint32),]
    def __init__(self,data):
        memmove(addressof(self), data, sizeof(MZHDR))

class PEHDR(Structure):
    _fields_ = [('Signature'        ,c_uint32),
                ('Machine'          ,c_uint16),
                ('NumberOfSections' ,c_uint16),
                ('TimeDateStamp'    ,c_uint32),
                ('pSymbolTable'     ,c_uint32),
                ('numSymbols'       ,c_uint32),
                ('optHdrSize'       ,c_uint16),
                ('Characteristics'  ,c_uint16),
                ('Magic'     ,c_uint16),
                ('MajorLinkerVersion'       ,c_uint8),
                ('MinorLinkerVersion'       ,c_uint8),
                ('CodeSize'  ,c_uint32),
                ('InitedDataSize'     ,c_uint32),
                ('UninitedDataSize'       ,c_uint32),
                ('EntryPoint'       ,c_uint32),
                ('BaseOfCode'  ,c_uint32),
                ('BaseOfData'     ,c_uint32),
                ('ImageBase'       ,c_uint32),
                ('SectionAlign'       ,c_uint32),
                ('MajorOSVersion'  ,c_uint16),
                ('MinorOSVersion'  ,c_uint16),
                ('MajorImgVersion'  ,c_uint16),
                ('MinorImgVersion'  ,c_uint16),
                ('MajorSubSysVersion'  ,c_uint16),
                ('MinorsubSysVersion'  ,c_uint16),
                ('Reserved1'  ,c_uint32),
                ('SizeOfImage'  ,c_uint32),
                ('Checksum'  ,c_uint32),
                ('Subsystem'  ,c_uint16),
                ('DLLCharacteristics'  ,c_uint16),
                ('SizeOfStackReserve'  ,c_uint32),
                ('SizeOfStackCommit'  ,c_uint32),
                ('SizeOfHeapReserve'  ,c_uint32),
                ('SizeOfHeapCommit'  ,c_uint32),
                ('LoaderFlags'  ,c_uint32),]
    def __init__(self,data):
        memmove(addressof(self), data, sizeof(PEHDR))

def isNear(loc1, loc2, near=0x20):
    if loc2 > loc1:
        if (loc2 - loc1) <= near:
            return True
    else:
        if (loc1 - loc2) <= near:
            return True
    return False

def findEndOfFunc(sdata):
    #print len(sdata)
    #chexdump(sdata[:0x200])
    pos = 0
    while 1:
        try:
            pos = sdata.index("\xC3", pos)
        except ValueError:
            return None
        #print "Found: 0x%08X" % pos
        pos+=1
        endfunc = pos
        if sdata[pos] == "\xCC":
            return endfunc
        if sdata[pos:pos+2] == "\x48\x89":
            return endfunc
        elif sdata[pos:pos+2] == "\x48\x83":
            return endfunc
        elif sdata[pos:pos+2] == "\x48\x81":
            return endfunc
    return None

class PEFILE():
    MZ = None
    PE = None
    is64Bit = False
    isValid = False
    rawdata = None
    Sections = []
    def __init__(self, data):
        try:
            self.MZ = MZHDR(data)
            self.rawdata = data
            self.rawpe = data[self.MZ.Offset:]
            self.PE = PEHDR(self.rawpe)
            self.is64Bit = (self.PE.Machine == 0x8664)
            sectionOffset = self.PE.optHdrSize + 24
        
            for i in range(0,self.PE.NumberOfSections):
                start = sectionOffset + (i*sizeof(PESECTIONHEADER))
                end = start + sizeof(PESECTIONHEADER)
                section = self.rawpe[start:end]
                self.Sections.append(PESECTIONHEADER(section))
            self.isValid = True
        except:
            self.isValid = False
    def getSectionByOffset(self, offset):
        return [i for i in self.Sections if ((i.PointerToRawData <= offset) and (i.PointerToRawData + i.SizeOfRawData >= offset))] 
    def getCodeSections(self):
        return [i for i in self.Sections if i.isCodeSection()]
    def getDataSections(self):
        return [i for i in self.Sections if (i.isInitedDataSection() and i.isWritable() and i.isReadable())]
    def findSendFormFunc(self, FormMainOffset, FormExitOffset):
        locs = self.searchGetInitFunctionLoads()
        for l in range(len(locs[0])):
            func = self.rawdata[locs[1][l]:]
            #print "0x%08X, 0x%08X"%(locs[0][l],locs[1][l])
            endfunc = findEndOfFunc(func)
            if not endfunc:
                continue
            func = func[:endfunc]
            #print "Ok, found init function"
                        
            #chexdump(func)
            varloads = self.searchLoadVarLocations(FormMainOffset, func, locs[1][l])
            if len(varloads[0]) > 0:
                varloads = self.searchLoadVarLocations(FormExitOffset, func, locs[1][l])
                if len(varloads[0]) > 0:
                    return [locs[1][l], locs[1][l] + endfunc]
        return None
    def searchGetInitFunctionLoads(self):
        found = []
        vals = []
        cs = self.getCodeSections()
        for s in cs:
            sdata = self.rawdata[self.PE.EntryPoint:]
            endfunc = findEndOfFunc(sdata)
            setupstring = sdata.index("Setu")
            positions = find_all(sdata,"\x48\x8D", lambda x: x, start=0, stop=endfunc)
            positions += find_all(sdata,"\x4C\x8D", lambda x: x, start=0, stop=endfunc)
            positions.sort()
            for p in positions:
                if isNear(p, setupstring):
                    p += self.PE.EntryPoint
                    val = unpack("= s.PointerToRawData and val <= s.PointerToRawData+s.SizeOfRawData:
                        found.append(p)
                        vals.append(val)
                
        return [found, vals]
    def searchLoadVarLocations(self, varAddress=None, sdata=None, offset = None):
        found = []
        vals = []

        cs = self.getCodeSections()
        if not sdata:
            sdata = self.rawdata[s.PointerToRawData:s.PointerToRawData+s.SizeOfRawData]

        def search(s, varAddress=None, sdataOffset=None):
            found = []
            vals = []
            if sdataOffset == None:
                sdataOffset = s.PointerToRawData
            positions = find_all(sdata,"\x48\x8D")
            positions += find_all(sdata,"\x4C\x8D")
            positions.sort()            
            for p in positions:
                p += sdataOffset
                val = unpack(" stop and what in buffer[stop:position]:
        
        position = buffer.rindex(what, stop, position)
        
        try:
            result.append(callback(position))
        except FindStopSearching, exc:
            return exc.result
        except FindBadPosition:
            pass
            
        position += 1
        
    return result

def read_with_progress(file_handle, total, chunk_size):
    assert not total % chunk_size, "chunk_size must be a divisor of total!"
    data = []
    length = (80 - 6)
    for i in xrange(0, total, chunk_size):
        data.append(file_handle.read(chunk_size))
        done = length*i // total
        print "\r[ %s>%s ]" % ("-"*done, " "*(length - done)),
        stdout.flush()
    print "\r[ %s> ]" % ("-"*length)
    return "".join(data)
    
from struct import unpack, Struct as pyStruct

class StructMeta(type):
    def __new__(meta, classname, bases, classDict):
            
        is_structitem = lambda x: isinstance(x[1], SI)
        struct_items = filter(is_structitem, classDict.iteritems())
        struct_items.sort(key=lambda x: x[1].position)
        
        struct_format = "".join(map(lambda x: x[1].packstr, struct_items))
        
        struct = pyStruct(struct_format)
        
        def __init__(self, data):
            self.rawdata = data
            data_tuple = struct.unpack_from(data)
            for (name, structitem), item_data in zip(struct_items, data_tuple):
                setattr(self, name, item_data)
                
            self.rest_of_data = data[struct.size:]
            
        #def repack(self):
            
            
        cls = type.__new__(meta, classname, bases, classDict)
        cls.py_struct = struct
        cls.struct_size = struct.size
        cls.__init__ = __init__
        
        return cls
        
class SI(object):
    "StructItem"
    counter = 0
    def __init__(self, packstr):
        self.position = SI.counter
        SI.counter += 1
        self.packstr = packstr

class Struct(object):
    __metaclass__ = StructMeta
    
def hexdump(s,sep=" "):
    return sep.join(map(lambda x: "%02x"%ord(x),s))

def ascii(s):
    s2 = ""
    for c in s:
        if ord(c)<0x20 or ord(c)>0x7e:
            s2 += "."
        else:
            s2 += c
    return s2

def pad(s,c,l):
    if len(s)