call javascript function from c++ || compile js function and library into exe || Crypto-js

preview_player
Показать описание
npm install -g node-gyp
npm install
npm install -g pkg

npm run build
Рекомендации по теме
Комментарии
Автор

here the code

#include <iostream>
#include <windows.h>
#include <string>
#include <vector>

std::string decryptAES(const std::string& encryptedText, const std::string& password) {
// Get the current directory
char currentDir[MAX_PATH];
if (!GetCurrentDirectoryA(MAX_PATH, currentDir)) {
return "Error getting current directory";
}

// Create the full path to aes_decrypt.exe
std::string exePath = std::string(currentDir) + "\\aes_decrypt.exe";

// Create the command line with full path
std::string command = "\"" + exePath + "\" \"" + encryptedText + "\" \"" + password + "\"";

// Create pipes for reading the output
SECURITY_ATTRIBUTES saAttr;
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;

HANDLE hChildStdoutRd, hChildStdoutWr;
if (!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) {
return "Error creating pipe";
}

// Ensure the read handle to the pipe for STDOUT is not inherited
if (!SetHandleInformation(hChildStdoutRd, HANDLE_FLAG_INHERIT, 0)) {
return "Error setting handle information";
}

// Create the process
PROCESS_INFORMATION piProcInfo;
STARTUPINFOA siStartInfo;
ZeroMemory(&piProcInfo,
ZeroMemory(&siStartInfo, sizeof(STARTUPINFOA));
siStartInfo.cb = sizeof(STARTUPINFOA);
siStartInfo.hStdError = hChildStdoutWr;
siStartInfo.hStdOutput = hChildStdoutWr;
siStartInfo.dwFlags |= STARTF_USESTDHANDLES;

// Create the child process
if (!CreateProcessA(NULL,
const_cast<LPSTR>(command.c_str()),
NULL,
NULL,
TRUE,
0,
NULL,
NULL,
&siStartInfo,
&piProcInfo)) {
DWORD error = GetLastError();
char errorMsg[256];
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errorMsg, sizeof(errorMsg), NULL);
return "Error creating process: " + std::string(errorMsg) + "\nCommand: " + command;
}

// Close the write end of the pipe
CloseHandle(hChildStdoutWr);

// Read output from the child process
std::string result;
char buffer[4096];
DWORD bytesRead;
while (ReadFile(hChildStdoutRd, buffer, sizeof(buffer), &bytesRead, NULL) && bytesRead > 0) {
result.append(buffer, bytesRead);
}

// Clean up


CloseHandle(hChildStdoutRd);

// Remove any trailing newlines
while (!result.empty() && (result.back() == '\n' || result.back() == '\r')) {
result.pop_back();
}

return result;
}

int main() {
// Example usage
std::string encryptedText = "";
std::string password = "";

std::string decryptedText = decryptAES(encryptedText, password);
std::cout << "Decrypted text: " << decryptedText << std::endl;

return 0;
}

gamedeviitian
welcome to shbcf.ru