Example #1
0
def dereference(c):
    c = map(utils.tokenify, c)
    label_length = utils.log256(len(c) * 4)
    iq = [x for x in c]
    mq = []
    pos = 0
    labelmap = {}
    beginning_stack = [0]
    while len(iq):
        front = iq.pop(0)
        if not utils.is_numeric(front.val) and front.val[0] == '~':
            labelmap[front.val[1:]] = pos - beginning_stack[-1]
        elif front.val == '#CODE_BEGIN':
            beginning_stack.append(pos)
        elif front.val == '#CODE_END':
            beginning_stack.pop()
        else:
            mq.append(front)
            if utils.is_numeric(front.val):
                pos += 1 + max(1, utils.log256(front.val))
            elif front.val[:1] == '$':
                pos += label_length + 1
            else:
                pos += 1
    oq = []
    for m in mq:
        oqplus = []
        if utils.is_numberlike(m.val):
            m.val = utils.numberize(m.val)
        if utils.is_numeric(m.val):
            L = max(1, utils.log256(m.val))
            oqplus.append('PUSH' + str(L))
            oqplus.extend(utils.tobytearr(m.val, L))
        elif m.val[:1] == '$':
            vals = m.val[1:].split('.')
            if len(vals) == 1:
                oqplus.append('PUSH' + str(label_length))
                oqplus.extend(utils.tobytearr(labelmap[vals[0]], label_length))
            else:
                oqplus.append('PUSH' + str(label_length))
                value = labelmap[vals[1]] - labelmap[vals[0]]
                oqplus.extend(utils.tobytearr(value, label_length))
        else:
            oqplus.append(m)
        oq.extend(map(lambda x: utils.tokenify(x, *m.metadata), oqplus))
    return oq
Example #2
0
def dereference(c):
    c = map(utils.tokenify, c)
    label_length = utils.log256(len(c)*4)
    iq = [x for x in c]
    mq = []
    pos = 0
    labelmap = {}
    beginning_stack = [0]
    while len(iq):
        front = iq.pop(0)
        if not utils.is_numeric(front.val) and front.val[0] == '~':
            labelmap[front.val[1:]] = pos - beginning_stack[-1]
        elif front.val == '#CODE_BEGIN':
            beginning_stack.append(pos)
        elif front.val == '#CODE_END':
            beginning_stack.pop()
        else:
            mq.append(front)
            if utils.is_numeric(front.val):
                pos += 1 + max(1, utils.log256(front.val))
            elif front.val[:1] == '$':
                pos += label_length + 1
            else:
                pos += 1
    oq = []
    for m in mq:
        oqplus = []
        if utils.is_numberlike(m.val):
            m.val = utils.numberize(m.val)
        if utils.is_numeric(m.val):
            L = max(1, utils.log256(m.val))
            oqplus.append('PUSH' + str(L))
            oqplus.extend(utils.tobytearr(m.val, L))
        elif m.val[:1] == '$':
            vals = m.val[1:].split('.')
            if len(vals) == 1:
                oqplus.append('PUSH'+str(label_length))
                oqplus.extend(utils.tobytearr(labelmap[vals[0]], label_length))
            else:
                oqplus.append('PUSH'+str(label_length))
                value = labelmap[vals[1]] - labelmap[vals[0]]
                oqplus.extend(utils.tobytearr(value, label_length))
        else:
            oqplus.append(m)
        oq.extend(map(lambda x: utils.tokenify(x, *m.metadata), oqplus))
    return oq
Example #3
0
def dereference(c):
    label_length = utils.log256(len(c)*4)
    iq = [x for x in c]
    mq = []
    pos = 0
    labelmap = {}
    beginning_stack = [0]
    while len(iq):
        front = iq.pop(0)
        if not utils.is_numeric(front) and front[0] == '~':
            labelmap[front[1:]] = pos - beginning_stack[-1]
        elif front == '#CODE_BEGIN':
            beginning_stack.append(pos)
        elif front == '#CODE_END':
            beginning_stack.pop()
        else:
            mq.append(front)
            if utils.is_numeric(front):
                pos += 1 + max(1, utils.log256(front))
            elif front[:1] == '$':
                pos += label_length + 1
            else:
                pos += 1
    oq = []
    for m in mq:
        oqplus = []
        if utils.is_numeric(m):
            L = max(1, utils.log256(m))
            oqplus.append('PUSH' + str(L))
            oqplus.extend(utils.tobytearr(m, L))
        elif m[:1] == '$':
            vals = m[1:].split('.')
            if len(vals) == 1:
                oqplus.append('PUSH'+str(label_length))
                oqplus.extend(utils.tobytearr(labelmap[vals[0]], label_length))
            else:
                oqplus.append('PUSH'+str(label_length))
                value = labelmap[vals[1]] - labelmap[vals[0]]
                oqplus.extend(utils.tobytearr(value, label_length))
        else:
            oqplus.append(m)
        oq.extend(oqplus)
    return oq
Example #4
0
 def enc(n):
     if utils.is_numeric(n):
         return ''.join(map(chr, utils.tobytearr(n, 32)))
     elif utils.is_string(n) and len(n) == 40:
         return '\x00' * 12 + n.decode('hex')
     elif utils.is_string(n):
         return '\x00' * (32 - len(n)) + n
     elif n is True:
         return 1
     elif n is False or n is None:
         return 0
Example #5
0
 def enc(n):
     if utils.is_numeric(n):
         return ''.join(map(chr, utils.tobytearr(n, 32)))
     elif utils.is_string(n) and len(n) == 40:
         return '\x00' * 12 + n.decode('hex')
     elif utils.is_string(n):
         return '\x00' * (32 - len(n)) + n
     elif n is True:
         return 1
     elif n is False or n is None:
         return 0