Coder Social home page Coder Social logo

rob-- / memoryjs Goto Github PK

View Code? Open in Web Editor NEW
626.0 17.0 84.0 411 KB

Read and write process memory in Node.js (Windows API functions exposed via Node bindings)

License: MIT License

Python 0.34% JavaScript 22.78% C++ 76.88%
node-addon npm-package javascript cpp memory-hacking memory game-hacking hacking nodejs winapi

memoryjs's Introduction


memoryjs is a an NPM package to read and write process memory!

GitHub License NPM Version NPM Downloads


FeaturesGetting StartedUsageDocumentationDebug

Features

  • List all open processes
  • List all modules associated with a process
  • Close process/file handles
  • Find a specific module within a process
  • Read and write process memory (w/big-endian support)
  • Read and write buffers (arbitrary structs)
  • Change memory protection
  • Reserve/allocate, commit or change regions of memory
  • Fetch a list of memory regions within a process
  • Pattern scanning
  • Execute a function within a process
  • Hardware breakpoints (find out what accesses/writes to this address, etc)
  • Inject & unload DLLs
  • Read memory mapped files

TODO:

  • WriteFile support (for driver interactions)
  • Async/await support

Getting Started

Install

This is a Node add-on (last tested to be working on v14.15.0) and therefore requires node-gyp to use.

You may also need to follow these steps to install and setup node-gyp.

npm install memoryjs

When using memoryjs, the target process should match the platform architecture of the Node version running. For example if you want to target a 64 bit process, you should try and use a 64 bit version of Node.

You also need to recompile the library and target the platform you want. Head to the memoryjs node module directory, open up a terminal and run one of the following compile scripts:

# 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

Node Webkit / Electron

If you are planning to use this module with Node Webkit or Electron, take a look at Liam Mitchell's build notes here.

Usage

Initialise

const memoryjs = require('memoryjs');
const processName = "csgo.exe";

Processes

  • Open a process
  • Get all processes
  • Close a process (release handle)
// 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);

See the Documentation section of this README to see what a process object looks like.

Modules

  • Find a module
  • Get all modules
// 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) => {});

See the Documentation section of this README to see what a module object looks like.

Memory

  • Read data type from memory
  • Read buffer from memory
  • Write data type to memory
  • Write buffer to memory
  • Fetch memory regions
// 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) => {});

See the Documentation section of this README to see what values dataType can be.

Memory Mapped Files

  • Open a named file mapping object
  • Map a view of a file into a specified process
  • Close handle to the file mapping object
// 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);

See the Documentation section of this README to see details on the parameters and return values for these functions.

Protection

  • Change/set the protection on a region of memory
// sync: change/set the protection on a region of memory
const oldProtection = memoryjs.virtualProtectEx(handle, address, size, protection);

See the Documentation section of this README to see what values protection can be.

Pattern Scanning

  • Pattern scan all modules and memory regions
  • Pattern scan a given module
  • Pattern scan a memory region or module at the given base address
// 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) => {});

Function Execution

  • Execute a function in a remote process
// 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) => {});

Click here to see what a result object looks like.

Click here for details about how to format the arguments and the return type.

DLL Injection

  • Inject a DLL
  • Unload a DLL by module base address
  • Unload a DLL by module name
// 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) => {});

Hardware Breakpoints

  • Attach debugger
  • Detach debugger
  • Wait for debug event
  • Handle debug event
  • Set hardware breakpoint
  • Remove hardware breakpoint
// 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);

Documentation

Note: this documentation is currently being updated, refer to the Wiki for more information.

Process Object

{ dwSize: 304,
  th32ProcessID: 10316,
  cntThreads: 47,
  th32ParentProcessID: 7804,
  pcPriClassBase: 8,
  szExeFile: "csgo.exe",
  modBaseAddr: 1673789440,
  handle: 808 }

The handle and modBaseAddr properties are only available when opening a process and not when listing processes.

Module Object

{ 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 }

Result Object

{ returnValue: 1.23,
  exitCode: 2 }

This object is returned when a function is executed in a remote process:

  • returnValue is the value returned from the function that was called
  • exitCode is the termination status of the thread

Data Types

When using the write or read functions, the data type (dataType) parameter should reference a constant from within the library:

Constant Bytes Aliases Range
memoryjs.BOOL 1 memoryjs.BOOLEAN 0 to 1
memoryjs.INT8 1 memoryjs.BYTE, memoryjs.CHAR -128 to 127
memoryjs.UINT8 1 memoryjs.UBYTE, memoryjs.UCHAR 0 to 255
memoryjs.INT16 2 memoryjs.SHORT -32,768 to 32,767
memoryjs.UINT16 2 memoryjs.USHORT, memoryjs.WORD 0 to 65,535
memoryjs.INT32 4 memoryjs.INT, memoryjs.LONG -2,147,483,648 to 2,147,483,647
memoryjs.UINT32 4 memoryjs.UINT, memoryjs.ULONG, memoryjs.DWORD 0 to 4,294,967,295
memoryjs.INT64 8 n/a -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
memoryjs.UINT64 8 n/a 0 to 18,446,744,073,709,551,615
memoryjs.FLOAT 4 n/a 3.4E +/- 38 (7 digits)
memoryjs.DOUBLE 8 n/a 1.7E +/- 308 (15 digits)
memoryjs.PTR 4/8 memoryjs.POINTER n/a
memoryjs.UPTR 4/8 memoryjs.UPOINTER n/a
memoryjs.STR n/a memoryjs.STRING n/a
memoryjs.VEC3 12 memoryjs.VECTOR3 n/a
memoryjs.VEC4 16 memoryjs.VECTOR4 n/a

Notes:

  • all functions that accept an address also accept the address as a BigInt
  • pointer will be 4 bytes in a 32 bit build, and 8 bytes in a 64 bit build.
  • to read in big-endian mode, append _BE to the data type. For example: memoryjs.DOUBLE_BE.
  • when writing 64 bit integers (INT64, UINT64, INT64_BE, UINT64_BE) you will need to supply a BigInt. When reading a 64 bit integer, you will receive a BigInt.

These data types are to used to denote the type of data being read or written.

64 bit integer example:

const value = memoryjs.readMemory(handle, address, memoryjs.INT64);
console.log(typeof value); // bigint
memoryjs.writeMemory(handle, address, value + 1n, memoryjs.INT64);

Vector3 is a data structure of three floats:

const vector3 = { x: 0.0, y: 0.0, z: 0.0 };
memoryjs.writeMemory(handle, address, vector3, memoryjs.VEC3);

Vector4 is a data structure of four floats:

const vector4 = { w: 0.0, x: 0.0, y: 0.0, z: 0.0 };
memoryjs.writeMemory(handle, address, vector4, memoryjs.VEC4);

Generic Structures

If you have a structure you want to write to memory, you can use buffers. For an example on how to do this, view the buffers example.

To write/read a structure to/from memory, you can use structron to define your structures and use them to write or parse buffers.

If you want to read a std::string using structron, the library exposes a custom type that can be used to read/write strings:

// 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');

Alternatively, you can use the concentrate and dissolve libraries to achieve the same thing. An old example of this is here.

Protection Type

Protection type is a bit flag DWORD value.

This parameter should reference a constant from the library:

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

Refer to MSDN's Memory Protection Constants for more information.

Memory Allocation Type

Memory allocation type is a bit flag DWORD value.

This parameter should reference a constat from the library:

memoryjs.MEM_COMMIT, memoryjs.MEM_RESERVE, memoryjs.MEM_RESET, memoryjs.MEM_RESET_UNDO

Refer to MSDN's VirtualAllocEx documentation for more information.

Strings

You can use this library to read either a "string", or "char*" and to write a string.

In both cases you want to get the address of the char array:

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;

From here you can simply use this address to write and read memory.

There is one caveat when reading a string in memory however, due to the fact that the library does not know how long the string is, it will continue reading until it finds the first null-terminator. To prevent an infinite loop, it will stop reading if it has not found a null-terminator after 1 million characters.

One way to bypass this limitation in the future would be to allow a parameter to let users set the maximum character count.

Signature Type

When pattern scanning, flags need to be raised for the signature types. The signature type parameter needs to be one of the following:

0x0 or memoryjs.NORMAL which denotes a normal signature.

0x1 or memoryjs.READ which will read the memory at the address.

0x2 or memoryjs.SUBSTRACT which will subtract the image base from the address.

To raise multiple flags, use the bitwise OR operator: memoryjs.READ | memoryjs.SUBTRACT.

Memory Mapped Files

The library exposes functions to map obtain a handle to and read a memory mapped file.

openFileMapping(fileName)

  • fileName: name of the file mapping object to be opened
  • returns: handle to the file mapping object

Refer to MSDN's OpenFileMappingA documentation for more information.

mapViewOfFile(processHandle, fileName)

  • 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 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
  • fileHandle: 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

Refer to MSDN's MapViewOfFile2 documentation for more information.

See Protection Type for page protection types.

Example

We have a process that creates a file mapping:

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");

We can map the file to a specified target process and read the file with memoryjs:

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);

If you want to read a memory mapped file without having a target process to map the file to, you can map it to the current Node process with global variable process.pid:

const processObject = memoryjs.openProcess(process.pid);

Function Execution

Remote function execution works by building an array of arguments and dynamically generating shellcode that is injected into the target process and executed, for this reason crashes may occur.

To call a function in a process, the callFunction function can be used. The library supports passing arguments to the function and need to be in the following format:

[{ type: T_INT, value: 4 }]

The library expects the arguments to be an array of objects where each object has a type which denotes the data type of the argument, and a value which is the actual value of the argument. The various supported data types can be found below.

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,

When using callFunction, you also need to supply the return type of the function, which again needs to be one of the above values.

For example, given the following C++ function:

int add(int a, int b) {
    return a + b;
}

You would call this function as so:

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 }

See the result object documentation for details on what callFunction returns.

Notes: currently passing a double as an argument is not supported, but returning one is.

Much thanks to the various contributors that made this feature possible.

Hardware Breakpoints

Hardware breakpoints work by attaching a debugger to the process, setting a breakpoint on a certain address and declaring a trigger type (e.g. breakpoint on writing to the address) and then continuously waiting for a debug event to arise (and then consequently handling it).

This library exposes the main functions, but also includes a wrapper class to simplify the process. For a complete code example, checkout our debugging example.

When setting a breakpoint, you are required to pass a trigger type:

  • memoryjs.TRIGGER_ACCESS - breakpoint occurs when the address is accessed
  • memoryjs.TRIGGER_WRITE - breakpoint occurs when the address is written to

Do note that when monitoring an address containing a string, the size parameter of the setHardwareBreakpoint function should be the length of the string. When using the Debugger wrapper class, the wrapper will automatically determine the size of the string by attempting to read it.

To summarise:

  • When using the Debugger class:

    • No need to pass the size parameter to setHardwareBreakpoint
    • No need to manually pick a hardware register
    • Debug events are picked up via an event listener
    • setHardwareBreakpoint returns the register that was used for the breakpoint
  • When manually using the debugger functions:

    • The size parameter is the size of the variable in memory (e.g. int32 = 4 bytes). For a string, this parameter is the length of the string
    • Manually need to pick a hardware register (via memoryjs.DR0 through memoryhs.DR3). Only 4 hardware registers are available (some CPUs may even has less than 4 available). This means only 4 breakpoints can be set at any given time
    • Need to manually wait for debug and handle debug events
    • setHardwareBreakpoint returns a boolean stating whether the operation as successful

For more reading about debugging and hardware breakpoints, checkout the following links:

Using the Debugger Wrapper:

The Debugger wrapper contains these functions you should use:

class Debugger {
  attach(processId, killOnDetach = false);
  detach(processId);
  setHardwareBreakpoint(processId, address, trigger, dataType);
  removeHardwareBreakpoint(processId, register);
}
  1. Attach the debugger
const hardwareDebugger = memoryjs.Debugger;
hardwareDebugger.attach(processId);
  1. Set a hardware breakpoint
const address = 0xDEADBEEF;
const trigger = memoryjs.TRIGGER_ACCESS;
const dataType = memoryjs.INT;
const register = hardwareDebugger.setHardwareBreakpoint(processId, address, trigger, dataType);
  1. Create an event listener for debug events (breakpoints)
// `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);
});

When Manually Debugging:

  1. Attach the debugger
const hardwareDebugger = memoryjs.Debugger;
hardwareDebugger.attach(processId);
  1. Set a hardware breakpoint (determine which register to use and the size of the data type)
// 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);
  1. Create the await/handle debug event loop
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);

Note: a loop is not required, e.g. no loop required if you want to simply wait until the first detection of the address being accessed or written to.

Debug

1. Re-compile the project to be debugged

Go to the root directory of the module and run one of the following commands:

# 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

2. Change the index.js file to require the debug module

Go to the root directory and change the line in index.js from:

const memoryjs = require('./build/Release/memoryjs');

To the following:

const memoryjs = require('./build/Debug/memoryjs');

3. Open the project in Visual Studio

Open the binding.sln solution in Visual Studio, found in the build folder in the project's root directory.

4. Setup Visual Studio debug configuration

  1. In the toolbar, click "Project" then "Properties"
  2. Under "Configuration Properties", click "Debugging"
  3. Set the "Command" property to the location of your node.exe file (e.g. C:\nodejs\node.exe)
  4. Set the "Command Arguments" property to the location of your script file (e.g. C:\project\test.js)

5. Set breakpoints

Explore the project files in Visual Studio (by expanding .. and then lib in the Solution Explorer). Header files can be viewed by holding Alt and clicking on the header file names at the top of the source code files.

Breakpoints are set by clicking to the left of the line number.

6. Run the debugger

Start debugging by either pressing F5, by clicking "Debug" in the toolbar and then "Start Debugging", or by clicking "Local Windows Debugger".

The script you've set as the command argument in step 4 will be run, and Visual Studio will pause on the breakpoints set and allow you to step through the code line by line and inspect variables.

memoryjs's People

Contributors

bumpmann avatar danwatco avatar dependabot[bot] avatar dnnyy avatar jaipe avatar liamkarlmitchell avatar p410n3 avatar rob-- avatar uplusion23 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

memoryjs's Issues

Issues with Strings and Exception Handling

Hey mate, really like this but i have problems with the string format and errors.

If i use string as type it just dies and even if i set a data type which not exists it also just dies i never get an error. (using async callback if i just use it static it thwrows one for unknown data type but not for string)

Everything else works nice Win10 x64.

I read in the other issue you dont have much time for this anymore but i would love to get a fix for this cause i am at the moment dont have the skills to debug it myself.

Thanks

Can not install memoryjs on ubuntu

make: Entering directory '/media/akshaya/New Volume/ctonode/node_modules/memoryjs/build'
CXX(target) Release/obj.target/memoryjs/lib/memoryjs.o
../lib/memoryjs.cc:3:21: fatal error: windows.h: No such file or directory
#include <windows.h>
^
compilation terminated.
memoryjs.target.mk:103: recipe for target 'Release/obj.target/memoryjs/lib/memoryjs.o' failed
make: *** [Release/obj.target/memoryjs/lib/memoryjs.o] Error 1
make: Leaving directory '/media/akshaya/New Volume/ctonode/node_modules/memoryjs/build'

freeze value

Hi guys, would like to ask how i'm going to freeze address value like ce? i'd try in looping but i got detected. thanks

electron crashed after readBuffer

when i call "readBuffer"
maybe call once or 5-8times
electron turn to whtie page and devtools only left “DevTools was disconnected from the page……”

how to specify a pointer?

I need to read a pointer from memory, and there is nothing available to specify the address is a pointer

for example, in Frida, I would do something like

var mem = Memory.readFloat(ptr(addr));

but I don't seem to have ptr() available in this library.

Installation error

Hi. I trying to install memoryjs with npm install Rob--/memory's and getting error

c:\users\sergey\desktop\offset-dumper\node_modules\memoryjs\lib\functions.h(39): error C2039: call: not a member "functions" (file: ..\lib\functions.cc) [C:\Users\Sergey\Desktop\offset-dumper\node_module s\memoryjs\build\memoryjs.vcxproj]

There is no problem when installing from npm, only from GitHub.

writeMemory with 8 bytes

I need writeMemory with value 144 (NOP) in address 0x74542B with 8 bytes of size in GTA San Andreas.

I trying use long datatype to this but it does not happen as expected.
memoryjs.writeMemory(processObject.handle, 0x74542B, 144, 'long')

What is the right datatype or how do I make size be 8 bytes??

Invalid data from readMemory

Hey. I'm trying to readMemory from address, which I've select from CheatEngine. In CE I see value 101, but shen I try to read this in JS I get 3.
What problems can i have?

P.S. Trying to access cs 1.6 data)

Confusion about using pointers.

I'm a little new to all of this, so please excuse my ignorance if I'm doing something wrong. I have a game that I'm going to call "game.exe" and the offset to the local player, and then a list of offsets that I want to obtain data for.

Here's what reading from this data looks like in C++

float GetHealth() {
    auto address = *(DWORD*)(BASE_ADDRESS + LOCAL_PLAYER_OFFSET);
    return *(float*)(address + OFFSET_HEALTH);
}

Here is what I'm trying the memoryjs

mjs.readMemory(process.handle, (baseAddress + localPlayerAddress) + healthOffset, mjs.FLOAT, (err, value) => {
        // ...
})

Printing these values out to hex shows up like this:

Base address: 1150000
Local player offset: 2f457fc
Health offset: 2280e0
Base + Local Player 40957fc
Health address: 42bd8dc

This is of-course being printed with .toString(16)

Not really sure what I'm doing wrong, as it grabs the correct value in C++ but not in memoryjs (I'm probably doing something wrong).

Question

Once my electron app is built, do my users need to have node-gyp?

Support Linux and OSX

Now it only supports Windows. Is it possible to support other operating systems? Or can you list some reading materials about process memory reading? Thanks all the same.

NW build instructions.

For patching values in memory at runtime of already compiled exe's with a GUI I wanted to use node webkit. (Server manager to spawn processes and keep em alive already done in an old version)

Here are my build notes if it might help others wanting to use this in NW or perhaps the newer Electron.


Building for Node Webkit

We need to install nw-gyp and configure target to the appropriate version of node webkit and architecture.

If you are not sure what version of Node Webkit you have.
You can run this in the debug console.

console.log("nw " + process.versions.nw + " " + process.arch + " node " + process.versions.node)

Note: I am using Python 2.7.12 for compiling.
https://www.python.org/downloads/release/python-2712/

I run the command from a Visual Studio 2017 command prompt window and have already changed directory to the memoryjs directory.

Note: I have nw version 0.15.4 and x64.
Change yours as needed below.

npm install -g nw-gyp
nw-gyp clean configure build --arch=x64 --target=0.15.4

If you get gyp info ok you should be good to go.

Add "byte" type to WriteMemory.

Could you by chance just add a byte type to write/read memory and do all the buffer handling behind the scenes? Been having tons of trouble.

Does VAC detect this?

I'm not sure where else to ask this, but if I were to use this to READ (but NOT write) memory of a Steam online multiplayer game, would I get banned? Can VAC "know" if I'm reading a game's memory?

I am not cheating by the way.

Pattern scan always returns same (wrong) address

const memoryjs = require('memoryjs')

memoryjs.openProcess('notepad++.exe', (error, process) => {
  if (error) { console.log(error) }
  memoryjs.findPattern(process.handle, 'notepad++.exe', '65 6C 6C ? 20 57 6F 72 6C 64 21', memoryjs.NORMAL, 0, 0, (error, offset) => {
    console.log(offset)
  })
});

No matter what process name I use, or pattern, the above code will always output this:

18446744073709552000

Which is of course incorrect. And looking at notepad++.exe's memory using Cheat Engine I can see Hello World! is definitely in the its memory, infact in three different locations, and not in utf16 format (it doesn't have 00 between each character).

But using the address found via Cheat Engine to read the text I typed in notepad++.exe works correctly:

memoryjs.readMemory(process.handle, 0x1A338732FB0, 'string', (error, data) => {
    console.log(data)
  })

Will output:

Hello World!

When i try to get modules it returns wrong information or if i build it as 32 bit it won't run-error

So i tried getting modules with no success.

If i get "hl2.exe" (cs:s) and i try to get modules with its th32ProcessID i get wrong modules (i need client.dll):

[ { modBaseAddr: 4194304,
    modBaseSize: 114688,
    szExePath: 'C:\\Games\\Counter-Strike Source\\hl2.exe',
    szModule: 'hl2.exe',
    th32ModuleID: 9764 },
  { modBaseAddr: 140734740627456,
    modBaseSize: 1970176,
    szExePath: 'C:\\Windows\\SYSTEM32\\ntdll.dll',
    szModule: 'ntdll.dll',
    th32ModuleID: 9764 },
  { modBaseAddr: 2009464832,
    modBaseSize: 335872,
    szExePath: 'C:\\Windows\\System32\\wow64.dll',
    szModule: 'wow64.dll',
    th32ModuleID: 9764 },
  { modBaseAddr: 2009923584,
    modBaseSize: 491520,
    szExePath: 'C:\\Windows\\System32\\wow64win.dll',
    szModule: 'wow64win.dll',
    th32ModuleID: 9764 },
  { modBaseAddr: 2009858048,
    modBaseSize: 40960,
    szExePath: 'C:\\Windows\\System32\\wow64cpu.dll',
    szModule: 'wow64cpu.dll',
    th32ModuleID: 9764 } ]

I also tried running npm run build32 in memoryjs root but it crashes if i try to run it:

\node_modules\memoryjs\build\Release\memoryjs.node is not a valid Win32 application.

How to read some weird kind of pointer with memoryjs?

Ik title isnt kinda good probably..

So i managed to read the pointer and the value of the address it points to but i got stuck at some other stuff.

So i need to read: "ac_client.exe"+0010F4F8 which as far as i know it should be: modBaseAddr + 0x0010F4F8

and then i add the offset to the address i get with this but i get the wrong value at the end.

Some weird behaviour of findPattern

Once I had the following situation. I ran a code where 2 pattern searches in normal mode are done. The first was correctly done, but the resulting address of the second search gave me just the base address of the module.

My code looks like this:

let pattern = Buffer.from('some string value').toString('hex').replace(/..\B/g, '$& ');
let address = memoryjs.findPattern(processObject.handle, module.szModule, pattern, memoryjs.NORMAL, 0, 0);
pattern = Buffer.alloc(4);
pattern.writeUInt32LE(address);
pattern = pattern.toString('hex').replace(/..\B/g, '$& ');
// doesn't work with memoryjs version > 3.0.2
address = memoryjs.findPattern(processObject.handle, module.szModule, pattern, memoryjs.NORMAL, 0, 0);

After some testing I found out, that for some reason I cannot explain yet, using a variable for the pattern string leads to the problem. The changes to lib/memoryjs.cc were made after version 3.0.2.

So this will have problems...

const char* pattern = std::string(*signature).c_str();
...
address = Pattern.findPattern(handle, moduleEntries[i], pattern, sigType, patternOffset, addressOffset);

...and this will work fine.

address = Pattern.findPattern(handle, moduleEntries[i], std::string(*signature).c_str(), sigType, patternOffset, addressOffset);

haveing a hard time geting it to compile

[email protected] install C:\Users\TheUnChosenOne\Desktop\DreamDebuger\node_modules\memoryjs
node-gyp rebuild

C:\Users\TheUnChosenOne\Desktop\DreamDebuger\node_modules\memoryjs>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Users\TheUnChosenOne\Desktop\DreamDebuger\node_modules\memoryjs\build\memoryj
s.vcxproj(20,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.p
rops" was not found. Confirm that the path in the declaration is correc
t, and that the file exists on disk.
gyp ERR! build error
gyp ERR! stack Error: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:203:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\TheUnChosenOne\Desktop\DreamDebuger\node_modules\memoryjs
gyp ERR! node -v v12.7.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
ne is installed. You must install peer dependencies yourself.
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\TheUnChosenOne\AppData\Roaming\npm-cache_logs\2020-03-15T18_25_34_195Z-debug.log
PS C:\Users\TheUnChosenOne\Desktop\DreamDebuger> npm install memoryjs

[email protected] install C:\Users\TheUnChosenOne\Desktop\DreamDebuger\node_modules\memoryjs
node-gyp rebuild

C:\Users\TheUnChosenOne\Desktop\DreamDebuger\node_modules\memoryjs>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Users\TheUnChosenOne\Desktop\DreamDebuger\node_modules\memoryjs\build\memoryj
s.vcxproj(20,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.p
rops" was not found. Confirm that the path in the declaration is correc
t, and that the file exists on disk.
gyp ERR! build error
gyp ERR! stack Error: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:203:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\TheUnChosenOne\Desktop\DreamDebuger\node_modules\memoryjs
gyp ERR! node -v v12.7.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN rollback Rolling back [email protected] failed (this is probably harmless): EPERM: operation not permitted, lstat 'C:\Users\TheUnChosenOne\Desktop\DreamDebuger\node_modules\eslint-plugin-import\node_modules'
ne is installed. You must install peer dependencies yourself.
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\TheUnChosenOne\AppData\Roaming\npm-cache_logs\2020-03-15T18_26_27_375Z-debug.log
PS C:\Users\TheUnChosenOne\Desktop\DreamDebuger> npm install memoryjs

[email protected] install C:\Users\TheUnChosenOne\Desktop\DreamDebuger\node_modules\memoryjs
node-gyp rebuild

C:\Users\TheUnChosenOne\Desktop\DreamDebuger\node_modules\memoryjs>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Users\TheUnChosenOne\Desktop\DreamDebuger\node_modules\memoryjs\build\memoryj
s.vcxproj(20,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.p
rops" was not found. Confirm that the path in the declaration is correc
t, and that the file exists on disk.
gyp ERR! build error
gyp ERR! stack Error: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:203:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\TheUnChosenOne\Desktop\DreamDebuger\node_modules\memoryjs
gyp ERR! node -v v12.7.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN [email protected] requires a peer of eslint@^4.9.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

dont know what i am doing worng

Pointer to local variable returned

memory.h 23:

  char* readBuffer(HANDLE hProcess, DWORD64 address, SIZE_T size) {
    char* buffer = new char[size];
    ReadProcessMemory(hProcess, (LPVOID)address, buffer, size, NULL);
    return buffer;
  }

Random crash

Types

Could we get some declaration files for typescript?

More examples

Could you please add some more simple examples. Like how to find numbers address in 'calc.exe'.

const memoryjs = require('memoryjs');
const processName = "calc.exe";
/*
	And then what ? How to find '5' in process ? How to get adress of this value and change it ?
*/

Unable to read memory address bigger than 0xFFFFFFFF

Hello,

I built memoryjs with npm run build64 but when i try to read memory with address that is bigger than 0xFFFFFFFF, it read wrong address.

For example, if i try to read address 0x141EA3612, it will return value of address 0x41EA3612 instead of 0x141EA3612 one.

My attached process is built with a 64bit architecture.

Do you have some idea to fix this ? Thanks

Module Base Addr Size?

Hi. Firstly, excellent library here, thank you so much for your work on it.

I've been retrieving the first module for a process, in both robot-js and memoryjs and I noticed the base address seems to be different in both. I'm not sure if it's something I'm doing wrong, or if it's an issue with offset values, or maybe the data type is too small in the C code. You can see the precision is greater in robotjs, but even the lower precision values seem different too.

The szExePath matches in both, but the modBaseAddr varies.

In memoryjs:
require("memoryjs").getModules(targetProcess.th32ProcessID)[0].modBaseAddr
Value: 1407975424

In robotjs:
targetProcess.getModules()[0].getBase()
Value: 140695946657792

I tried changing some of the types to long in the C code, but I'm a JS dev and am useless with C :D

Thanks!

MemoryJS can't get modules

MemoryJS can't find engine.dll or client.dll

All modules:
csgo.exe
ntdll.dll
wow64.dll
wow64win.dll
wow64cpu.dll

P.s even if I use example.js

I am new to this.

Hello!

As the title says im new to this and i have an issue.

I would like to ask how do i get the address of the specific value in the memory?

DLL Injection

Hello, I'd like to help with the implementation of DLL injection. Here is the process:

  1. VirtualAllocEx area in the target, where the size of the area is large enough to hold a c string of the full DLL path
  2. WriteProcessMemory the full path of the DLL, to the previously allocated memory
  3. CreateRemoteThread in the target, where the start routine is LoadLibraryA, with the parameter being the memory location of the dll path.

What step 3 would look like:
CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA"), remoteString, NULL, NULL);

  1. Free the memory, if you want to be a good boy programmer.

Its actually a really simple progress, should not be hard to implement. I'd love to fork and do it myself, but I have no idea how to work the node bindings.

Allocate new memory

First of all this library is amazing, ive been having tons of fun with it since Yesterday.

But while trying out writing bytearrays i noticed that it seems to be not possible to allocate new memory with this library. If you could allocate new memory in a process, then you could write way more Advanced assemly to inject into the game, since jumping to the new memory Location would give you tons of space to inject assemly.

Would it be possible to implement memory allocation in the library?

Open Process by ID & Multi Process support.

Just a feature request,
Can we open a process by id, specifying it by detecting if the argument is a string or int?

Rather than Process process could the library store the handle for re-use and support multiple processes?

A js object could be returned exposing methods which use that process handle, or similar to how SetTimeout works in js that you get a number you can put in to the functions as an arg.
Handle can just be passed as is as if it were an unsigned integer or by using a map of PID to handle.

I know I have done this in the past with node-ffi but a native module seems nicer to use.

Any thoughts?

Read/Write buffer.

It should also be possible to read/write a buffer which can be used to read say, an objects struct from memory at once then parse through it in js.

Maybe something like this?

process.read(buf, address, callback)
// Writing buffer, can get like this.
size_t packetLen = Buffer::Length(args[1]);
char* packet = Buffer::Data(args[1]);	

// Reading buffer.
char * buffer = new char[size];
ReadProcessMemory(hProcess, (LPVOID)dwAddress, &buffer, size, NULL);
info.GetReturnValue().Set(Nan::NewBuffer(buffer, size).ToLocalChecked());

Maybe this would be helpful?
https://community.risingstack.com/using-buffers-node-js-c-plus-plus/

https://github.com/Zysen/node-winprocess/blob/master/winprocess.cc#L229-L240

Async findPattern doesn't execute the callback / built in datatypes give wrong values

Yo! Really good library so far apart from one problem. Async findpattern is not working properly, it doesn't execute the callback, even if I change the arguments to 6 in index.js (if (arguments.length === 6)) - compile it new, it still does not work. No idea how to fix it since I'm not a cpp programmer, but the callback does not execute. Also when using the sync method, I noticed that when I used the build in types for example memoryjs.READ | memoryjs.SUBTRACT the wrong offset returns. However, when I use hexadecimals (0x1 | 0x2) it gives the correct offset.

Regards

Pattern scanning

Hello!

I've found your project on npm and I think it's the only memory editing module for node in there. Seen that your last update was 7 months ago.

Are you still working on this or is it dead?

Are you still planning on adding the pattern scanning feature from your TODO list?

Cheers,
Pupix

ReadMemory stops working at random

I'm trying to use memory.js to read the in game data, such as location, of Red Dead Redemption 2, to display it in Discord. My only issue is that the same memory addresses stop working at random after a while.

I checked with Cheat Engine to make sure the addresses haven't changed between gaming sessions and from what I've seen they haven't. The addresses I use still display the same values.
Memory.js gives me the following error:

TypeError: unable to read string (no null-terminator found after 1 million chars)
    at Object.readMemory (C:\bots\node_modules\memoryjs\index.js:104:23)
    at test (C:\bots\index.js:42:32)

At line 42 in my code is the ReadMemory function:
memoryjs.readMemory(handle, address, memoryjs.STRING)

Sync readmemory not working

X:\Dokumente\p410n3.JS\node_modules\memoryjs\index.js:64
    memoryjs.readMemory(handle, address, dataType.toLowerCase(), callback);
             ^

TypeError: fourth argument must be a function
    at Object.readMemory (X:\Dokumente\p410n3.JS\node_modules\memoryjs\index.js:
64:14)
    at Object.<anonymous> (X:\Dokumente\p410n3.JS\node_modules\memoryjs\example1
.js:86:61)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

How does one even use this?

Trying to get the hang of this before moving on to doing what I originally set out to, but can't even get a simple test to work. I've got a notepad window open with the text "Hello World!" and I'm trying to find it with this code:

const memoryjs = require('memoryjs');
const processes = memoryjs.getProcesses();

var p;

for (let i = 0; i < processes.length; i++) {
  if (processes[i].szExeFile == 'notepad.exe') {
    p = memoryjs.openProcess(processes[i].th32ProcessID);
    }
  }
}

addr = memoryjs.findPattern(p.handle, 'notepad.exe', /^H/, memoryjs.STRING, 0, 0);
txt = memoryjs.readMemory(p.handle, addr, memoryjs.STRING);
console.log(txt); // outputs 'MZ', but should output 'Hello World!'

MZ is apparently the magic byte identifying a DOS executable, so I have a feeling it's getting this string from the actual notepad.exe file in memory. Not what I want.

Function calling?

You should consider adding functionality to calling functions by address. The equivalent in C would be

int ( __cdecl *addValues )( int a, int b ) = ( int ( __cdecl* )( int, int ) )0xDEADBEEF;

Can't install in Macbook Pro // <windows.h> file not found

Does this work in Mac?

I'm trying to install it and getting this errors:

$ npm install memoryjs

> [email protected] install /Users/myuser/myproject/node_modules/memoryjs
> node-gyp rebuild

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
  CXX(target) Release/obj.target/memoryjs/lib/memoryjs.o
../lib/memoryjs.cc:2:10: fatal error: 'windows.h' file not found
#include <windows.h>
         ^~~~~~~~~~~
1 error generated.
make: *** [Release/obj.target/memoryjs/lib/memoryjs.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:125:13)
gyp ERR! stack     at ChildProcess.emit (events.js:213:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:197:12)
gyp ERR! System Darwin 17.6.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/myuser/myproject/node_modules/memoryjs
gyp ERR! node -v v8.1.3
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN enoent ENOENT: no such file or directory, open '/Users/myuser/myproject/package.json'
npm WARN dev-csgo No description
npm WARN dev-csgo No repository field.
npm WARN dev-csgo No README data
npm WARN dev-csgo No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/myuser/.npm/_logs/2018-06-26T20_13_58_457Z-debug.log
$ 

Unable to read String / Text

I've got a bunch of addresses from cheat engine. I can read ints just fine
memoryjs.readMemory(0xCA11F4, memoryjs.INT)
But i have never been able to read a string. memoryjs.STRING memoryjs.STR
Is this a bug?

Doing this async and printing the error gives nothing either

Using node version 6~

Update after trying some more stuff
Installed node version 6.9.1 32bit according to the instructions, since my application i want to read is 32bit. with nvm
npm run build32 inside project/node_modules/memoryjs

Now im getting this error

module.js:597
  return process.dlopen(module, path._makeLong(filename));
                 ^

Error: %1 is not a valid Win32 application.

My application is surely 32bit. As seen in task manager -> details -> platform

Help would be greatly appreciated, memoryjs seems awesome.

Get & Set memory permissions.

If you want to write .code sections of memory you need to set the memory protections.
And possibly a flush instruction cache.

A way I have done this in the past is to make a SetProtection method.

DWORD SetProtection(void* m_address, DWORD m_size, DWORD protection = PAGE_EXECUTE_READWRITE);

DWORD SetProtection(void* m_address, DWORD m_size, DWORD protection) 
{
	DWORD dwOldProtect;
	VirtualProtect(m_address, m_size, protection, &dwOldProtect);
	return dwOldProtect;
}

Then you can call it prior to writing over some memory, storing the return value, then use that return value to return the memory protections back to how they were.

void MemCpyProtected(void* m_address, const void* bytes, DWORD size)
{
	DWORD d = SetProtection(m_address, size);
	memcpy(m_address, bytes, size);
	SetProtection(m_address, size, d);
}

memory read

Hello can you explain how to read memory ? I ve an adress and i know this value from this adress and value is always integer but function returning always 0. Here is my code.

const memoryjs = require('memoryjs');
const processObject = memoryjs.openProcess('client_ogl.exe');
console.log(processObject);

const manaValue = memoryjs.readMemory(processObject, '15562EE4', 'int');
console.log('mana ' + manaValue);

Usage in browser environment

So i succesfully compiled memoryjs in node environment, but i would like to use it in browser enviro mnent and i get this error:
https://pasteboard.co/J5O0LRB.png

It seems to be problem with that thing browser didn't support require() import. I tried bundle file with browserify but it didnt works also tried requireJS but same result or i'm doing something wrong.

Issue writing a string

Alright, so I've tried multiple times to write a string back to memory, the string is the same length just the original text but reversed to make it a noticeable change.

This is the code I'm using to read the address and I know it is working perfectly to get me the value of the address.

let processName = "game.exe";

memory.openProcess(processName, (error, processObject) => {
    console.log(`Game PID: ${processObject.th32ProcessID}`);

    let exe = memory.findModule(processName, processObject.th32ProcessID);

    console.log(`Module PID: ${exe.th32ProcessID}`);

    let addr = `0x${(exe.modBaseAddr + 0x2829BFC).toString(16)}`;

    console.log(`Username Address: ${addr}`);

    let processMemory = memory.readMemory(processObject.handle, addr, 'string');

    console.log(`Current Value: ${processMemory}`);
});

I was going through some trouble at first reading until I changed the handle in the readMemory spot to the one from the original process instead of the module.

I've tried writting like this with both handles and none of them seem to have any effect of the memory.

setTimeout(() => {
    console.log(`Attempting to change the value now.`);

    setTimeout(() => {
        memory.writeMemory(processObject.handle, addr, updatedUsername, 'string');
    }, 100);


    setTimeout(() => {
        let processMemorynew = memory.readMemory(processObject.handle, addr, 'string');

        console.log(`This is the value now: ${processMemorynew}`);
    }, 500);
}, 1000);

The value never changes, I originally thought this was a permissions issue with windows but even in the Administrator CMD nothing seems to happen. I've also tried using setProtection before the writeMemory on the same address and it still seems to have no effect.

memory.setProtection(processObject.handle, addr, updatedUsername.length, memory.PAGE_EXECUTE_READWRITE);

If anyone happens to know what I can do to fix this or if I'm doing anything wrong. I'm able to change all the memory values I'm trying to change with this in other memory editors perfectly fine.

(Note: I would like to add this is a 64-bit process and I'm not sure if this matters or not with how it's done on the C++ side of it.)

Pointer problem

I saw in the last reports some issues or more some difficutlies in understanding how to use pointers in memoryjs.
Im also struggling with pointers in memoryjs, so is this framework already dead?

Here the pointer:
https://imgur.com/3eXW7LL
`
const memoryjs = require('memoryjs');
let offset_life = 0x01FC50F8;

const memRead = async() => {

memoryjs.openProcess("SildMerlin_x64Steam.exe", async(error, processObject) => {
    if(error){
        console.log('1ERR:' + error)
        return;
    }else{
        console.log(processObject)
    }

    memoryjs.findModule(processObject.szExeFile, processObject.th32ProcessID, async (error, processModule) => {
        if (error) {
            console.log('2ERR:' + error)
            return;
        } else {
            console.log(processModule)
        }

        let life = memoryjs.readMemory(processObject.handle, (processModule.modBaseAddr + offset_life), 'int');
        console.log(life);
    });

});

}

memRead();
`

i would really like to know why the pointer cannot be found, btw in CE and C++ its not a problem, please enlight me

DLL Injection

Hi, do you have a date for the DLL injection feature ?

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.