显示从ReadProcessMemory(c ++)到NodeJS / Electron覆盖的数据

时间:2019-04-05 02:01:28

标签: c++ node.js electron overlay readprocessmemory

我想使用c ++ ReadProcessMemory获取x,y,z数据并使用电子显示。

我尝试使用/理解 node-addon-api,node-gyp

我有透明的电子窗口和ReadProcessMemory作为它们各自的程序,但是我不知道如何弥合差距。

电子/ NodeJS

// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')

// Global reference of the window object
let mainWindow

function createWindow () {
  // Create the browser window.
  mainWindow = new BrowserWindow({
    alwaysOnTop: true,
    x: sWidth - winWidth,
    y: 50,
    width: winWidth,
    height: winHeight,
    webPreferences: {
      nodeIntegration: true
   },
   transparent: true,
   frame: false,
  })

  // and load the index.html of the app.
  mainWindow.loadFile('index.html')

  // Open the DevTools.
  // mainWindow.webContents.openDevTools()

  // Emitted when the window is closed.
  mainWindow.on('closed', function () {
    mainWindow = null
  })
}

// This method will be called when Electron has finished
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') app.quit()
})

app.on('activate', function () {
  if (mainWindow === null) createWindow()
})

c ++

============================ ReadProcessMemory.cpp ========================

#include<iostream>
#include<Windows.h>

using namespace std;

int main() {

    // Read Value
    int readTest = 0;

    HWND hwnd = FindWindowA(NULL, "BioShock");

    if (hwnd == NULL) {
        cout << "Cannot find window." << endl;
        Sleep(3000);
        exit(-1);
    }
    else {
        DWORD procID;
        GetWindowThreadProcessId(hwnd, &procID);
        HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);

        if (procID == NULL) {
            cout << "Cannot obtain process." << endl;
            Sleep(3000);
            exit(-1);
        }
        else {
            // Read
            ReadProcessMemory(handle, (PBYTE*)0x44CE137C, &readTest, sizeof(readTest), 0);

            cout << readTest << endl;

            Sleep(10000);
            exit(-1);
        }
    }
    return 0;
}

=============================== napi_test.cc =============================

#include <napi.h>

using namespace std;

Napi::String Method(const Napi::CallbackInfo& info) {
  Napi::Env env = info.Env();
  return Napi::String::New(env, "world");
}

Napi::Object Init(Napi::Env env, Napi::Object exports) {
  exports.Set(Napi::String::New(env, "hello"),
              Napi::Function::New(env, Method));
  return exports;
}

NODE_API_MODULE(hello, Init)

我希望将从c ++代码读取的数据传递给Electron进行显示。我根本无法让他们一起工作。

感谢您的帮助。我也只用了几个小时的c ++。

0 个答案:

没有答案