예제 #1
0
def process_loot(loot):
    try:
        loot = map(lambda x: x[1:], loot)
        loot_amounts = dict()
        for i in xrange(len(loot)):
            lootables = loot[i].split()
            if not lootables:
                #print 'skipping strange loot message: ', lootables
                continue
            loot_start = lootables[0]
            if loot_start.isdigit():
                loot[i] = loot[i][loot[i].find(' ') + 1:]
                if loot[i] in pluralMap:
                    loot[i] = pluralMap[loot[i]]
                else:
                    for suffix in plural_suffixes:
                        if loot[i].endswith(suffix):
                            loot[i].replace(suffix, plural_suffixes[suffix])
                            break
                    else:
                        for word in plural_words:
                            if loot[i].startswith(word):
                                loot[i].replace(word, plural_words[word])
                                break
                loot_amounts[loot[i]] = loot_start
            else:
                if loot_start in ['a', 'an']:
                    loot[i] = loot[i][loot[i].find(' ') + 1:]
                loot_amounts[loot[i]] = '0'
        return loot, loot_amounts
    except:
        print 'loot parser error!'
        stacktrace()
예제 #2
0
def process_loot(loot):
    try:
        loot = map(lambda x: x[1:], loot)
        loot_amounts = dict()
        for i in xrange(len(loot)):
            lootables = loot[i].split()
            if not lootables:
                #print 'skipping strange loot message: ', lootables
                continue
            loot_start = lootables[0]
            if loot_start.isdigit():
                loot[i] = loot[i][loot[i].find(' ') + 1:]
                if loot[i] in pluralMap:
                    loot[i] = pluralMap[loot[i]]
                else:
                    for suffix in plural_suffixes:
                        if loot[i].endswith(suffix):
                            loot[i].replace(suffix, plural_suffixes[suffix])
                            break
                    else:
                        for word in plural_words:
                            if loot[i].startswith(word):
                                loot[i].replace(word, plural_words[word])
                                break
                loot_amounts[loot[i]] = loot_start
            else:
                if loot_start in ['a', 'an']:
                    loot[i] = loot[i][loot[i].find(' ') + 1:]
                loot_amounts[loot[i]] = '0'
        return loot, loot_amounts
    except:
        print 'loot parser error!'
        stacktrace()
예제 #3
0
def read_process_memory(pid):
    global heap
    try:
        mem_file = open('/proc/%s/mem' % pid, 'r')
    except IOError:
        quit()  # Tibia client closed
    item_drops = []
    exp = dict()
    try:
        if not heap:
            start_new_thread(update_heap, (pid, ))
            while not heap:
                sleep(0.2)
        iniT = time()
        start, end = heap
        mem_file.seek(start)
        try:
            chunk = mem_file.read(end - start)  # read region contents
        except:
            chunk = ''
        if messages(chunk):
            for log_message in messages(chunk):
                if log_message[5:14] == ' Loot of ':
                    global cached_loot_messages
                    if log_message in cached_loot_messages:
                        continue
                    cached_loot_messages.add(log_message)
                    item_drops.append(log_message)
                elif log_message[5:17] == ' You gained ':
                    t = log_message[0:5]
                    try:
                        e = int(log_message[17:log_message.find(' ')])
                        if t not in exp: exp[t] = e
                        else: exp[t] += e
                    except:
                        pass
    except KeyboardInterrupt:
        return dict()
    except:
        print 'Error while reading memory!'
        stacktrace()
        return
    finally:
        mem_file.close()
        reads.append(time() - iniT)

    return_values = dict()
    return_values['item_drops'] = item_drops
    return_values['experience'] = exp
    return return_values
예제 #4
0
def read_process_memory(pid):
	global heap
	mem_file = open('/proc/%s/mem' % pid, 'r')
	item_drops = []
	exp = dict()
	try:
		if not heap:
			start_new_thread(update_heap, (pid,))
			while not heap:
				sleep(0.2)
		start, end = heap
		mem_file.seek(start)
		try:
			chunk = mem_file.read(end - start)  # read region contents
		except:
			chunk = ''
		if messages(chunk):
			for log_message in messages(chunk):
				if log_message[5:14] == ' Loot of ':
					global cached_loot_messages
					if log_message in cached_loot_messages:
						continue
					cached_loot_messages.add(log_message)
					item_drops.append(log_message)
				elif log_message[5:17] == ' You gained ':
					t = log_message[0:5]
					try:
						e = int(log_message[17:log_message.find(' ')])
						if t not in exp: exp[t] = e
						else: exp[t] += e
					except: pass
	except KeyboardInterrupt:
		return dict()
	except:
		print 'Error while reading memory!'
		stacktrace()
		return
	finally:
		mem_file.close()

	return_values = dict()
	return_values['item_drops'] = item_drops
	return_values['experience'] = exp
	return return_values
예제 #5
0
def main():
    global notifier
    sockfile = '/tmp/flarelyzer.sock'
    print 'Initializing memscan...'
    try:
        notifier = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        notifier.connect(sockfile)
        print 'connected to notification server!'
        tibiaPID = check_output(['pgrep', 'Tibia']).split('\n')[0]
        print 'Client PID: ' + str(tibiaPID)
    except socket.error:
        print 'Unable to connect to notification agent!'
    except CalledProcessError:
        print 'Tibia client not found!'
        quit(1)
    except:
        print 'Unexpected error'
        stacktrace()
    else:
        # we're good to go
        print '===Memory analyzer started==='
        try:
            notifier.sendall('ATTACHED')
            while True:
                res = read_process_memory(tibiaPID)
                if not res:
                    quit()
                for full_msg in res['item_drops']:
                    notifier.sendall(full_msg)
                    notifier.recv(8)
                notifier.sendall('NEXT')
                response = notifier.recv(8)
                if response == 'QUIT':
                    raise KeyboardInterrupt
                sleep(0.1)
        except KeyboardInterrupt:
            pass
        except Exception:
            stacktrace()
    print '==Aborting=='
    quit()
예제 #6
0
def main():
	global notifier
	sockfile = '/tmp/flarelyzer.sock'
	print 'Initializing memscan...'
	try:
		notifier = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
		notifier.connect(sockfile)
		print 'connected to notification server!'
		tibiaPID = check_output(['pgrep', 'Tibia']).split('\n')[0]
		print 'Client PID: ' + str(tibiaPID)
	except socket.error:
		print 'Unable to connect to notification agent!'
	except CalledProcessError:
		print 'Tibia client not found!'
	except:
		print 'Unexpected error'
		stacktrace()
	else:
		# we're good to go
		print '===Memory analyzer started==='
		notifier.sendall('ATTACHED')
		while True:
			try:
				res = read_process_memory(tibiaPID)
				if not res:
					quit()
				for full_msg in res['item_drops']:
					notifier.sendall(full_msg)
					notifier.recv(8)
				notifier.sendall('NEXT')
				response = notifier.recv(8)
				if response == 'QUIT':
					quit()
				sleep(0.1)
			except:
				stacktrace()
				quit()
			sleep(0.1)
	print '==Aborting=='
	exit(1)
예제 #7
0
            notify('Flarelyzer', 'Started successfully!')
            continue
        elif full_msg == 'NEXT':
            continue
        typeInd = full_msg.find('Loot of ') + 8
        monsterInd = typeInd
        if full_msg.find('a', typeInd) == -1:  # Not a valid loot message
            #print 'skipping invalid loot message: ', full_msg
            continue
        elif full_msg[typeInd] == 'a':  # not an 'a' if its the loot of a boss
            monsterInd = typeInd + 2
        monster = full_msg[monsterInd:full_msg.rfind(':')]
        loot = full_msg[full_msg.rfind(':') + 1:].split(',')
        loot, loot_amounts = process_loot(loot)
        loot = map(str.lower, loot)
        valuables = interesting.intersection(loot)
        if valuables:
            lootmsg = ''
            for v in valuables:
                if loot_amounts[v] != '0':
                    lootmsg += loot_amounts[v] + ' '
                lootmsg += v.title() + ', '
            else:
                lootmsg = lootmsg[:-2]
            notify(monster.title(), lootmsg)
except:
    print 'Notification agent error!'
    stacktrace()
finally:
    quit()
예제 #8
0
            notify('Flarelyzer', 'Started successfully!')
            continue
        elif full_msg == 'NEXT':
            continue
        typeInd = full_msg.find('Loot of ') + 8
        monsterInd = typeInd
        if full_msg.find('a', typeInd) == -1:  # Not a valid loot message
            #print 'skipping invalid loot message: ', full_msg
            continue
        elif full_msg[typeInd] == 'a':  # not an 'a' if its the loot of a boss
            monsterInd = typeInd + 2
        monster = full_msg[monsterInd:full_msg.rfind(':')]
        loot = full_msg[full_msg.rfind(':') + 1:].split(',')
        loot, loot_amounts = process_loot(loot)
        loot = map(str.lower, loot)
        valuables = interesting.intersection(loot)
        if valuables:
            lootmsg = ''
            for v in valuables:
                if loot_amounts[v] != '0':
                    lootmsg += loot_amounts[v] + ' '
                lootmsg += v.title() + ', '
            else:
                lootmsg = lootmsg[:-2]
            notify(monster.title(), lootmsg)
except:
    print 'Notification agent error!'
    stacktrace()
finally:
    quit()