Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Latest commit

 

History

History
99 lines (68 loc) · 7.25 KB

ReadMe.md

File metadata and controls

99 lines (68 loc) · 7.25 KB

FrozenTable.py Unlicensed work

wheel PyPi Status GitLab Build Status GitLab Coverage Libraries.io Status Code style: antiflash

We have moved to https://codeberg.org/KOLANICH-tools/FrozenTable.py, grab new versions there.

Under the disguise of "better security" Micro$oft-owned GitHub has discriminated users of 1FA passwords while having commercial interest in success of FIDO 1FA specifications and Windows Hello implementation which it promotes as a replacement for passwords. It will result in dire consequencies and is competely inacceptable, read why.

If you don't want to participate in harming yourself, it is recommended to follow the lead and migrate somewhere away of GitHub and Micro$oft. Here is the list of alternatives and rationales to do it. If they delete the discussion, there are certain well-known places where you can get a copy of it. Read why you should also leave GitHub.


Doxygen-generated docs are available.

Why?

Some python modules are baked into the cpython interpreter shared library (python<version>.dll on Windows). This shared library contains a symbol PyImport_FrozenModules, which points to _PyImport_FrozenModules, which is a table of _frozen, associating pointers to marshaled bytecodes of python modules (and objects) to their names.

When an interpreter imports a module, import machinery searches it first in this table. It is possible to disable this behavior, but some lookups are hardcoded into the interpreter and called during interpreter initialization. So you may want to replace the implementations there with own ones.

Use cases

Doing this is useful when you are debugging an own import machinery, but it doesn't work fine and spits weird errors, so you have to add some the debug output into importlib itself. But you will be surprised to see that your added code doesn't work. It turns out that part of importing machinery is baked into the table of frozen modules and is always imported from there.

This project provides a solution. With the help of this module you can:

Features

  • using make_redirector subcommand generate small stubs reading the needed files from disk and executing them and replace the frozen;
  • replace the entries in the frozen table with the stubs

Also you can

  • list the entries in the frozen table.
  • reorder the entries.
  • remove an entry from the frozen table.
  • dump an entry from the frozen table.

And of course all the features are available via API.

Usage

from FrozenTable import FrozenTable
from pprint import pprint
import mmap

with FrozenTable("./python37.dll") as t:
	pprint(t.dict)
	t.modifyEntry("__hello__", code)
	t.remove(("__hello__",))  # removes packages from the table, gets an itera(tor|ble)
	
	newOrder=list(t.keys())
	shuffle(newOrder)
	t.reorder(newOrder)  # shuffles the table. Should do no effect.
	t.writeTable() # you need to do it after all your actions

Command line interface (CLI)

The lib has a command line interface. Use

python -m FrozenTable

for getting help.

TL;DR

python -m FrozenTable make_redirector importlib._bootstrap | python -m FrozenTable replace python3.7
python -m FrozenTable make_redirector importlib._bootstrap_external | python -m FrozenTable replace python37.dll _frozen_importlib_external

to patch your python interpreter to use importlib._bootstrap from file.

Requirements

  • kaitaistruct PyPi Status License as a runtime for Kaitai Struct-generated code

  • And depending on what files you are going to process:

    • lief Licence PyPi Status CI Build Status Libraries.io Status - PE, ELF, Mach-O, fast, written in C++, but takes long to build and creating a package is problematic - ELF is broken

    • pefile Licence PyPi Status pefile test Libraries.io Status - PE

    • pyelftools Licence PyPi Status CI Build Status Libraries.io Status - ELF