-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathEnDeGUI.js
4652 lines (4441 loc) · 174 KB
/
EnDeGUI.js
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ========================================================================= //
#?
#? NAME
#? EnDeGUI.js
#?
#? SYNOPSIS
#? <SCRIPT language="JavaScript1.3" type="text/javascript" src="EnDeFile.js"></SCRIPT>
#? <SCRIPT language="JavaScript1.3" type="text/javascript" src="EnDeText.js"></SCRIPT>
#? <SCRIPT language="JavaScript1.5" type="text/javascript" src="EnDeGUI.js"></SCRIPT>
#? <SCRIPT language="JavaScript1.3" type="text/javascript" src="EnDeGUIx.js"></SCRIPT>
#?
#? Note that it should be used with language="JavaScript1.5" because
#? try{..}catch(){..} is used herein.
#?
#? DESCRIPTION
#? This file contains all functions/methods used to build HTML tags from
#? JSON definitions.
#? Some parts are defined in EnDeGUIx.js for better maintenance, but they
#? are part of the EnDeGUI object defined herein.
#?
#? It defines the EnDeGUI class with following functions (incomplete list):
#? .init - genesis rules
#? .alert - general function for alerts
#? .setTitle - set window title
#? .selectionGet - return selection and preserve selection
#? .positionGet - return position of cursor from browser
#? .MP.* - various functions for replace character map
#? .*.dispatch - dispatcher for various GUI functions
#? .win - create new browser window
#? .help - show help window
#? .scratch - show scratchpad window
#? .dau - show alert box with text for stupid usage
#? .stat - show alert box with statistic about text
#? .cont - show code (text, whatever) window
#? .info - show code (text, whatever) window with title
#? .code - return text with line numbers, take care for HTM Entities
#? .guess - create new browser window with given results of en-/decodings as content
#? .data - VIEW dispatcher for various data conversions (Text <--> Hex <--> parsed)
#? .checked - toggle checked value of given object
#? .display - toggle style.display from/to block to/from none
#? .visible - toggle style.visibility from/to visible to/from hidden
#? .dashed - toggle style.borderStyle from inset to dashed and vice versa
#? .show - dispatcher to toggle visibility of some fieldsets
#? .setPriv - set browser privileges
#? .tour - dispatcher for demo tour through EnDe
#? .showMap - show section with various internal constant and variable settings
#? .showSID - show defined SIDs of various files
#? .showIds - check for duplicate tag id attributes
#? .showFiles - show list of loaded files
#? .pathhack - try to get full path from input field of type=file
#? .readlocal - try to read local file
#? .readfile - read file from origin or local file system
#? .quirks - set new URL with specified browser search string
#? .clear - clear GUI fields
#? .preset - preset some options
#? .settrace - set trace variable according given object
#? .spr - write text to status tag; calls trace output if enabled
#? .dpr - write data to textarea (for trace/debug output)
#? .dprint - write data to textarea (for trace/debug output)
#? .dprobject - write object data to textarea (trace/debug)
#?
#? EXAMPLES
#? See EnDeMenu.txt
#?
#? SEE ALSO
#? EnDeGUIx.txt
#? EnDeMenu.txt
#?
# HACKER's INFO
# Cannot use 'class' as name in JSON because Safari complains with errors
# in JavaScript, hence we use 'css'.
#
# *dispatch() functions:
# These functions have 2 parameters obj and src due to historic reasons.
# // ToDo: second parameter is obsolete, but needs to be adapted here.
#
# obj.selectedIndex:
# HTML SELECT menus behave very special when used with size=1 (means that
# only one menuline is visible). In this configuration the last selection
# remains and cannot be selected again. This strange behaviour depends on
# the browser and if the menu is configured with the onClick or onChange
# event. Some browsers trigger the configured event (onClick or onChange)
# even if no selection is made or the the menu is released with the mouse
# pointer outside the menu.
# To avoid special browser hacks and/or using the onMouse* and onButton*
# events to get the expected result, a simple workaround is used instead:
# all SELECT menus set the Element.selectedIndex attribute as follows
# 1. initialization with -1, which forces an empty line
# 2. each selection resets Element.selectedIndex to -1 again
# This seems to inhibit triggering the event when no selection was done
# after selecting the menu itself. It also enables the menu to select the
# same item multiple time.
#
# A onClick=
# A tags inside LI for select menus use the onClick event for calling the
# desired fucnction. That's the default because some browsers behave very
# strange when using 'href="javascript:.."'.
#
# if (foo=='indexOf') { continue; }
# This check inside 'for (key in array)' loops is a contribution to old
# Mozilla 1.x which has this property.
#
# Also defines the EnDeGUI.errors array. If there are errors detected while
# building the GUI, EnDeGUI.init() will show the "Browser Quirks" window.
#?
#? VERSION
#? @(#) EnDeGUI.js 3.122 20/12/17 19:18:29
#?
#? AUTHOR
#? 07-apr-07 Achim Hoffmann, mailto: EnDe (at) my (dash) stp (dot) net
#?
* ========================================================================= */
// ========================================================================= //
// EnDeGUI object methods //
// ========================================================================= //
var EnDeGUI = new function() {
this.SID = '3.122';
this.sid = function() { return('@(#) EnDeGUI.js 3.122 20/12/17 19:18:29 EnDeGUI'); };
function $(id) { return document.getElementById(id); };
// ===================================================================== //
// global EnDeGUI variables //
// ===================================================================== //
this.isOpera = false;
this.isSafari = false;
this.isCamino = false;
this.isiCab = false;
this.isWebKit = false;
this.isMoz17 = false;
this.isFirefox = false;
this.isKonqueror= false;
this.isChrome = false;
this.isIE = false;
this.trace = false;
this.sample = 'http://beef.tld/path;sid=(abc);SSS?foo=bar&b+64=quot"apos\'btick`bspace\\gt>space nl\n\u0010tab\tex!percent%auml\u00e4ouml\u00f6uuml\u00fcszet\u00dfeuro\u20acat@hash#EnDe';
this.colour = true; // colourize formatted code
//this.regex = EnDeRE.sample;
this.onClick = true; // true: use onClick for SELECT tags, false: use onChange
this.a_Click = true; // true: use onClick for LI A tags, false: use href=javascript:
this.onload = true; // ** not yet used **
this.useLabel = false;// true: use label= attribute for OPTION tags
this.useANCHOR = false;// true: use UL>LI>A instead of SELECT>OPTION
this.experimental='hidden'; // 'visible': show experimental features/functions in GUI
this.joke = 'hidden'; // show "non technical" menu entries
this.sbar = 'none'; // show "Status Bar"
this.pimped = false;// true if pimped GUI
this.localpath = ''; // path in local file system used for "load file" functions
this.titles = {dumm:0}; // hash to store all title attributes, defined in EnDe.html
/* dummy key dumm to keep stupid browsers happy with this definition */
this.dir =''; // default directory to search for files
this.usr ='usr/';// directory to search for user files
this.nousr = false;// true: use files from ./usr/ directory
this.grpID = 1; // counter for dynamically generated SELECT OPTGROUP IDs
this.winX = '800';// width of new window
this.winY = '400';// height of new window
this.SIDs = {}; // hash to store all SID vor checkupdate() function
this.errors = []; // array to store GUI errors
/* empty definition, see EnDeGUIx.js
this.Obj = new function() {}
*/
// ===================================================================== //
// misc. methods //
// ===================================================================== //
this.saveeval = eval;
// save built-in eval()
this.eval = function(src) {
//#? wrapper for eval() function; returns given JavaScript source as text
return src;
};
this.alert = function(func,src) {
// this is the internal function used for delivering messages to the user
// ** needs to be adapted to the environment where EnDeGUI object is used **
//return;
alert('**' + func + ':\n' + src);
};
// ===================================================================== //
// debug methods //
// ===================================================================== //
this.settrace = function(obj) {
//#? set trace variable according given object
// obj is a DOM object if called from event handler
// obj might be a atring if called from .init()
var ccc = obj;
if (((typeof(obj)).match(/object/i))!==null) {
ccc = obj.id.replace(/^EnDeDOM.DBX./, '');
}
_spr('EnDeGUI.settrace(' + ccc + ')');
switch (ccc) {
case 'EnDe': EnDe.trace = !EnDe.trace; break;
case 'Trace': EnDeGUI.trace = !EnDeGUI.trace; break;
case 'Obj': EnDeGUI.Obj.trace = !EnDeGUI.Obj.trace; break;
case 'Txt': EnDeGUI.txt.trace = !EnDeGUI.txt.trace; break;
case 'txt': EnDeGUI.txt.trace = !EnDeGUI.txt.trace; break;
case 'Menu': EnDeGUI.Mnu.trace = !EnDeGUI.Mnu.trace; break;
case 'Maps': EnDe.Maps.trace = !EnDe.Maps.trace; break;
case 'File': EnDe.File.trace = !EnDe.File.trace; break;
case 'Form': EnDe.Form.trace = !EnDe.Form.trace; break;
case 'Text': EnDe.Text.trace = !EnDe.Text.trace; break;
case 'User': EnDe.User.trace = !EnDe.User.trace; break;
case 'B64': EnDe.B64.trace = !EnDe.B64.trace; break;
case 'UCS': EnDe.UCS.trace = !EnDe.UCS.trace; break;
case 'IP': EnDe.IP.trace = !EnDe.IP.trace; break;
case 'TS': EnDe.TS.trace = !EnDe.TS.trace; break;
}
return true;
}; // settrace
this.dbxtrace = function() {
//#? set checkbox in trace section
$('EnDeDOM.DBX.EnDe').checked = EnDe.trace;
$('EnDeDOM.DBX.Trace').checked = EnDeGUI.trace;
$('EnDeDOM.DBX.Obj').checked = EnDeGUI.Obj.trace;
$('EnDeDOM.DBX.txt').checked = EnDeGUI.txt.trace;
$('EnDeDOM.DBX.Menu').checked = EnDeGUI.Mnu.trace;
// following objects use a naming standard :)
var ccc = null;
var kkk = new Array( 'Maps', 'B64', 'IP', 'TS', 'UCS', 'FIle', 'Form', 'Text', 'User');
while ((ccc=kkk.shift())!==undefined) {
// ($('EnDeDOM.DBX.XXXXX' )) $('EnDeDOM.DBX.XXXXX' ).checked = EnDe.XXXX.trace;
if ($('EnDeDOM.DBX.' + ccc)) $('EnDeDOM.DBX.' + ccc).checked = EnDe[ccc].trace;
}
}; // dbxtrace
this.dpr = function(src,nl) {
//#? write simple text to trace output; output terminated with \n if nl is undefined
if (EnDeGUI.trace===false) { return false; }
if (nl===undefined) { var nl = '\n'; } // this var confuses lint, but keeps some browsers happy
try { $('EnDeDOM.DBX.text').value += src + nl; } catch(e) {}; // catch not important
return false;
}; // dpr
this.dprint = function(txt,src) {
//#? write verbose text to trace output; given src checked with typeof
function __obj(level,src) {
if ((level<0) || (level>3)) { return '(**level>3 out of range**)'; }
var _c = '';
var _t = '';
var _r = '';
var _x = null;
for (_c=0; _c<=level; _c++) { _t += '\t'; }
//if (src===null) { return 'Null'; }
_r += '(' + typeof src + ')';
switch (typeof src) { // ToDo: some browsers return mixed case :-(
//case 'function': _r += '\t' + ((src.match(/\[\s*native code\s*\]/)===null) ? src : src.replace(/\n/g,'')); break;
case 'function': _r += '\t' + src.toString().replace(/\n/g,''); break;
case 'boolean': _r += '\t' + src; break;
case 'number': _r += '\t' + src; break;
case 'string': _r += '\t' + src; if (src==='') { _r += '(**empty**)'; }; break;
case 'object':
if (src.length!==undefined) {
_r += ' Array (length:' + src.length + ') {'; // dumm }
} else {
_r += ' Object {'; // dumm }
}
for(_c in src) {
_r += '\n' + _t + _c + ':\t';
switch (_c) {
case 'indexOf': _r += '/* Mozilla 1.7? */'; continue; break;
case 'null': _r += '(**null**)'; continue; break;
case 'offsetParent': // avoid huge output (Firefox 3.x special?)
case 'style': // avoid huge output
case 'currentStyle': // avoid huge output (Safari)
case 'labels': // avoid huge output (Safari)
case 'innerHTML': // avoid huge output
case 'outerHTML': // avoid huge output (OmniWeb special)
case 'textContent': // avoid huge output
case 'form': // avoid huge output
_r += '(**skip huge data**)'; continue; break;
case 'all':
case 'childNodes':
case 'ownerElement':
case 'firstElementChild':
case 'lastElementChild':
case 'lastElementSibling': // (Safari only?)
case 'previousElementSibling': // (Opera only?)
case 'parent':
case 'parentElement':
case 'parentNode':
case 'parentWindow':
case 'previousSibling':
case 'nextSibling':
case 'firstChild':
case 'lastChild':
case 'document':
case 'ownerDocument':
case 'window': _r += src[_c] + '(**skipped**)'; break;
default:
try { _x = src[_c]; _r += __obj(level+1,src[_c]); }
catch(e) { _r += '(**no data**)'; } // DOM objects may have "no data" (seen in Firefox 3.x)
break;
}
}
_r += '\n' + _t + '}';
break;
default:
_r += '**unknwon**' + src[_c];
break;
}
return _r;
}
var ccc = '';
try { ccc = arguments.caller; } catch(e) { ccc = '"arguments.caller undefined"'; }
if (EnDeGUI.trace===false) { return false; }
var bux = $('EnDeDOM.DBX.text');
bux.value += '#{ ' + txt; // + '\ncaller: ' + ccc;
bux.value += __obj(0,src);
bux.value += '\n#----------------------------------------------------------------------#}\n';
bux = null;
return false;
}; // dprint
this.objproperties = function(obj) {
//#? return object properties
var bux = '';
for (var i in obj) { bux += i + ':[' + typeof i + ']:' + obj[i] + '\n'; }
return bux;
}; // objproperties
this.dprobject = function(obj) {
//#? write object to trace output
if (EnDeGUI.trace===false) { return false; }
return this.dprint('object', (typeof obj + '\n' + this.objproperties(obj)));
}; // dprobject
this.spr = function(src) {
//#? write text to status tag; calls trace output if enabled
try { $('EnDeDOM.SB.status').innerHTML = src; } catch(e) {}; // catch not important
if (EnDeGUI.trace===true) { EnDeGUI.dpr(src); }
return false;
}; // dpr
this.log = function(src) {
/*
function __log(src) {
//#? write string to console
var failed = 0;
try {
if (Application.console) { // Firefox 3
Application.console.open();
Application.console.log(src);
} else {
alert('Application.console missing');
}
alert(3);
} catch(e) { failed=1; }
if (failed==0) { return; }
alert(2);
try {
Console.log(src);
} catch(e) { failed=1; }
if (failed==0) { return; }
try {
netscape.security.PrivilegeManager.enablePrivilege('UniversalPreferencesRead');
var ccc=Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService); ccc.logStringMessage(src);
//Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService).logStringMessage(src);
//Components.utils.reportInfo(src);
} catch(e) { alert(e); failed=1; }
if (failed==0) { return; }
}; // __log
*/
//#? write string to console
if (Application.console) { // Firefox 3
Application.console.open();
Application.console.log(src);
} else {
//var ccc = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService); ccc.logStringMessage(src);
Components.utils.reportInfo(src);
}
}; // log
// ===================================================================== //
// callback functions in "Replace Map" window //
// ===================================================================== //
this.MP = new function() {
//#? class for functions used in "Replace Map" window
this.sid = function() { return(this.sid() + '.txt'); };
this.charID = 0; // counter for dynamically generated rows
this.newrow = function() {
//#? create a new row with input fields for character replacement
if ($('EnDeDOM.MP.Characters.s')===null) {
EnDeGUI.errors.push('EnDeGUI.MP.newrow: EnDeDOM.MP.Characters.s===null');
return null;
}
this.charID++;
$('EnDeDOM.MP.Characters.s').appendChild(EnDeGUI.Obj.create('EnDeDOM.MP.c'+this.charID,['item4','\char'+this.charID,'','','new: replacement character'],'TABLE','group',false));
return false;
}; // .newrow
this.select = function(src) {
//#? toggle border colour for selected input field
var obj = $('EnDeDOM.MP.selected'); // where object ID is stored
if (obj.value != '') {
$(obj.value).style.borderColor = $(src).style.borderColor; // save original colour
}
$(src).style.borderColor = '#ff0000';
obj.value = src;
}; // .select
this.setChar = function(self,src) {
//#? write given character (src) in specified format (typ) to selected input field
if (isNaN(src)===true) { alert('**invalid format NaN: '+src); return false; }
if (self.selectedIndex!=undefined) { if (self.selectedIndex<0) { return false; } }
var obj = $('EnDeDOM.MP.selected'); // where object ID is stored
if (obj.value==='') { alert('**please select destination field first'); return false; }
$(obj.value).value = this.getFormat($('EnDeDOM.MP.see').value,src);
return false;
}; // MPsetChar
this.getUnicode = function(typ,src) {
//#? returns given value as Unicode
// ToDo: buggy if value does not match given format (in typ)
var bux = src;
switch (typ) {
case 'oct': bux = parseInt(bux.substr(1),8); break;
case 'hex': bux = parseInt(bux.substr(2),16); break;
case 'url': bux = parseInt(bux.substr(1),16); break;
case 'uni': bux = parseInt(bux.substr(2),16); break;
case 'NCE': bux = parseInt(bux.substr(3),16); break;
case 'int': bux = parseInt(bux.substr(2),10); break;
case 'chr': bux = src.charCodeAt(0); break;
}
return bux.toString(10);
//return bux; // fallback
}; // getUnicode
this.getFormat = function(typ,src) {
//#? returns given Unicode in specified (typ) format
switch (typ) {
case 'oct': return '\\' + parseInt(src,10).toString(8); break;
case 'hex': return '\\x' + parseInt(src,10).toString(16); break;
case 'url': return '%' + parseInt(src,10).toString(16); break;
case 'NCE': return '&#x' + parseInt(src,10).toString(16) + ';'; break;
case 'int': return '&#' + parseInt(src,10).toString(10) + ';'; break;
case 'chr': return String.fromCharCode(src); break;
case 'uni':
var bux = parseInt(src,10).toString(16);
while(bux.length<4) { bux = '0' + bux; }
return '\\u' + bux;
break;
}
return src;
}; // getFormat
this.setFormat = function(self,src) {
//#? change all EnDeDOM.MP.new* values to given format
_spr('.MP.setFormat: '+ src);
var bux = this.replace(src, null);
$('EnDeDOM.MP.see').value = src;
return bux;
}; // .setFormat
this.replace= function(typ,src) {
//#? replace old with new character
//#typ? swap: swap new and old characters in "Replace Characters Map"; returns false
//#typ? user: replace old with new characters in given src; returns substituted src
_spr('.MP.replace: '+ typ);
var bux = src;
var id = '';
var ccc = '';
var rep = '';
var old = '';
var arr = document.getElementsByTagName('INPUT');
for (ccc=0; ccc<arr.length; ccc++) {
if (arr[ccc] == undefined) { continue; }
if (arr[ccc].id == undefined) { continue; }
if (arr[ccc].id.match(/^EnDeDOM\.MP\.new/)===null) { continue; }
id = arr[ccc].id;
rep = $(id).value;
//if (rep == '') { continue; }
id = id.replace('new','old'); // get other ID
//#dbx alert(id);
old = $(id).value;
switch (typ) {
case 'swap':
bux = false;
$(id).value = rep;
$(arr[ccc].id).value = old;
break;
case 'user':
old = EnDe.rex(old);
bux = bux.replace(new RegExp('('+old+')','g'),rep);
break;
default:
id = arr[ccc].id;
bux = this.getUnicode($('EnDeDOM.MP.see').value,rep);
if (isNaN(bux)) { continue; }
$(id).value = this.getFormat(typ,bux);
bux = false;
}
}
return bux;
}; // .replace
this.swap = function() { return this.replace('swap','EnDeDOM.MP.e','EnDeDOM.MP.d') };
}; // MP
// ===================================================================== //
// window functions //
// ===================================================================== //
this.setTitle = function() { document.title += ' (' + EnDe.VERSION + ')'; };
this.selectionGet= function(obj) {
//#? get selection from browser
if (window.getSelection) {
if (obj!=null) { // if we got an object, try to select from there
if (obj.selectionStart < obj.selectionEnd) {
var kkk = obj.value.substring(obj.selectionStart,obj.selectionEnd);
obj.setSelectionRange(obj.selectionStart,obj.selectionEnd);
obj.focus();
return kkk;
}
}
}
if (window.getSelection) {
return window.getSelection();
} else if (document.getSelection) {
return document.getSelection();
/* IE users change here, or switch to reliable browsers ;-)
} else if (document.selection) {
var txt = document.selection.craeteRange().text;
var kkk = obj.textbox.createTextRange();
kkk.moveStart("character", iStart);
kkk.moveEnd("character", iLength - obj.textbox.value.length);
kkk.select();
obj.focus();
return txt;
*/
} else { // don't support crappy browsers
return '';
}
return '';
}; // selectionGet
this.positionGet= function(obj) {
//#? get position of cursor from browser
if (window.getSelection) {
if (obj!=null) { // if we got an object, try to select from there
return obj.selectionStart
// } else { // no object, then it's 0 anyway
}
// } else { // don't support crappy browsers
}
return 0;
}; // positionGet
this.win = new function() {
var winscratch = null;
var wincnt = 1;
this.help = function(srcfile,wintitle,wincontent) {
//#? create new browser window using specified URL as content
var win = null;
_dpr('EnDeGUI.win.help(' + srcfile + ', ' + wintitle + ')');
//if (srcfile == '') { srcfile = 'EnDeDumm.html'; }
try {
win = window.open(srcfile, 'help',
'resizable=yes,scrollbars=yes,dependent=yes'
+',status=no,menubar=no,toolbar=no,location=no'
+',innerHeight=' + EnDeGUI.winY
+',innerWidth=' + EnDeGUI.winX
+',width=' + EnDeGUI.winX
+',height=' + EnDeGUI.winY
);
// ToDo: exception in Camino
/* following throws exception in Camino even with above Privilege settings */
// no ToDo: following throws error in IE8
win.document.title = wintitle;
if (wincontent!='') { win.document.body.innerHTML = wincontent; }
// ToDo: use DOM to assign CSS as follows:
/*
* .. but most browsers are too stupid to do that if there is no .html file given as source
var ccc = win.document.createElement('LINK');
ccc.rel = 'stylesheet'
ccc.type = 'text/css';
ccc.href = 'EnDe.css';;
win.document.getElementsByTagName('head')[0].appendChild(ccc);
*/
} catch (e) { EnDeGUI.alert('EnDeGUI.win.help',e); }
return win;
}; // win.help
this.scratch = function() {
//#? create browser window for scratchpad
var win = null;
try {
win = window.open('', 'scratch',
'resizable=yes,scrollbars=yes,dependent=yes'
+',status=no,menubar=no,toolbar=no,location=no'
+',innerHeight=400,innerWidth=800,width=800,height=400'
);
} catch (e) { EnDeGUI.alert('EnDeGUI.win.scratch (window)',e); }
try {
if (EnDeGUI.isKonqueror===true) {
// some browsers behave strange ..
win.document.body.innerHTML = '<textarea rows="28" cols="99" id="scratch"></textarea>';
} else {
var area = document.createElement('TEXTAREA');
area.setAttribute('rows',28);
area.setAttribute('cols',99);
area.id = 'scratch';
win.document.body.appendChild(area);
}
} catch (e) { EnDeGUI.alert('EnDeGUI.win.scratch (Konqueror)',e); }
return win;
}; // win.scratch
}; // win
this.scratch = function(item,txt) {
//#? add text to scratchpad window
var win = null;
if (!this.winscratch) { // create new window first time
win = this.win.scratch();
if (win != null) {
this.winscratch = win;
} else {
EnDeGUI.alert('EnDeGUI.scratch','creating scratchpad failed');
return false;
}
}
if (!this.winscratch.document) { // window does no longer exist
win = this.win.scratch();
if (win != null) {
this.winscratch = win;
} else {
EnDeGUI.alert('EnDeGUI.scratch','adding to scratchpad failed');
return false;
}
}
var area = this.winscratch.document.getElementById('scratch');
if (area) {
area.value += '#{ ------------------------------------------------------------------------------ ' + item + '\n' + txt + '\n#}\n';
area.focus();
this.winscratch.focus();
}
return false;
}; // scratch
this.dau = function(src) {
//#? show alert box with text for stupid usage
var bbb = '-';
var ccc = '-';
switch (src) {
case 'show payloads': bbb = 'show'; ccc = 'from'; break;
case 'create menu': bbb = 'create'; ccc = 'based on'; break;
case 'EnDeDOM.GUI.toDE': bbb = 'create'; ccc = 'based on'; src = 'create Decoding menu'; break;
case 'EnDeDOM.GUI.toEN': bbb = 'create'; ccc = 'based on'; src = 'create Encoding menu'; break;
case 'EnDeDOM.GUI.toRE': bbb = 'create'; ccc = 'based on'; src = 'create RegEx menu'; break;
}
EnDeGUI.alert('WARNING',
'\n\nTo ' + bbb + ' all ' + ccc + ' nothing is a very simple task.'
+'\nBut you have chosen to "' + src + '" ' + ccc + ' nothing, which'
+' confuses me. Should I ' + bbb + ' nothing, or should I ' + bbb + ' all?'
+' If you want to ' + bbb + ' nothing, no button needs to be clicked,'
+' then you will not see anything, even not this messages, which is'
+' nothing then, as requested. Or you want to ' + bbb + ' all ' + ccc
+' nothing' +' which does not contain anything and hence there is no'
+' need to ' + bbb + ' it anyway.\n\n'
+'So, please make your decission first.'
);
}; // .dau
this.stat = function(txt) {
//#? show alert box with statistic about text
var bux = '';
var kkk = null;
bux = '\ncharacters: ' + txt.length;
bux += '\nwords: '; kkk = txt.match(/[ \t]+/g); bux += (kkk===null) ? '1' : kkk.length + 1;
bux += '\nlines: '; kkk = txt.match(/[\n\r]+/g); bux += (kkk===null) ?'(1)': kkk.length + 1;
bux += '\nspaces: '; kkk = txt.match(/ /g); bux += (kkk===null) ? '0' : kkk.length;
bux += '\nnewline: ';kkk = txt.match(/\n/g); bux += (kkk===null) ? '0' : kkk.length;
bux += '\nnone-print: '; kkk = txt.match(/[^\x20-\x7e]/g); bux += (kkk===null) ? '0' : kkk.length;
alert(bux);
if (kkk!==null) { while(kkk.pop()){} }
bux = '';
return false;
}; // stat
this.cont = function(txt) {
//#? create new browser window with given text as content
var win = this.win.help('', 'Plain Text', txt);
win.focus();
return false;
}; // cont
this.info = function(title,txt) {
//#? create new browser window with given title and text as content
_dpr('EnDeGUI.info(' + title + ')');
var win = this.win.help('', title, txt);
win.focus();
return false;
}; // info
this.help = function(type) {
//#? Create new browser window with help text, uses given type as anchor
_spr('EnDeGUI.help: '+type);
var win = null;
/* Note: following does not work with default view as it is "text only".
* Hence EnDe.Man.init() uses location.search.hash to jump to the anchor
* when view is toggled from "text" to "HTML" (with JavaScript).
* As this.help() could be called with a filename as parameter, foo.html
* for example, the passed type parameter used as anchor (like ED below)
* should not contain the string "txt" because EnDe.Man.init() does not
* jump to an anchor if the passed URL fragment matches "txt" (which
* would result in an infinite loop). File names like EnDeRE.man.txt and
* EnDe.TS.html are none existing anchors, both load their own file and
* hence should not jump.
*/
var bux = { // map type to anchor (dirty hack, see EnDe.man.html)
'ABOUT' : 'VERSION',
'CH' : 'DETAILS_Character',
'ED' : 'DETAILS_En__Decoding',
'IP' : 'DETAILS_IP_Converter',
'TS' : 'DETAILS_Timestamp_Converter',
'RE' : 'DETAILS_RegEx',
'DBX' : 'DETAILS_Trace',
'TST' : 'DETAILS_Test',
'VAR' : 'DETAILS_Internal_Settings',
'GUI' : 'GUI_OPTIONS',
'QPT' : 'QUICK_GUI_BAR',
'API' : 'API_OPTIONS',
'MODE' : 'MODE',
'MAP' : 'REPLACE_MAP',
'QQ' : 'BROWSER_QUIRKS'
};
var x = EnDeGUI.winX;
var y = EnDeGUI.winY;
switch (type) {
case 'EnDeRE.man.txt':
EnDeGUI.winX = '1050';
EnDeGUI.winY = '800';
win = this.win.help('EnDe.man.html?EnDeRE.man.txt', 'Help: Regular Expressions', '');
EnDeGUI.winX = x;
EnDeGUI.winY = y;
break;
case 'EnDe.TS.html':
// ToDo: EnDe.TS should be moved to EnDe.man
win = this.win.help('EnDe.TS.html', 'Help: Timestamp Conversions', '');
break;
case 'EnDe.man.txt':
default :
EnDeGUI.winX = '710';
EnDeGUI.winY = '800';
win = this.win.help('EnDe.man.html#'+bux[type], 'Help: '+bux[type], '');
EnDeGUI.winX = x;
EnDeGUI.winY = y;
break;
}
bux = null;
return false;
}; // help
this.code = function(src) {
//#? return text with line numbers, take care for HTM Entities
// generate line numbers
var bux = src;
var ccc = '';
var kkk = bux.match(/\n/g);
if (kkk===null) { // defensive programming, otherwise we may get "no properties"
kkk = 1;
} else {
kkk = kkk.length;
}
for (var i=1; i<=kkk; i++) { ccc += i + '\n'; }
// colourize
if (EnDeGUI.colour===false) { // ToDo: should be a parameter
kkk = EnDe.Text.Entity(bux);
} else {
if (bux[bux.length-1] != '\n') { bux += '\n'; }// add missing newline
kkk = new JsColorizer();
kkk.s = EnDe.Text.Entity0(bux);
bux = kkk.colorize();
bux = bux.replace(/<font\s+/gi, '<font@@@@@'); // escape colourized data
bux = bux.replace(/( |\t)/g, ' ');
bux = bux.replace(/<font@@@@@/gi, '<font '); // de-escape colourized data
kkk = bux.replace(/\n/g,'<br>'); // add line break so we can C&P in the generated window (required for Firefox)
}
// build HTML content
// ToDo: following works only if we get our .css file in the new window
/*
bux = ''
+ '<table class="code">'
+ '<tr>'
+ ' <td>' + ccc + '</td>'
+ ' <td>' + kkk + '</td>'
+ '</tr></table>';
*/
bux = ''
+ '<table cellspacing="0" cellpadding="0" style="font-family:monospace; font-size:12px;width:99%;">'
+ '<tr>'
+ ' <td style="padding-right:.5em;width:3em;text-align:right;vertical-align:top;white-space:pre;">' + ccc + '</td>'
+ ' <td style="padding-left:0.3em;border-left:1px solid #000000;background:#e0e0e0;white-space:pre;">' + kkk + '</td>'
+ '</tr></table>';
ccc = null; kkk = null;
EnDeGUI.cont(bux);
bux = null;
return false;
}; // code
this.guess = function(type,mode,uppercase,src,prefix,suffix,delimiter) {
//#? create new browser window with given results of en-/decodings as content
// type is 'EN\tguess:\ta description' followed by tab seperated list of items
//#type? EN: call encoding functions given in item
//#type? DE: call decoding functions given in item
// the items are the types of en-/decoding functions used for EN.*.dispatch()
_dpr('EnDeGUI.guess(' + type + ')');
var bux ='';
var bbb ='';
var kkk = type.split('@');
var ccc = kkk.shift(); // 1'st one is type
kkk.shift(); // 2'nd one is 'guess:', remove it
var lbl = kkk.shift(); // 3'rd one is button label
var dsc = kkk.shift(); // 4'th one is description
// all others are types to be called
// ToDo: use inline style 'cause generated window dos not include EnDe.css
//_spr('EnDeGUI.guess: '+lbl);
/*
* ToDo: the "show payloads only" buttion is a quick&dirty implementation
* Reasons: it's not simple to write a script function inside the generated
* HTML; it's also difficult to use strings inside the code, hence we use
* String.fromCharCode() to generate strings.
* We also cannot access EnDeGUI.info() as it is not included, hence there
* is a simple alert() only.
*/
// ToDo: rewrite complete code, use DOM objects insted of HTML
bux = '<style type="text/css">'
+ '.labeled { font-family:monospace; font-size:10pt; border-collapse:collapse; }'
+ '.labeled caption { min-width:50em; font-weight:bold; text-align:left; background:#c0c0c0; }'
+ '.labeled tr { background:#ffffff; }'
+ '.labeled tr:hover{ background:#7b8abd; }'
+ '.labeled th { min-width:5em; font-weight:bold; text-align:right; }'
+ '.labeled td { min-width:50em; }'
+ '.labeled td.src { background:#ffffcf; }'
+ '</style>'
+ '<button id="EnDeDOM.guess.gen.do" onclick="tds=document.getElementsByTagName(String.fromCharCode(116,100));b=String.fromCharCode(32);for(k=0;k<tds.length;k++){b+=tds[k].innerHTML+String.fromCharCode(10);};alert(b);">show payloads only</button>'
+ '<table class="labeled" id="EnDeDOM.guess.gen">'
+ '<caption title="' +dsc+ '">#---------- ' + EnDe.EN.ncr('dez','strict',true,lbl,'',';','') + ' ----------#</caption>'
+ '<tr><th>input:</th><td class="src">' + EnDe.EN.ncr('dez','strict',true,src,'',';','') + '</td></tr>'
+ '<tr><th> </th><td><hr></td></tr>'
;
while ((bbb = kkk.shift())!==undefined) { // loop over given items
if (bbb.match(/(md|sha).*raw$/)!==null) { continue; } // ToDo: ignore raw data for now
if (bbb.match(/(_serial|JChar|ASCIIBr|dotBr|DadaUrka)$/)!==null) { continue; } // ToDo: produces alert (7/2009)
// compute human readable text for the label
txt = ["'"+bbb+"'","'"+mode+"'",uppercase,"'"+src+"'","'"+prefix+"'","'"+suffix+"'","'"+delimiter+"'"].join(','); // quote parameters
txt = ['EnDe.', ccc, '.dispatch(', txt, ')'].join('');
// generate table line
bux += '<tr><th title="' + txt + '">' + EnDe.EN.ncr('dez','strict',true,bbb,'',';','') + ':</th><td>';
try {
switch (ccc) {
case 'EN':
bux += EnDe.EN.ncr(
'dez','strict',true,
EnDe.EN.dispatch(bbb,mode,uppercase,src,prefix,suffix,delimiter),
'',';','');
break;
case 'DE':
bux += EnDe.EN.ncr(
'dez','strict',true,
EnDe.DE.dispatch(bbb,mode,uppercase,src,prefix,suffix,delimiter),
'',';','');
break;
}
} catch(e) { EnDeGUI.alert('EnDeGUI.guess('+bbb+')',e); }
bux += '</td></tr>';
}
bux += '<tr><th> </th><td><hr></td></tr>'
if ((type.match(/base64/)!==null) && (type.split('@')[0]==='DE')) {
// base64 guesses (starting at several positions)
// ToDo: implement other Base64 decodings
if (type.split('@')[0]==='DE') {
ccc = 0;
for (ccc=0; ccc<=8; ccc++) {
if (ccc>src.length) { break; }
bux += '<tr><th title="starting at position ' + ccc + '">base64[' + ccc + '..]:</th><td>'
+ EnDe.B64.DE.b64(src.substring(ccc))
+ '</td></tr>';
}
} // DEcoding only
}
if (type.split('@')[2]==='ALL') { // following ugly code but result looks nice ;-)
// UCS BOM checks
var box = '';
bux += '<tr><th>check BOM:</th><td><table border="1">';
kkk = new Array( 'UTF32BE', 'UTF32LE', 'UTF16BE', 'UTF16LE', 'UTF8');
while ((ccc=kkk.shift())!==undefined) {
//if (ccc==='indexOf') { continue; }
bbb = EnDe.UCS.isBOM(ccc,src.substring(0,8));
box = '<tr><th>' + ccc + '</th><td>[' + (bbb===true ? 'x]' : ' ]');
switch (ccc) {
case 'UTF32BE' : bux += box + ' UTF-32 big-endian'; break;
case 'UTF32LE' : bux += box + ' UTF-32 little-endian'; break;
case 'UTF16BE' : bux += box + ' UTF-16 big-endian'; break;
case 'UTF16LE' : bux += box + ' UTF-16 little-endian'; break;
case 'UTF8' : bux += box + ' UTF-8'; break;
default : EnDe.alert('EnDeGUI.DE.guess',"unknown '"+ccc+"'"); break;
}
bux += '</td></tr>';
box = null;
}
bux += '</table>';
// type checks
bux += '<tr><th>check type:</th><td><table border="1">'
+ '<tr><th>isBin:</th><td> [' + (EnDe.isBin(src)===true ? 'x]' : ' ]') + '</td></tr>'
+ '<tr><th>isOct:</th><td> [' + (EnDe.isOct(src)===true ? 'x]' : ' ]') + '</td></tr>'
+ '<tr><th>isInt:</th><td> [' + (EnDe.isInt(src)===true ? 'x]' : ' ]') + '</td></tr>'
+ '<tr><th>isHex:</th><td> [' + (EnDe.isHex(src)===true ? 'x]' : ' ]') + '</td></tr>'
+ '<tr><th>isB64:</th><td> [' + (EnDe.isB64(src)===true ? 'x]' : ' ]') + '</td></tr>'
+ '<tr><th>isU64:</th><td> [' + (EnDe.isU64(src)===true ? 'x]' : ' ]') + '</td></tr>'
+ '</table>'
+ '</td></tr>';
bux += '<tr><th>Checksums:</th><td>' + EnDe.User.Check.guess(src) + '</td></tr>';
} // ALL only
bux += '<tr><th> </th><td><hr></td></tr>'
bux += '</table>';
EnDeGUI.info( 'guess: ' + lbl, bux );
bux = null; bbb = null; ccc = null; kkk = null;
return false;
}; // guess
// ===================================================================== //
// object manipulation methods //
// ===================================================================== //
this.copyValue = function(from, to) {
//#? copy value from from.value to to.value; from and to are tag ids
$(to).value = $(from).value;
};
this.copy = function(txt) {
//#? Create new browser window for copying data between input fields.
/* txt unused .. */
// ToDo: replace hardcode HTML by DOM objects
// NOTE: cannot use $() as we are in another window, probably ...
_spr('EnDeGUI.copy: '+txt);
var win = window.open('', 'Shuffle','resizable=yes,scrollbars=yes,innerHeight=830,innerWidth=430,width=430,height=830,status=no,menubar=no,toolbar=no,location=no,dependent=yes');
win.EnDeGUI = EnDeGUI; // handover functions and object to new window
win.title = 'Shuffle ..'; // ToDo: does not work :-(
// prepare function to get value from created SELECT menu in new window
var bbb = "document.getElementById('EnDeDOM.CP.from').value"; // no $() here!
var ccc = "document.getElementById('EnDeDOM.CP.to').value"; // no $() here!
var k = 0;
var bux = document.createElement('H4');
bux.textContent = 'Copy text .. ** experimental **';
win.document.body.appendChild(bux);
bux = document.createElement('DIV');
bux.textContent = 'Select an object in left and right menu, then use one of the buttons to copy text from one object toanother<br>';
win.document.body.appendChild(bux);
// create buttons in new window which use above value and pass them to EnDeGUI.copyValue()
// Note that EnDeGUI.copyValue() is a function in the calling window !
bux = document.createElement('BUTTON');
bux.style.width = '13em';
bux.setAttribute('onClick', 'EnDeGUI.copyValue(' + ccc + ',' + bbb + ');');
bux.textContent = 'copy to here <';
win.document.body.appendChild(bux);
bux = document.createElement('BUTTON');
bux.style.width = '13em';
bux.setAttribute('onClick', 'EnDeGUI.copyValue(' + bbb + ',' + ccc + ');');
bux.textContent = 'copy to here >';
win.document.body.appendChild(bux);
bbb = null;
ccc = [];
// collect all input and textarea fileds
var kkk = document.getElementsByTagName('input');
for (k=0; k<kkk.length; k++) {
bbb = kkk[k].getAttribute('id');
if ((bbb != null) && (kkk[k].getAttribute('type') == 'text')) {
ccc.push(kkk[k].getAttribute('id').toString());
}
}
kkk = document.getElementsByTagName('textarea');
for (k=0; k<kkk.length; k++) {
bbb = kkk[k].getAttribute('id');
if (bbb != null) {
ccc.push(kkk[k].getAttribute('id').toString());
}
}
ccc = ccc.sort();
//#dbx for (k=0; k<ccc.length; k++) { bux += ccc[k] + '<br>'; }
// create 2 SELECT menus
var select = null;
var group = null;
var option = null;
var last = '--';