hackedteam/fuzzer-android

View on GitHub
trinity-android/gen_recursive.py

Summary

Maintainability
D
2 days
Test Coverage
import string
import os

struct_list = [
    "timeval",
    "timezone",
    "timex",
    "tms",
    "timespec",
    "itimerval",
    "sigevent",
    "itimerspec",
    "sched_param",
    "kexec_segment",
    "rusage",
    "siginfo",
    "statfs",
    "statfs64",
    "stat",
    "ustat",
    "stat64",
    "io_event",
    "iocb",
    "utimbuf",
    "iovec",
    "linux_dirent",
    "linux_dirent64",
    "sockaddr",
    "msghdr",
    "mmsghdr",
    "pollfd",
    "sel_arg_struct",
    "epoll_event",
    "new_utsname",
    "rlimit",
    "rlimit64",
    "msgbuf",
    "msqid_ds",
    "sembuf",
    "shmid_ds",
    "mq_attr",
    "__sysctl_args",
    "robust_list_head",
    "getcpu_cache",
    "perf_event_attr",
    "mmap_arg_struct",
    "file_handle"
]


head = "/***** Automatically generated by gen_recursive.c *********/\n\n#include <stdio.h>\n#include <time.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <sys/mman.h>\n#include <libxml/xmlwriter.h>\n#include <libxml/encoding.h>\n#include <sys/timex.h>\n#include <sys/times.h>\n#include <sched.h>\n#include <linux/kexec.h>\n#include <sys/time.h>\n#include <sys/resource.h>\n#include <sys/vfs.h>\n#include <sys/syscall.h>\n#include <linux/aio_abi.h>\n#include <unistd.h>\n#include <utime.h>\n#include <dirent.h>\n#include <stdlib.h>\n#include <netinet/in.h>\n#include <poll.h>\n#include <sys/epoll.h>\n#include <sys/utsname.h>\n#include <sys/msg.h>\n#include <sys/ipc.h>\n#include <linux/shm.h>\n#include <linux/futex.h>\n#include <linux/fs.h>\n\n#include \"struct_analyze.h\"\n#include \"syscall.h\"\n\nint nullfd = 0;\n\nvoid struct_recursive_analyze(void *arg_ptr, enum struct_argtype struct_argtype, xmlTextWriterPtr writer) {\n\nif(arg_ptr == NULL)\nreturn;\nif(nullfd == 0)\nnullfd = open(\"/dev/random\", O_WRONLY);\n\nswitch(struct_argtype) {\n"


f = open("test.c", "w")
f.write(head)

for i in struct_list:
    f.write("struct " + i + " " + i + "_s;\n")
    f.write("struct " + i + " *" + i + "_p;\n\n")


for i in struct_list:
    f.write("case STRUCT_ARG_" + i + ":\n")
    f.write("if(write(nullfd, (void *) arg_ptr, sizeof(" + i + "_s"  +")) < 0) {\n")
    f.write("xmlTextWriterWriteElement(writer, \"STRUCT_" + i + "\", \"unmapped\");\n")
    f.write("return;\n }\n\n")

    f.write(i + "_p = (struct " + i + " *) arg_ptr;\n")
    f.write("xmlTextWriterStartElement(writer, \"STRUCT_" + i + "\");\n")
    f.write("xmlTextWriterWriteBase64(writer, (char *) " + i + "_p, 0, sizeof(" + i + "_s));\n")
    f.write("xmlTextWriterEndElement(writer);\n\n")
    f.write("break;\n\n")
        

f.write("default:\nbreak;\n}\n}")
f.close()