Skip to content

Import Submodule NamesObfuscator error #2

@loqpa

Description

@loqpa

While playing around with example python API provided by the docs I have encountered an error in NamesObfuscator.

Take following source as example:

import urllib.request
from urllib.error import URLError, HTTPError

url = 'http://example.com/'

with urllib.request.urlopen(url) as response:
    html = response.read()
    html = html.decode('utf-8')
print(html)

While trying to obfuscate the code the following error is thrown:

Traceback (most recent call last):
  File "pof_obfuscator.py", line 117, in <module>
    open('pof_testing.py','w').write(obfuscate(source))
                                  ~~~~~~~~~^^^^^^^^
  File "pof_obfuscator.py", line 101, in obfuscate
    tokens = NamesObfuscator(generator=generator).obfuscate_tokens(tokens)
  File "venv/lib/python3.13/site-packages/pof/obfuscator/names.py", line 493, in obfuscate_tokens
    return self.import_as(result, new_names)
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.13/site-packages/pof/obfuscator/names.py", line 343, in import_as
    raise e
  File "venv/lib/python3.13/site-packages/pof/obfuscator/names.py", line 320, in import_as
    n.name = inew_names[n.name]
             ~~~~~~~~~~^^^^^^^^
KeyError: 'oL_9_VR62F._238'

To understand the issue a little more I added couple of debug prints, here is the contents of new_names variable:

{'urllib': 'oL_9_VR62F', 'request': '_238', 'error': 'errnos', 'URLError': 'blob', 'HTTPError': 'mod_name', 'url': 'stdev', 'urlopen': 'tag_remove', 'response': 'listobj', 'html': 'writeHeader'}

It looks like AST library threats urllib.request as a single token, while the pof code splits it into two.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions