Metadata-Version: 2.4
Name: pyprivate-obf
Version: 1.0.0
Summary: Python source obfuscator — encode strings, bytecode, and CPython C compilation
License: MIT License
        
        Copyright (c) 2025 pooraddyy
        Original Py Private tool Copyright (c) PSH Team (t.me/psh_team)
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        This project is a Python reconstruction of the Py Private v4.1.2 Android
        application originally created by the PSH Team. All obfuscation algorithms,
        guard logic, and the CPython/Cython-based compilation approach are derived
        from the original work of PSH Team. This package does not claim original
        authorship of those techniques.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/pooraddyy/pyprivate
Project-URL: Repository, https://github.com/pooraddyy/pyprivate
Project-URL: Issues, https://github.com/pooraddyy/pyprivate/issues
Keywords: obfuscation,python,bytecode,cython,protection
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Code Generators
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: cpython
Requires-Dist: cython>=0.29; extra == "cpython"
Dynamic: license-file

<div align="center">

<h1>PyPrivate-Obf</h1>

<p>A Python source obfuscator reconstructed from the <strong>Py Private</strong> Android application.<br>
The original author and owner of this encoder is the <strong>PSH Team</strong> — <a href="https://t.me/psh_team">t.me/psh_team</a>.<br>
This repository is a reverse-engineered Python reconstruction of their work from the APK source.</p>

<a href="https://pypi.org/project/pyprivate-obf"><img src="https://img.shields.io/pypi/v/pyprivate-obf?color=blue&label=PyPI" alt="PyPI"></a>
<a href="https://pypi.org/project/pyprivate-obf"><img src="https://img.shields.io/pypi/pyversions/pyprivate-obf" alt="Python"></a>
<img src="https://img.shields.io/github/license/pooraddyy/pyprivate" alt="License">
<img src="https://img.shields.io/pypi/dm/pyprivate-obf?label=downloads" alt="Downloads">

<br><br>

<a href="#installation"><kbd>Installation</kbd></a>
&nbsp;&nbsp;
<a href="#cli-usage"><kbd>CLI Usage</kbd></a>
&nbsp;&nbsp;
<a href="#encoding-methods"><kbd>Encoders</kbd></a>
&nbsp;&nbsp;
<a href="#guard-layers"><kbd>Guards</kbd></a>
&nbsp;&nbsp;
<a href="#python-api"><kbd>Python API</kbd></a>

</div>

## CLI Preview

<div align="center">
  <img src="img/1.jpeg" alt="pyprivate-obf CLI demo" width="820">
</div>

---

## Installation

```bash
pip install pyprivate-obf
```

To use **CPython obfuscation** (Cython + GCC compilation), also install:

```bash
pip install cython

# Debian / Ubuntu
sudo apt install gcc python3-dev

# Termux
pkg install clang python-dev
```

---

## CLI Usage

### Interactive wizard

Run without any arguments to get a step-by-step menu:

```
pyprivate-obf
```

Or force interactive mode explicitly:

```
pyprivate-obf --interactive
```

### Non-interactive (flags)

```
pyprivate-obf <input.py> [OPTIONS] [-o output.py]
```

<details>
<summary><strong>All available flags</strong></summary>

| Flag | Description |
|---|---|
| `--encode-strings` | Replace every string literal with `bytes([...]).decode()` |
| `--bytecode` | Marshal bytecode + opcode-pattern swap |
| `--cpython` | Cython `--embed` → C source → GCC native binary launcher |
| `--layers N` | Number of marshal layers to apply (default: 1, max: 20) |
| `--re-check-version` | Re-prepend Python version guard inside every layer |
| `--expiry "YYYY-MM-DD HH:MM:SS.000000"` | Add an expiry date guard |
| `--expiry-message "..."` | Message shown when expired (default: "This file has expired.") |
| `--pip PKG1 PKG2 ...` | Auto-install packages on first run |
| `--check-version` | Lock script to the current Python major.minor version |
| `--telegram-bot-token TOKEN` | Telegram channel guard — bot token |
| `--telegram-channel-id @channel` | Telegram channel guard — channel id |
| `-o / --output FILE` | Output file path (default: `<input>.enc.py`) |

</details>

### Examples

```bash
# Encode strings + 3 bytecode layers
pyprivate-obf script.py --encode-strings --bytecode --layers 3

# CPython (native binary) obfuscation
pyprivate-obf script.py --cpython

# Add an expiry date
pyprivate-obf script.py --bytecode --expiry "2025-12-31 23:59:59.000000"

# Auto-install dependencies on first run
pyprivate-obf script.py --bytecode --pip requests numpy pillow

# Lock to current Python version
pyprivate-obf script.py --bytecode --check-version

# Telegram channel membership gate
pyprivate-obf script.py --bytecode \
  --telegram-bot-token 123456:ABCdef \
  --telegram-channel-id @mychannel

# Chain everything with a custom output path
pyprivate-obf script.py --encode-strings --bytecode --layers 2 \
  --check-version -o protected.py
```

---

## Encoding Methods

There are four independent encoding methods. They live in `pyprivate_obf/encoding_methods/` and each one accepts a `source: str` and returns an obfuscated `str`.

### `encode_strings`

Rewrites every string literal in the source as `bytes([...]).decode()`.

```bash
pyprivate-obf script.py --encode-strings
```

Before:
```python
print("hello world")
```

After:
```python
print(bytes([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]).decode())
```

---

### `bytecode_obfuscation`

Compiles the source, serialises it with `marshal`, then swaps a known opcode pattern in the bytecode so it cannot be cleanly disassembled with stock `dis`. Output format:

```python
import marshal
exec(marshal.loads(b'...'))
```

```bash
pyprivate-obf script.py --bytecode
pyprivate-obf script.py --bytecode --layers 5   # 5 nested marshal layers
```

---

### `cpython_obfuscation`

Compiles the source to C using Cython `--embed`, strips the compressed string-table sections so only clean ASCII C code remains, then wraps it in a Python launcher that writes the `.c` file to `.py_private/<timestamp>`, compiles it with GCC, and runs the native binary.

Requires: `cython` (pip) + `gcc` + Python headers.

```bash
pyprivate-obf script.py --cpython
```

The output `.py` file contains only the clean C source as a plain string — no binary or base64 data.

---

### `simple_marshal`

Plain `marshal` wrap with no opcode swap. Used as a fallback when no encoding method is selected, and in DEBUG mode.

```bash
# applied automatically when no --bytecode / --cpython flag is given
pyprivate-obf script.py
```

---

## Guard Layers

Guards are injected at the top of the output script before encoding. Multiple guards can be combined.

### Expiry Time

Refuses to run after a given date and time.

```bash
pyprivate-obf script.py --expiry "2025-06-30 23:59:59.000000"
pyprivate-obf script.py --expiry "2025-06-30 23:59:59.000000" --expiry-message "License expired."
```

### Python Version Lock

Refuses to run on any Python version other than the one used to obfuscate.

```bash
pyprivate-obf script.py --check-version
```

### Pip Installer

Auto-installs missing packages on first run.

```bash
pyprivate-obf script.py --pip requests numpy pillow
```

### Telegram Channel Guard

Verifies that the user has joined a Telegram channel before allowing execution.

```bash
pyprivate-obf script.py \
  --telegram-bot-token 123456:ABCxyz \
  --telegram-channel-id @mychannel
```

---

## Python API

Use the encoders and guards directly from Python:

```python
from pyprivate_obf import encode_strings, bytecode_obfuscation
from pyprivate_obf import ExpiryTime, CheckVersion, LibrariesInstaller, EnterChannel

source = open("script.py").read()

# Encode strings
source = encode_strings(source)

# Bytecode obfuscation
source = bytecode_obfuscation(source)

# CPython obfuscation (requires cython + gcc)
from pyprivate_obf.encoding_methods.cpython_obfuscation import cpython_obfuscation
source = cpython_obfuscation(source)

# Add expiry guard
source = ExpiryTime(
    time="2025-12-31 23:59:59.000000",
    message="This script has expired."
).get_new_source(source)

# Add pip installer guard
source = LibrariesInstaller(
    package_names=["requests", "numpy"]
).get_new_source(source)

# Add Python version lock
source = CheckVersion().get_new_source(source)

# Add Telegram channel guard
source = EnterChannel(
    bot_token="123456:ABCxyz",
    channel_id="@mychannel"
).get_new_source(source)

with open("protected.py", "w") as f:
    f.write(source)
```

---

## Credits

This project is a reverse-engineered Python reconstruction of the **Py Private v4.1.2** Android application.

The original encoder was authored by the **PSH Team**: [t.me/psh_team](https://t.me/psh_team)

The APK was decompiled using apktool. The inner Python source was bundled via Chaquopy as `.pyc` files (Python 3.9 bytecode) inside `assets/chaquopy/app.imy`. Each `.pyc` was decompiled and reconstructed into clean Python source.

---

## License

MIT © pooraddyy
