Esempio n. 1
0
 def build_automatas(self):
     nfa = reCompiler.compileRE(self.expr, minimize=0).trimmed()
     dfa = nfa.determinized()
     dfa_min = dfa.minimized()
     automatas = [nfa, dfa, dfa_min]
     suffixes = ["nfa", "dfa", "dfa_min"]
     for p in zip(automatas, suffixes):
         self.work_automata(self.name, *p)
     return dfa
Esempio n. 2
0
def createContent(pattern, graphKey=None):
    import FSA
    import reCompiler
    from rematch import parseDot, fsa2dot, fsa2obj
    from encoder import JSONEncoder

    obj = {}
    obj["pattern"] = pattern
    fsa = reCompiler.compileRE(pattern, minimize=0, recordSourcePositions=1)
    # withoutEpsilons doesn't preserve metadata, so capture it in the
    # dfa first
    dfa = fsa.minimized()
    fsa = fsa.withoutEpsilons()
    obj["nfa"] = {"graph": parseDot(fsa2dot(fsa)), "model": fsa2obj(fsa)}
    obj["dfa"] = {"graph": parseDot(fsa2dot(dfa)), "model": fsa2obj(dfa)}
    if graphKey:
        obj = obj[graphKey]["graph"]

    return JSONEncoder().encode(obj)
Esempio n. 3
0
def createContent(pattern, graphKey=None):
    import FSA
    import reCompiler
    from rematch import parseDot, fsa2dot, fsa2obj
    from encoder import JSONEncoder

    obj = {}
    obj['pattern'] = pattern
    fsa = reCompiler.compileRE(pattern, minimize=0, recordSourcePositions=1)
    # withoutEpsilons doesn't preserve metadata, so capture it in the
    # dfa first
    dfa = fsa.minimized()
    fsa = fsa.withoutEpsilons()
    obj['nfa'] = {'graph': parseDot(fsa2dot(fsa)), 'model': fsa2obj(fsa)}
    obj['dfa'] = {'graph': parseDot(fsa2dot(dfa)), 'model': fsa2obj(dfa)}
    if graphKey:
        obj = obj[graphKey]['graph']

    return JSONEncoder().encode(obj)
Esempio n. 4
0
def getDotString():
    global regex, graphfile, dotstring

    print
    print "[+] Generating dot string ..."
    fsa4re = recompiler.compileRE(regex).determinized().minimized().trimmed().sorted()

    print "[+] Label: %s" % (fsa4re.label)
    print "[+] states: %s" % (fsa4re.states)
    print "[+] states count: %d" % (len(fsa4re.states))
    print "[+] initialState: %s" % (fsa4re.initialState)
    print "[+] finalStates: %s" % (fsa4re.finalStates)
    print "[+] alphabet: %s" % (fsa4re.alphabet)
    print "[+] transitions:"

    for transition in fsa4re.transitions:
        print "\t%s" % (str(transition))

    dotstring = fsa4re.toDotString()
    print
Esempio n. 5
0
import reCompiler
import random

c = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'

fsm = reCompiler.compileRE('Hi-[0-9][0-9][0-9][0-9]', minimize = 1)
states = fsm.states
transitions = fsm.transitions

useless_states = [random.randint(0, 0xffffffff) for _ in range(random.randint(50, 100))]
states += useless_states

# We don't want to have dead nodes, so let's create transition
deadnodes = set(useless_states)
while len(deadnodes) != 0:
    s, d, t = random.choice(states), random.choice(states), random.choice(c)
    transitions += [(s, d, t)]
    deadnodes -= set([s])

# To obfuscate we can use random state number
dic_states = dict(
    (i, random.randint(0, 0xffffffff)) for i in states
)

random.shuffle(states)
assert(len(dic_states.values()) == len(set(dic_states.values())))

print 'unsigned char checkinput(char *p){\nunsigned int state = %d;\nwhile(*p)\n{\nswitch(state)\n{' % dic_states[fsm.initialState]

for i in states:
    if i in fsm.finalStates:
Esempio n. 6
0
'''
Created on Nov 11, 2014

@author: prasanna
'''
import FSA
from reCompiler import compileRE

if __name__ == '__main__':
    myFSA = compileRE('a(b|c*)')
    myFSA.view()
    
#     states = ['r1','r2']
#     alphabet = ['a','b']
#     transitions = [[]]
Esempio n. 7
0
'''
Created on Nov 11, 2014

@author: prasanna
'''
import FSA
from reCompiler import compileRE

if __name__ == '__main__':
    myFSA = compileRE('a(b|c*)')
    myFSA.view()

#     states = ['r1','r2']
#     alphabet = ['a','b']
#     transitions = [[]]
import reCompiler
import random

c = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'

fsm = reCompiler.compileRE('Hi-[0-9][0-9][0-9][0-9]', minimize=1)
states = fsm.states
transitions = fsm.transitions

useless_states = [
    random.randint(0, 0xffffffff) for _ in range(random.randint(50, 100))
]
states += useless_states

# We don't want to have dead nodes, so let's create transition
deadnodes = set(useless_states)
while len(deadnodes) != 0:
    s, d, t = random.choice(states), random.choice(states), random.choice(c)
    transitions += [(s, d, t)]
    deadnodes -= set([s])

# To obfuscate we can use random state number
dic_states = dict((i, random.randint(0, 0xffffffff)) for i in states)

random.shuffle(states)
assert (len(dic_states.values()) == len(set(dic_states.values())))

print 'unsigned char checkinput(char *p){\nunsigned int state = %d;\nwhile(*p)\n{\nswitch(state)\n{' % dic_states[
    fsm.initialState]

for i in states: