-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dump_Hex.bsh
78 lines (69 loc) · 1.64 KB
/
Dump_Hex.bsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
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 );
}
*/
void dump_hex() {
String text = textArea.getSelectedText();
if ( text==null || text=="" ) {
textArea.selectAll();
text = textArea.getSelectedText();
textArea.selectNone();
}
if ( text!=null && text!="" ) {
Registers.setRegister( '$', text );
runCommandToBuffer( view, "System", "pbpaste | xxd -u -g1 -c24" );
}
}
dump_hex();