看我怎樣把editplus用巧

看我怎樣把editplus用巧

堅(jiān)果 Jimbowhy 前后端腳本編程輕松篇集合文章:

editplus很小卻可以很巧

續(xù)前面的文章小而巧 editplus 腳本編程, 接下來我想分享一下editplus在工作方面給我的幫助, 對(duì)于編碼者, 一個(gè)好用的工具是很得力, 不一定非editplus不可. 在我現(xiàn)在開發(fā)微信小程序的工作中, 我將editplus和sublime搭配起來用, 他們都支持插件的擴(kuò)展, 可以連FTP可以遠(yuǎn)程修改文件, sublime在多查找方面做得很好, 會(huì)將匹配的內(nèi)容收集到一個(gè)臨時(shí)文件中展示, 這些功能都是實(shí)用的, 可以節(jié)省好多時(shí)間.

遇到的不是問題

當(dāng)前我的工作是逆向微信小程序, 需要通過原有的前端來構(gòu)建后端. 使用的工具有微信小程序開發(fā)者工具, Sublime, editplus, 還有用來抓包的 Fiddler. 為了后面開發(fā) Fiddler 插件, SharpDevelop 是不錯(cuò)的候選. 所以, 我是偏愛輕量的, Visual Stuio 也是最喜歡 97 版.

日常工作 Fiddler 抓包的分析是最繁雜的, 本身不復(fù)雜, 但是將抓包得到的數(shù)據(jù)再整理成后端, 重構(gòu)成后端代碼的過程卻很費(fèi)時(shí). 例如下面抓到的這個(gè)包,

Fiddler Capture

客戶端發(fā)起 Request 需要傳參數(shù), 后端需要對(duì)參數(shù)進(jìn)行接收處理, 中間邏輯占時(shí)不管, 返回的數(shù)據(jù)卻是必要的:

terminalApplication letv_leview
bsChannel   
terminalSeries  Le_X620_whole-netcom
versionCode 90
terminalBrand   LeEco
devId   

將傳入?yún)?shù)拷貝一份, 接下來就需要處理成后端接收參數(shù)的代碼, 這個(gè)過程是典型的. 現(xiàn)有的框架還是 thinkPHP, 需要轉(zhuǎn)換成以下這樣的代碼:

$terminalApplication = I("get.terminalApplication")); //    letv_leview
$bsChannel = I("get.bsChannel")); //    
$terminalSeries = I("get.terminalSeries")); //  Le_X620_whole-netcom
$versionCode = I("get.versionCode")); //    90
$terminalBrand = I("get.terminalBrand")); //    LeEco
$devId = I("get.devId")); //    

這個(gè)工作本身不是難事, 但是用人工來做字符串處理這件事挺費(fèi)事也挺費(fèi)時(shí), 應(yīng)為每敲一次鍵盤都是費(fèi)時(shí)間的, 特別是大量這樣的重復(fù)時(shí), 更簡潔的處理流程就會(huì)產(chǎn)生, 不然市面上就不會(huì)有一堆的框架存在了.

解決這個(gè)問題也不難, Windows 平臺(tái)的腳本足夠用,而且有 JScript 和正則表達(dá)式, 這樣的字符串處理 so easy.

給editplus裝上利刃

腳本我用 WSF 來管理, 用 JScript 來寫代碼, 配合正則表達(dá)式處理文字. 寫好腳本后對(duì) editplus 進(jìn)行配置, 通過 Windows 腳本寄主運(yùn)行. 原始內(nèi)容經(jīng)過腳本處理, 將輸出到控制臺(tái), editplus 責(zé)抓取控制臺(tái)內(nèi)容, 配置 editplus 的抓取動(dòng)作為 Capture output 或 Run as Text Filter (Copy Result), 建議使用后者, 這樣執(zhí)行腳本后, 處理過的內(nèi)容直接就存儲(chǔ)到剪貼板了, 方便使用, 先在就來貼代碼, 將以下代碼保存為 WSF 文件放到 editplus 的目錄下, 然后按后面要求對(duì) editplus 做簡單配置即可:

    <?XML version="1.0" standalone="yes" ?>
    <package>
    <job id="smart" args="datafile action and more" prompt="no">
        <?job error="true" debug="true" ?>
        <runtime>
            <description>
    This Scripting programme is tools for my daily work,
    so it does really helpful! And also it is a demo form my article.
    You can visit it on this relative articles:
    [輕松搭建PHP開發(fā)環(huán)境Win32](http://www.itdecent.cn/p/d6c5c8a959a0)
    [小而巧 editplus 腳本編程](http://www.itdecent.cn/p/2a27a788e3ea)
    [Windows Script Technology](http://www.itdecent.cn/p/a443991462d7)
    [看我怎樣把editplus用巧](http://www.itdecent.cn/p/c70c679888fc)
    [HTTP協(xié)議入門與Fiddler抓包](http://www.itdecent.cn/p/311fef023f0d)
            </description>
            <named helpstring="data.txt" name="data file input" required="false" type="string"/>
            <named helpstring="post" name="action for processing" required="true" type="string"/>
        </runtime>
        <object id="fso" progid="Scripting.FileSystemObject"/>
        <script language="JScript">
    <![CDATA[
            var log = function (msg){
                return WScript.Echo(msg);
            }
            function readFile(path){
                // user object element instead of code
                //var fso = new ActiveXObject("Scripting.FileSystemObject");
                
                //var path = WScript.Arguments(0);
                if(!fso.FileExists(path)){
                    var raw = fso.CreateTextFile(path);
                }
                var ForReading = 1, ForWriting = 2, ForAppending = 8;
                var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
                var f = fso.GetFile(path);
                var raw = f.OpenAsTextStream(ForReading, TristateUseDefault);
                var c = raw.ReadAll();
                raw.Close();
                return c;
            }

            function json2array(c){
                if( /^ *\{/.test(c) ){ // JSON
                    c = c.replace(/\{/g,"[").replace(/\}/g, "]");
                    c = c.replace(/":/g,"\"=>");
                    log(c);
                }else{
                    log("smart.wsf do nothing");
                }
            }

            function reverseWebForm(c){
                var ACTION = "post";
                var act = WScript.Arguments(1);
                if( /[post|get]/.test(act) ) ACTION = act;
                c = c.replace(/^(\w+)/mg, '$0$1 = I("' + ACTION + '.$1")); //');
                c = c.replace(/\$0/g, "$");
                //c = c.replace(/^/mg, '$'); this regexp working unstable in different OS
                log(c);
            }

            !function main(){
                var s = "";
                for(var i=0; i<WScript.Arguments.Length; i++){
                    s+= i+": "+WScript.Arguments(i)+"\n";
                }
                // log(s);
                if( WScript.Arguments.length<2 ){
                    log('This script tranlate between JSON and php Array\n'
                        +'Also it can reverse web form parameters to generate ThinkPHP code\n'
                        +'Usage:\n'
                        +'  CScript.exe //nologo "$(AppDir)\smart.wsf" raw.txt json2array\n'
                        +'  CScript.exe //nologo "$(AppDir)\\smart.wsf" raw.txt post\n'
                        +'  CScript.exe //nologo "$(AppDir)\\smart.wsf" raw.txt get\n'
                        +'Example:\n'
                        +'  {"message":"page"} ==> ["message"=>"page"]\n'
                        +'  message page ==> $message = I("post.message"); //some value\n'
                        +'editplus settings:\n'
                        +'  CScript.exe //nologo "$(AppDir)\\smart.wsf" "$(FilePath)" json2array\n'
                        +'  CScript.exe //nologo "$(AppDir)\\smart.wsf" "$(FilePath)" post\n'
                        +'  CScript.exe //nologo "$(AppDir)\\smart.wsf" "$(FilePath)" get\n'
                    );
                    return false;
                }
                var act = WScript.Arguments(1);
                var raw = WScript.Arguments(0);
                if( !fso.FileExists(raw) ){
                    log("No such data file: "+raw);
                    return false;
                }
                var data = readFile(raw);
                if(act=="json2array"){
                    json2array(data);
                }else if( /[post|get]/.test(act) ){
                    reverseWebForm(data);
                }else{
                    log("No such action: "+act);
                }
            }(); // execute enter
    ]]>
        </script>
    </job>
    </package>

代碼執(zhí)行流程入口是 main 方法, 他會(huì)檢查參數(shù), 然后根據(jù)參數(shù)調(diào)用指定方法來處理內(nèi)容, 如果參數(shù)沒有正確傳入, 則打印提示信息. 其中 named 命名參數(shù)在實(shí)際運(yùn)行時(shí)并沒有用, 只是方便在 PrimalScript 運(yùn)行調(diào)試. 打開editplus用戶工具配置, Tools => Configure User Tools, 點(diǎn)擊 Add Tool 添加一個(gè)程序工具并設(shè)置:

Text=JSON 2 phpArray
Command=CScript.exe
Action=Run as Text Filter (Copy Result)
Argument="$(AppDir)\smart.wsf" //nologo "$(FilePath)" json2array

Text=Reverse Web Form(post)
Command=CScript.exe
Argument="$(AppDir)\smart.wsf" //nologo "$(FilePath)" post
ACTiON=Run as Text Filter (Copy Result)

Text=Reverse Web Form(get)
Command=CScript.exe
Argument="$(AppDir)\smart.wsf" //nologo "$(FilePath)" get
ACTiON=Run as Text Filter (Copy Result)
editplus config smart

配置完后, editplus 工具菜單看起來應(yīng)該是這個(gè)樣的, 通過快捷鍵 CTRL+1...5 對(duì)應(yīng)的數(shù)字就可以執(zhí)行預(yù)設(shè)的功能腳本:

user tools smart

如果不想動(dòng)手, 可以直接下載已經(jīng)配置好的 epp500_0651_smart, 源程序在官方網(wǎng)站下載, 只更新配置文件. 現(xiàn)在看上去還不錯(cuò), 來測試看看, 將前面抓包得到的 WebForm 參數(shù)拷貝到一個(gè)文件, 在 editplus 打開. 然后按下 CTRL+5, 運(yùn)行腳本進(jìn)行處理, editplus 會(huì)在狀態(tài)欄提示: User tools Reverse Web Form(get), 然后處理內(nèi)容好的內(nèi)容就被存儲(chǔ)到剪貼板了, 然后再按下 Ctrl+V 將內(nèi)容回帖到文件檢查一下, 注意配置 editplus 工具時(shí)要選 Copy Result, 沒錯(cuò)挺好:

webform_reverse.png

然后再對(duì) WebForm 的響應(yīng), 即后端輸出的 JSON 數(shù)據(jù)進(jìn)行處理, 內(nèi)容不多, 但有多字節(jié)字符, 控制臺(tái)可能會(huì)出現(xiàn)編碼不匹配導(dǎo)致亂碼, 一般中文系統(tǒng)用GB23312就可以, 也就是 editplus 顯示的 ANSI 編碼, 這個(gè) ANSI 表示 editplus 在使用系統(tǒng)默認(rèn)編碼:

{"status":1,"data":{"status":"7","message":"不用升級(jí)!"}}
json2array.png

同樣, 回帖處理好的字符串, 檢查一下, 已經(jīng)轉(zhuǎn)換成 PHP 數(shù)組了, 好了就這樣繼續(xù)工作。

參考文檔

強(qiáng)烈推薦Microsoft Windows腳本技術(shù), 英文版 script56.chm 內(nèi)容更新更齊全, 特別是關(guān)于正則表達(dá)式的內(nèi)容, 這部分內(nèi)容很豐富, 值得另取一文講解. 還有Advanced Windows Script Host Developers Guide 這本書深入講解了Windows腳本編程技術(shù), 腳本與應(yīng)用程序的交互, 配合 Visual Basic 開發(fā)的 ActiveX 組件來擴(kuò)展腳本功能. 書中舉例 JScript 實(shí)現(xiàn) VBScript 的 InputBox 功能, 通過 Internet Explorer 組件加載頁面來模擬, 又可以通過開發(fā) ActiveX 來實(shí)現(xiàn), 使用 wsf 集合 VBScript 和 JScript 來實(shí)現(xiàn), 甚至更直接地使用 WScript.Shell 的 Environment 屬性實(shí)現(xiàn)通過環(huán)境變量來傳遞數(shù)據(jù).

還有一本資料《Advanced Development with Microsoft Windows Script Host 2.0》, 看標(biāo)題應(yīng)該是深層次的數(shù), 可惜找不到資源. 此外,SAPIEN 即 PrimalScript 發(fā)行公司初版的以本書是《WSH and VBScript Core 》。

微軟官方早期的 MSDN 也可以作為參考, 在 Microsoft Visual 97 下載鏈接中可以找到.

PrimalScript 2014_7.0.32 x86
epp500_0651_smart.exe
《Microsoft Windows Script Host 2.0 Developer's Guide》 scripthost20dev.chm
《Advanced Windows Script Host Developers Guide (2003)》
Microsoft Windows腳本技術(shù)
Microsoft Windows Script Technologies script56.chm
Microsoft Visual 97 我喜歡的
Microsoft Visual 97 加密分享: 9km8

微信掃一掃打賞堅(jiān)果
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容