Skip to content

Instantly share code, notes, and snippets.

@jabyrd3
Last active November 11, 2022 00:28
Show Gist options
  • Save jabyrd3/2dff8b4296834da6d6939880b1a3d347 to your computer and use it in GitHub Desktop.
Save jabyrd3/2dff8b4296834da6d6939880b1a3d347 to your computer and use it in GitHub Desktop.
read raw mem given pid and start/end range nodejs
import {open, read} from 'fs';
export default (pid, rawStart, rawEnd) => {
return new Promise((res, rej) => {
// 4d674600000-4d674640000 rw-p 00000000 00:00 0
const start = parseInt(`0x${rawStart}`, 16);
const end = parseInt(`0x${rawEnd}`, 16);
const length = end - start;
const buffer = Buffer.alloc(length);
open(`/proc/${pid}/mem`, 'r', (err, fd) => {
read(fd, buffer, 0, length, start, (err, bytesRead, buffer) => {
res(buffer);
});
});
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment