From dac01f6510abf8c42efdf25ec5358e066cc5bd32 Mon Sep 17 00:00:00 2001 From: Dibyamartanda Samanta Date: Thu, 1 Aug 2024 14:02:45 +0200 Subject: [PATCH] [NTOSKRNL:CC] Added Bounds Checked Array Class This Bounds Checked array will be used for OBCB type --- NTOSKRNL/CC/ccinternal.hpp | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/NTOSKRNL/CC/ccinternal.hpp b/NTOSKRNL/CC/ccinternal.hpp index b79d147..9d3e57c 100644 --- a/NTOSKRNL/CC/ccinternal.hpp +++ b/NTOSKRNL/CC/ccinternal.hpp @@ -103,4 +103,44 @@ public: private: PEX_SPIN_LOCK m_SpinLock; KIRQL m_OldIrql; -}; \ No newline at end of file +}; + +template +class Array { +public: + Array(T* data, size_t size) : data_(data), size_(size) {} + + T& operator[](size_t index) { + checkBounds(index); + return data_[index]; + } + + const T& operator[](size_t index) const { + checkBounds(index); + return data_[index]; + } + + T& at(size_t index) { + checkBounds(index); + return data_[index]; + } + + const T& at(size_t index) const { + checkBounds(index); + return data_[index]; + } + + size_t size() const { + return size_; + } + +private: + T* data_; + size_t size_; + + void checkBounds(size_t index) const { + if (index >= size_) { + ExRaiseStatus(STATUS_ARRAY_BOUNDS_EXCEEDED); + } + } +};