Example #1
0
 def FindSinkFromMethodCode(self, target_method, sink_method, deepmatch = False):
     """
     Judge whether a sink is located in a specific method
     
     Parameters
     ----------
     target_method: an EncodedMethod
     sink_method: a sink method set
     deepmatch: a boolean flag determine whether it needs deep match
     
     Return
     -----------
     TYPE: True or False
     """
     if target_method.get_code() != None:
         nb = idx= 0
         code = []
         for i in target_method.get_code().code.get_instructions():
             code.append("%-8d(%08x)" % (nb, idx)) 
             code.append("%s %s" %(i.get_name(), i.get_output(idx)))
             idx += i.get_length()
             nb += 1                
         #if code.find(sink_method["method"])!= -1:
         newcode="".join(code)
         #guo 0329            
         #print newcode
         if self.SinkMatchCode(sink_method, newcode, deepmatch):
             return True
     return False
 def get_register_methods(self):
     #for DVMBasicMethodBlock in mx.basic_blocks.gets():
         #ins_idx = DVMBasicMethodBlock.start
         #block_id = hashlib.md5(sha256 + DVMBasicMethodBlock.get_name()).hexdigest()       
         #for DVMBasicMethodBlockInstruction in DVMBasicMethodBlock.get_instructions():  
             ##print DVMBasicMethodBlockInstruction.get_output() +"\n"
             #if DVMBasicMethodBlockInstruction.get_output().find(sink_name)>-1:
                 ##print "sink_name: " + sink_name+"\n"
                 #ret_block.append(DVMBasicMethodBlock)        
                 ##operands = DVMBasicMethodBlockInstruction.get_operands(0)        
             #ins_idx += DVMBasicMethodBlockInstruction.get_length()
             ##last_instru = DVMBasicMethodBlockInstruction    
         #return ret_block   
     ret_reg = []
     for cls in self.dvm.classes.class_def:
         for j in cls.get_methods():
             if j.get_code()!= None:
                 nb = idx= 0
                 code = []                    
                 for i in j.get_code().code.get_instructions():
                     #code.append("%-8d(%08x)" % (nb, idx)) 
                     #code.append("%s %s" %(i.get_name(), i.get_output(idx)))
                     code.append("%-8d(%08x) %s %s" % (nb, idx, i.get_name(), i.get_output(idx)))                   
                     idx += i.get_length()
                     nb += 1   
                 #newcode="".join(code)
                 
                 for reg in AndroConf.register_vectors:
                     for c in code:            
                         if self.match_reg(c,reg):
                             #tmp_list = method_code_list[0:method_code_list.index(c)-1].reverse()
                             #for t in tmp_list:                    
                                 #if t.find(reg["key_para"])>-1:
                                     #listener = t
                                     #methods_f = self.get_invokee_callbacks(listener)
                             methods_f = self.get_invokee_callbacks(cls, reg)
                             methods_b = self.get_invoker_callbacks(j)                    
                     
                             ret_reg.append({"method_b":methods_b,"register":reg,"methods_f": methods_f})
     return ret_reg               
def dumpstacks():
    id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
    code = []
    for threadId, stack in sys._current_frames().items():
        code.append("\n# Thread: %s(%d)" % (id2name.get(threadId,""), threadId))
        for filename, lineno, name, line in traceback.extract_stack(stack):
            code.append('File: "%s", line %d, in %s' % (filename, lineno, name))
            if line:
                code.append("  %s" % (line.strip()))
    print "\n".join(code)
Example #4
0
def dumpstacks():
    id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
    code = []
    for threadId, stack in sys._current_frames().items():
        code.append("\n# Thread: %s(%d)" %
                    (id2name.get(threadId, ""), threadId))
        for filename, lineno, name, line in traceback.extract_stack(stack):
            code.append('File: "%s", line %d, in %s' %
                        (filename, lineno, name))
            if line:
                code.append("  %s" % (line.strip()))
    print("\n".join(code))
Example #5
0
def dumpstacks(signal, frame):
    """Returns the traceback on all threads running IdeaLoom"""
    id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
    code = []
    for threadId, stack in sys._current_frames().items():
        code.append("\n# Thread: %s(%d)" %
                    (id2name.get(threadId, ""), threadId))
        for filename, lineno, name, line in traceback.extract_stack(stack):
            code.append('File: "%s", line %d, in %s' %
                        (filename, lineno, name))
            if line:
                code.append("  %s" % (line.strip()))
    sys.stderr.write("\n".join(code) + "\n\n")
Example #6
0
def printstacks():
    print >> sys.stderr, "\n*** STACKTRACE - START ***\n"
    code = []
    for threadId, stack in sys._current_frames().items():
        code.append("\n# ThreadID: %s" % threadId)
        for filename, lineno, name, line in traceback.extract_stack(stack):
            code.append('File: "%s", line %d, in %s' % (filename, lineno, name))
            if line:
                code.append("  %s" % (line.strip()))

    for line in code:
        print >> sys.stderr, line
    print >> sys.stderr, "\n*** STACKTRACE - END ***\n"
Example #7
0
    def printall():
        print("\n*** STACKTRACE - START ***\n", file=sys.stderr)
        code = []
        for threadid, stack in sys._current_frames().items():
            code.append("\n# ThreadID: %s" % threadid)
            for filename, lineno, name, line in traceback.extract_stack(stack):
                code.append('File: "%s", line %d, in %s' %
                            (filename, lineno, name))
                if line:
                    code.append("  %s" % (line.strip()))

        for line in code:
            print(line, file=sys.stderr)
        print("\n*** STACKTRACE - END ***\n", file=sys.stderr)
Example #8
0
def _sigusr1_handler(sig, frame):
    id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
    code = []
    for threadId, stack in sys._current_frames().items():
        code.append("\n# Thread: %s(%d)" % (id2name.get(threadId,""), threadId))
        for filename, lineno, name, line in traceback.extract_stack(stack):
            code.append('File: "%s", line %d, in %s' % (filename, lineno, name))
            if line:
                code.append("  %s" % (line.strip()))
    print("\n".join(code))

    d={'_frame':frame}         # Allow access to frame object.
    d.update(frame.f_globals)  # Unless shadowed by global
    d.update(frame.f_locals)
Example #9
0
def check_for_full_house(cards):
    '''check for full house, 3 element code, FH, trips rank, pair rank'''
    code = [0]

    rank_count = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    for c in cards:
        rank_count[c.return_rank() - 2] += 1

    for r in range(len(rank_count)):
        if rank_count[r] == 3:  # we have trips
            for p in range(len(rank_count)):
                if rank_count[p] == 2:  # we have a pair, thus, FH
                    code.clear()
                    code.append(7)  #code for full house
                    code.append(r + 2)  #rank of trips
                    code.append(p + 2)  #rank of pair
                    return code

    return [0]
Example #10
0
def check_for_quads(cards):
    '''checking for 4 of a kind, 3 element code. quads, quads rank, kicker rank'''
    code = [0]

    rank_count = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    for c in cards:
        rank_count[c.return_rank() - 2] += 1

    for r in range(len(rank_count)):
        if rank_count[r] == 4:  # we have quads
            code.clear()
            code.append(8)  #code for quads
            code.append(r + 2)  #rank of quads

            for r in range(len(rank_count)):
                if rank_count[r] == 1:  #we have found the kicker
                    code.append(r + 2)
                    return code

    return [0]  #no quqds
Example #11
0
print random.random()
print random.random()*10
#生成0-1之间的随机数
print random.randint(1,5)
#生成1-5间的整形随机数

print random.randrange(1,3)
#生成1和2,不会生成3,整形

print random.randint(100000,999999)
#生成6位随机数

code = []
for i in range(6):
    if i == random.randint(1,5):
        code.append(str(random.randint(1,5))) 
    else:
        tmp = random.randint(65,90)
        code.append(chr(tmp))
print code
print ''.join(code)

#生成六位随机数,数字字符混合
#列表转字符串,非常有用,''.join(code)

import hashlib

hash = hashlib.md5()
hash.update('admin')
print hash.hexdigest()
print hash.digest()
Example #12
0
def read_hand(cards, lower_limit=0, possibilities=[True, True, True]):
    '''read a poker hand. will search for hands >= to lower limit. will not search for hands lower
       than lower limit parameter. if searching is ended prematurely due to the lower limit parameter, 
       a list containing -1 will be returned. the "cards" parameter expects a list of exactly 5 card instances'''

    cards = sort_cards(
        cards)  #sort cards first, descending order based on rank

    if possibilities[1]:
        code = check_for_straight_flush(cards)
        if code[0] == 9:
            return code

    #if we dont need to check for any hands lower than straight flush
    if lower_limit == 9:
        return [-1]

    if possibilities[0]:
        code = check_for_quads(cards)
        if code[0] == 8:
            return code

    #if we dont need to check for any hands lower than quads
    if lower_limit == 8:
        return [-1]

    if possibilities[0]:
        code = check_for_full_house(cards)
        if code[0] == 7:
            return code

    #if we dont need to check for any hands lower than full house
    if lower_limit == 7:
        return [-1]

    if possibilities[1]:
        code = check_for_flush(cards)
        if code[0] == 6:
            return code

    #if we dont need to sheck for any hands lower than flush
    if lower_limit == 6:
        return [-1]

    code = check_for_straight(cards)
    if code[0] == 5:
        return code

    #if we don't need to check for any hands lower than straight
    if lower_limit == 5:
        return [-1]

    code = check_for_trips(cards)
    if code[0] == 4:
        return code

    #if we don't need to check for any hands lower than trips
    if lower_limit == 4:
        return [-1]

    code = check_for_two_pair(cards)
    if code[0] == 3:
        return code

    #if we don't need to check for any hands lower than 2 pair
    if lower_limit == 3:
        return [-1]

    code = check_for_pair(cards)
    if code[0] == 2:
        return code

    #if we don't need to check for any hands lower than 1 pair
    if lower_limit == 2:
        return [-1]

    #if we get here, the hand is 'high card'
    code.clear()
    code.append(1)  #code for high card

    for c in cards:
        code.append(c.return_rank())  #value of high card

    return code
Example #13
0
print random.random()
print random.random() * 10
#生成0-1之间的随机数
print random.randint(1, 5)
#生成1-5间的整形随机数

print random.randrange(1, 3)
#生成1和2,不会生成3,整形

print random.randint(100000, 999999)
#生成6位随机数

code = []
for i in range(6):
    if i == random.randint(1, 5):
        code.append(str(random.randint(1, 5)))
    else:
        tmp = random.randint(65, 90)
        code.append(chr(tmp))
print code
print ''.join(code)

#生成六位随机数,数字字符混合
#列表转字符串,非常有用,''.join(code)

import hashlib

hash = hashlib.md5()
hash.update('admin')
print hash.hexdigest()
print hash.digest()