Escolar Documentos
Profissional Documentos
Cultura Documentos
#include <stdio.h>
#include <string>
#include <unistd.h>
#include <sys/mman.h>
#include <vector>
namespace KittyMemory {
typedef enum {
FAILED = 0,
SUCCESS = 1,
INV_ADDR = 2,
INV_LEN = 3,
INV_BUF = 4,
INV_PROT = 5
} Memory_Status;
struct ProcMap {
void *startAddr;
void *endAddr;
size_t length;
std::string perms;
long offset;
std::string dev;
int inode;
std::string pathname;
/*
* Changes protection of an address with given length
*/
bool ProtectAddr(void *addr, size_t length, int protection);
/*
* Writes buffer content to an address
*/
Memory_Status memWrite(void *addr, const void *buffer, size_t len);
/*
* Reads an address content into a buffer
*/
Memory_Status memRead(void *buffer, const void *addr, size_t len);
/*
* Reads an address content and returns hex string
*/
std::string read2HexStr(const void *addr, size_t len);
/*
* Wrapper to dereference & get value of a multi level pointer
* Make sure to use the correct data type!
*/
template<typename Type>
Type readMultiPtr(void *ptr, std::vector<int> offsets) {
Type defaultVal = {};
if (ptr == NULL)
return defaultVal;
if (finalPtr == 0)
return defaultVal;
/*
* Wrapper to dereference & set value of a multi level pointer
* Make sure to use the correct data type!, const objects won't work
*/
template<typename Type>
bool writeMultiPtr(void *ptr, std::vector<int> offsets, Type val) {
if (ptr == NULL)
return false;
if (finalPtr == 0)
return false;
/*
* Wrapper to dereference & get value of a pointer
* Make sure to use the correct data type!
*/
template<typename Type>
Type readPtr(void *ptr) {
Type defaultVal = {};
if (ptr == NULL)
return defaultVal;
/*
* Wrapper to dereference & set value of a pointer
* Make sure to use the correct data type!, const objects won't work
*/
template<typename Type>
bool writePtr(void *ptr, Type val) {
if (ptr == NULL)
return false;
/*
* Gets info of a mapped library in self process
*/
ProcMap getLibraryMap(const char *libraryName);
/*
* Expects a relative address in a library
* Returns final absolute address
*/
uintptr_t getAbsoluteAddress(const char *libraryName, uintptr_t relativeAddr,
bool useCache=false);
};