LoadLibrary-based DLL injection for Windows | Based on node-dll-injector but finaly fixed for newer versions by h110m
npm install dll-injectNative node addon for dll injection in windows.
Requires a working node-gyp setup to compile the native addon.
Simply add dll-inject as a dependency in the package.json of your NodeJs Project:
``bash`
npm install dll-inject
`javascript
const injector = require('dll-inject');
if (injector.isProcessRunning('notepad.exe')) {
const error = injector.inject('notepad.exe', 'mydll.dll');
if (!error) {
console.log('Successfully injected!');
} else {
console.log('Injection failed. Error Code:', error);
}
}
`
javascript
const injector = require('dll-inject');if (injector.isProcessRunningPID(1234)) {
const error = injector.injectPID(1234, 'mydll.dll');
if (!error) {
console.log('Successfully injected!');
} else {
console.log('Injection failed. Error Code:', error);
}
}
`
Error Codes
These codes are returned by the inject() and injectPID() functions as integer valuesInt | Error
------------ | -------------
0 | Injection Successfull
1 | Process is not open
2 | Getting path name failed
3 | Buffer too small for path name
4 | Failed to allocate memory
5 | Failed to write memory
6 | Failed to create remote thread to load the DLL
Testing
There is a testdll.dll in the package folder of this project which will just open a new window from the process it was injected in which tells you when the dll is loaded and unloaded. There is also already a test js file in the test folder that you can run with npm test (be aware that for this to work notepad needs to be running and you are inside the package folder when executing npm test`)
Coded with ❤ by h110m