/*
 * Copyright © 2023 Contrast Security, Inc.
 * See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
 */
/* THIS FILE WAS AUTOMATICALLY GENERATED BY HOOKSPY */
/* Python requires its own header to always be included first */
#define PY_SSIZE_T_CLEAN
#include <Python.h>

#include <contrast/assess/patches.h>
#include <contrast/assess/propagate.h>
#include <contrast/assess/scope.h>
#include <contrast/assess/utils.h>

typedef PyObject *(*fastcall_func)(PyObject *, PyObject *const *, Py_ssize_t);
typedef PyObject *(*fastcall_kwargs_func)(
    PyObject *, PyObject *const *, Py_ssize_t, PyObject *);

#define STRINGIO_READ_OFFSET 2
#define STRINGIO_READLINE_OFFSET 3

fastcall_func stringio_read_orig;
fastcall_func stringio_readline_orig;

HOOK_STREAM_FASTCALL(stringio_read, "read");
HOOK_STREAM_FASTCALL(stringio_readline, "readline");

int patch_stringio_methods(PyTypeObject *StreamType) {

    ADD_STREAM_HOOK(StreamType, stringio_read, STRINGIO_READ_OFFSET);
    ADD_STREAM_HOOK(StreamType, stringio_readline, STRINGIO_READLINE_OFFSET);

    /* Indicates success */
    return 0;
}

void reverse_stringio_methods(PyTypeObject *StreamType) {

    REVERSE_STREAM_HOOK(StreamType, stringio_read, STRINGIO_READ_OFFSET);
    REVERSE_STREAM_HOOK(StreamType, stringio_readline, STRINGIO_READLINE_OFFSET);
}
