### Build memoryjs for Node Webkit Source: https://github.com/rob--/memoryjs/wiki/Node-Webkit-&-Electron This bash command sequence installs nw-gyp globally and then cleans, configures, and builds the memoryjs library for a specified architecture and Node Webkit target version. Ensure you have Python 2.7.12 or a compatible version installed. ```bash npm install -g nw-gyp nw-gyp clean configure build --arch=x64 --target=0.15.4 ``` -------------------------------- ### Install memoryjs Source: https://github.com/rob--/memoryjs/blob/master/README.md Installs the memoryjs package using npm. It also provides commands to build the package for specific architectures (32-bit or 64-bit) or automatically detect the current Node.js architecture. ```bash npm install memoryjs # will automatically compile based on the detected Node architecture npm run build # compile to target 32 bit processes npm run build32 # compile to target 64 bit processes npm run build64 ``` -------------------------------- ### Install memoryjs Source: https://github.com/rob--/memoryjs/wiki/Install Installs the memoryjs Node.js module using npm. Ensure you have node-gyp installed and configured correctly. ```bash npm install memoryjs ``` -------------------------------- ### Attaching the Debugger Source: https://github.com/rob--/memoryjs/blob/master/README.md Example of how to attach the Debugger to a process. ```javascript const hardwareDebugger = memoryjs.Debugger; hardwareDebugger.attach(processId); ``` -------------------------------- ### Setting a Hardware Breakpoint Source: https://github.com/rob--/memoryjs/blob/master/README.md Example of setting a hardware breakpoint on a specific address with a given trigger and data type. ```javascript const address = 0xDEADBEEF; const trigger = memoryjs.TRIGGER_ACCESS; const dataType = memoryjs.INT; const register = hardwareDebugger.setHardwareBreakpoint(processId, address, trigger, dataType); ``` -------------------------------- ### Process Management with memoryjs Source: https://github.com/rob--/memoryjs/wiki/Old-README Demonstrates how to open and retrieve process information using memoryjs. Supports both synchronous and asynchronous operations for opening a process and getting a list of all running processes. ```javascript const memoryjs = require('memoryjs'); const processName = "csgo.exe"; // Open a process (sync) const processObject = memoryjs.openProcess(processName); // Open a process (async) memoryjs.openProcess(processName, (error, processObject) => { // Handle error or processObject }); // Get all processes (sync) const processes = memoryjs.getProcesses(); // Get all processes (async) memoryjs.getProcesses((error, processes) => { // Handle error or processes array }); ``` -------------------------------- ### Get All Processes Functionality Source: https://github.com/rob--/memoryjs/wiki/Process Explains the `getProcesses` function, used to retrieve information about all running processes on the system. It supports both synchronous and asynchronous calls. ```javascript // synchronously const processes = memoryjs.getProcesses(); // asynchronously memoryjs.getProcesses((error, processes) => { }); ``` -------------------------------- ### Get Node Webkit Version and Architecture Source: https://github.com/rob--/memoryjs/wiki/Node-Webkit-&-Electron This JavaScript snippet helps you determine the Node Webkit version and architecture currently in use. This information is crucial for correctly configuring the build process. ```javascript console.log("nw " + process.versions.nw + " " + process.arch + " node " + process.versions.node) ``` -------------------------------- ### Get All Modules in Process Source: https://github.com/rob--/memoryjs/wiki/Modules Retrieves all modules associated with a specific process. Can be used synchronously or asynchronously. Requires the process ID. ```javascript // synchronously const modules = memoryjs.getModules(processId); // asynchronously memoryjs.getModules(processId, (error, modules) => { }); ``` -------------------------------- ### Remote Function Execution with memoryjs Source: https://github.com/rob--/memoryjs/wiki/Old-README Details how to execute functions in a remote process using memoryjs. It covers building argument arrays with specified data types and values, and how to specify the return type of the function. Includes an example of calling a C++ 'add' function. ```javascript memoryjs.T_VOID = 0x0, memoryjs.T_STRING = 0x1, memoryjs.T_CHAR = 0x2, memoryjs.T_BOOL = 0x3, memoryjs.T_INT = 0x4, memoryjs.T_DOUBLE = 0x5, memoryjs.T_FLOAT = 0x6, ``` ```javascript const args = [{ type: memoryjs.T_INT, value: 2, }, { type: memoryjs.T_INT, value: 5, }]; const returnType = T_INT; memoryjs.callFunction(handle, args, returnType, address); ``` ```javascript int add(int a, int b) { return a + b; } ``` -------------------------------- ### Reading and Writing Strings in Memory Source: https://github.com/rob--/memoryjs/wiki/Old-README Demonstrates how to get the memory address of a C++ std::string or a char* to read or write string data. It also explains the library's behavior when reading strings, including the null-terminator limitation and a safeguard against infinite loops. ```c++ std::string str1 = "hello"; std::cout << "Address: 0x" << hex << (DWORD) str1.c_str() << dec << std::endl; char* str2 = "hello"; std::cout << "Address: 0x" << hex << (DWORD) str2 << dec << std::endl; ``` -------------------------------- ### Process Management with memoryjs Source: https://github.com/rob--/memoryjs/blob/master/README.md Demonstrates how to open a process, retrieve a list of all running processes, and close a process handle using memoryjs. Both synchronous and asynchronous methods are shown. ```javascript // sync: open a process const processObject = memoryjs.openProcess(processName); // async: open a process memoryjs.openProcess(processName, (error, processObject) => {}); // sync: get all processes const processes = memoryjs.getProcesses(); // async: get all processes memoryjs.getProcesses((error, processes) => {}); // close a process (release handle) memoryjs.closeHandle(handle); ``` -------------------------------- ### List Processes and Modules with memoryjs Source: https://github.com/rob--/memoryjs/wiki/Home Demonstrates how to list all open processes and find specific modules within a process using the memoryjs library. This is a foundational step for interacting with other processes. ```javascript const memoryjs = require('memoryjs'); // List all open processes const processes = memoryjs.getProcesses(); console.log('Open Processes:', processes); // Example: Find a specific module (e.g., 'notepad.exe') const notepadProcess = processes.find(p => p.szExeFile === 'notepad.exe'); if (notepadProcess) { const modules = memoryjs.getModules(notepadProcess.th32ProcessID); console.log(`Modules for ${notepadProcess.szExeFile}:`, modules); // Find a specific module by name const kernel32Module = modules.find(m => m.szModule.includes('kernel32.dll')); if (kernel32Module) { console.log('Found kernel32.dll:', kernel32Module); } } else { console.log('Notepad process not found.'); } ``` -------------------------------- ### Memory Mapping Files with memoryjs Source: https://github.com/rob--/memoryjs/blob/master/README.md Demonstrates how to open a file mapping and map it into a process's address space using memoryjs. It covers reading the entire file and specific byte ranges, as well as closing the file handle. ```c++ HANDLE fileHandle = CreateFileA("C:\\foo.txt", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE fileMappingHandle = CreateFileMappingA(fileHandle, NULL, PAGE_READONLY, 0, 0, "MappedFooFile"); ``` ```javascript const processObject = memoryjs.openProcess("example.exe"); const fileHandle = memoryjs.openFileMapping("MappedFooFile"); // read entire file const baseAddress = memoryjs.mapViewOfFile(processObject.handle, fileHandle.handle); const data = memoryjs.readMemory(processObject.handle, baseAddress, memoryjs.STR); // read 10 bytes after 64KB const baseAddress = memoryjs.mapViewOfFile(processObject.handle, fileHandle.handle, 65536, 10, constants.PAGE_READONLY); const buffer = memoryjs.readBuffer(processObject.handle, baseAddress, 10); const data = buffer.toString(); const success = memoryjs.closeHandle(fileHandle); ``` -------------------------------- ### Process Identification in JavaScript Source: https://github.com/rob--/memoryjs/wiki/Process Demonstrates how to specify a process using its name or PID, which is required for opening and interacting with a process. ```javascript const processName = 'csgo.exe'; const processId = 1234; ``` -------------------------------- ### Get Process Modules Source: https://github.com/rob--/memoryjs/wiki/Old-README Retrieves all modules associated with a given process ID. It returns an array of module objects or an error if the process is not found or accessible. ```javascript getModules(processId[, callback]) - processId: (int) The ID of the process. - callback: (function) Called with (err, modules). - err: (string) Error message. - modules: (array) Array of module objects. ``` -------------------------------- ### Handling Debug Events Source: https://github.com/rob--/memoryjs/blob/master/README.md Demonstrates how to set up event listeners for debug events, both general and specific to a hardware register. ```javascript // `debugEvent` event emission catches debug events from all registers hardwareDebugger.on('debugEvent', ({ register, event }) => { console.log(`Hardware Register ${register} breakpoint`); console.log(event); }); // You can listen to debug events from specific hardware registers // by listening to whatever register was returned from `setHardwareBreakpoint` hardwareDebugger.on(register, (event) => { console.log(event); }); ``` -------------------------------- ### Process Object Structure Source: https://github.com/rob--/memoryjs/wiki/Process Illustrates the structure of the process object returned when a process is opened, highlighting the 'handle' property crucial for further interactions. ```javascript { dwSize: 304, th32ProcessID: 10316, cntThreads: 47, th32ParentProcessID: 7804, pcPriClassBase: 8, szExeFile: "csgo.exe", modBaseAddr: 1673789440, handle: 808 } ``` -------------------------------- ### Memory Reading and Writing with memoryjs Source: https://github.com/rob--/memoryjs/blob/master/README.md Illustrates how to read and write data types and buffers from/to a process's memory using memoryjs. It also includes fetching memory regions. Both synchronous and asynchronous methods are provided. ```javascript // sync: read data type from memory const value = memoryjs.readMemory(handle, address, dataType); // async: read data type from memory memoryjs.readMemory(handle, address, dataType, (error, value) => {}); // sync: read buffer from memory const buffer = memoryjs.readBuffer(handle, address, size); // async: read buffer from memory memoryjs.readBuffer(handle, address, size, (error, buffer) => {}); // sync: write data type to memory memoryjs.writeMemory(handle, address, value, dataType); // sync: write buffer to memory memoryjs.writeBuffer(handle, address, buffer); // sync: fetch memory regions const regions = memoryjs.getRegions(handle); // async: fetch memory regions memoryjs.getRegions(handle, (regions) => {}); ``` -------------------------------- ### Write Generic Structure to Memory with concentrate Source: https://github.com/rob--/memoryjs/wiki/Buffers Demonstrates how to convert a JavaScript object into a buffer using the 'concentrate' library and then write that buffer to a specified memory address. ```javascript const vector = { x: 1.23, y: 4.56, z: 7.89, }; const buffer = Concentrate() .floatle(vector.x) .floatle(vector.y) .floatle(vector.z) .result(); memoryjs.writeBuffer(processObject.handle, structAddress, buffer); ``` -------------------------------- ### Reading/Writing Structures with Structron Source: https://github.com/rob--/memoryjs/blob/master/README.md Shows how to use the structron library to define and manage custom data structures for memory operations, including custom string types. ```javascript // To create the type, we need to pass the process handle, base address of the // structure, and the target process architecture (either "32" or "64"). const stringType = memoryjs.STRUCTRON_TYPE_STRING(processObject.handle, structAddress, '64'); // Create a custom structure using the custom type, full example in /examples/buffers.js const Struct = require('structron'); const Player = new Struct() .addMember(string, 'name'); ``` -------------------------------- ### Remote Function Execution with memoryjs Source: https://github.com/rob--/memoryjs/blob/master/README.md Explains how to execute functions in a target process using memoryjs. It details the required argument format (array of type/value objects) and the return type specification. ```javascript const args = [{ type: memoryjs.T_INT, value: 2, }, { type: memoryjs.T_INT, value: 5, }]; const returnType = T_INT; > memoryjs.callFunction(handle, args, returnType, address); { returnValue: 7, exitCode: 7 } ``` -------------------------------- ### Mapping Memory to Current Process Source: https://github.com/rob--/memoryjs/blob/master/README.md Shows how to map a memory-mapped file to the current Node.js process using its PID, allowing interaction with the file without needing a separate target process. ```javascript const processObject = memoryjs.openProcess(process.pid); ``` -------------------------------- ### Open Process Functionality Source: https://github.com/rob--/memoryjs/wiki/Process Details the `openProcess` function, which opens a handle to a specified process. It can be used synchronously or asynchronously with a callback. ```javascript // synchronously const processObject = memoryjs.openProcess(processIdentifier); // asynchronously memoryjs.openProcess(processIdentifier, (error, processObject) => { }); ``` -------------------------------- ### Allocate and Reserve Memory with memoryjs Source: https://github.com/rob--/memoryjs/wiki/Home Demonstrates using `VirtualAllocEx` to reserve, commit, or change regions of memory within a target process. This is useful for allocating space for code or data. ```javascript const memoryjs = require('memoryjs'); const targetProcess = memoryjs.getProcesses().find(p => p.szExeFile === 'notepad.exe'); const sizeToAllocate = 4096; // Allocate 4KB if (targetProcess) { // Allocate memory with default protection (MEM_COMMIT | MEM_RESERVE) try { const allocatedAddress = memoryjs.allocateMemory(targetProcess.modBaseAddr, sizeToAllocate); console.log(`Allocated ${sizeToAllocate} bytes at address: ${allocatedAddress}`); // You can now write data to this allocated memory const dataToWrite = Buffer.from('Hello from Node.js!'); memoryjs.writeBuffer(allocatedAddress, dataToWrite); console.log('Wrote buffer to allocated memory.'); // Read the buffer back const readBuffer = memoryjs.readBuffer(allocatedAddress, dataToWrite.length); console.log('Read buffer:', readBuffer.toString()); // Free the allocated memory (equivalent to VirtualFreeEx) memoryjs.freeMemory(targetProcess.modBaseAddr, allocatedAddress, sizeToAllocate); console.log('Freed allocated memory.'); } catch (error) { console.error('Error allocating/freeing memory:', error); } } else { console.log('Target process not found.'); } ``` -------------------------------- ### Vector3 and Vector4 Structures Source: https://github.com/rob--/memoryjs/blob/master/README.md Illustrates how to define and write Vector3 and Vector4 structures to memory using memoryjs. ```javascript const vector3 = { x: 0.0, y: 0.0, z: 0.0 }; memoryjs.writeMemory(handle, address, vector3, memoryjs.VEC3); const vector4 = { w: 0.0, x: 0.0, y: 0.0, z: 0.0 }; memoryjs.writeMemory(handle, address, vector4, memoryjs.VEC4); ``` -------------------------------- ### Module Operations with memoryjs Source: https://github.com/rob--/memoryjs/blob/master/README.md Shows how to find a specific module within a process and retrieve a list of all modules associated with a process using memoryjs. Both synchronous and asynchronous operations are covered. ```javascript // sync: find a module const moduleObject = memoryjs.findModule(moduleName, processId); // async: find a module memoryjs.findModule(moduleName, processId, (error, moduleObject) => {}); // sync: get all modules const modules = memoryjs.getModules(processId); // async: get all modules memoryjs.getModules(processId, (error, modules) => {}); ``` -------------------------------- ### Initialize memoryjs Source: https://github.com/rob--/memoryjs/blob/master/README.md Initializes the memoryjs module in a Node.js application by requiring the package and specifying the target process name. ```javascript const memoryjs = require('memoryjs'); const processName = "csgo.exe"; ``` -------------------------------- ### Recompile Memory.js for Debugging Source: https://github.com/rob--/memoryjs/blob/master/README.md Commands to recompile the memory.js project for debugging purposes, with options for automatic architecture detection, 32-bit, or 64-bit compilation. ```bash # will automatically compile based on the detected Node architecture npm run debug # compile to target 32 bit processes npm run debug32 # compile to target 64 bit processes npm run debug64 ``` -------------------------------- ### Memory Mapped Files Source: https://github.com/rob--/memoryjs/blob/master/README.md Provides functions to open, map, and close memory-mapped files. It allows mapping entire files or portions into a specified process, with options for offset, size, and page protection. ```javascript // sync: open a named file mapping object const fileHandle = memoryjs.openFileMapping(fileName); // sync: map entire file into a specified process const baseAddress = memoryjs.mapViewOfFile(processHandle, fileName); // sync: map portion of a file into a specified process const baseAddress = memoryjs.mapViewOfFile(processHandle, fileName, offset, viewSize, pageProtection); // sync: close handle to a file mapping object const success = memoryjs.closeHandle(fileHandle); ``` -------------------------------- ### 64-bit Integer Operations Source: https://github.com/rob--/memoryjs/blob/master/README.md Demonstrates how to read and write 64-bit integers using memoryjs, highlighting the use of BigInt for these operations. ```javascript const value = memoryjs.readMemory(handle, address, memoryjs.INT64); console.log(typeof value); // bigint memoryjs.writeMemory(handle, address, value + 1n, memoryjs.INT64); ``` -------------------------------- ### Read and Write Process Memory with memoryjs Source: https://github.com/rob--/memoryjs/wiki/Home Shows how to read and write data to the memory of a target process using memoryjs. This includes reading specific data types and writing new values, essential for memory manipulation. ```javascript const memoryjs = require('memoryjs'); // Assume 'targetProcess' and 'address' are obtained from previous steps // Example: Reading an integer from a known address in notepad.exe const targetProcess = memoryjs.getProcesses().find(p => p.szExeFile === 'notepad.exe'); if (targetProcess) { // Example address (replace with a valid address for your target) const addressToRead = 0x12345678; const dataType = 'int'; // 'int', 'float', 'double', 'byte', 'short', 'long', 'char', 'string' try { const readValue = memoryjs.readMemory(targetProcess.modBaseAddr + addressToRead, dataType); console.log(`Value at address ${addressToRead}:`, readValue); // Example: Writing a new integer value to the address const newValue = 42; memoryjs.writeMemory(targetProcess.modBaseAddr + addressToRead, newValue, dataType); console.log(`Wrote ${newValue} to address ${addressToRead}`); // Verify the write const updatedValue = memoryjs.readMemory(targetProcess.modBaseAddr + addressToRead, dataType); console.log(`Updated value at address ${addressToRead}:`, updatedValue); } catch (error) { console.error('Error reading/writing memory:', error); } } else { console.log('Target process not found.'); } ``` -------------------------------- ### Process Management API Source: https://github.com/rob--/memoryjs/wiki/Old-README Provides documentation for core memoryjs functions related to process management: openProcess, closeProcess, getProcesses, and findModule. It details the parameters, return values, and callback structures for each function. ```APIDOC openProcess(processIdentifier[, callback]) Opens a process to read from and write to it. - processIdentifier (string/int): The identifier of the process to open (name or id). - callback (function): Called with err and processObject. Returns: process object. closeProcess(handle) Closes the handle on the opened process. - handle (int): The handle of the process to close. getProcesses([callback]) Collects information about all running processes. - callback (function): Called with err and processes array. Returns: Array of process objects. findModule(moduleName, processId[, callback]) Finds a module associated with a given process. - moduleName (string): The name of the module to find. - processId (int): The id of the process. - callback (function): Called with err and module object. Returns: module object. ``` -------------------------------- ### memoryjs API: writeBuffer Source: https://github.com/rob--/memoryjs/wiki/Buffers Writes a buffer to a specified memory address within a process. Requires the process handle and the target address. ```APIDOC writeBuffer(handle, address, buffer) - handle: The process handle obtained from openProcess. - address: The memory address to write to. - buffer: The buffer containing the data to write. Writes the provided buffer to the specified memory address. Example: memoryjs.writeBuffer(processObject.handle, address, buffer); ``` -------------------------------- ### Compile memoryjs for 32-bit or 64-bit Targets Source: https://github.com/rob--/memoryjs/wiki/Install Instructions for recompiling the memoryjs library to target specific process architectures (32-bit or 64-bit). Navigate to the memoryjs node module directory and run the appropriate build script. ```bash npm run build32 # or npm run build64 ``` -------------------------------- ### Windows API Functions Exposed by memoryjs Source: https://github.com/rob--/memoryjs/wiki/Home Lists the core Windows API functions that memoryjs directly wraps, providing access to low-level memory operations. These functions are fundamental for interacting with other processes' memory spaces. ```APIDOC memoryjs: getProcesses() -> Array Lists all running processes. ProcessInfo: { th32ProcessID: number, szExeFile: string, szModule32: string } getModules(processId: number) -> Array Lists all modules loaded by a process. ModuleInfo: { modBaseAddr: number, modBaseSize: number, szModule: string } readMemory(address: number, dataType: string) -> any Reads data from a specified memory address. Supported dataTypes: 'int', 'float', 'double', 'byte', 'short', 'long', 'char', 'string' writeMemory(address: number, value: any, dataType: string) -> void Writes data to a specified memory address. readBuffer(address: number, size: number) -> Buffer Reads a block of memory into a Buffer. writeBuffer(address: number, buffer: Buffer) -> void Writes a Buffer to a specified memory address. protectMemory(address: number, size: number, newProtection: number) -> number Changes the memory protection of a region. Returns the original protection flags. Common protection flags: memoryjs.PAGE_READONLY = 0x02 memoryjs.PAGE_READWRITE = 0x04 memoryjs.PAGE_EXECUTE_READ = 0x20 memoryjs.PAGE_EXECUTE_READWRITE = 0x40 allocateMemory(processHandle: number, size: number, protection?: number, allocationType?: number) -> number Allocates memory within a process. Returns the base address of the allocated memory. Default protection: memoryjs.PAGE_EXECUTE_READWRITE Default allocationType: memoryjs.MEM_COMMIT | memoryjs.MEM_RESERVE freeMemory(processHandle: number, address: number, size: number) -> void Frees previously allocated memory. // Pattern scanning and function execution are also available but not detailed here. ``` -------------------------------- ### Read Generic Structure from Memory with dissolve Source: https://github.com/rob--/memoryjs/wiki/Buffers Explains how to read a buffer from memory and parse it into a JavaScript object using the 'dissolve' library, enabling the handling of complex data structures. ```javascript const buffer = memoryjs.readBuffer(processObject.handle, address, size); const parser = Dissolve().loop(function(end) { this .floatle("x") .floatle("y") .floatle("z") .tap(function() { this.push(this.vars); this.vars = {}; }); }); parser.on("readable", function() { let e; while (e = parser.read()) { console.log(e); } }); parser.write(buffer); ``` -------------------------------- ### Hardware Breakpoints Source: https://github.com/rob--/memoryjs/blob/master/README.md Enables managing hardware breakpoints within a process, including attaching/detaching debuggers, waiting for debug events, handling events, setting, and removing breakpoints. ```javascript // sync: attach debugger const success = memoryjs.attachDebugger(processId, exitOnDetach); // sync: detach debugger const success = memoryjs.detachDebugger(processId); // sync: wait for debug event const success = memoryjs.awaitDebugEvent(hardwareRegister, millisTimeout); // sync: handle debug event const success = memoryjs.handleDebugEvent(processId, threadId); // sync: set hardware breakpoint const success = memoryjs.setHardwareBreakpoint(processId, address, hardwareRegister, trigger, length); // sync: remove hardware breakpoint const success = memoryjs.removeHardwareBreakpoint(processId, hardwareRegister); ``` -------------------------------- ### Module Object Structure Source: https://github.com/rob--/memoryjs/wiki/Modules An object returned when retrieving module details, containing base address, size, executable path, module name, and process ID. ```javascript { modBaseAddr: 468123648, modBaseSize: 80302080, szExePath: 'c:\\program files (x86)\\steam\\steamapps\\common\\counter-strike global offensive\\csgo\\bin\\client.dll', szModule: 'client.dll', th32ProcessID: 10316 } ``` -------------------------------- ### Memory Protection Constants Source: https://github.com/rob--/memoryjs/wiki/Protection Defines the various protection types that can be applied to memory regions using the memory.js library. These correspond to Windows VirtualProtectEx constants. ```APIDOC PAGE_NOACCESS: 0x01 PAGE_READONLY: 0x02 PAGE_READWRITE: 0x04 PAGE_WRITECOPY: 0x08 PAGE_EXECUTE: 0x10 PAGE_EXECUTE_READ: 0x20 PAGE_EXECUTE_READWRITE: 0x40 PAGE_EXECUTE_WRITECOPY: 0x80 PAGE_GUARD: 0x100 PAGE_NOCACHE: 0x200 PAGE_WRITECOMBINE: 0x400 PAGE_ENCLAVE_UNVALIDATED: 0x20000000 PAGE_TARGETS_INVALID: 0x40000000 PAGE_TARGETS_NO_UPDATE: 0x40000000 PAGE_ENCLAVE_THREAD_CONTROL: 0x80000000 ``` -------------------------------- ### Generic Structures with Buffers Source: https://github.com/rob--/memoryjs/wiki/Old-README Describes how to write and read generic data structures to/from memory using buffers. It suggests using the 'concentrate' library to create buffers from structures and 'dissolve' to parse buffers back into structures. ```javascript // Writing a structure to memory using concentrate and writeBuffer // const buffer = concentrate(structure); // memoryjs.writeBuffer(address, buffer); // Reading a structure from memory using readBuffer and dissolve // const buffer = memoryjs.readBuffer(address, size); // const structure = dissolve(buffer); ``` -------------------------------- ### Debugger Class Methods Source: https://github.com/rob--/memoryjs/blob/master/README.md Defines the methods available in the Debugger wrapper class for managing hardware breakpoints. ```javascript class Debugger { attach(processId, killOnDetach = false); detach(processId); setHardwareBreakpoint(processId, address, trigger, dataType); removeHardwareBreakpoint(processId, register); } ``` -------------------------------- ### Function Execution Source: https://github.com/rob--/memoryjs/blob/master/README.md Allows executing a function in a remote process with specified arguments and return type. Supports both synchronous and asynchronous execution. ```javascript // sync: execute a function in a remote process const result = memoryjs.callFunction(handle, args, returnType, address); // async: execute a function in a remote process memoryjs.callFunction(handle, args, returnType, address, (error, result) => {}); ``` -------------------------------- ### Module Information with memoryjs Source: https://github.com/rob--/memoryjs/wiki/Old-README Shows how to find specific modules within a process and retrieve a list of all modules associated with a process using memoryjs. Both synchronous and asynchronous methods are available. ```javascript const memoryjs = require('memoryjs'); const processName = "csgo.exe"; // Find a module (sync) const module = memoryjs.findModule("client.dll", processObject.processId); // Find a module (async) memoryjs.findModule("client.dll", processObject.processId, (error, module) => { // Handle error or module object }); // Get all modules (sync) const modules = memoryjs.getModules(processObject.processId); // Get all modules (async) memoryjs.getModules(processObject.processId, (error, modules) => { // Handle error or modules array }); ``` -------------------------------- ### Await and Handle Debug Event Loop Source: https://github.com/rob--/memoryjs/blob/master/README.md Creates an interval to continuously await debug events from a specific register with a timeout. If an event occurs, it handles the debug event. ```javascript const timeout = 100; setInterval(() => { // `debugEvent` can be null if no event occurred const debugEvent = memoryjs.awaitDebugEvent(register, timeout); // If a breakpoint occurred, handle it if (debugEvent) { memoryjs.handleDebugEvent(debugEvent.processId, debugEvent.threadId); } }, timeout); ``` -------------------------------- ### Memory Protection and Pattern Scanning with memoryjs Source: https://github.com/rob--/memoryjs/wiki/Old-README Details how to change memory protection settings for a given memory region and perform pattern scanning to find specific byte sequences within a process's memory. ```javascript const memoryjs = require('memoryjs'); const processObject = memoryjs.openProcess("csgo.exe"); const address = 0x12345678; // Example address const size = 1024; const protection = 'PAGE_EXECUTE_READWRITE'; // e.g., 'PAGE_READONLY', 'PAGE_READWRITE', 'PAGE_EXECUTE_READWRITE' // Set protection of memory const oldProtection = memoryjs.setProtection(processObject.handle, address, size, protection); // Pattern scanning (sync) const signature = "55 8B EC 83 E4 F8 83 EC 18"; // Example signature const moduleName = "client.dll"; const patternOffset = 0; const addressOffset = 0; const offset = memoryjs.findPattern(processObject.handle, moduleName, signature, 'hex', patternOffset, addressOffset); // Pattern scanning (async) memoryjs.findPattern(processObject.handle, moduleName, signature, 'hex', patternOffset, addressOffset, (error, offset) => { // Handle error or offset }); ``` -------------------------------- ### String Handling and Address Retrieval Source: https://github.com/rob--/memoryjs/blob/master/README.md Demonstrates how to obtain the memory address of C++ strings (std::string and char*) for reading and writing operations. The library reads strings until a null terminator is found, with a safeguard against infinite loops. ```C++ std::string str1 = "hello"; std::cout << "Address: 0x" << hex << (DWORD) str1.c_str() << dec << std::endl; char* str2 = "hello"; std::cout << "Address: 0x" << hex << (DWORD) str2 << dec << std::endl; ``` -------------------------------- ### Supported Data Types for Function Arguments Source: https://github.com/rob--/memoryjs/blob/master/README.md Lists the data types supported by memoryjs for passing arguments to remote functions, including void, string, char, boolean, integer, double, and float. ```javascript memoryjs.T_VOID = 0x0, memoryjs.T_STRING = 0x1, memoryjs.T_CHAR = 0x2, memoryjs.T_BOOL = 0x3, memoryjs.T_INT = 0x4, memoryjs.T_DOUBLE = 0x5, memoryjs.T_FLOAT = 0x6, ``` -------------------------------- ### Module Object Structure Source: https://github.com/rob--/memoryjs/blob/master/README.md Represents information about a loaded module within a process, including its base address, size, executable path, module name, and process ID. ```javascript { modBaseAddr: 468123648, modBaseSize: 80302080, szExePath: 'c:\\program files (x86)\\steam\\steamapps\\common\\counter-strike global offensive\\csgo\\bin\\client.dll', szModule: 'client.dll', th32ProcessID: 10316, GlblcntUsage: 2 } ``` -------------------------------- ### Memory Read/Write Operations with memoryjs Source: https://github.com/rob--/memoryjs/wiki/Old-README Illustrates reading and writing data to a process's memory using memoryjs. Supports reading/writing individual values of specified data types and entire memory buffers. ```javascript const memoryjs = require('memoryjs'); const processObject = memoryjs.openProcess("csgo.exe"); const address = 0x12345678; // Example address const dataType = 'int'; // e.g., 'int', 'float', 'double', 'byte', 'short', 'long', 'char' // Read from memory (sync) const value = memoryjs.readMemory(processObject.handle, address, dataType); // Read from memory (async) memoryjs.readMemory(processObject.handle, address, dataType, (error, value) => { // Handle error or value }); // Read buffer from memory (sync) const buffer = memoryjs.readBuffer(processObject.handle, address, 1024); // Read 1024 bytes // Read buffer from memory (async) memoryjs.readBuffer(processObject.handle, address, 1024, (error, buffer) => { // Handle error or buffer }); // Write to memory memoryjs.writeMemory(processObject.handle, address, 100, 'int'); // Write buffer to memory const dataToWrite = Buffer.from([0x01, 0x02, 0x03]); memoryjs.writeBuffer(processObject.handle, address, dataToWrite); ``` -------------------------------- ### Configure Index.js for Debug Build Source: https://github.com/rob--/memoryjs/blob/master/README.md Modifies the index.js file to require the debug version of the memory.js module. ```javascript const memoryjs = require('./build/Debug/memoryjs'); ``` -------------------------------- ### Memory Mapped Files - Open File Mapping Source: https://github.com/rob--/memoryjs/blob/master/README.md Opens an existing file mapping object to obtain a handle. This handle is used in subsequent operations to access the file's content in memory. ```JavaScript openFileMapping(fileName) - fileName: name of the file mapping object to be opened - returns: handle to the file mapping object ``` -------------------------------- ### Pattern Scanning Source: https://github.com/rob--/memoryjs/blob/master/README.md Enables pattern scanning across all modules, specific modules, or memory regions within a process. Supports both synchronous and asynchronous operations. ```javascript // sync: pattern scan all modules and memory regions const address = memoryjs.findPattern(handle, pattern, flags, patternOffset); // async: pattern scan all modules and memory regions memoryjs.findPattern(handle, pattern, flags, patternOffset, (error, address) => {}); // sync: pattern scan a given module const address = memoryjs.findPattern(handle, moduleName, pattern, flags, patternOffset); // async: pattern scan a given module memoryjs.findPattern(handle, moduleName, pattern, flags, patternOffset, (error, address) => {}); // sync: pattern scan a memory region or module at the given base address const address = memoryjs.findPattern(handle, baseAddress, pattern, flags, patternOffset); // async: pattern scan a memory region or module at the given base address memoryjs.findPattern(handle, baseAddress, pattern, flags, patternOffset, (error, address) => {}); ``` -------------------------------- ### Change Memory Protection with memoryjs Source: https://github.com/rob--/memoryjs/wiki/Home Illustrates how to modify the memory protection flags of a region in a target process using `VirtualProtectEx`. This is crucial for making memory readable, writable, or executable. ```javascript const memoryjs = require('memoryjs'); // Assume 'targetProcess' and 'address' are obtained const targetProcess = memoryjs.getProcesses().find(p => p.szExeFile === 'notepad.exe'); const addressToProtect = 0x12345678; // Example address const sizeOfRegion = 1024; // Example size if (targetProcess) { // Define new protection flags (e.g., PAGE_EXECUTE_READWRITE) // See Windows API documentation for all possible flags const newProtection = memoryjs.PAGE_EXECUTE_READWRITE; try { const originalProtection = memoryjs.protectMemory(targetProcess.modBaseAddr + addressToProtect, sizeOfRegion, newProtection); console.log(`Memory protection changed for region starting at ${addressToProtect}. Original protection: ${originalProtection}`); // You can now read/write/execute memory in this region as permitted by newProtection // To restore original protection (optional): // memoryjs.protectMemory(targetProcess.modBaseAddr + addressToProtect, sizeOfRegion, originalProtection); // console.log('Memory protection restored.'); } catch (error) { console.error('Error changing memory protection:', error); } } else { console.log('Target process not found.'); } ``` -------------------------------- ### DLL Injection and Unloading Source: https://github.com/rob--/memoryjs/blob/master/README.md Provides functionality to inject a DLL into a remote process and unload a DLL either by its base address or by its module name. Supports both synchronous and asynchronous operations. ```javascript // sync: inject a DLL const success = memoryjs.injectDll(handle, dllPath); // async: inject a DLL memoryjs.injectDll(handle, dllPath, (error, success) => {}); // sync: unload a DLL by module base address const success = memoryjs.unloadDll(handle, moduleBaseAddress); // async: unload a DLL by module base address memoryjs.unloadDll(handle, moduleBaseAddress, (error, success) => {}); // sync: unload a DLL by module name const success = memoryjs.unloadDll(handle, moduleName); // async: unload a DLL by module name memoryjs.unloadDll(handle, moduleName, (error, success) => {}); ``` -------------------------------- ### Set Hardware Breakpoint Source: https://github.com/rob--/memoryjs/blob/master/README.md Sets a hardware breakpoint on a given address for a process. Requires specifying the debug register, data size, address, trigger type, and data type. ```javascript // available registers: DR0 through DR3 const register = memoryjs.DR0; // int = 4 bytes const size = 4; const address = 0xDEADBEEF; const trigger = memoryjs.TRIGGER_ACCESS; const dataType = memoryjs.INT; const success = memoryjs.setHardwareBreakpoint(processId, address, register, trigger, size); ``` -------------------------------- ### Memory Mapped Files - Map View of File Source: https://github.com/rob--/memoryjs/blob/master/README.md Maps a file into the target process's memory. This function can map the entire file or a specific portion with configurable page protection. ```JavaScript mapViewOfFile(processHandle, fileName) - processHandle: the target process to map the file to - fileName: name of the file mapping object - Description: maps the entire file to target process' memory. Page protection defaults to constants.PAGE_READONLY. - Returns: the base address of the mapped file mapViewOfFile(processHandle, fileName, offset, viewSize, pageProtection) - processHandle: the target process to map the file to - fileName: handle of the file mapping object, obtained by memoryjs.openFileMapping - offset (number or bigint): the offset from the beginning of the file (has to be multiple of 64KB) - viewSize (number or bigint): the number of bytes to map (if 0, the entire file will be read, regardless of offset) - pageProtection: desired page protection - Description: maps a view of the file to the target process' memory - Returns: the base address of the mapped file ``` -------------------------------- ### Function Execution (Sync) Source: https://github.com/rob--/memoryjs/wiki/Old-README Executes a function synchronously within a target process. Requires the process handle, arguments, return type, and the address of the function. ```javascript const result = memoryjs.callFunction(handle, args, returnType, address); ``` -------------------------------- ### Process Object Structure Source: https://github.com/rob--/memoryjs/blob/master/README.md Defines the structure of a process object returned by memoryjs functions, including process ID, thread count, parent process ID, executable name, and module base address. Note that 'handle' and 'modBaseAddr' are only available when opening a process. ```javascript { dwSize: 304, th32ProcessID: 10316, cntThreads: 47, th32ParentProcessID: 7804, pcPriClassBase: 8, szExeFile: "csgo.exe", modBaseAddr: 1673789440, handle: 808 } ``` -------------------------------- ### Memory Allocation Constants Source: https://github.com/rob--/memoryjs/blob/master/README.md Defines bit flag DWORD values for memory allocation types. These constants specify how memory should be committed or reserved. ```JavaScript memoryjs.MEM_COMMIT memoryjs.MEM_RESERVE memoryjs.MEM_RESET memoryjs.MEM_RESET_UNDO ``` -------------------------------- ### memoryjs API: readBuffer Source: https://github.com/rob--/memoryjs/wiki/Buffers Reads a specified number of bytes from a given memory address into a buffer. Supports both synchronous and asynchronous operations. ```APIDOC readBuffer(handle, address, size[, callback]) - handle: The process handle obtained from openProcess. - address: The memory address to read from. - size: The number of bytes to read. - callback (optional): A function with (error, buffer) parameters for asynchronous operation. Returns: A buffer containing the bytes read from memory. Example (synchronous): const buffer = memoryjs.readBuffer(processObject.handle, address, size); Example (asynchronous): memoryjs.readBuffer(processObject.handle, address, size, (error, buffer) => { // Handle error or buffer }); ``` -------------------------------- ### virtualAllocEx Source: https://github.com/rob--/memoryjs/wiki/Old-README Reserves, commits, or changes the state of a memory region within a specified process. Allows specifying address, size, allocation type, and protection. Supports asynchronous calls via a callback. ```APIDOC virtualAllocEx(handle, address, size, allocationType, protection[, callback]) Reserves, commits or changes the state of a region of memory within the virtual address space of a specified process. Parameters: - handle (int): The handle of the process. - address (int): The starting address for the region. Use null to let the function determine the address. - size (int): The size of the region to allocate. - allocationType (int): The type of memory allocation (refer to allocation types). - protection (int): The memory protection for the region (refer to protection types). - callback (function): Optional. A callback function with 'err' and 'result' parameters. Returns: Base address of the allocated region of pages if successful. Notes: Refer to Microsoft's VirtualAllocEx documentation for more details. Errors are thrown if no callback is provided and the function fails. Leave 'address' as null to allocate memory. ```