-
Notifications
You must be signed in to change notification settings - Fork 4
/
common.py
executable file
·966 lines (739 loc) · 24.5 KB
/
common.py
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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import sys
import types
import traceback
def split_ns(text):
"""
Splits an ElementTree style namespace out
input: {namespace}element
output: (namespace, element)
input: element
output: (None, element)
"""
if text.startswith("{"):
return text[1:].split("}", 1)
else:
return None, text
class Holder(object):
"""
Holds static stuff
"""
globals = None
locals = None
class SoftException(Exception):
"""
Soft exceptions should end the current test iteration, but not the run.
They are "recoverable" or "try again" errors.
"""
pass
class HardException(Exception):
"""
Hard exceptions are non-recoverable and should end the fuzzing run.
"""
pass
class RedoTestException(SoftException):
"""
Indicate we should re-run the current test. A recoverable error occurred.
The main engine loop should only retry the test case 3 times before turning this into a hard exception.
"""
pass
class PeachException(HardException):
"""
Peach exceptions are specialized hard exceptions.
The message contained in a PeachException is presentable to the user w/o any stack trace, etc.
Examples would be:
"Error: The DataModel element requires a name attribute."
"""
def __init__(self, msg, module="Unknown"):
Exception.__init__(self, msg)
self.module = module
self.msg = msg
def peachEval(code, environment=False):
"""
Eval using the Peach namespace stuffs.
"""
return eval(code, Holder.globals, Holder.locals)
def GetClassesInModule(module):
"""
Return array of class names in module.
"""
classes = []
for item in dir(module):
i = getattr(module, item)
if type(i) == types.ClassType and item[0] != '_':
classes.append(item)
elif type(i) == types.MethodType and item[0] != '_':
classes.append(item)
elif type(i) == types.FunctionType and item[0] != '_':
classes.append(item)
return classes
def buildImports(node, g, l):
root = node.getRoot()
for child in root:
if child.elementType == 'import':
# Import module
importStr = child.importStr
fromStr = child.fromStr
if fromStr is not None:
if importStr == "*":
module = __import__(fromStr, globals(), locals(), [importStr], -1)
try:
# If we are a module with other modules in us then we have an __all__
for item in module.__all__:
g[item] = getattr(module, item)
except:
# Else we just have some classes in us with no __all__
for item in GetClassesInModule(module):
g[item] = getattr(module, item)
else:
module = __import__(fromStr, globals(), locals(), [importStr], -1)
for item in importStr.split(','):
item = item.strip()
g[item] = getattr(module, item)
else:
g[importStr] = __import__(importStr, globals(), locals(), [], -1)
def peachPrint(msg):
print("Print: %s", msg)
return True
def domPrint(node):
from Peach.Engine.dom import DomPrint
print("vv[ DomPrint ]vvvvvvvvvvvvvvvv\n%s\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" % DomPrint(0, node))
return True
def changeDefaultEndian(endian):
if endian not in ['little', 'big']:
raise PeachException("Called ChangeEndian with invalid paramter [%s]" % endian)
from Peach.Engine.dom import Number
Number.defaultEndian = endian
return True
def evalEvent(code, environment, node=None):
"""
Eval python code returning result.
code - String
environment - Dictionary, keys are variables to place in local scope
"""
globalScope = {
'Print': peachPrint,
'peachPrint': peachPrint,
'ChangeDefaultEndian': changeDefaultEndian,
'DomPrint': domPrint,
}
localScope = {
'Print': peachPrint,
'peachPrint': peachPrint,
'ChangeDefaultEndian': changeDefaultEndian,
'DomPrint': domPrint,
}
if node is not None:
buildImports(node, globalScope, localScope)
if Holder.globals is not None:
for k in Holder.globals:
globalScope[k] = Holder.globals[k]
if Holder.locals is not None:
for k in Holder.locals:
localScope[k] = Holder.locals[k]
for k in environment.keys():
globalScope[k] = environment[k]
localScope[k] = environment[k]
try:
ret = eval(code, globalScope, localScope)
except:
print("Code: [%s]" % code)
print("Exception: %s" % sys.exc_info()[1])
print("Environment:")
for k in environment.keys():
print(" [%s] = [%s]" % (k, repr(environment[k])))
raise
return ret
class _Getch(object):
"""Gets a single character from standard input. Does not echo to the screen."""
def __init__(self):
try:
self.impl = _GetchWindows()
except ImportError:
self.impl = _GetchUnix()
def __call__(self): return self.impl()
class _GetchUnix(object):
def __call__(self):
import tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
class _GetchWindows(object):
def __call__(self):
import msvcrt
return msvcrt.getch()
getch = _Getch()
class StreamBuffer(object):
"""
A Peach data stream. Used when generating or cracking data.
"""
def __init__(self, data=None):
#: Current position
self.pos = 0
#: Data buffer
self.data = ""
#: History of data locations
self.positions = {}
#: History of data length
self.lengths = {}
if data is not None:
self.data = data
def getValue(self):
"""
Return the value created by this stream.
"""
return self.data
def setValue(self, data):
"""
Set the internal buffer.
"""
self.data = data
def peek(self, size=None):
"""
Read data with out changing position.
"""
if size is None:
return self.data[self.pos:]
if self.pos + size > len(self.data):
raise Exception("StreamBuffer.peek(%d): Peeking passed end of buffer." % size)
return self.data[self.pos:self.pos + size]
def read(self, size=None):
"""
Read from current position. If size
isn't specified, read rest of stream.
Read will shift the current position.
"""
if size is None:
ret = self.data[self.pos:]
self.pos = len(self.data)
return ret
if self.pos + size > len(self.data):
raise Exception("StreamBuffer.read(%d): Reading passed end of buffer." % size)
ret = self.data[self.pos:self.pos + size]
self.pos += size
return ret
def storePosition(self, name):
"""
Store our position by name
"""
#print "Storing position of %s at %d" % (name, self.pos)
self.positions[name] = self.pos
return self.pos
def getPosition(self, name):
"""
Retreave position by name
"""
if name not in self.positions:
return None
return self.positions[name]
def write(self, data, name=None):
"""
Write a block of data at current position.
Stream will expand if needed to support the
written data. Otherwise it will overright
the existing data.
@type data: string
@param data: Data to write
@type name: string
@param name: Name to store position under [optional]
"""
if name is not None:
#print "write: %s: %s" % (name, repr(data))
self.storePosition(name)
self.lengths[name] = len(data)
dataLen = len(data)
ourDataLen = len(self.data)
# Replace existing data
if ourDataLen - self.pos > dataLen:
ret = self.data[:self.pos]
ret += data
ret += self.data[self.pos + dataLen:]
self.data = ret
# Append new data
elif self.pos == ourDataLen:
self.data += data
# Do both
else:
self.data = self.data[:self.pos] + data
# Move position
self.pos += dataLen
def count(self):
"""
Get the current size in bytes of the data stream.
"""
return len(self.data)
def tell(self):
"""
Return the current position in the data stream.
"""
return self.pos
def seekFromCurrent(self, pos):
"""
Change current position in data.
NOTE: If the position is past the end of the
existing stream data the data will be expanded
such that the position exists padded with '\0'
"""
newpos = self.pos + pos
self.seekFromStart(newpos)
def seekFromStart(self, pos):
"""
Change current position in data.
NOTE: If the position is past the end of the
existing stream data the data will be expanded
such that the position exists padded with '\0'
"""
if pos < 0:
raise Exception("StreamBuffer.seekFromStart(%d) results in negative position" % pos)
# Should we expand buffer?
if pos > len(self.data):
self.data += '\0' * (pos - len(self.data))
self.pos = pos
def seekFromEnd(self, pos):
"""
Change current position in data.
NOTE: If the position is past the end of the
existing stream data the data will be expanded
such that the position exists padded with '\0'
"""
newpos = len(self.data) + pos
self.seekFromStart(newpos)
import weakref
class PeachEvent(object):
"""
A .NET like Event system. Uses weak references
to avoid memory issues.
"""
def __init__(self):
self.handlers = set()
def _objectFinalized(self, obj):
"""
Called when an object we have a weak reference
to is being garbage collected.
"""
self.handlers.remove(obj)
def handle(self, handler):
"""
Add a handler to our event
"""
self.handlers.add(weakref.ref(handler, self._objectFinalized))
return self
def unhandle(self, handler):
"""
Remove a handler from our event
"""
try:
for ref in self.handlers:
if ref() == handler:
self.handlers.remove(ref)
except:
raise ValueError("Handler is not handling this event, so cannot unhandle it.")
return self
def fire(self, *args, **kargs):
"""
Trigger event and call our handlers
"""
for handler in self.handlers:
handler()(*args, **kargs)
def getHandlerCount(self):
"""
Count of handlers registered for this event
"""
return len(self.handlers)
__iadd__ = handle
__isub__ = unhandle
__call__ = fire
__len__ = getHandlerCount
#class MockFileWatcher:
# def __init__(self):
# self.fileChanged = Event()
#
# def watchFiles(self):
# source_path = "foo"
# self.fileChanged(source_path)
#
#def log_file_change(source_path):
# print "%r changed." % (source_path,)
#
#def log_file_change2(source_path):
# print "%r changed!" % (source_path,)
#
#watcher = MockFileWatcher()
#watcher.fileChanged += log_file_change2
#watcher.fileChanged += log_file_change
#watcher.fileChanged -= log_file_change2
#watcher.watchFiles()
class ArraySetParent(object):
"""
Special array type that will
set the parent on all children.
"""
def __init__(self, parent):
if parent is None:
raise Exception("Whoa, parent == None!")
self._parent = parent
self._array = []
def append(self, obj):
#if hasattr(obj, "of"):
# if obj.of == "Tables":
# print "SETTING TABLES PARENT TO:", self._parent
# print obj
# traceback.print_stack();
obj.parent = self._parent
return self._array.append(obj)
def index(self, obj):
return self._array.index(obj)
def insert(self, index, obj):
obj.parent = self._parent
return self._array.insert(index, obj)
def remove(self, obj):
return self._array.remove(obj)
def __len__(self):
return self._array.__len__()
def __getitem__(self, key):
return self._array.__getitem__(key)
def __setitem__(self, key, value):
value.parent = self._parent
return self._array.__setitem__(key, value)
def __delitem__(self, key):
return self._array.__delitem__(key)
def __iter__(self):
return self._array.__iter__()
def __contains__(self, item):
return self._array.__contains__(item)
class BitBuffer(object):
"""
Access buffer as bit stream. Support the normal reading from left to right
of bits as well as the reverse right to left.
"""
def __init__(self, buf='', bigEndian=False):
self.buf = [ord(x) for x in buf]
self.pos = 0
self.len = len(buf) * 8
self.closed = False
self.softspace = 0
self.bigEndian = bigEndian
def close(self):
"""Let me think... Closes and flushes the toilet!"""
if not self.closed:
self.closed = True
del self.buf, self.pos, self.len, self.softspace
def isatty(self):
if self.closed:
raise ValueError("I/O operation on closed file")
return 0
def seek(self, pos, mode=0):
"""Set new position"""
if self.closed:
raise ValueError("I/O operation on closed file")
if mode == 1:
pos += self.pos
elif mode == 2:
pos += self.len
self.pos = max(0, pos)
def tell(self):
"""Tell current position"""
if self.closed:
raise ValueError("I/O operation on closed file")
return self.pos
def flush(self):
"""Flush the toilet"""
if self.closed:
raise ValueError("I/O operation on closed file")
def truncate(self, size=None):
if self.closed:
raise ValueError("I/O operation on closed file")
if size is None:
size = self.pos
elif size < 0:
raise IOError(EINVAL, "Negative size not allowed")
elif size < self.pos:
self.pos = size
self.len = size
self.buf = self.buf[:(size // 8) + (size % 8 != 0)]
if self.buf: self.buf[-1] &= (1 << (size % 8)) - 1
def writebits(self, n, bitlen):
"""Writes bits"""
if self.closed:
raise ValueError("I/O operation on closed file")
n &= (1 << bitlen) - 1
newpos = self.pos + bitlen
startBPos = self.pos % 8
startBlock = self.pos // 8
endBPos = newpos % 8
endBlock = newpos // 8 + (endBPos != 0)
#print startBlock, startBPos, endBlock, endBPos
while len(self.buf) < endBlock: self.buf += [0]
pos = startBPos
if not self.bigEndian:
while bitlen > 0:
bitsLeft = 8 - (pos % 8)
if bitsLeft > bitlen: bitsLeft = bitlen
mask = (1 << bitsLeft) - 1
self.buf[startBlock + (pos // 8)] ^= self.buf[startBlock + (pos // 8)] & (mask << (pos % 8))
self.buf[startBlock + (pos // 8)] |= int(n & mask) << (pos % 8)
n >>= bitsLeft
bitlen -= bitsLeft
pos += bitsLeft
self.pos = newpos
if self.pos > self.len:
self.len = self.pos
else:
while bitlen > 0:
bitsLeft = 8 - (pos % 8)
if bitsLeft > bitlen: bitsLeft = bitlen
mask = (1 << bitsLeft) - 1
shift = (8 - self.bitlen(self.binaryFormatter(mask, 8))) - (pos - (pos / 8 * 8))
byte = n >> bitlen - self.bitlen(self.binaryFormatter(mask, 8))
self.buf[startBlock + (pos // 8)] |= ((byte & mask) << shift)
bitlen -= bitsLeft
pos += bitsLeft
self.pos = newpos
if self.pos > self.len:
self.len = self.pos
def binaryFormatter(self, num, bits):
"""
Create a string in binary notation
"""
ret = ""
for i in range(bits - 1, -1, -1):
ret += str((num >> i) & 1)
assert len(ret) == bits
return ret
def bitlen(self, s):
return len(s) - s.find('1')
def readbits(self, bitlen):
"""
Reads bits based on endianness
"""
if self.closed:
raise ValueError("I/O operation on closed file")
newpos = self.pos + bitlen
orig_bitlen = bitlen
startBPos = self.pos % 8
startBlock = self.pos // 8
endBPos = newpos % 8
endBlock = newpos // 8 + (endBPos != 0)
ret = 0
pos = startBPos
while bitlen > 0:
bitsLeft = 8 - (pos % 8)
bitsToLeft = pos - (pos / 8 * 8)
if bitsLeft > bitlen:
bitsLeft = bitlen
mask = (1 << bitsLeft) - 1
byte = self.buf[startBlock + (pos // 8)]
if not self.bigEndian:
# Reverse all bits
newByte = 0
for _ in range(8):
bit = byte & 0x01
byte >>= 1
newByte <<= 1
newByte |= bit
byte = newByte
byte >>= (8 - bitsLeft) - bitsToLeft
shift = self.bitlen(self.binaryFormatter(mask, 8))
ret <<= shift
ret |= byte & mask
shift += bitsLeft
bitlen -= bitsLeft
pos += bitsLeft
# Reverse requested bits
if not self.bigEndian:
newByte = 0
for _ in range(orig_bitlen):
bit = ret & 0x01
ret >>= 1
newByte <<= 1
newByte |= bit
ret = newByte
self.pos = newpos
return ret
def getvalue(self):
"""Get the buffer"""
return ''.join(map(chr, self.buf))
def write(self, s):
for c in str(s):
self.writebits(ord(c), 8)
def writelines(self, list):
self.write(''.join(list))
def read(self, i):
ret = []
for i in range(i):
ret.append(chr(self.readbits(8)))
return ''.join(ret)
def writebit(self, b):
"""Writes Bit (1bit)"""
self.writebits(b, 1)
def readbit(self):
"""Reads Bit (1bit)"""
return self.readbits(1)
def writebyte(self, i):
"""Writes Byte (8bits)"""
self.writebits(i, 8)
def readbyte(self):
"""Reads Byte (8bits)"""
return self.readbits(8)
def writeword(self, i):
"""Writes Word (16bits)"""
self.writebits(i, 16)
def readword(self):
"""Reads Word (16bits)"""
return self.readbits(16)
def writedword(self, i):
"""Writes DWord (32bits)"""
self.writebits(i, 32)
def readdword(self):
"""Reads DWord (32bits)"""
return self.readbits(32)
def writevbl(self, n):
"""Writes Variable bit length."""
self.writebit(n < 0)
n = abs(n)
self.writebits(n, 6)
n >>= 6
while n:
self.writebit(1)
self.writebits(n, 8)
n >>= 8
self.writebit(0)
def readvbl(self):
"""Reads Variable bit length."""
isNeg = self.readbit()
r = self.readbits(6)
pos = 6
while self.readbit():
r |= self.readbits(8) << pos
pos += 8
if isNeg:
r = -r
return r
import threading
class DomBackgroundCopier(object):
"""
This class spins up a thread that makes
copies of Data Models. This should
allow us to take advantage of multi-core
CPUs and increase fuzzing speed.
"""
copyThread = None
stop = None
def __init__(self):
self.doms = []
self.copies = {}
self.minCopies = 1
self.maxCopies = 10
self.copiesLock = threading.Lock()
DomBackgroundCopier.needcopies = threading.Event()
DomBackgroundCopier.copyThread = None
DomBackgroundCopier.stop = threading.Event()
self.singleThread = True
if os.getenv("PEACH_SINGLETHREAD") is None:
self.singleThread = False
DomBackgroundCopier.copyThread = threading.Thread(target=self.copier)
self.copyThread.start()
def copier(self):
while not self.stop.isSet():
for dom in self.doms:
self.copiesLock.acquire()
if len(self.copies[dom]) < self.minCopies:
self.copiesLock.release()
domCopy = dom.copy(None)
self.copiesLock.acquire()
self.copies[dom].append(domCopy)
self.copiesLock.release()
else:
self.copiesLock.release()
for dom in self.doms:
self.copiesLock.acquire()
if len(self.copies[dom]) < self.maxCopies:
#print "DOM[%s]: %d copies < %d" % (dom, len(self.copies[dom]), self.maxCopies)
self.copiesLock.release()
domCopy = dom.copy(None)
self.copiesLock.acquire()
self.copies[dom].append(domCopy)
self.copiesLock.release()
else:
self.copiesLock.release()
DomBackgroundCopier.needcopies.wait()
DomBackgroundCopier.needcopies.clear()
def addDom(self, dom):
if dom in self.doms:
return
self.copiesLock.acquire()
try:
self.doms.append(dom)
self.copies[dom] = []
finally:
self.copiesLock.release()
DomBackgroundCopier.needcopies.set()
def getCopy(self, dom):
# If using a single thread just return a copy
if self.singleThread:
return dom.copy(None)
if not dom in self.doms:
return None
if len(self.copies[dom]) == 0:
return None
if len(self.copies[dom]) < (self.maxCopies / 2):
DomBackgroundCopier.needcopies.set()
self.copiesLock.acquire()
try:
c = self.copies[dom][0]
self.copies[dom] = self.copies[dom][1:]
return c
finally:
self.copiesLock.release()
def removeDom(self, dom):
if not dom in self.doms:
return
self.copiesLock.acquire()
try:
self.doms.remove(dom)
del self.copies[dom]
finally:
self.copiesLock.release()
class Highlight(object):
HEADER = '\033[95m'
INFO = '\033[36m'
OK = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
REPR = '\033[35m'
BLOCK = '\033[30;47m'
NOTE = '\033[1;37m'
ENDC = '\033[0m'
def __init__(self):
if os.sys.platform == "win32":
self.disable()
def error(self, msg):
return "%s%s%s" % (self.FAIL, msg, self.ENDC)
def ok(self, msg):
return "%s%s%s" % (self.OK, msg, self.ENDC)
def warning(self, msg):
return "%s%s%s" % (self.WARNING, msg, self.ENDC)
def repr(self, msg):
return "%s%s%s" % (self.REPR, msg, self.ENDC)
def block(self, msg):
return "%s%s%s" % (self.BLOCK, msg, self.ENDC)
def info(self, msg):
return "%s%s%s" % (self.INFO, msg, self.ENDC)
def note(self, msg):
return "%s%s%s" % (self.NOTE, msg, self.ENDC)
def disable(self):
self.HEADER = ''
self.INFO = ''
self.GREEN = ''
self.WARNING = ''
self.FAIL = ''
self.ENDC = ''
highlight = Highlight()