今天給大家弄了個十六進制編輯器擴展庫 com.hexEditor ,安裝包僅 22 KB,體積很小。在 「aardio 工具> 擴展庫」內雙擊 com.hexEditor 可以打開範例。也可以直接雙擊運行「aardio 工具> 文本文本> 十六進制編輯器 」。

運行效果:

可直接拖放文件到窗口內,實現拖放功能的源碼如下:
import com.hexEditor;var hexEditor = com.hexEditor(mainForm.static);hexEditor.setBuffer('請拖動文件到當前窗口');mainForm.onDropFiles = function(files){ hexEditor.load(files[1]);}支持查找替換,查找支持模式匹配語法,也支持\x 前綴的十六進制字節編碼,實現該功能的源碼如下:
//查找mainForm.btnFind.oncommand = function(id,event){ var str = string.unhex(mainForm.editFind.text,"\x"); if(!#str){ return mainForm.editFind.editBox.showErrorTip("請輸入要查找的數據"); } hexEditor.findNext(str);}//替換mainForm.btnReplace.oncommand = function(id,event){ var selStart,selEnd = hexEditor.getsel(); if(!selEnd) return mainForm.btnFind.oncommand(); var str = string.unhex(mainForm.editReplace.text,"\x"); hexEditor.replace(str); mainForm.btnFind.oncommand();}可以在下拉框中切換文本編碼 —— 默認為 65001 (UTF-8)。實現該功能的源碼如下:
mainForm.cmbCodePage.items = {"UTF-8(65001)";"Unicode(1200)";"Unicode BE(1201)";"ANSI(0)";"GB2312(936)";"BIG5(950)"};mainForm.cmbCodePage.selIndex = 1;mainForm.cmbCodePage.onListChange = function(){ var text = mainForm.cmbCodePage.selText; var cp = tonumber(string.match(text,"\((\d+)")); if(cp!==null) { cp = tonumber(cp); hexEditor.setCodePage(cp); }}支持自定義右鍵菜單,實現該功能的源碼如下:
import win.clip;import win.ui.menu;hexEditor.onContextMenu = function(x,y){ var menu = win.ui.popmenu(mainForm.static); menu.add('複製\tCtrl+C',function(){ hexEditor.copy(); }) menu.add('複製 16 進制編碼',function(){ var hex = hexEditor.getSelHex() if(#hex){ win.clip.write(hex); } }) menu.add('粘貼\tCtrl+V',function(){ hexEditor.paste(); }) menu.popup(x,y,true); }