Skip to content

Commit

Permalink
consistent name N for input length, update example
Browse files Browse the repository at this point in the history
  • Loading branch information
huettenhain committed Feb 13, 2020
1 parent b05dd51 commit a8d8a8e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ emit MIL0001781108.xls \
| sep \
] \
| pack 10 \
| sub dec:ev:n \
| blockop --dec -sN B-S \
]] \
| dump payload.ps1
```
Expand Down
6 changes: 3 additions & 3 deletions refinery/lib/argformats.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ class DelayedNumbinArgument(DelayedArgument):
defined here.
"""

_EV_PARSER = PythonExpression('n')
_EV_PARSER = PythonExpression('N')

def _mbin(self, expr: str) -> bytes:
binary = multibin(expr)
Expand Down Expand Up @@ -669,14 +669,14 @@ def handler(self, expression: str) -> Iterable[int]:
def ev(self, expression: str) -> Iterable[int]:
"""
Final modifier `ev:expression`; uses a `refinery.lib.argformats.PythonExpression`
parser to process expressions that may contain the variable `n` whose value will be
parser to process expressions that may contain the variable `N` whose value will be
the size of the input data.
"""
ev = self._EV_PARSER(expression)
try:
return self._iter(ev())
except Exception:
return lambda d: self._iter(ev(n=len(d)))
return lambda d: self._iter(ev(N=len(d)))

@handler.register('unpack', final=True)
def unpack(self, expression: str) -> Iterable[int]:
Expand Down
2 changes: 1 addition & 1 deletion test/lib/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_documentation_example_04(self):
def test_real_world_01(self):
encoded = B'''301815214850156721331018480063340936214488055910529404970112631124608113197561534315323106291311611118111571030916590053421252410301171850583912575068111856414554157930507606789054031912510227182600807906431133491248306004123002146510940169690710820141169320955312014120171102115059068660995810412198261688106236171480925510919175470806111215112451580216678065680593716920140350943309471097820618705622181381760512207200740695112292051860572813684059730540612867133770664415988405914129061377506879064041396607792051271161313019124720712811569074680757406931112780654609788055291148605702141810628505815128490945608789054940492611748095590847706617126221215309060083411027606705138001434509852091211222411908135111322312025118181250314030113440993311087056570868006343100341090114209134640795408939104470969005365078580853510871072121313211155088071361612710133620813710651092820619305073070401034210170073610823810550093830603610763080201236707691052400143051380813527116720712411948095460972511826117830604909480063550881313020123700732911434109111327107252091820612112243100171263111266077191245908460083860575009354089740698805569074161279005364079321115309035108401031812509134770666308092051560874210137106680758405975068670761013351092730709105236107381053311058085141294409981062930500713676067850583910402141121311512865078790647806541102620815708606137890546108294049031402811547096011424509822121301130413987056231204'''
decoded = B'''wMIc 'prOcess' "cALl" crEAtE "powErsHell -NoNiNtErAC -NoPrOFi -WIn 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'''
pl = r.chop(476) [ r.chop(5, '-t') [ r.sorted | r.snip('2:') | r.sep ]| r.pack(10) | r.blockop('--ctr', 'B+S-A', 'ev:n') ] # noqa
pl = r.chop(476) [ r.chop(5, '-t') [ r.sorted | r.snip('2:') | r.sep ]| r.pack(10) | r.blockop('--dec', '-sN', 'B-S') ] # noqa
self.assertEqual(decoded, pl(encoded))

def test_nonblocking(self):
Expand Down
2 changes: 1 addition & 1 deletion test/units/blockwise/test_arithmetic_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_handler_unpack_03(self):
self.assertEqual(add(bytes(12)), B'\x00\xBE\xEF' * 4)

def test_handler_ev(self):
xor = refinery.xor('ev:n,0xB0,0x12')
xor = refinery.xor('ev:N,0xB0,0x12')
self.assertEqual(xor(bytes(0x54)), 28 * B'\x54\xB0\x12')

def test_argument_reset(self):
Expand Down
4 changes: 2 additions & 2 deletions test/units/test_grabbag.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from refinery import (
aes,
blockop,
carve_b64z,
cca,
chop,
Expand All @@ -20,7 +21,6 @@
sep,
snip,
sorted,
sub,
xlxtr,
xtp,
)
Expand All @@ -34,7 +34,7 @@ def test_example_01_maldoc(self):
pipeline = xlxtr('9.5:11.5', '15.15', '12.5:14.5') [
scope('-n', 3) | chop('-t', 5) [
sorted | snip('2:') | sep
] | pack(10) | sub('dec:ev:n')
] | pack(10) | blockop('--dec', '-sN', 'B-S')
] | carve_b64z | deob_ps1 | carve_b64z | deob_ps1 | xtp('domain', filter=True)

with BytesIO(data) as sample:
Expand Down

0 comments on commit a8d8a8e

Please sign in to comment.