Code Monkey home page Code Monkey logo

hapih-2's Introduction

HAPIH-2

API for supporting C++14 external memory hacking. Complete redesign from HAPIH.

Elements

HAPIH 2 uses 3 objects in order to do its job:

  1. HandleIH
  2. PointerIH
  3. HackIH

HandleIH

Used to store and close either generic or OpenProcess handles upon object destruction, but can't be copied. If initialized from a DWORD, it will open the process with enough privileges to fully support HAPIH 2. Usage example is inside source code, the object basically works like a normal HANDLE.

PointerIH

Defines the internal structure of a pointer. It can either be initialized by a void* or by a numeric type ( size_t ).

Using Cheat Engine pointer notation, the PointerIH object will point to an address following this scheme: [[[[[BaseAddr + Offs1] + Offs2] + Offs3] + Offs4] + ...]

  • Offsets can be added by the << operator, following the offset or by initializing the pointer directly with it. They can be accessed by the [] operator.
#include "HAPIH.h"
int main() {
	PointerIH Pointer1 = { 0xDEADBEEF,1,2,3,4 };	//Initialization
	PointerIH Pointer2 = 0xDEADBEEF;
	Pointer2 << 1 << 2 << 3 << 4;         //Adding offsets after initialization
	Pointer1[0] == Pointer2[0];           //Will access the first offsets of both pointers, the result is 1.
}
  • PointerIH supports final addition and substraction using the operators +, -, +=, -=, the final offset will be added AFTER the pointer is read from the process.

HackIH

Handles the entire API, it's responsible to do the direct memory operations, search for open processes and binding to them.

  • Once initialized it will store internally all the running processes, thru which you can index them easily with binding or vector manipulation.
#include "HAPIH.h"
int main() {
  HackIH MyObj;
  MyObj.WriteProcesses(std::cout);
  std::cin.get();
}
#include "HAPIH.h"
int main() {
	HackIH MyObj;
	for (auto & proc : MyObj.GetProcesses()) {
		std::cout << std::get<1>(proc) << std::endl;	//Iterates thru every process, only by its name.
		//Use std::get<0>(proc) to get the corresponding process ID
	}
}
  • HackIH can also enable logging features, using any stream object you desire (Files, STDOUT or any custom wrapper).
#include "HAPIH.h"
int main() {
  HackIH MyObj;
  MyObj.SetDebugOutput(std::cout);  //From now on, the operations happening inside HAPIH 2 will write what's happening on STDOUT
  //Code...
}
  • You can then use the .bind function to bind to a process, using it's process name or process ID.
#include "HAPIH.h"
int main() {
  HackIH MyObj;
  MyObj.SetDebugOutput(std::cout);  
  MyObj.bind("GeometryDash.exe");   //Binding to the Geometry Dash process.
  //Code...
}
#include "HAPIH.h"
int main() {
  HackIH MyObj;
  MyObj.SetDebugOutput(std::cout);  
  MyObj.bind(GetCurrentProcessId());   //Binding to itself.
  //Code...
}
  • After binding, the HackIH object is guaranteed access to the process and can now handle modules, memory spaces and operations, such as:
  1. Reading
#include "HAPIH.h"
int main() {
	HackIH MyObj;
	MyObj.SetDebugOutput(std::cout);
	MyObj.bind("GeometryDash.exe");		//Binding to the Geometry Dash process.
	int IconID;			//Icon to read from memory
	IconID = MyObj.Read<int>({ MyObj.BaseAddress , 0x303118 , 0x1E8 });
        //IconID = MyObj.Read<int>({ MyObj.GetModuleAddress("GeometryDash.exe") , 0x303118 , 0x1E8 }); //Alternative
        //.GetModuleAddress can be used on every process' module (DLLs)
	std::cout << IconID << std::endl;
	std::cin.get();
}
  1. Writing
#include "HAPIH.h"
int main() {
	HackIH MyObj;
	MyObj.SetDebugOutput(std::cout);
	MyObj.bind("GeometryDash.exe");		//Binding to the Geometry Dash process.
	int IconID= 33;						//Icon to write to memory
	PointerIH IconPtr = { MyObj.BaseAddress , 0x303118 , 0x1E8 };
	MyObj.Write(IconPtr, IconID);
	MyObj.Write(IconPtr - 8, MyObj.Read<int>(IconPtr - 4) + IconID);	
	std::cin.get();
}
  1. DLL Injection
#include "HAPIH.h"
#include <iostream>
int main(int argc,char** argv) {
	SetConsoleTitle("DLL Injector");
	if (argc < 2) { 
		std::cout << "Invalid." << std::endl;
		return 0;
	}
	std::string File = argv[1];
	std::string Process;
	if (argc == 3) Process = argv[2];
	else Process = "GeometryDash.exe";
	HackIH Injector;
	do {
		Sleep(250);
	} while (!Injector.bind(Process));
	Injector.DllInject(File, 0);
	std::cout << "Injected." << std::endl;
}

Other Features

HAPIH 2 is able to perform DLL injection using the .DllInject and .DllEject functions, which work by spawning a thread on the needed kernel32.dll function, thus this feature only work for a target with the same bits as the compiled executable.

Memory allocation, thread spawning and chunk memory I/O is also made available (.ReadBytes and .WriteBytes), a function for computing an hash of data inside a vector is also made available (DJBHash)

Todo

Adding a binary searcher for the executable and some other memory manipulation functions. Also completing this readme since it's trash.

hapih-2's People

Contributors

mgostih avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hapih-2's Issues

Help with library

Hi, I am really new to C++, and I think I am having issues importing your library. (as you can probably tell, i am mostly familiar with python.) Here is the code I have and the output I get when I try to build it. Any help would be greatly appreciated.

Building

#include "HAPIH.h"
int main() {
  HackIH MyObj;
  MyObj.WriteProcesses(std::cout);
  std::cin.get();
}

results in

> Executing task: C:\MinGW\bin\g++.exe -g c:\Users\[censored]\Desktop\AI\GD\main.cpp -o c:\Users\[censored]\Desktop\AI\GD\main.exe <

C:\Users\[censored]\AppData\Local\Temp\ccAMgFtt.o: In function `main':
c:/Users/[censored]/Desktop/AI/GD/main.cpp:3: undefined reference to `HackIH::HackIH()'
c:/Users/[censored]/Desktop/AI/GD/main.cpp:4: undefined reference to `HackIH::WriteProcesses(std::ostream&) const'
c:/Users/[censored]/Desktop/AI/GD/main.cpp:3: undefined reference to `HackIH::~HackIH()'
c:/Users/[censored]/Desktop/AI/GD/main.cpp:3: undefined reference to `HackIH::~HackIH()'
collect2.exe: error: ld returned 1 exit status
The terminal process terminated with exit code: 1

Getting an error in the HAPIH.h

I am coding a cheat for a game and i keep on getting this error: 'static_cast': cannot convert from 'PointerIH' to 'size_t'
Someone please help me with this cause it's pissing me off

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.