0% found this document useful (0 votes)
13 views4 pages

Game Memory Modification Tool

Uploaded by

resultbosjankill
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Game Memory Modification Tool

Uploaded by

resultbosjankill
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include "MemoryTools.

h"
#include <iostream>
#include <string>
#include <vector>
#include <cstring>

using namespace std;

// Global variables
int mHandle;
int ipid;
long int libbase;
string currentClassName;
string currentFieldName;
int currentType;

// Function prototypes
long int get_the_module_base(int pid, const char *module_name);
int get_the_PID(PACKAGENAME * PackageName);
int findClassField(const string& className, const string& fieldName, int type);
void modifyField(int type, const char* newValue);
void F1(); // Player Speed
void F2(); // Unlimited Ammo
void clearResults();
void errorMessage();

int main(int argc, char *argv[]) {


char packageName[] = "[Link]"; // Ganti dengan package name game
char modeNoRoot[] = "MODE_NO_ROOT";

// Initialize MemoryTools
initXMemoryTools(packageName, modeNoRoot);

// Get PID
ipid = get_the_PID(packageName);
if (ipid == 0) {
SetTextColor(COLOR_RED);
cout << "Application not running!" << endl;
return 1;
}

// Open memory handle


char lj[64];
sprintf(lj, "/proc/%d/mem", ipid);
mHandle = open(lj, O_RDWR);
if (mHandle == -1) {
SetTextColor(COLOR_RED);
cout << "Failed to get memory handle!" << endl;
return 1;
}

// Find module base


char moduleName[] = "[Link]";
libbase = get_the_module_base(ipid, moduleName);
if (libbase == 0) {
SetTextColor(COLOR_RED);
cout << "Module not found!" << endl;
close(mHandle);
return 1;
}

// Langsung eksekusi semua modifikasi tanpa menu


SetTextColor(COLOR_CYAN);
cout << "=== Memory Tools by Krojzanovic ===" << endl;

// Player Speed modification


F1();

// Unlimited Ammo modification


F2();

close(mHandle);
return 0;
}

// Implementasi fungsi-fungsi
long int get_the_module_base(int pid, const char *module_name) {
FILE *fp;
long addr = 0;
char filename[32];
char line[1024];
snprintf(filename, sizeof(filename), "/proc/%d/maps", pid);
fp = fopen(filename, "r");
if (fp != NULL) {
while (fgets(line, sizeof(line), fp)) {
if (strstr(line, module_name) && strstr(line, "r-xp")) {
char *pch = strtok(line, "-");
addr = strtoul(pch, NULL, 16);
break;
}
}
fclose(fp);
}
SetTextColor(COLOR_GREEN);
cout << "Module found at: 0x" << hex << addr << dec << endl;
return addr;
}

int get_the_PID(PACKAGENAME * PackageName) {


DIR *dir = opendir("/proc");
if (dir == NULL) return 0;

struct dirent *ptr;


while ((ptr = readdir(dir)) != NULL) {
if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0)
continue;
if (ptr->d_type != DT_DIR)
continue;

char filepath[256];
sprintf(filepath, "/proc/%s/cmdline", ptr->d_name);

FILE *fp = fopen(filepath, "r");


if (fp != NULL) {
char filetext[128];
fgets(filetext, sizeof(filetext), fp);
fclose(fp);
if (strcmp(filetext, PackageName) == 0) {
closedir(dir);
return atoi(ptr->d_name);
}
}
}
closedir(dir);
return 0;
}

int findClassField(const string& className, const string& fieldName, int type) {


currentClassName = className;
currentFieldName = fieldName;
currentType = type;

SetTextColor(COLOR_YELLOW);
cout << "Searching for " << className << "::" << fieldName << "..." << endl;

// Cari class PlayerControl terlebih dahulu


SetSearchRange(C_DATA | C_ALLOC | OTHER);

// Pattern untuk mencari class PlayerControl


MemorySearch((char*)className.c_str(), TYPE_BYTE);

int resultCount = GetResultCount();


if (resultCount == 0) {
errorMessage();
return 0;
}

// Jika field adalah playerSpeed, tambahkan offset 0xA8


if (fieldName == "playerSpeed") {
// Simulasikan penambahan offset
for (int i = 0; i < resultCount; i++) {
long address = GetResults(i) + 0xA8;
SetResults(i, address);
}
SetTextColor(COLOR_GREEN);
cout << "Added offset 0xA8 to PlayerSpeed field" << endl;
}

// Jika field adalah ammo, tambahkan offset 0xBC


if (fieldName == "ammo") {
// Simulasikan penambahan offset
for (int i = 0; i < resultCount; i++) {
long address = GetResults(i) + 0xBC;
SetResults(i, address);
}
SetTextColor(COLOR_GREEN);
cout << "Added offset 0xBC to Ammo field" << endl;
}

SetTextColor(COLOR_GREEN);
cout << "Field found! Ready to modify." << endl;
return 1;
}

void modifyField(int type, const char* newValue) {


if (GetResultCount() == 0) {
errorMessage();
return;
}

// Modify all found results


MemoryWrite((char*)newValue, 0, type);

SetTextColor(COLOR_GREEN);
cout << "✅ " << currentFieldName << " modified to " << newValue << endl;

clearResults();
}

void F1() {
if (findClassField("PlayerControl", "playerSpeed", TYPE_FLOAT)) {
// First refine to current value (6.0)
SetSearchRange(ALL);
MemorySearch("6", TYPE_FLOAT);

// Then modify to new value (25.0)


modifyField(TYPE_FLOAT, "25.0");
}
}

void F2() {
if (findClassField("Weapon", "ammo", TYPE_DWORD)) {
// First refine to current ammo value
SetSearchRange(ALL);
MemorySearch("30", TYPE_DWORD); // Asumsi ammo awal adalah 30

// Then modify to new value (999)


modifyField(TYPE_DWORD, "999");
}
}

void clearResults() {
ClearResults();
}

void errorMessage() {
SetTextColor(COLOR_RED);
cout << "Error: Value not found!" << endl;
}

Common questions

Powered by AI

Offset additions in 'findClassField' are significant as they adjust the precise memory location for particular gameplay elements, like 'playerSpeed' and 'ammo', by adding specific hexadecimal offsets (0xA8 and 0xBC, respectively). This adjustment stems from the need to navigate complex memory structures to locate the exact variable representing a gameplay feature within class memory layouts. These calculated offsets are applied to ensure that direct modification targets the right variable locations, thereby enabling modifications (e.g., on player speed or ammo count) without unintended side effects on other fields .

When intended operations fail, such as not finding certain memory values, the program utilizes specific error handling measures like outputting an error message with 'errorMessage()' that notifies the user. This function sets the console text color to red and displays "Error: Value not found!" to clearly indicate an operational problem. Additionally, processes terminate in certain cases, such as when failing to open a memory handle or locate a module base, to prevent incorrect operations and maintain system stability .

The 'initXMemoryTools' function is used to initialize the memory management tools needed for this program. It requires two arguments: the package name of the target application ('packageName') and a mode type string ('modeNoRoot'). This setup allows the program to interact with the memory of the specified application without needing root access .

When modifying in-game ammunition, the program employs a two-step refinement process within the function 'F2'. It begins by calling 'findClassField' to locate the 'ammo' field within the 'Weapon' class, setting a baseline understanding of the memory structure. The search is then refined to the current ammo value, 30, using 'MemorySearch' with the type DWORD. After pinpointing the memory area representing the ammunition count, it proceeds to modify this value to 999, providing unlimited ammo .

The program obtains the PID by scanning the '/proc' directory, which contains process information. It checks each directory for a 'cmdline' file, reading the contained text to compare against the desired package name. This method loops through existing process directories, ignoring non-process entries. When a matching cmdline text is found, the directory name (a numeric string representing the PID) is returned. Obtaining the PID is critical for subsequent memory operations, as it allows the program to hone in on the specific memory space allocated to the target application for modification .

The program ensures the target application is modified properly by first obtaining the PID of the package with 'get_the_PID' and then acquiring a memory handle for the application. If obtaining either fails, it outputs error messages. Once the memory handle is successfully opened, it confirms the presence of the module base by locating 'libil2cpp.so'. If the module is not found, it again outputs an error and terminates. This verification ensures that the modifications are only attempted on the correct application memory space .

Setting search ranges, such as 'ALL', is significant because it defines the memory scope for operations, enabling the program to efficiently target desired memory regions. This broad range allows for comprehensive searches across all allocated areas that match the criteria set by initial values or structures. In the context of this program, an 'ALL' range means every possible related memory section is analyzed, enhancing the accuracy and success rates of detecting the right values required for subsequent modifications, thus ensuring the effectiveness of gameplay changes such as speed and ammunition levels .

The 'get_the_module_base' method works by opening the memory map file (/proc/PID/maps) of the given process ID (PID) and searching through it to find a specific module ('libil2cpp.so') with read-execute permissions ('r-xp'). The starting address of this module is extracted using string manipulation, which is crucial because it identifies where the module's code is loaded in memory, enabling subsequent operations such as modifying specific fields. This constitutes the foundation for precisely targeting game mechanics changes without affecting other unrelated memory regions .

The 'modifyField' function clears results after changes using 'clearResults()' to maintain performance and reliability by freeing resources and clearing any remnants of previous search results. This prevents outdated or irrelevant data from influencing future operations. Clearing results ensures that every memory operation starts afresh, avoiding potential conflicts or errors that might arise if previous memory states were inadvertently reused. This methodical clearance improves the program’s efficiency and accuracy in applying modifications .

The program modifies the player's speed in the function 'F1' by first identifying the 'playerSpeed' field within the class 'PlayerControl'. It refines the search to isolate the float value of 6.0, which is the default player speed. Once located, it modifies this value to 25.0, significantly increasing the player's speed. This change directly alters the speed at which the player's avatar moves, offering a rapid gameplay experience .

You might also like