auto-type bugfixes

This commit is contained in:
antelle 2016-04-19 20:39:17 +03:00
parent 35c19e4578
commit f9d593356b
6 changed files with 79 additions and 53 deletions

View File

@ -51,7 +51,7 @@
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings "laxbreak" : false, // true: Tolerate possibly unsafe line breakings
"laxcomma" : false, // true: Tolerate comma-first style coding "laxcomma" : false, // true: Tolerate comma-first style coding
"loopfunc" : false, // true: Tolerate functions being defined in loops "loopfunc" : false, // true: Tolerate functions being defined in loops
"multistr" : true, // true: Tolerate multi-line strings "multistr" : false, // true: Tolerate multi-line strings
"noyield" : false, // true: Tolerate generator functions with no yield statement in them. "noyield" : false, // true: Tolerate generator functions with no yield statement in them.
"notypeof" : false, // true: Tolerate invalid typeof operator values "notypeof" : false, // true: Tolerate invalid typeof operator values
"proto" : false, // true: Tolerate using the `__proto__` property "proto" : false, // true: Tolerate using the `__proto__` property

View File

@ -5,7 +5,7 @@ var Logger = require('../../util/logger');
var logger = new Logger('auto-type-obfuscator'); var logger = new Logger('auto-type-obfuscator');
logger.setLevel(localStorage.autoTypeDebug ? Logger.Level.All : Logger.Level.Warn); logger.setLevel(localStorage.autoTypeDebug ? Logger.Level.All : Logger.Level.Warn);
var MaxFakeOps = 50; var MaxFakeOps = 30;
var MaxSteps = 1000; var MaxSteps = 1000;
var MaxCopy = 2; var MaxCopy = 2;
var FakeCharAlphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz123456789O0oIl'; var FakeCharAlphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz123456789O0oIl';

View File

@ -2,8 +2,6 @@
var Launcher = require('../../launcher'); var Launcher = require('../../launcher');
var spawn = Launcher.req('child_process').spawn;
var KeyMap = { var KeyMap = {
tab: 48, enter: 36, space: 49, tab: 48, enter: 36, space: 49,
up: 126, down: 125, left: 123, right: 124, home: 115, end: 119, pgup: 116, pgdn: 121, up: 126, down: 125, left: 123, right: 124, home: 115, end: 119, pgup: 116, pgdn: 121,
@ -89,11 +87,11 @@ AutoTypeEmitterImpl.prototype.mapMod = function(mod) {
AutoTypeEmitterImpl.prototype.runScript = function(script, callback) { AutoTypeEmitterImpl.prototype.runScript = function(script, callback) {
script = 'tell application "System Events" \n' + script + '\nend tell'; script = 'tell application "System Events" \n' + script + '\nend tell';
var ps = spawn('osascript'); Launcher.spawn({
ps.stdin.setEncoding('utf-8'); cmd: 'osascript',
ps.stdin.write(script); data: script,
ps.stdin.end(); complete: callback
ps.on('close', function(code) { callback(code ? 'Exit code ' + code : undefined); }); });
}; };
module.exports = AutoTypeEmitterImpl; module.exports = AutoTypeEmitterImpl;

View File

@ -2,8 +2,6 @@
var Launcher = require('../../launcher'); var Launcher = require('../../launcher');
var spawn = Launcher.req('child_process').spawn;
var KeyMap = { var KeyMap = {
tab: '{tab}', enter: '{enter}', space: '{space}', tab: '{tab}', enter: '{enter}', space: '{space}',
up: '{up}', down: '{down}', left: '{left}', right: '{right}', home: '{home}', end: '{end}', pgup: '{pgup}', pgdn: '{pgdn}', up: '{up}', down: '{down}', left: '{left}', right: '{right}', home: '{home}', end: '{end}', pgup: '{pgup}', pgdn: '{pgdn}',
@ -49,7 +47,7 @@ AutoTypeEmitterImpl.prototype.text = function(text, callback) {
return callback(); return callback();
} }
text = this.addMod(this.escapeText(text.replace(TextReplaceRegex, function(match) { return '{' + match + '}'; }))); text = this.addMod(this.escapeText(text.replace(TextReplaceRegex, function(match) { return '{' + match + '}'; })));
this.pendingScript.push('[System.Windows.Forms.SendKeys]::SendWait("' + text + '");'); this.pendingScript.push('[System.Windows.Forms.SendKeys]::SendWait("' + text + '")');
callback(); callback();
}; };
@ -66,18 +64,18 @@ AutoTypeEmitterImpl.prototype.key = function(key, callback) {
Object.keys(this.mod).forEach(function(mod) { this.pendingScript.push('[KwHelper]::Up(' + ModVk[mod] + ')'); }, this); Object.keys(this.mod).forEach(function(mod) { this.pendingScript.push('[KwHelper]::Up(' + ModVk[mod] + ')'); }, this);
} else { } else {
var text = this.addMod(key); var text = this.addMod(key);
this.pendingScript.push('[System.Windows.Forms.SendKeys]::SendWait("' + text + '");'); this.pendingScript.push('[System.Windows.Forms.SendKeys]::SendWait("' + text + '")');
} }
callback(); callback();
}; };
AutoTypeEmitterImpl.prototype.copyPaste = function(text, callback) { AutoTypeEmitterImpl.prototype.copyPaste = function(text, callback) {
this.pendingScript.push('[System.Threading.Thread]::Sleep(5000)'); this.pendingScript.push('[System.Threading.Thread]::Sleep(500)');
this.pendingScript.push('[System.Windows.Forms.Clipboard]::SetText("' + this.escapeText(text) + '")'); this.pendingScript.push('[System.Windows.Forms.Clipboard]::SetText("' + this.escapeText(text) + '")');
this.pendingScript.push('[System.Threading.Thread]::Sleep(5000)'); this.pendingScript.push('[System.Threading.Thread]::Sleep(500)');
this.pendingScript.push('[System.Windows.Forms.SendKeys]::SendWait("+{ins}")'); this.pendingScript.push('[System.Windows.Forms.SendKeys]::SendWait("+{ins}")');
this.pendingScript.push('[System.Threading.Thread]::Sleep(5000)'); this.pendingScript.push('[System.Threading.Thread]::Sleep(500)');
this.waitComplete(callback); callback();
}; };
AutoTypeEmitterImpl.prototype.waitComplete = function(callback) { AutoTypeEmitterImpl.prototype.waitComplete = function(callback) {
@ -103,25 +101,29 @@ AutoTypeEmitterImpl.prototype.addMod = function(text) {
}; };
AutoTypeEmitterImpl.prototype.runScript = function(script, callback) { AutoTypeEmitterImpl.prototype.runScript = function(script, callback) {
script = 'Add-Type @"\ script =
using System;\ 'Add-Type @"\n' +
using System.Runtime.InteropServices;\ 'using System;\n' +
public static class KwHelper {\ 'using System.Runtime.InteropServices;\n' +
[DllImport("user32.dll")]\ 'public static class KwHelper {\n' +
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);\ '[DllImport("user32.dll")]\n' +
public static void Down(byte code) { keybd_event(code, 0, 1, UIntPtr.Zero); }\ 'static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);\n' +
public static void Up(byte code) { keybd_event(code, 0, 3, UIntPtr.Zero); }\ 'public static void Down(byte code) { keybd_event(code, 0, 1, UIntPtr.Zero); }\n' +
public static void Press(byte code) { Down(code); Up(code); }\ 'public static void Up(byte code) { keybd_event(code, 0, 3, UIntPtr.Zero); }\n' +
}\ 'public static void Press(byte code) { Down(code); Up(code); }\n' +
"@\ '}\n' +
[Console]::InputEncoding = [System.Text.Encoding]::UTF8\ '"@\n\n' +
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")\n' + script; '[Console]::InputEncoding = [System.Text.Encoding]::UTF8\n' +
'[Console]::OutputEncoding = [System.Text.Encoding]::UTF8\n' +
'[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")\n' +
script;
var ps = spawn('powershell', ['-Command', '-']); Launcher.spawn({
ps.stdin.setEncoding('utf-8'); cmd: 'powershell',
ps.stdin.write(script); args: ['-Command', '-'],
ps.stdin.end(); data: script,
ps.on('close', function(code) { callback(code ? 'Exit code ' + code : undefined); }); complete: callback
});
}; };
module.exports = AutoTypeEmitterImpl; module.exports = AutoTypeEmitterImpl;

View File

@ -2,8 +2,6 @@
var Launcher = require('../../launcher'); var Launcher = require('../../launcher');
var spawn = Launcher.req('child_process').spawn;
var ForeMostAppScript = 'tell application "System Events" to set frontApp to name of first process whose frontmost is true'; var ForeMostAppScript = 'tell application "System Events" to set frontApp to name of first process whose frontmost is true';
var ChromeScript = 'tell application "{}" to set appUrl to URL of active tab of front window\n' + var ChromeScript = 'tell application "{}" to set appUrl to URL of active tab of front window\n' +
'tell application "{}" to set appTitle to title of active tab of front window\n' + 'tell application "{}" to set appTitle to title of active tab of front window\n' +
@ -53,21 +51,10 @@ AutoTypeHelper.prototype.getActiveWindowTitle = function(callback) {
}; };
AutoTypeHelper.exec = function(script, callback) { AutoTypeHelper.exec = function(script, callback) {
var ps = spawn('osascript', ['-e', script]); Launcher.spawn({
var stderr = ''; cmd: 'osascript',
var stdout = ''; args: ['-e', script],
ps.stdout.on('data', function(data) { complete: callback
stdout += data.toString();
});
ps.stderr.on('data', function(data) {
stderr += data.toString();
});
ps.on('close', function(code) {
if (code) {
callback('Exit code ' + code + ': ' + stderr + (stdout ? '\nout: ' + stdout : ''));
} else {
callback(null, stdout);
}
}); });
}; };

View File

@ -1,10 +1,13 @@
'use strict'; 'use strict';
var Backbone = require('backbone'), var Backbone = require('backbone'),
Locale = require('../util/locale'); Locale = require('../util/locale'),
Logger = require('../util/logger');
var Launcher; var Launcher;
var logger = new Logger('launcher');
if (window.process && window.process.versions && window.process.versions.electron) { if (window.process && window.process.versions && window.process.versions.electron) {
/* jshint node:true */ /* jshint node:true */
Launcher = { Launcher = {
@ -128,6 +131,42 @@ if (window.process && window.process.versions && window.process.versions.electro
} }
return true; return true;
}, },
spawn: function(config) {
var ts = logger.ts();
var complete = config.complete;
var ps = this.req('child_process').spawn(config.cmd, config.args);
[ps.stdin, ps.stdout, ps.stderr].forEach(function(s) { s.setEncoding('utf-8'); });
var stderr = '';
var stdout = '';
ps.stderr.on('data', function(d) { stderr += d.toString('utf-8'); });
ps.stdout.on('data', function(d) { stdout += d.toString('utf-8'); });
ps.on('close', function(code) {
stdout = stdout.trim();
stderr = stderr.trim();
var msg = 'spawn ' + config.cmd + ': ' + code + ', ' + logger.ts(ts);
if (code) {
logger.error(msg + '\n' + stdout + '\n' + stderr);
} else {
logger.info(msg + (stdout ? '\n' + stdout : ''));
}
if (complete) {
complete(code ? 'Exit code ' + code : null, stdout, code);
complete = null;
}
});
ps.on('error', function(err) {
logger.error('spawn error: ' + config.cmd + ', ' + logger.ts(ts), err);
if (complete) {
complete(err);
complete = null;
}
});
if (config.data) {
ps.stdin.write(config.data);
ps.stdin.end();
}
return ps;
},
platform: function() { platform: function() {
return process.platform; return process.platform;
} }