if (typeof AkelPad == "undefined")
{
try
{
AkelPad = new ActiveXObject("AkelPad.Document");
var _X64 = AkelPad.Constants._X64;
}
catch (oError)
{
WScript.Echo("You need to register Scripts.dll");
WScript.Quit();
}
}
var oSys = AkelPad.SystemFunction();
var nSASize = _X64 ? 24 : 12 /*sizeof(SECURITY_ATTRIBUTES)*/;
var lpSA = AkelPad.MemAlloc(nSASize);
var lpOutRead = AkelPad.MemAlloc(_X64 ? 8 : 4);
var lpOutWrite = AkelPad.MemAlloc(_X64 ? 8 : 4);
var nBufSize = 65536;
var hOutRead;
var hOutWrite;
AkelPad.MemCopy(lpSA, nSASize, 3 /*DT_DWORD*/); //nLength
AkelPad.MemCopy(lpSA + (_X64 ? 8 : 4), 0, 2 /*DT_QWORD*/); //lpSecurityDescriptor
AkelPad.MemCopy(lpSA + (_X64 ? 16 : 8), 1, 3 /*DT_DWORD*/); //bInheritHandle
if (oSys.Call("Kernel32::CreatePipe", lpOutRead, lpOutWrite, lpSA, nBufSize))
{
hOutRead = AkelPad.MemRead(lpOutRead, 2 /*DT_QWORD*/);
hOutWrite = AkelPad.MemRead(lpOutWrite, 2 /*DT_QWORD*/);
WScript.Echo("Pipe has been created.\nhOutRead: " + hOutRead + "\nhOutWrite: " + hOutWrite);
oSys.Call("Kernel32::CloseHandle", hOutRead);
oSys.Call("Kernel32::CloseHandle", hOutWrite);
}
else
WScript.Echo("Last error code: " + oSys.GetLastError());
AkelPad.MemFree(lpSA);
AkelPad.MemFree(lpOutRead);
AkelPad.MemFree(lpOutWrite);
This script works on WinXP x86 and on Win7 x64 with AkelPad x86. Works also as Activex (x86 and x64).
If run it on Win7 x64 in AkelPad x64 window, CreatePipe fails and last error is 998 - ERROR_NOACCESS ("Invalid access to memory location").
Please help me.
Posted: Wed Dec 03, 2014 8:25 am
by Infocatcher
VladSh wrote:По backupVersion.js 0.1.5pre2.
Там уже 0.1.5pre3 образовалась, кое-что уже подправлено.
VladSh wrote:Параметр forceDate (при "-forceDate=false -dateType=1") на файле, не имеющем информации о версии, почему-то влияет на выдачу сообщения "Не удалось определить версию файла!"; хотя может так и должно быть.
Не совсем понятно назначение этого флага. Думал, что если true, то будет брать дату файла, а если нет, то текущую. Или наоборот...))
Не, -forceDate=true только отключает поиск версии в самом файле (и берет дату модификации файла).
VladSh wrote:При вызове с параметрами "-warnings=false -forceDate=false -dateType=1" на файле, не имеющем информации о версии, сначала сохранило с минутами, затем с секундами, а на 3-й раз выдало оригинальное имя файла, что не очень хорошо.
if (oSys.Call("Kernel32::CreatePipe", lpOutRead, lpOutWrite, 0, nBufSize))
Posted: Wed Dec 03, 2014 2:59 pm
by FeyFre
Instructor, KDJ желает что-бы хендлы были унаследованы, именно для этого и вся затея со структурой SECURITY_ATTRIBUTES.
KDJ, trying to reproduce, but currently my 64bit development environment is broken. For now I can advice you workaround(while I looking for cause): let Security Atttributes parameter default(pass NULL). Result handles cannot be inherited. Next step: use DuplicateHnadle WINAPI function to create inheritable handles. Just temporary workaround (Well, in most cases I know people use DuplicateHandle, because in most cases they need to make inheritable only one end of pipe, not both)
Posted: Wed Dec 03, 2014 6:42 pm
by KDJ
Instructor and FeyFre thank you very much.
But the error is in another place. I found, it is here:
If the tests you run in AkelPad window:
ActiveX_1.js: typeof _X64: "undefined"
ActiveX_2.js: typeof _X64: "number"
Posted: Thu Dec 04, 2014 5:27 am
by Instructor
KDJ wrote:If the tests you run in AkelPad window:
ActiveX_1.js: typeof _X64: "undefined"
ActiveX_2.js: typeof _X64: "number"
Interesting, behaviour
Posted: Thu Dec 04, 2014 10:42 am
by FeyFre
Interesting, behaviour
Without "var" all works fine.
Well, this is intended behavior by language specification.
Declaring variable using var keyword is actually creating Environment Record(ER) in topmost so called Lexical Environments(LE) scoped by compound statement(i.e. local variable, i.e. automatic variable in terms of C/C++). After exiting try's body LE is destroyed(actually just unreference. It will be destroyed after all references will be unreferenced), so binding to such _X64 variable not known/accessible anymore.
Operation assigning to some identifier value a bit longer than it can appears. First it searches for binding in topmost LE(if found - assigns, end). Than it searches in next LE... then in next, ... and next.... last LE in this chain we know as Global Environment. If identifier not bound by "var" keyword to specific(i.e currently topmost) LE, it will be bound to Global Environment.
*There are may appear some tricks in described process if context is in strict mode.
More info at Identifier Resolution
Posted: Thu Dec 04, 2014 12:17 pm
by Instructor
FeyFre wrote:After exiting try's body LE is destroyed(actually just unreference. It will be destroyed after all references will be unreferenced), so binding to such _X64 variable not known/accessible anymore.
Yes, but what is interesting is that execution never goes to try's block.
VladSh wrote:При вызове с параметрами "-warnings=false -forceDate=false -dateType=1" на файле, не имеющем информации о версии, сначала сохранило с минутами, затем с секундами, а на 3-й раз выдало оригинальное имя файла, что не очень хорошо.
Хм, подробную дату в последний запрос вписывать?
Думаю, да. Потому что это надо помнить, что "если файл без даты, значит исходный не пересохранялся и его сохранять не надо". Раз уж начали добавлять к файлу дату, то было бы логично видеть её там и дальше.
Infocatcher wrote:Не, -forceDate=true только отключает поиск версии в самом файле (и берет дату модификации файла).
Ага, понятно.
Лучше в описание к этому аргументу добавить, что "поиск версии в таком случае отключается".
Подскажите, плз, какие передать параметры, чтобы оно сначала смотрело версию, далее:
- если версия найдена, пыталась добавить дату;
- если не найдена, то просто работало с датами.
Хотелось бы обойтись одной такой универсальной строкой, - я чего-то прошлый раз упустил из виду (недотестил), что -forceDate=true игнорирует версию.
Posted: Fri Dec 05, 2014 8:52 pm
by KDJ
FindReplaceEx.js
Added: "Bookmark" and "Unmark" buttons in "Find/Replace" dialog.