| 1>1 |
| |
| |
| |
| |
| |
| var undefined = void 0 |
| var arrCodeBlock = [] |
| |
| while(!WScript.StdIn.AtEndOfStream){ |
| var line_base = WScript.StdIn.ReadLine() |
| |
| |
| var line_analyze = analyze_ExpandString(line_base) |
| |
| |
| arrCodeBlock.push(line_analyze) |
| |
| |
| if(!test_AtEndOfCodeBlock&&!WScript.StdIn.AtEndOfStream)continue |
| |
| |
| var text_CodeBlock = arrCodeBlock.join('\n') |
| |
| |
| WSH.Echo(text_CodeBlock) |
| |
| |
| var text_CodeBlock = analyze_CleanCrLf(text_CodeBlock) |
| |
| |
| var split_CodeBlock = analyze_Split(text_CodeBlock) |
| |
| |
| for(var i=0;i<split_CodeBlock.length;i++){ |
| split_CodeBlock[i] = analyze_Handle(split_CodeBlock[i]) |
| |
| |
| split_CodeBlock[i] = analyze_Command(split_CodeBlock[i]) |
| |
| } |
| |
| arrCodeBlock = [] |
| |
| } |
| |
| |
| |
| function test_AtEndOfCodeBlock(strText){ |
| var tmpText = strText |
| .replace(/[<>&|]/g,' ') |
| .replace(/\^[\s\S]|"[^"\n]*"|[^()]\(|\)[^()]/g,' ') |
| .replace(/[^()]+/g,'') |
| |
| while(/\(\)/.test(tmpText)){ |
| tmpText=tmpText.replace(/\(\)/g,'') |
| } |
| |
| return tmpText.length == 0 |
| } |
| |
| |
| |
| function analyze_CleanCrLf(strText){ |
| return strText |
| .replace(/\r\n/g,'\n') |
| .replace(/\^\n/g,'') |
| } |
| |
| function analyze_ExpandString(strText){ |
| return strText |
| .replace( |
| /%([0-9])|%:|%[^%]*%|%$/g, |
| function(strText,intArgv){ |
| if(strText==='%')return '' |
| |
| if(strText==='%%')return strText |
| |
| if(strText==='%:')return ':' |
| |
| if(intArgv !== undefined)return strText |
| |
| return analyze_Variable(strText.replace(/%/g,'')) |
| } |
| ) |
| } |
| |
| function analyze_Variable(strText){ |
| |
| var match = strText.match(/([^:]+)(?::(.*))?/) |
| var variableName = match[1] |
| var variableCode = match[2] ? match[2] : '' |
| |
| var ws = new ActiveXObject("Wscript.Shell") |
| var variableValue = ws.ExpandEnvironmentStrings('%'+variableName+'%') |
| |
| if(!variableCode)return variableValue |
| |
| |
| var match = variableCode.match(/^~\s*(-?0x[0-9a-f]+|-?[0-9]+)?,?\s*(-?0x[0-9a-f]+|-?[0-9]+)?$/i) |
| if(match){ |
| var splitStart = match[1] ? match[1]*1 : 0 |
| var splitLength = match[2] ? match[2]*1 : 8191 - variableName.length |
| |
| return cut(variableValue,splitStart,splitLength) |
| } |
| |
| |
| var match = variableCode.match(/^([^=]+)=?(\*)?([s\S]+)?$/) |
| if(match){ |
| var replaceFrom = match[1].replace(/\W/g,'\\$&') |
| var replaceHead = !!match[2] |
| var replaceTo = match[3] ? match[3].replace(/\$/g,'$$$$') : '' |
| |
| if(replaceHead){ |
| return variableValue.replace(new RegExp('^.*?'+replaceFrom,'i'),replaceTo) |
| } else { |
| return variableValue.replace(new RegExp(replaceFrom,'ig'),replaceTo) |
| } |
| } |
| |
| |
| return strText |
| |
| function cut(strText,intStart,intLength){ |
| if(intStart<0){ |
| variableValue = variableValue.substr(variableValue.length - -intStart) |
| } else { |
| variableValue = variableValue.substr(intStart) |
| } |
| |
| if(intLength<0){ |
| return variableValue.substring(0,-intLength) |
| } else { |
| return variableValue.substr(0,intLength) |
| } |
| } |
| |
| } |
| |
| |
| function analyze_Split(strText){ |
| var retArr = [] |
| var strText = strText.replace( |
| /(^|&&?|\|\|?)?[\(\s]*([^\^\"&|]*(?:"[^"]*(?:"|$))*[^\^\"&|]*)?[\s\)]*/mg, |
| function(strMatch,strSpecial,strCommand){ |
| retArr.push({strSpecial:strSpecial,strCommand:strCommand}) |
| } |
| ) |
| return retArr |
| } |
| |
| |
| function analyze_Handle(objCommand){ |
| var tmpArr = [] |
| var strCommand = objCommand.strCommand.replace( |
| /"[^"]*"|\^[<>]|([0-9]?)(&?[<>]|\>\>)([^\^\"\s&|<>]*(?:"[^"]*(?:"|$))*[^\^\"\s&|<>]*)?/mg, |
| function(strMatch,intHandle,strSpecial,strTarget){ |
| intHandle = intHandle?intHandle:'' |
| strTarget = strTarget?strTarget:'' |
| if(strSpecial){ |
| tmpArr.push(' '+intHandle+strSpecial+strTarget) |
| return '' |
| } else { |
| return strMatch |
| } |
| } |
| ) |
| return {Command:strCommand,Handle:tmpArr} |
| } |
| |
| |
| function analyze_Command(objCommand){ |
| var RegExp_command = /^\s*(ASSOC|BREAK|CALL|CD|CHDIR|CLS|COLOR|COPY|DEL|ENDLOCAL|ERASE|EXIT|FOR|FTYPE|GOTO|GRAFTABL|IF|MD|MKLINK|MOVE|PATH|PAUSE|POPD|PROMPT|PUSHD|RD|REM|REN|SET|SETLOCAL|SHIFT|START|TIME|TITLE|TYPE|VER|VERIFY|VOL)(?:([ \t,;=]*|$)(.*))?$/mi |
| |
| var match = objCommand.Command.match(RegExp_command) |
| if(match){ |
| objCommand.commandName = match[1] |
| objCommand.spaceChar = match[2] ? match[2] : '' |
| objCommand.commandValue = match[3] ? match[3] : '' |
| |
| if(objCommand.commandName.toUpperCase()==='SET'){ |
| Command_SET(objCommand.commandValue) |
| } |
| } |
| |
| return objCommand |
| } |
| |
| |
| function Command_SET(strText){ |
| strText = strText.replace(/^"(.*)"?$/,'$1') |
| |
| var match = strText.match(/^\s*([^=]+)=?([^\^\"&|]*(?:"[^"]*(?:"|$))*[^\^\"&|]*)?\s*/) |
| if(match){ |
| var variableName = match[1] |
| var variableCode = match[2] ? match[2] : '' |
| |
| var ws = new ActiveXObject("Wscript.Shell") |
| ws.Environment("Process")(variableName) = variableCode |
| |
| } |
| }COPY |