uniptr_t - C++ Pointer Utility Class

uniptr_t - C++ Pointer Utility Class

uniptr_t stands for univerasl pointer. It's a small C++ class wrapping any pointer type. It removes the need to cast any pointer to any other pointer type, or to cast a numerical to a pointer type and vice versa.

The purpose of this library is to make working with pointers a lot a lot easier, but you still must understand how memory and pointers work. Be careful: uniptr_t is not always the best to use when working with pointers or memory addresses.

Features

  • Automatic pointer casting
  • Utility functions
  • All operators are overloaded
  • Platform independent
  • Works on C++14 and newer versions (I haven't tested it on C++11 or older versions)
  • 1 file include
  • Doesn't affect performance of your code at all

Showcase

You can assign all uniptr_t objects to any pointer type or to a numerical.

// assign to a void pointer
void* a_void_pointer = nullptr;
uniptr_t p1 = a_void_pointer;

// assign to any other pointer
int* any_pointer_type = nullptr;
uniptr_t p2 = any_pointer_type;

// assign to nullptr
uniptr_t p3 = nullptr;

// assign to 0 without any casting
uniptr_t p4 = 0;

// assign to any other numerical without casting
uniptr_t p5 = 0x18401;

Of course you can also do this vice versa - automatically cast uniptr_t to any pointer or numerical:

uniptr_t p1 = 0xDEADBEEF;

// assign to a void pointer
void* a_void_pointer = p1;

// assign to any other pointer
int* any_pointer_type = p1;

// assign to any numerical
int numerical1 = p1;
uintptr_t numerical2 = p1;
// and even to floats or doubles!
float floating1 = p1;
double floating2 = p1;

All operators are overloaded and work with any pointer type or numerical:

int numerical1 = 10;
uintptr_t numerical2 = 20;
float floating1 = 10.f;
double floating2 = 49.0;
void* void_ptr = (void*)0x100;
int* any_ptr = (int*)0x81;

uniptr_t my_ptr = 0;
my_ptr += numerical1;
my_ptr = my_ptr - floating1;
my_ptr /= any_ptr;
my_ptr++;
--my_ptr;
// etc.

uniptr_t has some utility functions:

uniptr_t my_ptr = nullptr;

my_ptr.set<int>(10); // same as *(int*)my_ptr = 10;

int my_num = my_ptr.get<int>(); // same as int my_num = *(int*)my_ptr;

// if you want to make sure the pointer is casted properly, you can use .as() or .as_ptr()
uintptr_t numerical = my_ptr.as<uintptr_t>();
int* void_ptr = my_ptr.as_ptr<int>(); // here you only need to specify the type of the pointer without *

// get the size of void* (same as sizeof(void*))
size_t pointer_size = my_ptr.size(); // you can even do uniptr_t::size() since it's a static function

// .relative_addr() and .to_relative_addr() are hard to explain but
// as the name suggests, I use them to caluclate relative addresses
// that an assembly instruction might be holding

// and finally we have some windows specific functions
// .is_valid() checks if the memory address uniptr_t is pointing to is valid (checks if it's commited memory)
// .is_readable() checks if the memory address uniptr_t is pointing to is readable
// .is_writeable() checks if the memory address uniptr_t is pointing to is writeable
// .region_size() if the function succeeds, the return value is non-zero and holds the number of bytes in memory of the
// region uniptr_t is pointing to (in other words how big the region is)
Owner
1hAck
I love game hacking and programming, everything you find on this profile will be related to those topics.
1hAck
Similar Resources

Epoxy is a library for handling OpenGL function pointer management for you

Epoxy is a library for handling OpenGL function pointer management for you. It hides the complexity of dlopen(), dlsym(), glXGetProcAddress(), eglGetP

Sep 22, 2022

Epoxy is a library for handling OpenGL function pointer management for you

Epoxy is a library for handling OpenGL function pointer management for you. It hides the complexity of dlopen(), dlsym(), glXGetProcAddress(), eglGetP

Sep 21, 2022

Simple C++ script that will move the mouse pointer lighthly on the screen, perfect to prank your friends.

Simple C++ script that will move the mouse pointer lighthly on the screen, perfect to prank your friends.

tembleke Simple script written in C++ that when it is executed, the mouse pointer moves lighthly above the screen. I have made this script in order to

Oct 28, 2021

Extracts high-precision mouse/pointer motion data on Windows. Good for drawing software!

Extracts high-precision mouse/pointer motion data on Windows. Good for drawing software!

window_mouse_queue This is a wrapper for GetMouseMovePointsEx function that allows to extract high-precision mouse/pointer motion data on Windows. Goo

Feb 21, 2022

C++ Type Traits for Smart Pointer

C++ Type Traits for Smart Pointer

SmartPointerTypeTrait C++ Type Traits for Smart Pointer is_a_pointer is_smart_pointer template typename T struct is_smart_ptr : is_smart_ptr_impl

Aug 27, 2022

C-function for traversing files/directories effectively and calling a given function with each encountered file and a void-pointer as parameters

C-function for traversing files/directories effectively and calling a given function with each encountered file and a void-pointer as parameters

Jun 27, 2022

Simple Kernel Mode Data Pointer Swap, Credits To FoxiTV On UC for Great Resources About This Topic

Simple Kernel Mode Data Pointer Swap, Credits To FoxiTV On UC for Great Resources About This Topic

Data-Pointer-Swap Simple Kernel Mode Data Pointer Swap, Credits To FoxiTV On UC for Great Resources About This Topic. This Source Was Made Back In Aug

Aug 20, 2022

libsequence: a C++ class library for evolutionary genetic analysis

libsequence2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

Apr 30, 2022

free C++ class library of cryptographic schemes

Crypto++: free C++ Class Library of Cryptographic Schemes Version 8.4 - TBD Crypto++ Library is a free C++ class library of cryptographic schemes. Cu

Sep 16, 2022

A simple C++ 03/11/etc timer class for ~microsecond-precision cross-platform benchmarking. The implementation is as limited and as simple as possible to create the lowest amount of overhead.

plf_nanotimer A simple C++ 03/11/etc timer class for ~microsecond-precision cross-platform benchmarking. The implementation is as limited and simple a

Sep 18, 2022

A simple class for parsing JSON data into a QVariant hierarchy and vice versa.

The qt-json project is a simple collection of functions for parsing and serializing JSON data to and from QVariant hierarchies. NOTE: Qt5 introduced a

Sep 15, 2022

CLASS Project Generator

zproject - CLASS Project Generator Contents Overview Scope and Goals Tutorial Installation Getting started Setup your project environment Configuratio

Jan 11, 2022

Class containing Anti-RE, Anti-Debug and Anti-Hook methods. Made for C++/CLI

Umium Class containing Anti-RE, Anti-Debug and Anti-Hook methods. Easy to use and easy to implement. Disclaimer This code has been made and optimized

Sep 10, 2022

Disassembling .class files

jvmdisassembler Contribution You can contribute by creating an issue or pull request. Please keep the code clean and readable. All contributed code mu

Jun 20, 2022

DOS Web browser for 8088 class machines

DOS Web browser for 8088 class machines

MicroWeb MicroWeb is a web browser for DOS! It is a 16-bit real mode application, designed to run on minimal hardware. Minimum requirements To run you

Sep 1, 2022

This was the first ever Computer Science project that I made back in Class XII (2016). I thought I should upload it on GitHub so that it does not get lost. :)

This was the first ever Computer Science project that I made back in Class XII (2016). I thought I should upload it on GitHub so that it does not get lost. :)

First Ever Project This was the first ever Computer Science project that I made back in Class XII (2016). I thought I should upload it on github so th

Jun 7, 2021

C++20 N-dimensional Matrix class for hobby project

Ndim-Matrix C++20 N-dimensional Matrix class for hobby project Supporting matrix operations STL compatible iterators reshape (O(1) move operation, no

Jul 27, 2022

cavi is an open-source library that aims to provide performant utilities for closed hierarchies (i.e. all class types of the hierarchy are known at compile time).

cavi cavi is an open-source library that aims to provide performant utilities for closed hierarchies (i.e. all class types of the hierarchy are known

Mar 9, 2022
cs49n class materials: stanford autumn quarter 2021

CS49n (Aut, 21): using bits to control atoms. Overview This is a lab-based class. It is structured where you will write the code to control 1-2 hardwa

Dec 24, 2021
Implementation using C in programming lab class when being Teacher Assistant.

C Programming Lab Implementation using C in programming lab class when being Teacher Assistant. The problems are here Problems and Description Week2 w

Aug 16, 2022
Project for C programming class building a casino that includes blackjack, slots, and scratch offs.

Casino Project for C programming class building a casino that includes blackjack, slots, and scratch offs. Project description This project will requi

Nov 4, 2021
A custom,multifunctional class template for arrays which supports lambda functions for removing and selecting

C++ Array Template Class This is an implementation of a template class for storing data in any type.It includes user-friendly interface with lots of h

Dec 8, 2021
Background Music, a macOS audio utility: automatically pause your music, set individual apps' volumes and record system audio.
Background Music, a macOS audio utility: automatically pause your music, set individual apps' volumes and record system audio.

Background Music macOS audio utility Overview Auto-pause music Application volume Recording system audio Download Build and Install Uninstall Troubles

Sep 17, 2022
Small single-header C++20 utility providing CRTP base classes for

affine_space Small single-header C++20 utility providing CRTP base classes for strongly-typed values and differences. This is similar to a very simpli

Jan 11, 2022
Trackable ptr - Smart pointer for any movable objects. When trackable object moved/destroyed, trackers updated with new object's pointer.

trackable_ptr Trackable pointer. When trackable object moved/destroyed, trackable_ptrs updated with new object's location. Allow to have stable pointe

Mar 3, 2022
Stateful pointer - Use unused bits in your pointer

Stateful Pointer Library Sometimes space is tight! What if you could squeeze extra state into a pointer at (almost) no additional cost? A pointer occu

Jun 7, 2020
A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON

JSONCONS jsoncons is a C++, header-only library for constructing JSON and JSON-like data formats such as CBOR. For each supported data format, it enab

Sep 14, 2022