1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-19 17:53:28 +00:00

1. Fixed memory corruption in GDI+ initialization

2. Fixed memory leak in message pump
3. Updated enhanced user consent
This commit is contained in:
Bryan Roe
2021-12-10 11:43:52 -08:00
parent 14e54ceda8
commit 1512eb192d
4 changed files with 77 additions and 15 deletions

File diff suppressed because one or more lines are too long

View File

@@ -175,7 +175,7 @@ function childContainer()
ret._proc = require('child_process').execFile(process.execPath, [process.execPath.split(process.platform == 'win32' ? '\\' : '/').pop(), '-b64exec', script], child_options);
ret._proc.descriptorMetadata = "child-container";
ret._proc.parent = ret;
ret._proc.stdout.on('data', function (c) { });
ret._proc.stdout.on('data', function (c) { console.info2(c.toString()); });
ret._proc.stderr.on('data', function (c) { });
ret._proc.on('exit', function (code)
{

View File

@@ -55,6 +55,7 @@ function WindowsMessagePump(options)
this._user32.CreateMethod('ShowWindow');
this._user32.CreateMethod('SystemParametersInfoA');
this._user32.CreateMethod('TranslateMessage');
this._user32.CreateMethod('UnregisterClassW');
this._user32.CreateMethod('IsDlgButtonChecked');
this._user32.CreateMethod('CheckDlgButton');
@@ -72,16 +73,15 @@ function WindowsMessagePump(options)
this.wndclass = GM.CreateVariable(GM.PointerSize == 4 ? 48 : 80);
this.wndclass.mp = this;
this.wndclass.hinstance = this._kernel32.GetModuleHandleA(0);
//this.wndclass.cname = GM.CreateVariable('MainWWWClass');
if (options && options.window && options.window.background != null)
{
console.info1('SETTING BACKGROUND BRUSH');
console.info1('SETTING BACKGROUND BRUSH', options.window.background);
this.wndclass.bkbrush = this._gdi32.CreateSolidBrush(options.window.background);
this.wndclass.bkbrush.pointerBuffer().copy(this.wndclass.Deref(GM.PointerSize == 4 ? 32 : 48, GM.PointerSize).toBuffer())
}
this.wndclass.cnamew = GM.CreateVariable('MainWWWClass', { wide: true });
this.wndclass.cnamew = GM.CreateVariable('MainWWWClass_' + this.wndclass._hashCode(), { wide: true });
this.wndclass.wndproc = GM.GetGenericGlobalCallback(4);
this.wndclass.wndproc.mp = this;
this.wndclass.toBuffer().writeUInt32LE(this.wndclass._size);
@@ -235,12 +235,14 @@ function WindowsMessagePump(options)
// We got a 'QUIT' message
this.nativeProxy.DestroyWindow.async(this.nativeProxy.RegisterClassExW.async, this.nativeProxy.mp._hwnd).then(function ()
{
this.nativeProxy.RegisterClassExW.async.abort();
delete this.nativeProxy.mp._hwnd;
this.nativeProxy.mp.emit('exit', 0);
this.nativeProxy.mp.wndclass.wndproc.removeAllListeners('GlobalCallback');
this.nativeProxy.mp.wndclass.wndproc = null;
this.nativeProxy.UnregisterClassW.async(this.nativeProxy.RegisterClassExW.async, this.nativeProxy.mp.wndclass.cnamew, this.nativeProxy.mp.wndclass.hinstance).then(function ()
{
this.nativeProxy.RegisterClassExW.async.abort();
delete this.nativeProxy.mp._hwnd;
this.nativeProxy.mp.emit('exit', 0);
this.nativeProxy.mp.wndclass.wndproc.removeAllListeners('GlobalCallback');
this.nativeProxy.mp.wndclass.wndproc = null;
});
});
}
}, function (err) { this.nativeProxy.mp.stop(); });

View File

@@ -295,7 +295,7 @@ function createLocal(title, caption, username, options)
var rect = GM.CreateVariable(16);
var startupinput = require('_GenericMarshal').CreateVariable(24);
ret.gdipToken = require('_GenericMarshal').CreateVariable(4);
ret.gdipToken = require('_GenericMarshal').CreatePointer();
ret.pump = new MessagePump(ret.opt);
if (ret.pump._user32.SystemParametersInfoA(SPI_GETWORKAREA, 0, rect, 0).Val != 0)
@@ -332,8 +332,7 @@ function createLocal(title, caption, username, options)
var hbitmap = require('_GenericMarshal').CreatePointer();
var status = gdip.GdipCreateBitmapFromStream(istream, pimage);
status = gdip.GdipCreateHBITMAPFromBitmap(pimage.Deref(), hbitmap, options.background);
if (status.Val == 0) { options.bitmap = hbitmap; }
if (status.Val == 0) { options.bitmap = hbitmap; }
}
ret.pump.on('message', pump_onMessage);
@@ -376,9 +375,69 @@ function create(title, caption, username, options)
}
// Need to dispatch to user session to display dialog
var ret = new promise(promise.defaultInit);
ret.options = { launch: { module: 'win-userconsent', method: '_child', args: [] } };
ret._ipc = require('child-container').create(ret.options);
ret._ipc.master = ret;
ret._ipc.once('exit', function () { console.log('child exited'); });
ret._ipc.on('ready', function ()
{
console.log('READY');
this.descriptorMetadata = 'win-userconsent';
this.message({ command: 'dialog', title: title, caption: caption, username: username, options: options });
});
ret._ipc.on('message', function (msg)
{
try
{
switch (msg.command)
{
case 'allow':
this.master.resolve(msg.always);
break;
case 'deny':
this.master.reject(msg.reason);
break;
case 'log':
console.log(msg.text);
break;
default:
break;
}
}
catch (ff)
{
}
});
return (ret);
}
function _child()
{
global.master = require('child-container');
global.master.on('message', function (msg)
{
switch (msg.command)
{
case 'dialog':
var p = createLocal(msg.title, msg.caption, msg.username, msg.options);
p.then(function (always)
{
global.master.message({ command: 'allow', always: always });
}, function (msg)
{
global.master.message({ command: 'deny', reason: msg });
}).finally(function (msg)
{
process._exit();
});
break;
}
});
}
module.exports =
{
create: create
create: create, _child: _child
};