pcczy 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pcczy-1.0.0/PKG-INFO +124 -0
- pcczy-1.0.0/README.md +110 -0
- pcczy-1.0.0/pyproject.toml +40 -0
- pcczy-1.0.0/setup.cfg +4 -0
- pcczy-1.0.0/src/pcczy/__init__.py +101 -0
- pcczy-1.0.0/src/pcczy/animations.py +61 -0
- pcczy-1.0.0/src/pcczy/banners.py +77 -0
- pcczy-1.0.0/src/pcczy/decompiler.py +192 -0
- pcczy-1.0.0/src/pcczy/logo.py +290 -0
- pcczy-1.0.0/src/pcczy/menus.py +77 -0
- pcczy-1.0.0/src/pcczy/randoms.py +54 -0
- pcczy-1.0.0/src/pcczy/security.py +64 -0
- pcczy-1.0.0/src/pcczy/telegram.py +49 -0
- pcczy-1.0.0/src/pcczy/terminal.py +119 -0
- pcczy-1.0.0/src/pcczy/utilities.py +44 -0
- pcczy-1.0.0/src/pcczy.egg-info/PKG-INFO +124 -0
- pcczy-1.0.0/src/pcczy.egg-info/SOURCES.txt +18 -0
- pcczy-1.0.0/src/pcczy.egg-info/dependency_links.txt +1 -0
- pcczy-1.0.0/src/pcczy.egg-info/requires.txt +1 -0
- pcczy-1.0.0/src/pcczy.egg-info/top_level.txt +1 -0
pcczy-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pcczy
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A Python utility library for terminal styling, animations, security and code analysis.
|
|
5
|
+
Author: PCCZY
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: pcczy,python,terminal,colors,animations,utilities,reverse-engineering,bytecode
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: cryptography>=41.0
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# PCCZY 🐍
|
|
17
|
+
|
|
18
|
+
A Python utility library for terminal styling, animations, security, random generators, Telegram integration and Python code analysis.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install pcczy
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import pcczy as pc
|
|
30
|
+
|
|
31
|
+
pc.logo()
|
|
32
|
+
|
|
33
|
+
pc.cprint("PCCZY is ready!", color="green")
|
|
34
|
+
pc.rgb("Welcome to PCCZY")
|
|
35
|
+
pc.gradient("Hello World", "red", "blue")
|
|
36
|
+
|
|
37
|
+
pc.loading("Starting", 2)
|
|
38
|
+
pc.info()
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
### Terminal
|
|
44
|
+
- cprint()
|
|
45
|
+
- rgb()
|
|
46
|
+
- gradient()
|
|
47
|
+
- clear()
|
|
48
|
+
|
|
49
|
+
### Banners
|
|
50
|
+
- banner()
|
|
51
|
+
- gradient_banner()
|
|
52
|
+
- logo()
|
|
53
|
+
|
|
54
|
+
### Animations
|
|
55
|
+
- loading()
|
|
56
|
+
- progress()
|
|
57
|
+
- countdown()
|
|
58
|
+
|
|
59
|
+
### Utilities
|
|
60
|
+
- expire()
|
|
61
|
+
- info()
|
|
62
|
+
|
|
63
|
+
### Security
|
|
64
|
+
- encrypt()
|
|
65
|
+
- decrypt()
|
|
66
|
+
- generate_key()
|
|
67
|
+
|
|
68
|
+
### Menus
|
|
69
|
+
- menu()
|
|
70
|
+
- table()
|
|
71
|
+
|
|
72
|
+
### Random Generators
|
|
73
|
+
- random_string()
|
|
74
|
+
- random_number()
|
|
75
|
+
- random_color()
|
|
76
|
+
- random_choice()
|
|
77
|
+
- random_shuffle()
|
|
78
|
+
|
|
79
|
+
### Telegram
|
|
80
|
+
- telegram_send()
|
|
81
|
+
|
|
82
|
+
### Python Code Analysis
|
|
83
|
+
- inspect_file()
|
|
84
|
+
- analyze_file()
|
|
85
|
+
- disassemble()
|
|
86
|
+
- disassemble_pyc()
|
|
87
|
+
- extract_strings()
|
|
88
|
+
- get_metadata()
|
|
89
|
+
- save_report()
|
|
90
|
+
|
|
91
|
+
## Security Example
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
import pcczy as pc
|
|
95
|
+
|
|
96
|
+
encrypted = pc.encrypt("Hello PCCZY", "my-password")
|
|
97
|
+
original = pc.decrypt(encrypted, "my-password")
|
|
98
|
+
|
|
99
|
+
print(original)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Code Analysis Example
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
import pcczy as pc
|
|
106
|
+
|
|
107
|
+
result = pc.analyze_file("example.py")
|
|
108
|
+
print(result)
|
|
109
|
+
|
|
110
|
+
pc.save_report(result, "report.txt")
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Requirements
|
|
114
|
+
|
|
115
|
+
- Python 3.9+
|
|
116
|
+
- cryptography
|
|
117
|
+
|
|
118
|
+
## Author
|
|
119
|
+
|
|
120
|
+
PCCZY
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
MIT
|
pcczy-1.0.0/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
|
|
2
|
+
# PCCZY 🐍
|
|
3
|
+
|
|
4
|
+
A Python utility library for terminal styling, animations, security, random generators, Telegram integration and Python code analysis.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install pcczy
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
import pcczy as pc
|
|
16
|
+
|
|
17
|
+
pc.logo()
|
|
18
|
+
|
|
19
|
+
pc.cprint("PCCZY is ready!", color="green")
|
|
20
|
+
pc.rgb("Welcome to PCCZY")
|
|
21
|
+
pc.gradient("Hello World", "red", "blue")
|
|
22
|
+
|
|
23
|
+
pc.loading("Starting", 2)
|
|
24
|
+
pc.info()
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
### Terminal
|
|
30
|
+
- cprint()
|
|
31
|
+
- rgb()
|
|
32
|
+
- gradient()
|
|
33
|
+
- clear()
|
|
34
|
+
|
|
35
|
+
### Banners
|
|
36
|
+
- banner()
|
|
37
|
+
- gradient_banner()
|
|
38
|
+
- logo()
|
|
39
|
+
|
|
40
|
+
### Animations
|
|
41
|
+
- loading()
|
|
42
|
+
- progress()
|
|
43
|
+
- countdown()
|
|
44
|
+
|
|
45
|
+
### Utilities
|
|
46
|
+
- expire()
|
|
47
|
+
- info()
|
|
48
|
+
|
|
49
|
+
### Security
|
|
50
|
+
- encrypt()
|
|
51
|
+
- decrypt()
|
|
52
|
+
- generate_key()
|
|
53
|
+
|
|
54
|
+
### Menus
|
|
55
|
+
- menu()
|
|
56
|
+
- table()
|
|
57
|
+
|
|
58
|
+
### Random Generators
|
|
59
|
+
- random_string()
|
|
60
|
+
- random_number()
|
|
61
|
+
- random_color()
|
|
62
|
+
- random_choice()
|
|
63
|
+
- random_shuffle()
|
|
64
|
+
|
|
65
|
+
### Telegram
|
|
66
|
+
- telegram_send()
|
|
67
|
+
|
|
68
|
+
### Python Code Analysis
|
|
69
|
+
- inspect_file()
|
|
70
|
+
- analyze_file()
|
|
71
|
+
- disassemble()
|
|
72
|
+
- disassemble_pyc()
|
|
73
|
+
- extract_strings()
|
|
74
|
+
- get_metadata()
|
|
75
|
+
- save_report()
|
|
76
|
+
|
|
77
|
+
## Security Example
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import pcczy as pc
|
|
81
|
+
|
|
82
|
+
encrypted = pc.encrypt("Hello PCCZY", "my-password")
|
|
83
|
+
original = pc.decrypt(encrypted, "my-password")
|
|
84
|
+
|
|
85
|
+
print(original)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Code Analysis Example
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
import pcczy as pc
|
|
92
|
+
|
|
93
|
+
result = pc.analyze_file("example.py")
|
|
94
|
+
print(result)
|
|
95
|
+
|
|
96
|
+
pc.save_report(result, "report.txt")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Requirements
|
|
100
|
+
|
|
101
|
+
- Python 3.9+
|
|
102
|
+
- cryptography
|
|
103
|
+
|
|
104
|
+
## Author
|
|
105
|
+
|
|
106
|
+
PCCZY
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
[build-system]
|
|
3
|
+
requires = ["setuptools>=68", "wheel"]
|
|
4
|
+
build-backend = "setuptools.build_meta"
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "pcczy"
|
|
8
|
+
version = "1.0.0"
|
|
9
|
+
description = "A Python utility library for terminal styling, animations, security and code analysis."
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
license = "MIT"
|
|
13
|
+
authors = [
|
|
14
|
+
{name = "PCCZY"}
|
|
15
|
+
]
|
|
16
|
+
keywords = [
|
|
17
|
+
"pcczy",
|
|
18
|
+
"python",
|
|
19
|
+
"terminal",
|
|
20
|
+
"colors",
|
|
21
|
+
"animations",
|
|
22
|
+
"utilities",
|
|
23
|
+
"reverse-engineering",
|
|
24
|
+
"bytecode"
|
|
25
|
+
]
|
|
26
|
+
classifiers = [
|
|
27
|
+
"Programming Language :: Python :: 3",
|
|
28
|
+
"Operating System :: OS Independent",
|
|
29
|
+
"Topic :: Software Development :: Libraries :: Python Modules"
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
dependencies = [
|
|
33
|
+
"cryptography>=41.0"
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[tool.setuptools]
|
|
37
|
+
package-dir = {"" = "src"}
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.packages.find]
|
|
40
|
+
where = ["src"]
|
pcczy-1.0.0/setup.cfg
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
|
|
2
|
+
"""
|
|
3
|
+
PCCZY - Python Utility Library
|
|
4
|
+
|
|
5
|
+
Terminal styling, animations, security, utilities,
|
|
6
|
+
random generators, Telegram tools and Python analysis.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__version__ = "1.0.0"
|
|
10
|
+
__author__ = "PCCZY"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Terminal
|
|
14
|
+
from .terminal import (
|
|
15
|
+
cprint,
|
|
16
|
+
rgb,
|
|
17
|
+
gradient,
|
|
18
|
+
clear,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# Banners and logo
|
|
23
|
+
from .banners import (
|
|
24
|
+
banner,
|
|
25
|
+
gradient_banner,
|
|
26
|
+
logo,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# Animations
|
|
31
|
+
from .animations import (
|
|
32
|
+
loading,
|
|
33
|
+
progress,
|
|
34
|
+
countdown,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Utilities
|
|
39
|
+
from .utilities import (
|
|
40
|
+
expire,
|
|
41
|
+
info,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# Security
|
|
46
|
+
from .security import (
|
|
47
|
+
encrypt,
|
|
48
|
+
decrypt,
|
|
49
|
+
generate_key,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# Menus and tables
|
|
54
|
+
from .menus import (
|
|
55
|
+
menu,
|
|
56
|
+
table,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# Random utilities
|
|
61
|
+
from .randoms import (
|
|
62
|
+
random_string,
|
|
63
|
+
random_number,
|
|
64
|
+
random_color,
|
|
65
|
+
random_choice,
|
|
66
|
+
random_shuffle,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# Telegram
|
|
71
|
+
from .telegram import (
|
|
72
|
+
telegram_send,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# Python reverse engineering and analysis
|
|
77
|
+
from .decompiler import (
|
|
78
|
+
inspect_file,
|
|
79
|
+
analyze_file,
|
|
80
|
+
disassemble,
|
|
81
|
+
disassemble_pyc,
|
|
82
|
+
extract_strings,
|
|
83
|
+
get_metadata,
|
|
84
|
+
save_report,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
__all__ = [
|
|
89
|
+
"cprint", "rgb", "gradient", "clear",
|
|
90
|
+
"banner", "gradient_banner", "logo",
|
|
91
|
+
"loading", "progress", "countdown",
|
|
92
|
+
"expire", "info",
|
|
93
|
+
"encrypt", "decrypt", "generate_key",
|
|
94
|
+
"menu", "table",
|
|
95
|
+
"random_string", "random_number",
|
|
96
|
+
"random_color", "random_choice", "random_shuffle",
|
|
97
|
+
"telegram_send",
|
|
98
|
+
"inspect_file", "analyze_file",
|
|
99
|
+
"disassemble", "disassemble_pyc",
|
|
100
|
+
"extract_strings", "get_metadata", "save_report",
|
|
101
|
+
]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
import sys
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def loading(text="Loading", duration=2, style="dots"):
|
|
7
|
+
frames = {
|
|
8
|
+
"dots": [" ", ". ", ".. ", "..."],
|
|
9
|
+
"line": ["|", "/", "-", "\\"],
|
|
10
|
+
"circle": ["◐", "◓", "◑", "◒"],
|
|
11
|
+
"bar": ["[ ]", "[= ]", "[== ]", "[=== ]", "[====]"]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if style not in frames:
|
|
15
|
+
raise ValueError("Style must be dots, line, circle or bar")
|
|
16
|
+
|
|
17
|
+
animation = frames[style]
|
|
18
|
+
end_time = time.time() + max(0, duration)
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
while time.time() < end_time:
|
|
22
|
+
for frame in animation:
|
|
23
|
+
sys.stdout.write(f"\r{text} {frame}")
|
|
24
|
+
sys.stdout.flush()
|
|
25
|
+
time.sleep(0.12)
|
|
26
|
+
|
|
27
|
+
if time.time() >= end_time:
|
|
28
|
+
break
|
|
29
|
+
finally:
|
|
30
|
+
sys.stdout.write("\r" + " " * (len(text) + 15) + "\r")
|
|
31
|
+
sys.stdout.flush()
|
|
32
|
+
|
|
33
|
+
print(f"{text} Done!")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def progress(current, total, label="Progress", width=30):
|
|
37
|
+
if total <= 0:
|
|
38
|
+
raise ValueError("Total must be greater than zero")
|
|
39
|
+
|
|
40
|
+
current = max(0, min(current, total))
|
|
41
|
+
percentage = (current / total) * 100
|
|
42
|
+
filled = int(width * current / total)
|
|
43
|
+
|
|
44
|
+
bar = "█" * filled + "░" * (width - filled)
|
|
45
|
+
|
|
46
|
+
sys.stdout.write(
|
|
47
|
+
f"\r{label}: [{bar}] {percentage:5.1f}%"
|
|
48
|
+
)
|
|
49
|
+
sys.stdout.flush()
|
|
50
|
+
|
|
51
|
+
if current == total:
|
|
52
|
+
print()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def countdown(seconds, label="Starting in"):
|
|
56
|
+
for remaining in range(seconds, 0, -1):
|
|
57
|
+
sys.stdout.write(f"\r{label}: {remaining} ")
|
|
58
|
+
sys.stdout.flush()
|
|
59
|
+
time.sleep(1)
|
|
60
|
+
|
|
61
|
+
print("\r" + " " * 40 + "\rDone!")
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
|
|
2
|
+
from .terminal import cprint, rgb, gradient
|
|
3
|
+
|
|
4
|
+
FONTS = {
|
|
5
|
+
"standard": {
|
|
6
|
+
"A": [" A ", " A A ", "AAAAA", "A A", "A A"],
|
|
7
|
+
"B": ["BBBB ", "B B", "BBBB ", "B B", "BBBB "],
|
|
8
|
+
"C": [" CCC ", "C C", "C ", "C C", " CCC "],
|
|
9
|
+
"D": ["DDD ", "D D ", "D D", "D D ", "DDD "],
|
|
10
|
+
"E": ["EEEEE", "E ", "EEEE ", "E ", "EEEEE"],
|
|
11
|
+
"F": ["FFFFF", "F ", "FFFF ", "F ", "F "],
|
|
12
|
+
"G": [" GGG ", "G ", "G GGG", "G G", " GGG "],
|
|
13
|
+
"H": ["H H", "H H", "HHHHH", "H H", "H H"],
|
|
14
|
+
"I": ["IIIII", " I ", " I ", " I ", "IIIII"],
|
|
15
|
+
"J": ["JJJJJ", " J ", " J ", "J J ", " JJ "],
|
|
16
|
+
"K": ["K K", "K K ", "KKK ", "K K ", "K K"],
|
|
17
|
+
"L": ["L ", "L ", "L ", "L ", "LLLLL"],
|
|
18
|
+
"M": ["M M", "MM MM", "M M M", "M M", "M M"],
|
|
19
|
+
"N": ["N N", "NN N", "N N N", "N NN", "N N"],
|
|
20
|
+
"O": [" OOO ", "O O", "O O", "O O", " OOO "],
|
|
21
|
+
"P": ["PPPP ", "P P", "PPPP ", "P ", "P "],
|
|
22
|
+
"Q": [" QQQ ", "Q Q", "Q Q Q", "Q Q ", " QQ Q"],
|
|
23
|
+
"R": ["RRRR ", "R R", "RRRR ", "R R ", "R R"],
|
|
24
|
+
"S": [" SSSS", "S ", " SSS ", " S", "SSSS "],
|
|
25
|
+
"T": ["TTTTT", " T ", " T ", " T ", " T "],
|
|
26
|
+
"U": ["U U", "U U", "U U", "U U", " UUU "],
|
|
27
|
+
"V": ["V V", "V V", "V V", " V V ", " V "],
|
|
28
|
+
"W": ["W W", "W W", "W W W", "WW WW", "W W"],
|
|
29
|
+
"X": ["X X", " X X ", " X ", " X X ", "X X"],
|
|
30
|
+
"Y": ["Y Y", " Y Y ", " Y ", " Y ", " Y "],
|
|
31
|
+
"Z": ["ZZZZZ", " Z ", " Z ", " Z ", "ZZZZZ"],
|
|
32
|
+
" ": [" ", " ", " ", " ", " "]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def banner(text, font="standard", color=None):
|
|
38
|
+
text = str(text).upper()
|
|
39
|
+
|
|
40
|
+
if font not in FONTS:
|
|
41
|
+
raise ValueError("Font not found")
|
|
42
|
+
|
|
43
|
+
output = [""] * 5
|
|
44
|
+
|
|
45
|
+
for char in text:
|
|
46
|
+
pattern = FONTS[font].get(char, FONTS[font][" "])
|
|
47
|
+
|
|
48
|
+
for i in range(5):
|
|
49
|
+
output[i] += pattern[i] + " "
|
|
50
|
+
|
|
51
|
+
for line in output:
|
|
52
|
+
if color:
|
|
53
|
+
cprint(line, color=color)
|
|
54
|
+
else:
|
|
55
|
+
print(line)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def gradient_banner(text, start="red", end="blue"):
|
|
59
|
+
text = str(text).upper()
|
|
60
|
+
output = [""] * 5
|
|
61
|
+
|
|
62
|
+
for char in text:
|
|
63
|
+
pattern = FONTS["standard"].get(
|
|
64
|
+
char, FONTS["standard"][" "]
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
for i in range(5):
|
|
68
|
+
output[i] += pattern[i] + " "
|
|
69
|
+
|
|
70
|
+
for line in output:
|
|
71
|
+
gradient(line, start, end)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def logo():
|
|
75
|
+
from .logo import main
|
|
76
|
+
main()
|
|
77
|
+
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
|
|
2
|
+
import ast
|
|
3
|
+
import dis
|
|
4
|
+
import io
|
|
5
|
+
import marshal
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import sys
|
|
9
|
+
import types
|
|
10
|
+
import tokenize
|
|
11
|
+
from collections import Counter
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _read_file(path):
|
|
15
|
+
if not os.path.isfile(path):
|
|
16
|
+
raise FileNotFoundError(f"File not found: {path}")
|
|
17
|
+
|
|
18
|
+
with open(path, "rb") as file:
|
|
19
|
+
return file.read()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def inspect_file(path):
|
|
23
|
+
"""Inspect Python source and extract its structure."""
|
|
24
|
+
|
|
25
|
+
source = _read_file(path).decode("utf-8-sig")
|
|
26
|
+
tree = ast.parse(source, filename=path)
|
|
27
|
+
|
|
28
|
+
result = {
|
|
29
|
+
"file": os.path.basename(path),
|
|
30
|
+
"lines": len(source.splitlines()),
|
|
31
|
+
"imports": [],
|
|
32
|
+
"functions": [],
|
|
33
|
+
"classes": [],
|
|
34
|
+
"variables": []
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
for node in ast.walk(tree):
|
|
38
|
+
if isinstance(node, ast.Import):
|
|
39
|
+
for name in node.names:
|
|
40
|
+
result["imports"].append(name.name)
|
|
41
|
+
|
|
42
|
+
elif isinstance(node, ast.ImportFrom):
|
|
43
|
+
result["imports"].append(node.module or "")
|
|
44
|
+
|
|
45
|
+
elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
46
|
+
result["functions"].append(node.name)
|
|
47
|
+
|
|
48
|
+
elif isinstance(node, ast.ClassDef):
|
|
49
|
+
result["classes"].append(node.name)
|
|
50
|
+
|
|
51
|
+
elif isinstance(node, ast.Assign):
|
|
52
|
+
for target in node.targets:
|
|
53
|
+
if isinstance(target, ast.Name):
|
|
54
|
+
result["variables"].append(target.id)
|
|
55
|
+
|
|
56
|
+
return result
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def analyze_file(path):
|
|
60
|
+
"""Analyze Python source code."""
|
|
61
|
+
|
|
62
|
+
source = _read_file(path).decode("utf-8-sig")
|
|
63
|
+
tree = ast.parse(source, filename=path)
|
|
64
|
+
|
|
65
|
+
functions = []
|
|
66
|
+
classes = []
|
|
67
|
+
imports = []
|
|
68
|
+
strings = []
|
|
69
|
+
constants = Counter()
|
|
70
|
+
|
|
71
|
+
for node in ast.walk(tree):
|
|
72
|
+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
73
|
+
functions.append({
|
|
74
|
+
"name": node.name,
|
|
75
|
+
"line": node.lineno,
|
|
76
|
+
"arguments": [
|
|
77
|
+
arg.arg for arg in node.args.args
|
|
78
|
+
]
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
elif isinstance(node, ast.ClassDef):
|
|
82
|
+
classes.append({
|
|
83
|
+
"name": node.name,
|
|
84
|
+
"line": node.lineno
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
elif isinstance(node, (ast.Import, ast.ImportFrom)):
|
|
88
|
+
imports.append(ast.unparse(node))
|
|
89
|
+
|
|
90
|
+
elif isinstance(node, ast.Constant):
|
|
91
|
+
if isinstance(node.value, str):
|
|
92
|
+
strings.append(node.value)
|
|
93
|
+
elif isinstance(node.value, (int, float, bool, type(None))):
|
|
94
|
+
constants[type(node.value).__name__] += 1
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
"file": os.path.basename(path),
|
|
98
|
+
"total_lines": len(source.splitlines()),
|
|
99
|
+
"functions": functions,
|
|
100
|
+
"classes": classes,
|
|
101
|
+
"imports": imports,
|
|
102
|
+
"strings": strings,
|
|
103
|
+
"constant_types": dict(constants)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def disassemble(path):
|
|
108
|
+
"""Disassemble Python source or compiled Python bytecode."""
|
|
109
|
+
|
|
110
|
+
if path.endswith(".py"):
|
|
111
|
+
source = _read_file(path).decode("utf-8-sig")
|
|
112
|
+
code = compile(source, path, "exec")
|
|
113
|
+
else:
|
|
114
|
+
raise ValueError(
|
|
115
|
+
"This function currently accepts .py files. "
|
|
116
|
+
"Use disassemble_pyc() for .pyc files."
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
output = io.StringIO()
|
|
120
|
+
dis.dis(code, file=output)
|
|
121
|
+
|
|
122
|
+
return output.getvalue()
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def disassemble_pyc(path):
|
|
126
|
+
"""Read and disassemble a compatible .pyc file."""
|
|
127
|
+
|
|
128
|
+
data = _read_file(path)
|
|
129
|
+
|
|
130
|
+
if len(data) < 16:
|
|
131
|
+
raise ValueError("Invalid or incomplete .pyc file")
|
|
132
|
+
|
|
133
|
+
if data[:4] != __import__("importlib.util").util.MAGIC_NUMBER:
|
|
134
|
+
raise ValueError(
|
|
135
|
+
"This .pyc file was compiled for a different Python version."
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
code = marshal.loads(data[16:])
|
|
139
|
+
|
|
140
|
+
if not isinstance(code, types.CodeType):
|
|
141
|
+
raise ValueError("No valid code object found")
|
|
142
|
+
|
|
143
|
+
output = io.StringIO()
|
|
144
|
+
dis.dis(code, file=output)
|
|
145
|
+
|
|
146
|
+
return output.getvalue()
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def extract_strings(path, minimum_length=4):
|
|
150
|
+
"""Extract readable strings from a Python file or .pyc file."""
|
|
151
|
+
|
|
152
|
+
data = _read_file(path)
|
|
153
|
+
|
|
154
|
+
found = re.findall(
|
|
155
|
+
rb"[ -~]{%d,}" % minimum_length,
|
|
156
|
+
data
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
return list(dict.fromkeys(
|
|
160
|
+
item.decode("utf-8", errors="replace")
|
|
161
|
+
for item in found
|
|
162
|
+
))
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def get_metadata(path):
|
|
166
|
+
"""Get basic file and Python environment metadata."""
|
|
167
|
+
|
|
168
|
+
data = _read_file(path)
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
"filename": os.path.basename(path),
|
|
172
|
+
"size_bytes": len(data),
|
|
173
|
+
"extension": os.path.splitext(path)[1],
|
|
174
|
+
"python_version": sys.version,
|
|
175
|
+
"is_pyc": path.endswith(".pyc"),
|
|
176
|
+
"pyc_magic": data[:4].hex() if path.endswith(".pyc") else None
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def save_report(data, output_path):
|
|
181
|
+
"""Save analysis output as a text report."""
|
|
182
|
+
|
|
183
|
+
with open(output_path, "w", encoding="utf-8") as file:
|
|
184
|
+
if isinstance(data, dict):
|
|
185
|
+
for key, value in data.items():
|
|
186
|
+
file.write(f"\n{key.upper()}\n")
|
|
187
|
+
file.write("-" * 35 + "\n")
|
|
188
|
+
file.write(str(value) + "\n")
|
|
189
|
+
else:
|
|
190
|
+
file.write(str(data))
|
|
191
|
+
|
|
192
|
+
return output_path
|