<commit_before>import idaapi
import idautils
import idc

def __get_range(seg):
    # get instruction range
    for s in idautils.Segments():
        if idc.SegName(s) == seg:
            start_ea = idc.SegStart(s)
            end_ea = idc.SegEnd(s)

    debug = True
    if debug:
        print 'Start: {}, End: {}'.format(hex(start_ea).strip('L'), hex(end_ea).strip('L'))

    return start_ea, end_ea

def get_func_symbols(): 
    symbols = []
    start_ea, end_ea = __get_range('.text')
    for func in idautils.Functions():
        name = GetFunctionName(func)
        # normal function
        if func > start_ea and func < end_ea:
            if 'sub_' in name: # skip default
                continue
            symbols.append({name: func})
    return symbols

def get_data_symbols():
    symbols = []

    start_ea, end_ea = __get_range('.rodata')
    ea = start_ea
    while ea < end_ea:
        symbols.append(idaapi.get_ea_name(ea))
        ea = NextHead(ea)

    start_ea, end_ea = __get_range('.bss')
    ea = start_ea
    while ea < end_ea:
        symbols.append(idaapi.get_ea_name(ea))
        ea = NextHead(ea)

    return symbols

print get_data_symbols()
        <commit_msg>add server to transmit symbol<commit_after>import idaapi
import idautils
import idc
import socket, sys
from thread import *
import cPickle

def __get_range(seg):
    for s in idautils.Segments():
        if idc.SegName(s) == seg:
            start_ea = idc.SegStart(s)
            end_ea = idc.SegEnd(s)

    return start_ea, end_ea

def get_func_symbols(): 
    symbols = []
    start_ea, end_ea = __get_range('.text')
    for ea in idautils.Functions():
        name = GetFunctionName(ea)
        # normal function
        if ea >= start_ea and ea < end_ea:
            if 'sub_' in name: # skip default
                continue
            symbols.append({name: ea})

    return symbols

def get_data_symbols():
    symbols = []
    start_ea, end_ea = __get_range('.rodata')
    ea = start_ea
    while ea < end_ea:
        name = idaapi.get_ea_name(ea)
        if name != '':
            symbols.append({name: ea})
        ea = NextHead(ea)

    start_ea, end_ea = __get_range('.bss')
    ea = start_ea
    while ea < end_ea:
        name = idaapi.get_ea_name(ea)
        if name != '':
            symbols.append({name: ea})
        ea = NextHead(ea)

    return symbols

def transmit_symbol():
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    except socket.error, msg:
        sys.stderr.write("[ERROR] %s\n" % msg[1])
        sys.exit(1)
     
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind(('', 50216))
    sock.listen(5)
     
    while True:
        (csock, adr) = sock.accept()
        cmd = csock.recv(1024).strip()
        if 'GETFUNCSYM' in cmd:
            csock.send(cPickle.dumps(get_func_symbols()))
        elif 'GETDATASYM' in cmd:
            csock.send(cPickle.dumps(get_data_symbols()))
        elif 'GETALLSYM' in cmd:
            csock.send(cPickle.dumps(get_func_symbols() + get_data_symbols()))

start_new_thread(transmit_symbol, ())
{'fraction_non_alphanumeric': 0.1166077738515901, 'fraction_numerical': 0.004176035978156119, 'mean_word_length': 2.3127659574468087, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6298809', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1077, 'n_words': 239}