- 論壇徽章:
- 0
|
因?yàn)閷?duì)jEdit現(xiàn)有Hex相關(guān)功能插件(Hex、HexEdit、HexTools)功能不太滿意,寫了一個(gè)簡(jiǎn)單的macro提供Dump Hex功能,設(shè)置一個(gè)快捷鍵或者添加到右鍵菜單的話會(huì)更方便,效果見(jiàn)附圖,另外jedit-cn討論組鏈接為: http://t.cn/zl8AOWG
54862a3fjw1dxzflyt1q1j.jpg (399.27 KB, 下載次數(shù): 39)
下載附件
2012-10-19 11:47 上傳
macro代碼如下
- char[] hex_digit = new char[] {
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
- };
- String byte_to_hex( byte b ) {
- char[] chars = new char[] {
- hex_digit[ (b >> 4) & 0x0f ],
- hex_digit[ b & 0x0f ]
- };
- return new String( chars );
- }
- String dump_hex( String target ) {
- byte[] string = target.getBytes();
- StringBuffer hex = new StringBuffer();
- int tail = 0;
- String src = "";
- int length = string.length;
- for ( int i=0; i<length; ++i ) {
-
- char curr = string[i];
- if ( curr == '\r' || curr=='\n' || curr=='\t' ) {
- src += " ";
- } else {
- src += curr;
- }
-
- hex.append( byte_to_hex(string[i]) + " " );
- if ( ((i+1)%19) == 0 ) {
- hex.append( " | " + src + "\n" );
- src = "";
- tail = 1;
- } else {
- tail = 0;
- }
- }
-
- if ( tail==0 && src!="" ) {
- int align = 19 - src.length();
- String blank = "";
- for ( int i=0; i<align; ++i ) {
- blank += " ";
- }
- hex.append( blank + " | " + src );
- }
-
- return hex.toString();
- }
- String text = textArea.getSelectedText();
- if ( text==null || text=="" ) {
- textArea.selectAll();
- text = textArea.getSelectedText();
- textArea.selectNone();
- }
- if ( text != null ) {
- String hex = dump_hex( text );
- newbuf = jEdit.newFile( view );
- newbuf.insert( 0, hex );
- }
復(fù)制代碼 |
|