Skip to content

Commit 9473f77

Browse files
authored
Remove NC code (#3824)
1 parent ef352bd commit 9473f77

File tree

2 files changed

+0
-207
lines changed

2 files changed

+0
-207
lines changed

scapy/volatile.py

-113
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from scapy.base_classes import Net
2323
from scapy.compat import bytes_encode, chb, plain_str
2424
from scapy.utils import corrupt_bits, corrupt_bytes
25-
from scapy.libs.six.moves import zip_longest
2625

2726
from scapy.compat import (
2827
List,
@@ -1412,115 +1411,3 @@ class CorruptedBits(CorruptedBytes):
14121411
def _fix(self):
14131412
# type: () -> bytes
14141413
return corrupt_bits(self.s, self.p, self.n)
1415-
1416-
1417-
class CyclicPattern(VolatileValue[bytes]):
1418-
"""
1419-
Generate a cyclic pattern
1420-
1421-
:param size: Size of generated pattern. Default is random size.
1422-
:param start: Start offset of the generated pattern.
1423-
:param charset_type: Charset types:
1424-
0: basic (0-9A-Za-z)
1425-
1: extended
1426-
2: maximum (almost printable chars)
1427-
1428-
1429-
The code of this class was inspired by
1430-
1431-
PEDA - Python Exploit Development Assistance for GDB
1432-
Copyright (C) 2012 Long Le Dinh <longld at vnsecurity.net>
1433-
License: This work is licensed under a Creative Commons
1434-
Attribution-NonCommercial-ShareAlike 3.0 Unported License.
1435-
"""
1436-
1437-
@staticmethod
1438-
def cyclic_pattern_charset(charset_type=None):
1439-
# type: (Optional[int]) -> str
1440-
"""
1441-
:param charset_type: charset type
1442-
0: basic (0-9A-Za-z)
1443-
1: extended (default)
1444-
2: maximum (almost printable chars)
1445-
:return: list of charset
1446-
"""
1447-
1448-
charset = \
1449-
[string.ascii_uppercase, string.ascii_lowercase, string.digits]
1450-
1451-
if charset_type == 1: # extended type
1452-
charset[1] = "%$-;" + re.sub("[sn]", "", charset[1])
1453-
charset[2] = "sn()" + charset[2]
1454-
1455-
if charset_type == 2: # maximum type
1456-
charset += [string.punctuation]
1457-
1458-
return "".join(
1459-
["".join(k) for k in zip_longest(*charset, fillvalue="")])
1460-
1461-
@staticmethod
1462-
def de_bruijn(charset, n, maxlen):
1463-
# type: (str, int, int) -> str
1464-
"""
1465-
Generate the De Bruijn Sequence up to `maxlen` characters
1466-
for the charset `charset` and subsequences of length `n`.
1467-
Algorithm modified from wikipedia
1468-
https://en.wikipedia.org/wiki/De_Bruijn_sequence
1469-
"""
1470-
k = len(charset)
1471-
a = [0] * k * n
1472-
sequence = [] # type: List[str]
1473-
1474-
def db(t, p):
1475-
# type: (int, int) -> None
1476-
if len(sequence) == maxlen:
1477-
return
1478-
1479-
if t > n:
1480-
if n % p == 0:
1481-
for j in range(1, p + 1):
1482-
sequence.append(charset[a[j]])
1483-
if len(sequence) == maxlen:
1484-
return
1485-
else:
1486-
a[t] = a[t - p]
1487-
db(t + 1, p)
1488-
for j in range(a[t - p] + 1, k):
1489-
a[t] = j
1490-
db(t + 1, t)
1491-
1492-
db(1, 1)
1493-
return ''.join(sequence)
1494-
1495-
def __init__(self, size=None, start=0, charset_type=None):
1496-
# type: (Optional[int], int, Optional[int]) -> None
1497-
self.size = size if size is not None else RandNumExpo(0.01)
1498-
self.start = start
1499-
self.charset_type = charset_type
1500-
1501-
def _command_args(self):
1502-
# type: () -> str
1503-
ret = ""
1504-
if isinstance(self.size, VolatileValue):
1505-
if self.size.lambd != 0.01 or self.size.base != 0:
1506-
ret += "size=%r" % self.size.command()
1507-
else:
1508-
ret += "size=%r" % self.size
1509-
1510-
if self.start != 0:
1511-
ret += ", start=%r" % self.start
1512-
1513-
if self.charset_type:
1514-
ret += ", charset_type=%r" % self.charset_type
1515-
1516-
return ret
1517-
1518-
def _fix(self):
1519-
# type: () -> bytes
1520-
if isinstance(self.size, VolatileValue):
1521-
size = self.size._fix()
1522-
else:
1523-
size = self.size
1524-
charset = self.cyclic_pattern_charset(self.charset_type or 0)
1525-
pattern = self.de_bruijn(charset, 3, size + self.start)
1526-
return pattern[self.start:size + self.start].encode('utf-8')

test/random.uts

-94
Original file line numberDiff line numberDiff line change
@@ -134,97 +134,3 @@ assert de.command() == "DelayedEval(expr='3 + 1')"
134134
v = IncrementalValue(restart=2)
135135
assert v == 0 and v == 1 and v == 2 and v == 0
136136
assert v.command() == "IncrementalValue(restart=2)"
137-
138-
= CyclicPattern charset 0
139-
140-
cs0 = b'AAAaAA0AABAAbAA1AACAAcAA2AADAAdAA3AAEAAeAA4AAFAAfAA5AAGAAgAA6AAHAAhAA7AAIAAiAA8AAJAAjAA9AAKAAkAALAAlAAMAAmAANAAnAAOAAoAAPAApAAQAAqAARAArAASAAsAATAAtAAUAAuAAVAAvAAWAAwAAXAAxAAYAAyAAZAAzAaaAa0AaBAabAa1AaCAacAa2AaDAadAa3AaEAaeAa4AaFAafAa5AaGAagAa6AaHAahAa7AaIAaiAa8AaJ'
141-
142-
p = Raw(load=CyclicPattern())
143-
b = bytes(p)
144-
if len(b):
145-
if len(b) > len(cs0):
146-
assert cs0 in b
147-
else:
148-
assert b in cs0 or b == cs0
149-
150-
p = Raw(load=CyclicPattern(5))
151-
b = bytes(p)
152-
assert len(b) == 5
153-
assert b == b'AAAaA'
154-
155-
p = Raw(load=CyclicPattern(2, 3))
156-
b = bytes(p)
157-
print(b)
158-
assert len(b) == 2
159-
assert b == b'aA'
160-
161-
= CyclicPattern charset 1
162-
163-
cs1 = b'AAA%AAsAABAA$AAnAACAA-AA(AADAA;AA)AAEAAaAA0AAFAAbAA1AAGAAcAA2AAHAAdAA3AAIAAeAA4AAJAAfAA5AAKAAgAA6AALAAhAA7AAMAAiAA8AANAAjAA9AAOAAkAAPAAlAAQAAmAARAAoAASAApAATAAqAAUAArAAVAAtAAWAAuAAXAAvAAYAAwAAZAAxAAyAAzA%%A%sA%BA%$A%nA%CA%-A%(A%DA%;A%)A%EA%aA%0A%FA%bA%1A%GA%'
164-
165-
p = Raw(load=CyclicPattern(None, 0, 1))
166-
b = bytes(p)
167-
if len(b):
168-
if len(b) > len(cs1):
169-
assert cs1 in b
170-
else:
171-
assert b in cs1 or b == cs1
172-
173-
p = Raw(load=CyclicPattern(10, 0, 1))
174-
b = bytes(p)
175-
assert len(b) == 10
176-
assert b == b'AAA%AAsAAB'
177-
178-
p = Raw(load=CyclicPattern(2, 8, 1))
179-
b = bytes(p)
180-
print(b)
181-
assert len(b) == 2
182-
assert b == b'AB'
183-
184-
= CyclicPattern charset 2
185-
186-
cs2 = b'AAAaAA0AA!AABAAbAA1AA"AACAAcAA2AA#AADAAdAA3AA$AAEAAeAA4AA%AAFAAfAA5AA&AAGAAgAA6AA\'AAHAAhAA7AA(AAIAAiAA8AA)AAJAAjAA9AA*AAKAAkAA+AALAAlAA,AAMAAmAA-AANAAnAA.AAOAAoAA/AAPAApAA:AAQAAqAA;AARAArAA<AASAAsAA=AATAAtAA>AAUAAuAA?AAVAAvAA@AAWAAwAA[AAXAAxAA\\AAYAAyAA]AAZAAzAA^AA_AA`AA{AA|AA}AA~AaaAa0Aa!AaBAabAa1Aa"Aa'
187-
188-
p = Raw(load=CyclicPattern(None, 0, 2))
189-
b = bytes(p)
190-
if len(b):
191-
if len(b) > len(cs2):
192-
assert cs2 in b
193-
else:
194-
assert b in cs2 or b == cs2
195-
196-
p = Raw(load=CyclicPattern(10, 0, 2))
197-
b = bytes(p)
198-
assert len(b) == 10
199-
assert b == b'AAAaAA0AA!'
200-
201-
p = Raw(load=CyclicPattern(2, 8, 2))
202-
b = bytes(p)
203-
print(b)
204-
assert len(b) == 2
205-
assert b == b'A!'
206-
207-
= CyclicPattern command
208-
209-
p = Raw(load=CyclicPattern(2, 8, 2))
210-
cmd = p.command()
211-
212-
assert "charset_type=2" in cmd
213-
assert "start=8" in cmd
214-
assert "size=2" in cmd
215-
216-
p = Raw(load=CyclicPattern(2))
217-
cmd = p.command()
218-
219-
assert "charset_type" not in cmd
220-
assert "start" not in cmd
221-
assert "size=2" in cmd
222-
223-
p = Raw(load=CyclicPattern())
224-
cmd = p.command()
225-
226-
assert "charset_type" not in cmd
227-
assert "start" not in cmd
228-
assert "size" not in cmd
229-
230-

0 commit comments

Comments
 (0)