/*
 * 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 BYTESIO_READ_OFFSET 13
#define BYTESIO_READLINE_OFFSET 11
#define BYTESIO_READLINES_OFFSET 12
#define BYTESIO_READ1_OFFSET 9

binaryfunc bytesio_read_orig;
binaryfunc bytesio_readline_orig;
binaryfunc bytesio_readlines_orig;
binaryfunc bytesio_read1_orig;

HOOK_STREAM_BINARYFUNC(bytesio_read, "read");
HOOK_STREAM_BINARYFUNC(bytesio_readline, "readline");
HOOK_STREAM_BINARYFUNC(bytesio_readlines, "readlines");
HOOK_STREAM_BINARYFUNC(bytesio_read1, "read1");

int patch_bytesio_methods(funchook_t *funchook, PyTypeObject *StreamType) {

    ADD_STREAM_HOOK(StreamType, bytesio_read, BYTESIO_READ_OFFSET);
    ADD_STREAM_HOOK(StreamType, bytesio_readline, BYTESIO_READLINE_OFFSET);
    ADD_STREAM_HOOK(StreamType, bytesio_readlines, BYTESIO_READLINES_OFFSET);
    ADD_STREAM_HOOK(StreamType, bytesio_read1, BYTESIO_READ1_OFFSET);

    /* Indicates success */
    return 0;
}
