1. 代码
代码参考: https://github.com/node-ffi/node-ffi/issues/355
const fs = require('fs');
const ref = require('ref');
const ffi = require('ffi');
const Struct = require('ref-struct')
const Array = require('ref-array')
const DATA_BLOB = Struct({
cbData: ref.types.uint32,
pbData: 'string' // ref.refType(ref.types.byte)
})
const PDATA_BLOB = new ref.refType(DATA_BLOB)
const Crypto = new ffi.Library('Crypt32', {
'CryptUnprotectData': ['bool', [PDATA_BLOB, 'string', 'string', 'void *', 'string', 'int', PDATA_BLOB]],
});
const data_blob_input = new DATA_BLOB();
data_blob_input.cbData = row.encrypted_value.length;
data_blob_input.pbData = row.encrypted_value;
const data_blob_output = new DATA_BLOB();
const result = Crypto.CryptUnprotectData(data_blob_input.ref(), null, null, null, null, 0, data_blob_output.ref());
cookies[row.name] = data_blob_output.pbData.slice(0, data_blob_output.cbData);
console.log(row.name, cookies[row.name])
2. ffi安装
Node 10 and lower
npm i ffi
https://www.npmjs.com/package/ffi
https://github.com/node-ffi/node-ffi
Node 11 and 12
npm i @saleae/ffi
https://www.npmjs.com/package/@saleae/ffi
https://github.com/lxe/node-ffi/tree/node-12
Node 13 and higher
npm i ffi-napi
https://www.npmjs.com/package/ffi-napi
https://github.com/node-ffi-napi/node-ffi-napi
2.1 安装ffi注意事项
-
需要python2环境
-
MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”
解决: 管理员身份启动cmd运行:
npm install --global --production windows-build-tools
网友评论