### Install memoryjs Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Installs the memoryjs package using npm. Requires node-gyp for compilation. Ensure your Node.js version and target process architecture match. ```bash npm install memoryjs ``` ```bash # Automatically compile based on detected Node architecture npm run build # Compile to target 32 bit processes npm run build32 # Compile to target 64 bit processes npm run build64 ``` -------------------------------- ### Attaching the Debugger Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Example of how to attach the Debugger wrapper to a process. ```javascript const hardwareDebugger = memoryjs.Debugger; hardwareDebugger.attach(processId); ``` -------------------------------- ### Process Management with memoryjs Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Demonstrates how to open, get, and close process handles using memoryjs. Supports both synchronous and asynchronous operations. ```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); ``` -------------------------------- ### Memory Reading and Writing with memoryjs Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Provides examples for reading and writing data types and buffers in process memory using memoryjs. Includes fetching memory regions. Supports sync and async operations. ```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) => {}); ``` -------------------------------- ### Setting a Hardware Breakpoint Source: https://github.com/hook-ac/memoryjs-ts/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); ``` -------------------------------- ### Remote Function Execution with memoryjs Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Explains how to execute functions in a remote process using memoryjs. It details the required argument format (array of objects with type and value), supported data types, and how to specify the return type. 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); { returnValue: 7, exitCode: 7 } ``` -------------------------------- ### String Memory Address Example Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Demonstrates how to obtain the memory address of a C++ string literal or a char pointer. This is useful for reading or writing string data in memory using the memoryjs library. ```c++ #include #include #include // Assuming DWORD is defined elsewhere, e.g., as unsigned long // using DWORD = unsigned long; int main() { std::string str1 = "hello"; std::cout << "Address of str1: 0x" << std::hex << (DWORD)str1.c_str() << std::dec << std::endl; char* str2 = "hello"; std::cout << "Address of str2: 0x" << std::hex << (DWORD)str2 << std::dec << std::endl; return 0; } ``` -------------------------------- ### Memory File Mapping with memoryjs Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Demonstrates how to map a file into a target process's memory using memoryjs and read its contents. It covers opening processes, file mappings, mapping views, reading data, and closing handles. Also shows how to map to the current Node process. ```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); ``` ```javascript const processObject = memoryjs.openProcess(process.pid); ``` -------------------------------- ### Memory Mapped Files - MapViewOfFile Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Details the `mapViewOfFile` function for mapping memory-mapped files into a target process. It covers both mapping the entire file and mapping specific views with customizable protection. ```APIDOC mapViewOfFile(processHandle: ProcessHandle, fileHandle: Handle): BaseAddress - processHandle: The target process to map the file to. - fileHandle: Handle of the file mapping object, obtained by `memoryjs.openFileMapping`. - Description: Maps the entire file to the target process' memory. Page protection defaults to `constants.PAGE_READONLY`. - Returns: The base address of the mapped file. mapViewOfFile(processHandle: ProcessHandle, fileHandle: Handle, offset: number | bigint, viewSize: number | bigint, pageProtection: PageProtectionConstant): BaseAddress - processHandle: The target process to map the file to. - fileHandle: Handle of the file mapping object, obtained by `memoryjs.openFileMapping`. - offset: The offset from the beginning of the file (must be a multiple of 64KB). - viewSize: The number of bytes to map (if 0, the entire file will be read, regardless of offset). - pageProtection: Desired page protection (refer to Protection Type section). - Description: Maps a view of the file to the target process' memory. - Returns: The base address of the mapped file. ``` -------------------------------- ### Memory Mapped Files - OpenFileMapping Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Provides the signature and description for the `openFileMapping` function, which obtains a handle to a named file mapping object. This is the first step in working with memory-mapped files. ```APIDOC openFileMapping(fileName: string): Handle - fileName: The name of the file mapping object to be opened. - Returns: A handle to the file mapping object. ``` -------------------------------- ### Structron for String Handling Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Demonstrates using structron with a custom type to read and write std::string from memory, requiring process handle, base address, and architecture. ```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'); ``` -------------------------------- ### Recompile Project for Debugging Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Commands to recompile the memory.js project for debugging purposes, supporting 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 ``` -------------------------------- ### Handling Debug Events Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Demonstrates how to create event listeners for debug events, both for all registers and specific registers. ```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); }); ``` -------------------------------- ### Initialize memoryjs Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Initializes the memoryjs module in your Node.js application by requiring the package and specifying the target process name. ```javascript const memoryjs = require('memoryjs'); const processName = "csgo.exe"; ``` -------------------------------- ### Await and Handle Debug Event Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Creates a loop to periodically await debug events for a specific register with a timeout, and handles the event if one occurs. ```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 Mapped Files Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Functions for opening, mapping, and closing named file mapping objects. Allows mapping entire files or portions into a process's memory space. ```javascript const fileHandle = memoryjs.openFileMapping(fileName); ``` ```javascript const baseAddress = memoryjs.mapViewOfFile(processHandle, fileName); ``` ```javascript const baseAddress = memoryjs.mapViewOfFile(processHandle, fileName, offset, viewSize, pageProtection); ``` ```javascript const success = memoryjs.closeHandle(fileHandle); ``` -------------------------------- ### Pattern Scanning Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Provides functionality to scan for patterns within process memory. Supports scanning all modules, a specific module, or a memory region at a given base address. Both synchronous and asynchronous methods are available. ```javascript // sync: pattern scan all modules and memory regions const address = memoryjs.findPattern(handle, pattern, flags, patternOffset); ``` ```javascript // async: pattern scan all modules and memory regions memoryjs.findPattern(handle, pattern, flags, patternOffset, (error, address) => {}); ``` ```javascript // sync: pattern scan a given module const address = memoryjs.findPattern(handle, moduleName, pattern, flags, patternOffset); ``` ```javascript // async: pattern scan a given module memoryjs.findPattern(handle, moduleName, pattern, flags, patternOffset, (error, address) => {}); ``` ```javascript // sync: pattern scan a memory region or module at the given base address const address = memoryjs.findPattern(handle, baseAddress, pattern, flags, patternOffset); ``` ```javascript // async: pattern scan a memory region or module at the given base address memoryjs.findPattern(handle, baseAddress, pattern, flags, patternOffset, (error, address) => {}); ``` -------------------------------- ### Module Operations with memoryjs Source: https://github.com/hook-ac/memoryjs-ts/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 ID. Supports sync and async calls. ```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) => {}); ``` -------------------------------- ### Debugger Class Methods Source: https://github.com/hook-ac/memoryjs-ts/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); } ``` -------------------------------- ### 64-bit Integer Memory Operations Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Demonstrates reading and writing 64-bit integers using BigInt in JavaScript, highlighting the type conversion 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); ``` -------------------------------- ### DLL Injection and Unloading Source: https://github.com/hook-ac/memoryjs-ts/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. Both synchronous and asynchronous operations are available. ```javascript // sync: inject a DLL const success = memoryjs.injectDll(handle, dllPath); ``` ```javascript // async: inject a DLL memoryjs.injectDll(handle, dllPath, (error, success) => {}); ``` ```javascript // sync: unload a DLL by module base address const success = memoryjs.unloadDll(handle, moduleBaseAddress); ``` ```javascript // async: unload a DLL by module base address memoryjs.unloadDll(handle, moduleBaseAddress, (error, success) => {}); ``` ```javascript // sync: unload a DLL by module name const success = memoryjs.unloadDll(handle, moduleName); ``` ```javascript // async: unload a DLL by module name memoryjs.unloadDll(handle, moduleName, (error, success) => {}); ``` -------------------------------- ### Function Execution Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Enables the execution of functions within a remote process, allowing for passing arguments and specifying return types. Both synchronous and asynchronous execution are supported. ```javascript // sync: execute a function in a remote process const result = memoryjs.callFunction(handle, args, returnType, address); ``` ```javascript // async: execute a function in a remote process memoryjs.callFunction(handle, args, returnType, address, (error, result) => {}); ``` -------------------------------- ### Hardware Breakpoints Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Manages hardware breakpoints for debugging purposes, including attaching and detaching debuggers, waiting for and handling debug events, and setting/removing hardware breakpoints on specific addresses and registers. ```javascript // sync: attach debugger const success = memoryjs.attachDebugger(processId, exitOnDetach); ``` ```javascript // sync: detach debugger const success = memoryjs.detachDebugger(processId); ``` ```javascript // sync: wait for debug event const success = memoryjs.awaitDebugEvent(hardwareRegister, millisTimeout); ``` ```javascript // sync: handle debug event const success = memoryjs.handleDebugEvent(processId, threadId); ``` ```javascript // sync: set hardware breakpoint const success = memoryjs.setHardwareBreakpoint(processId, address, hardwareRegister, trigger, length); ``` ```javascript // sync: remove hardware breakpoint const success = memoryjs.removeHardwareBreakpoint(processId, hardwareRegister); ``` -------------------------------- ### Memory Allocation Constants Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Defines the bit flag DWORD values for memory allocation types used with functions like VirtualAllocEx. These constants are part of the memoryjs library. ```javascript memoryjs.MEM_COMMIT memoryjs.MEM_RESERVE memoryjs.MEM_RESET memoryjs.MEM_RESET_UNDO ``` -------------------------------- ### Module Object Structure Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Represents a loaded module within a process, including its base address, size, path, 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 } ``` -------------------------------- ### Signature Type Flags Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Explains the different flags used for signature types in pattern scanning. These flags determine how memory addresses are interpreted or manipulated during the scan. ```javascript 0x0 or memoryjs.NORMAL // Normal signature 0x1 or memoryjs.READ // Read memory at the address 0x2 or memoryjs.SUBSTRACT // Subtract image base from the address // Example of combining flags: memoryjs.READ | memoryjs.SUBSTRACT ``` -------------------------------- ### Set Hardware Breakpoint Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Sets a hardware breakpoint on a specific address within a process, using a given register, trigger type, and data size. ```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); ``` -------------------------------- ### Vector4 Memory Operations Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Illustrates reading and writing a Vector4 structure, consisting of four float values (w, x, y, z), to and from memory. ```javascript const vector4 = { w: 0.0, x: 0.0, y: 0.0, z: 0.0 }; memoryjs.writeMemory(handle, address, vector4, memoryjs.VEC4); ``` -------------------------------- ### Process Object Structure Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Defines the structure of a process object, including properties like process ID, thread count, parent process ID, executable file name, base module address, and handle. Note that 'handle' and 'modBaseAddr' are only available when a process is opened, not when listing processes. ```javascript { dwSize: 304, th32ProcessID: 10316, cntThreads: 47, th32ParentProcessID: 7804, pcPriClassBase: 8, szExeFile: "csgo.exe", modBaseAddr: 1673789440, handle: 808 } ``` -------------------------------- ### Vector3 Memory Operations Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Shows how to read and write a Vector3 structure, which is composed of three float values (x, y, z), to and from memory. ```javascript const vector3 = { x: 0.0, y: 0.0, z: 0.0 }; memoryjs.writeMemory(handle, address, vector3, memoryjs.VEC3); ``` -------------------------------- ### Memory Protection Constants Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Defines the bit flag DWORD values for memory protection types used in memory operations. These constants are provided by the memoryjs library and correspond to Windows memory protection settings. ```javascript memoryjs.PAGE_NOACCESS memoryjs.PAGE_READONLY memoryjs.PAGE_READWRITE memoryjs.PAGE_WRITECOPY memoryjs.PAGE_EXECUTE memoryjs.PAGE_EXECUTE_READ memoryjs.PAGE_EXECUTE_READWRITE memoryjs.PAGE_EXECUTE_WRITECOPY memoryjs.PAGE_GUARD memoryjs.PAGE_NOCACHE memoryjs.PAGE_WRITECOMBINE memoryjs.PAGE_ENCLAVE_THREAD_CONTROL memoryjs.PAGE_TARGETS_NO_UPDATE memoryjs.PAGE_TARGETS_INVALID memoryjs.PAGE_ENCLAVE_UNVALIDATED ``` -------------------------------- ### Attach Debugger Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Attaches the memory.js debugger to a specified process ID. ```javascript const hardwareDebugger = memoryjs.Debugger; hardwareDebugger.attach(processId); ``` -------------------------------- ### Update index.js for Debug Build Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Modifies the require statement in index.js to load the debug build of the memory.js module. ```javascript const memoryjs = require('./build/Debug/memoryjs'); ``` -------------------------------- ### Memory Data Types Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Defines constants for various data types used in memory read/write operations, including their byte sizes, aliases, and value ranges. ```javascript memoryjs.BOOL (1 byte) memoryjs.BOOLEAN (1 byte) memoryjs.INT8 (1 byte) memoryjs.BYTE (1 byte) memoryjs.CHAR (1 byte) memoryjs.UINT8 (1 byte) memoryjs.UBYTE (1 byte) memoryjs.UCHAR (1 byte) memoryjs.INT16 (2 bytes) memoryjs.SHORT (2 bytes) memoryjs.UINT16 (2 bytes) memoryjs.USHORT (2 bytes) memoryjs.WORD (2 bytes) memoryjs.INT32 (4 bytes) memoryjs.INT (4 bytes) memoryjs.LONG (4 bytes) memoryjs.DWORD (4 bytes) memoryjs.UINT32 (4 bytes) memoryjs.UINT (4 bytes) memoryjs.ULONG (4 bytes) memoryjs.DWORD (4 bytes) memoryjs.INT64 (8 bytes) memoryjs.UINT64 (8 bytes) memoryjs.FLOAT (4 bytes) memoryjs.DOUBLE (8 bytes) memoryjs.PTR (4/8 bytes) memoryjs.POINTER (4/8 bytes) memoryjs.UPTR (4/8 bytes) memoryjs.UPOINTER (4/8 bytes) memoryjs.STR (n/a) memoryjs.STRING (n/a) memoryjs.VEC3 (12 bytes) memoryjs.VECTOR3 (12 bytes) memoryjs.VEC4 (16 bytes) memoryjs.VECTOR4 (16 bytes) ``` -------------------------------- ### Result Object Structure Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Represents the outcome of a function executed in a remote process, containing the return value and exit code. ```javascript { returnValue: 1.23, exitCode: 2 } ``` -------------------------------- ### Memory Protection Source: https://github.com/hook-ac/memoryjs-ts/blob/master/README.md Allows changing or setting the protection attributes on a specified region of memory within a process. ```javascript const oldProtection = memoryjs.virtualProtectEx(handle, address, size, protection); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.