Exemplo n.º 1
2
def gen_syscalls(sct_file, x32=False):
    """
        Generate an Array of syscalls

        sct_file: File handle of the name table
        x32: the name table is 32 bit syscalls?
    """

    tags = CTags('tags')
    entry = TagEntry()
    sys_calls = []
    i = 0

    for line in sct_file:
        if line.startswith("#"):
            continue
        parts = line.split()
        if (len(parts) > 3 and parts[0] >= '0'):
            name = parts[3].encode("utf-8")
            if tags.find(entry, name,
                         ctags.TAG_FULLMATCH | ctags.TAG_OBSERVECASE):
                found_sym = False
                while (not found_sym):
                    if (entry["kind"].decode("utf-8") == "prototype"):
                        found_sym = True
                        details = {
                            "number": {
                                "int": i,
                                "hex": ("%0#4x" % (i))
                            },
                            "name": name,
                            "parameters": entry[b"signature"]
                        }
                        if (entry[b"signature"] != "(void)"):
                            sig = entry[b"signature"].decode("utf-8").strip(
                                '()').split(',')
                        else:
                            sig = []
                        regs = {}

                        details["parameters_details"] = []
                        if (len(sig) < (7 if x32 else 8)):
                            for param in sig:
                                par = param.strip()
                                par_def = ""

                                if (param.find("struct") != -1):
                                    type_match = re.search(
                                        "struct (\w+)", param)
                                    if (type_match):
                                        par_entry = TagEntry()
                                        if (tags.find(
                                                par_entry,
                                                type_match.group(1).encode(
                                                    "utf-8"),
                                                ctags.TAG_FULLMATCH
                                                | ctags.TAG_OBSERVECASE)):
                                            if (par_entry[b'kind'] == "struct"
                                                ):
                                                par_def = {
                                                    'file':
                                                    par_entry['file'],
                                                    'line':
                                                    int(par_entry['lineNumber']
                                                        )
                                                }
                                details["parameters_details"].append({
                                    'type':
                                    par,
                                    'def':
                                    par_def
                                })
                        else:
                            details["parameters_details"].append({
                                "type": "param addr*",
                                "def": par_def
                            })
                        remaining = (5 if x32 else 6) - \
                            len(details["parameters_details"])
                        for x in range(0, remaining):
                            details["parameters_details"].append("")

                        pattern = "SYSCALL_DEFINE%d(%s" % (
                            len(sig), name.decode("utf-8").replace("sys_", ""))
                        search = "SYSCALL_DEFINE%d" % (len(sig))
                        if tags.find(
                                entry, search.encode("utf-8"),
                                ctags.TAG_FULLMATCH | ctags.TAG_OBSERVECASE):
                            found = False
                            while (not found):
                                if (entry["pattern"].decode("utf-8").find(
                                        pattern) >= 2):
                                    # details['found'] = entry['pattern']
                                    details["definition"] = {
                                        "file": entry["file"],
                                        "lineno": int(entry['lineNumber'])
                                    }
                                    found = True
                                    break
                                if (not tags.findNext(entry)):
                                    details["definition"] = {
                                        "file": "",
                                        "lineno": ""
                                    }
                                    break
                        else:
                            details["definition"] = {"file": "", "lineno": ""}
                        sys_calls.append(details)
                    else:
                        if (not tags.findNext(entry)):
                            sys_calls.append([i].append([""] *
                                                        (7 if x32 else 8)))
                            break
            i += 1
        else:
            details = {
                "number": {
                    "int": i,
                    "hex": ("%0#4x" % (i))
                },
                "name": "not implemented",
                "parameters": "",
                "parameters_details": {},
                "definition": {
                    "file": "",
                    "lineno": ""
                }
            }
            sys_calls.append(details)
            i += 1

    return sys_calls
Exemplo n.º 2
2
					if(not is_ptregs):
						pattern = "SYSCALL_DEFINE%d(%s"%(len(sig), name.replace("sys_", ""))
						search = "SYSCALL_DEFINE%d"%(len(sig))
					else:
						pattern = name
						search = name
					if tags.find(entry, search, ctags.TAG_FULLMATCH | ctags.TAG_OBSERVECASE):
						found = False
						while(found == False):
							if(entry['pattern'].find(pattern) == 2):
								#details['found'] = entry['pattern']
								details.append(entry['file'])
								details.append(int(entry['lineNumber']))
								found = True
								break
							if(not tags.findNext(entry)):
								details.append("not found")
								details.append("")
								break
					else:
						details.append("not found")
						details.append("")
					sys_calls.append(details)
				else:
					if(not tags.findNext(entry)):
						sys_calls.append([i, "", "", "", "", "", "", "", "", "", ""])
						break
		i += 1

print simplejson.dumps({'aaData': sys_calls}, indent="   ")
Exemplo n.º 3
1
except:
    sys.exit(1)

entry = TagEntry()
status = tagFile.setSortType(ctags.TAG_SORTED)
status = tagFile.first(entry)

print(tagFile["name"])
print(tagFile["author"])
print(tagFile["format"])
if status:
    print(entry["name"])
    print(entry["kind"])

if tagFile.find(entry, b"find", ctags.TAG_PARTIALMATCH | ctags.TAG_IGNORECASE):
    print("found")
    print(entry["lineNumber"])
    print(entry["pattern"])
    print(entry["kind"])

status = tagFile.findNext(entry)
if status:
    print(entry["lineNumber"])
    print(entry["pattern"])
    print(entry["kind"])

if tagFile.next(entry):
    print(entry["lineNumber"])
    print(entry["pattern"])
    print(entry["kind"])
Exemplo n.º 4
-1
def _find_github_tag(phenny, fname, types=("c", "f", "t")):
    import ctags
    from ctags import CTags, TagEntry

    t = CTags(phenny.config.tagfile)
    e = TagEntry()
    if not t.find(e, fname, ctags.TAG_PARTIALMATCH):
        phenny.say("Could not find any tags matching %s" % fname)
        return
    tags = [getTag(e)]
    while t.findNext(e):
        if e["kind"] in types:
            tags.append(getTag(e))

    newtags = []
    for e in tags:
        if e not in newtags: newtags.append(e)

    phenny.say("Found %s possible matches. Displaying %s" % (len(newtags), min(len(newtags), 5)))

    for entry in tags[:5]:
        url = "https://github.com/%s/tree/%s/%s" % (phenny.config.github_project, "master", entry["file"])
        if entry["lineNumber"]:
            url += "#%s" % entry["lineNumber"]
        url = shorten(url)
        phenny.say("%s (%s) found in %s: %s" % (entry["pattern"], entry["kind"], entry["file"], url))
Exemplo n.º 5
-1
                            len(sig), name.replace("sys_", ""))
                        search = "SYSCALL_DEFINE%d" % (len(sig))
                    else:
                        pattern = name
                        search = name
                    if tags.find(entry, search,
                                 ctags.TAG_FULLMATCH | ctags.TAG_OBSERVECASE):
                        found = False
                        while (found == False):
                            if (entry['pattern'].find(pattern) == 2):
                                #details['found'] = entry['pattern']
                                details.append(entry['file'])
                                details.append(int(entry['lineNumber']))
                                found = True
                                break
                            if (not tags.findNext(entry)):
                                details.append("not found")
                                details.append("")
                                break
                    else:
                        details.append("not found")
                        details.append("")
                    sys_calls.append(details)
                else:
                    if (not tags.findNext(entry)):
                        sys_calls.append(
                            [i, "", "", "", "", "", "", "", "", "", ""])
                        break
        i += 1

print simplejson.dumps({'aaData': sys_calls}, indent="   ")
Exemplo n.º 6
-1
    
   
entry = TagEntry()
status = tagFile.setSortType(ctags.TAG_SORTED)
status = tagFile.first(entry)

print(tagFile['name'])
print(tagFile['author'])
print(tagFile['format'])
if status:
    print(entry['name'])
    print(entry['kind'])
    
if tagFile.find(entry, b'find', ctags.TAG_PARTIALMATCH | ctags.TAG_IGNORECASE):
    print('found')
    print(entry['lineNumber'])
    print(entry['pattern'])
    print(entry['kind'])

status = tagFile.findNext(entry)
if status:
    print(entry['lineNumber'])
    print(entry['pattern'])
    print(entry['kind'])
    
if tagFile.next(entry):
    print(entry['lineNumber'])
    print(entry['pattern'])
    print(entry['kind'])
    
Exemplo n.º 7
-2
def generate(sysent_path, ctags_path, output_path):
    syscall_data = {}

    print(">>> Processing syscallent.h file...", file=sys.stderr, end=' ')
    with open(sysent_path, "r") as fin:
        for line in fin:
            line = line.strip()
            m = re.match(sysent_pattern, line)
            syscall = {}
            if m:
                syscall['num'] = int(m.group(1).strip())
                data = re.split(r'[",\t ]+', m.group(2).strip())
                syscall['name'] = data[3]
                syscall['flags'] = fix_flags(data[1])
                syscall['complete'] = False

                syscall_data[syscall['num']] = syscall

    print("done.", file=sys.stderr)

    print(">>> Processing kernel ctags to get the function signatures...", file=sys.stderr, end=' ')

    tags = CTags(ctags_path)
    entry = TagEntry()
    i = 0
    for k, syscall in syscall_data.items():
        if tags.find(entry, "sys_%s" % syscall['name'], ctags.TAG_FULLMATCH | ctags.TAG_OBSERVECASE):
            while entry['kind'] != 'prototype':
                if not tags.findNext(entry):
                    print("Could not find signature for {}".format(syscall['name']), file=sys.stderr)
                    break

            sig = process_signature(entry['signature'])
            syscall['signature_str'] = sig_to_str(sig)
            syscall['args'] = "\n".join([arg_template.format(**x) for x in sig])
            syscall['file_info'] = "{}:{}".format(entry['file'], entry['lineNumber'])
            syscall['complete'] = 'true'
        else:
            print("Could not find signature for {}".format(syscall['name']), file=sys.stderr)
            syscall['signature_str'] = "?"
            syscall['args'] = ''
            syscall['file_info'] = '?'
            syscall['complete'] = 'false'

    print("done.", file=sys.stderr)

    with open(output_path, "w") as fout:
        fout.write(out_start.format(includes="\n".join(includes)))
        i = 0
        for syscall in sorted(syscall_data.values(), key=lambda x: x['num']):
            if syscall['num'] != i:
                raise Exception("There's a gap in syscall table.")

            fout.write(item_template.format(**syscall))
            i += 1

        fout.write(out_end)