Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scanner): support *PUT instructions #16

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/picklescan/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ def _list_globals(data: IO[bytes], multiple_pickles=True) -> Set[Tuple[str, str]
op_name = op[0].name
op_value = op[1]

if op_name == "MEMOIZE" and n > 0:
if op_name in ["MEMOIZE", "PUT", "BINPUT", "LONG_BINPUT"] and n > 0:
memo[len(memo)] = ops[n - 1][1]

if op_name == "GLOBAL":
globals.add(tuple(op_value.split(" ", 1)))
elif op_name == "STACK_GLOBAL":
values = []
for offset in range(1, n):
if ops[n - offset][0].name == "MEMOIZE":
if ops[n - offset][0].name in ["MEMOIZE", "PUT", "BINPUT", "LONG_BINPUT"]:
continue
if ops[n - offset][0].name in ["GET", "BINGET", "LONG_BINGET"]:
values.append(memo[int(ops[n - offset][1])])
Expand All @@ -220,6 +220,7 @@ def _list_globals(data: IO[bytes], multiple_pickles=True) -> Set[Tuple[str, str]
f"Found {len(values)} values for STACK_GLOBAL at position {n} instead of 2."
)
globals.add((values[1], values[0]))

if not multiple_pickles:
break

Expand Down
Loading