Skip to content

Commit

Permalink
automatic pypanda ppp header setup
Browse files Browse the repository at this point in the history
  • Loading branch information
off-by-1-error authored and lacraig2 committed Feb 18, 2024
1 parent a1b448b commit 5eb1339
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions panda/python/core/create_panda_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,22 @@ def expand_ppp_def(line):

# MANUAL curated list of PPP headers
define_clean_header(ffi, include_dir + "/syscalls_ext_typedefs.h")

define_clean_header(ffi, include_dir + "/callstack_instr.h")

define_clean_header(ffi, include_dir + "/hooks2_ppp.h")
define_clean_header(ffi, include_dir + "/proc_start_linux_ppp.h")
define_clean_header(ffi, include_dir + "/forcedexec_ppp.h")
define_clean_header(ffi, include_dir + "/stringsearch_ppp.h")
#define clean header for files ending in "_ppp.h"

import os
plugin_dirs = [os.path.join(PLUGINS_DIR, f) for f in os.listdir(PLUGINS_DIR) if os.path.isdir(os.path.join(PLUGINS_DIR, f))]

pattern = re.compile(r"_ppp\.h$")
for plugin_dir in plugin_dirs:
plugin_files = os.listdir(plugin_dir)

for plugin_file in plugin_files:
if pattern.search(plugin_file):
define_clean_header(ffi, f"{include_dir}/{os.path.basename(plugin_file)}")


# END PPP headers

define_clean_header(ffi, include_dir + "/breakpoints.h")
Expand Down Expand Up @@ -376,17 +385,29 @@ def main(install=False,recompile=True):
copy_ppp_header("%s/%s" % (PLUGINS_DIR+"/osi", "os_intro.h"))
pypanda_headers.append(os.path.join(INCLUDE_DIR_PYP, "os_intro.h"))

copy_ppp_header("%s/%s" % (PLUGINS_DIR+"/hooks2", "hooks2_ppp.h"))
# TODO: programtically copy anything that ends with _ppp.h
copy_ppp_header("%s/%s" % (PLUGINS_DIR+"/forcedexec", "forcedexec_ppp.h"))
copy_ppp_header("%s/%s" % (PLUGINS_DIR+"/stringsearch", "stringsearch_ppp.h"))
create_pypanda_header("%s/%s" % (PLUGINS_DIR+"/hooks2", "hooks2.h"))

copy_ppp_header("%s/%s" % (PLUGINS_DIR+"/proc_start_linux", "proc_start_linux_ppp.h"))
create_pypanda_header("%s/%s" % (PLUGINS_DIR+"/proc_start_linux", "proc_start_linux.h"))
create_pypanda_header("%s/%s" % (PLUGINS_DIR+"/cosi", "cosi.h"))

copy_ppp_header("%s/taint2/taint2.h" % PLUGINS_DIR)


#programtically copy anything that ends with _ppp.h

#for each subdirectory under PLUGINS_DIR
plugin_dirs = [os.path.join(PLUGINS_DIR, f) for f in os.listdir(PLUGINS_DIR) if os.path.isdir(os.path.join(PLUGINS_DIR, f))]

pattern = re.compile(r"_ppp\.h$") #matches strings ending with _ppp.h
for plugin_dir in plugin_dirs:
plugin_files = os.listdir(plugin_dir)

for plugin_file in plugin_files:
if pattern.search(plugin_file):
copy_ppp_header(f"{plugin_dir}/{plugin_file}")

#if the directory with the _ppp.h file also has a [plugin_name].h file, include it
header_filepath = f"{plugin_dir}/{os.path.basename(plugin_dir) + '.h'}"
if os.path.isfile(header_filepath):
create_pypanda_header(header_filepath)

with open(os.path.join(OUTPUT_DIR, "panda_datatypes.py"), "w") as pdty:
pdty.write("""from __future__ import print_function
\"\"\"
Expand Down

0 comments on commit 5eb1339

Please sign in to comment.