Ejemplo n.º 1
0
def generate_bugcheck_items(config, context, file):
    with open(file) as fp:
        lines = fp.readlines()
        line_index = -1

        rexp = r'#define\s*(\S+)\s*\(\(ULONG\)([x0-9abcdefABCDEF]+)L\).*$'

        for line in lines:
            line_index += 1

            m = re.search(rexp, line)
            if not m:
                continue

            name = m.group(1)
            value = m.group(2)

            if name.lower() in config.Maps["bugcheckdescr"].keys():
                description = config.Maps["bugcheckdescr"][name.lower()]
            else:
                ok, description = allstat.extract_description(
                    lines, line_index)
                if not ok:
                    continue

            allstat.append_status_item(context, name, value, description,
                                       "bugcodes.h", "AS_OS_WINDOWS")

    print("Processed {}. {} items added".format(file, len(context["items"])))
    return context
Ejemplo n.º 2
0
def generate_status_items(config, context, file):
    with open(file) as fp:
        lines = fp.readlines()
        line_index = -1

        rexp = r'#define\s+(\S+)\s+(\d+)L\s*(//.*)?\n?$'

        for line in lines:
            line_index += 1

            m = re.search(rexp, line)
            if not m:
                continue

            name = m.group(1)
            value = m.group(2)
            ok, description = allstat.extract_description(lines, line_index)
            if not ok:
                continue

            allstat.append_status_item(context, name, value, description,
                                       "winerror.h", "AS_OS_WINDOWS")

    print("Processed {}. {} items added".format(file, len(context["items"])))
    return context
Ejemplo n.º 3
0
def process_ioreturn(config, context, file):

    with open(file) as fp:
        lines = fp.readlines()
        line_index = -1

        rexp = r'#define\s*(kIO\S+)\s+iokit_common_err\((0x[\da-fA-F]+)\)\s*//\s+(.*)$'
        src = 'IOReturn.h'

        name = ""
        for line in lines:
            line_index += 1
                
            m = re.search(rexp, line)
            if not m:
                continue

            name = m.group(1)
            value = allstat.codestr2int(m.group(2)) + 0xE0000000
            value = "0x{0:08X}".format(value & 0xFFFFFFFF)            
            description = m.group(3).rstrip()

            allstat.append_status_item(context, name, value, description, src, "AS_OS_MAC")

    print("Processed {}. {} items added".format(file, len(context["items"])))
    return context
Ejemplo n.º 4
0
def process_os_return(config, context, file, rexp, base):
    incfile = os.path.basename(file)

    with open(file) as fp:
        lines = fp.readlines()
        line_index = -1

        for line in lines:
            line_index += 1
                
            m = re.search(rexp, line)
            if not m:
                continue

            name = m.group(1)

            value = allstat.codestr2int(m.group(2)) + base
            value = "0x{0:08X}".format(value & 0xFFFFFFFF)

            ok, description = extract_os_return_description(lines, line_index)
            if not ok:
                continue

            allstat.append_status_item(context, name, value, description, incfile, "AS_OS_MAC")

    print("Processed {}. {} items added".format(file, len(context["items"])))
    return context
Ejemplo n.º 5
0
def generate_status_items(config, context, file):
    initial_count = len(context["items"])

    with open(file) as fp:
        lines = fp.readlines()
        line_index = -1

        rexp = [
            r'#define\s+(\S+)\s*\(\(HRESULT\)([x0-9abcdefABCDEF]+)L\).*$',
            r'#define\s+(\S+)\s*\_HRESULT_TYPEDEF_\(([x0-9abcdefABCDEF]+)L\).*$',
            r'#define\s+(\S+)\s*\_NDIS_ERROR_TYPEDEF_\(([x0-9abcdefABCDEF]+)L\).*$'
        ]

        for line in lines:
            line_index += 1

            for r in rexp:
                m = re.search(r, line)
                if m:
                    break
            if not m:
                continue

            name = m.group(1)
            value = m.group(2)

            if not value.startswith("0x"):
                continue

            if name.startswith("NOT_AN_ERROR") or name == "NOT_N_PARSE_ERROR":
                continue

            ok, description = allstat.extract_description(lines, line_index)
            if not ok:
                continue

            source = os.path.basename(file)
            if source.lower() in config.Maps["hpp2source"].keys():
                source = config.Maps["hpp2source"][source.lower()]

            allstat.append_status_item(context, name, value, description,
                                       source, "AS_OS_WINDOWS")

    added = len(context["items"]) - initial_count
    if added:
        print("Processed {}. {} items added".format(file, added))

    return context
Ejemplo n.º 6
0
def process_kern_return(config, context, file):
    incfile = os.path.basename(file)

    with open(file) as fp:
        lines = fp.readlines()
        line_index = -1

        rexp = r'#define\s*(KERN_\S+)\s*(\d+)\s*$'
        rcms = r'\s*/\*\s*(.*)$'
        rcmc = r'\s*\*\s*(.*)$'
        comm = False

        name = ""
        for line in lines:
            line_index += 1
                
            if re.search(r'^(\s*)$', line) or re.search(r'^\s*\*/\s*$', line):
                name = ""
                comm = False
                continue

            if name:
                m = re.search(rcms if not comm else rcmc, line)
                if m:
                    comm = True
                    descr = m.group(1).translate(trans)
                    m = re.search(r'(.*)\s+\*/$', descr)
                    if m:
                        descr = m.group(1)

                    allstat.append_item_description(context, name, 'AS_OS_MAC', descr)
                    continue

            m = re.search(rexp, line)
            if not m:
                continue

            comm = False
            name = m.group(1)
            value = m.group(2)

            allstat.append_status_item(context, name, value, "", incfile, "AS_OS_MAC")

    print("Processed {}. {} items added".format(file, len(context["items"])))
    return context
Ejemplo n.º 7
0
def read_status_items(config, context, file):

    with open(file) as fp:
        lines = fp.readlines()

        #  {100, "HTTP_STATUS_CONTINUE", "100 Continue"},
        rexp = r'\s*\{\s*(\d+)\s*,\s*\"([^\"]*)\"\s*,\s*\"([^\"]*)\"\s*,\s*\"([^\"]*)\"\s*\}\s*,\s*\n$'

        for line in lines:
            m = re.search(rexp, line)
            if not m:
                continue

            value = m.group(1)
            name = m.group(2)
            description = m.group(3)
            source = m.group(4)

            allstat.append_status_item(context, name, value, description,
                                       source, "AS_OS_ANY")

    return context
Ejemplo n.º 8
0
def generate_status_items(config, context, file):
    with open(file) as fp:
        lines = fp.readlines()
        line_index = -1

        rexp = r'^\s+(ippSts\S+)\s*=\s*([\+\-\d]+)\s*,?\s*/\*\s*(.*)\*/\s*$'

        for line in lines:
            line_index += 1

            m = re.search(rexp, line)
            if not m:
                continue

            comm = False
            name = m.group(1)
            value = m.group(2)
            descr = m.group(3).strip()

            allstat.append_status_item(context, name, value, descr,
                                       "ippdefs.h", "AS_OS_ANY")

    print("Processed {}. {} items added".format(file, len(context["items"])))
    return context
Ejemplo n.º 9
0
def generate_errno_items(config, context, file):
    location = os.path.dirname(file)
    as_os = "AS_OS_" + os.path.basename(location).upper()
    source = "errno.h"

    if "os_count" in context:
        context["os_count"] += 1
    else:
        context["os_count"] = 1

    with open(file) as fp:
        lines = fp.readlines()

        rexp = r'\s*#define\s+(E\S+)\s+(\d+)\s*(/\*.*\*/)?\s*\n$'

        for line in lines:
            m = re.search(rexp, line)
            if not m:
                continue

            value = m.group(2)
            name = m.group(1)
            description = m.group(3)

            if description == None:
                description = ""
            else:
                rexp2 = r'/\*\s*(.*)\s*\*/\s*$'
                m = re.search(rexp2, description)
                if m:
                    description = m.group(1).rstrip()

            allstat.append_status_item(context, name, value, description,
                                       source, as_os)

    return context
Ejemplo n.º 10
0
def process_message(config, context, file):
    incfile = os.path.basename(file)

    with open(file) as fp:
        lines = fp.readlines()
        line_index = -1

        rexp = r'#define\s*(MACH_\S+)\s+(0x[\da-fA-F]+)\s*$'
        comm = r'^/\*\s*(.*)\s+\*/\s*$'

        name = ""
        for line in lines:
            line_index += 1
                
            if name:
                m = re.search(comm, line)
                if m:
                    descr = m.group(1)
                    allstat.append_item_description(context, name, 'AS_OS_MAC', descr.translate(trans))
                    continue

            m = re.search(rexp, line)
            if not m:
                continue

            # Skip all matches till MACH_MSG_SUCCESS
            if not name and m.group(1) != "MACH_MSG_SUCCESS":
                continue

            name = m.group(1)
            value = m.group(2)

            allstat.append_status_item(context, name, value, "", incfile, "AS_OS_MAC")

    print("Processed {}. {} items added".format(file, len(context["items"])))
    return context