pyobject 1.2.8__tar.gz → 1.2.9__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.
- {pyobject-1.2.8/pyobject.egg-info → pyobject-1.2.9}/PKG-INFO +20 -14
- {pyobject-1.2.8 → pyobject-1.2.9}/README.rst +17 -12
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/__init__.py +19 -19
- pyobject-1.2.8/pyobject/code_.py → pyobject-1.2.9/pyobject/code.py +0 -2
- pyobject-1.2.9/pyobject/objproxy/__init__.py +740 -0
- pyobject-1.2.9/pyobject/objproxy/builtin_hook.py +106 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/objproxy/dynobj.py +1 -1
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/objproxy/optimize.py +62 -18
- pyobject-1.2.9/pyobject/objproxy/utils.py +112 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/pyobj_extension.c +1 -1
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/search.py +1 -2
- pyobject-1.2.9/pyobject/tests/test_code.py +4 -0
- pyobject-1.2.9/pyobject/tests/test_objproxy.py +128 -0
- {pyobject-1.2.8 → pyobject-1.2.9/pyobject.egg-info}/PKG-INFO +20 -14
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject.egg-info/SOURCES.txt +3 -1
- {pyobject-1.2.8 → pyobject-1.2.9}/setup.py +2 -1
- pyobject-1.2.8/pyobject/objproxy/__init__.py +0 -522
- pyobject-1.2.8/pyobject/objproxy/utils.py +0 -54
- pyobject-1.2.8/pyobject/tests/test_objproxy.py +0 -67
- {pyobject-1.2.8 → pyobject-1.2.9}/LICENSE +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/MANIFEST.in +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/browser.py +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/examples/README.md +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/examples/__init__.py +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/examples/empty_cp37.pyc +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/examples/pyc_zipper_unpack.py +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/examples/pyc_zipper_zlib.py +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/examples/test_inject.py +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/back.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/codeobject.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/dict.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/empty_dict.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/empty_list.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/empty_tuple.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/forward.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/function.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/list.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/number.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/python.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/python.ico +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/refresh.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/string.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/images/tuple.gif +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject/other/browser_chs_locale.py +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject.egg-info/dependency_links.txt +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject.egg-info/requires.txt +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/pyobject.egg-info/top_level.txt +0 -0
- {pyobject-1.2.8 → pyobject-1.2.9}/setup.cfg +0 -0
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyobject
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.9
|
|
4
4
|
Summary: A multifunctional all-in-one utility tool for managing internal Python objects, compatible with nearly all Python 3 versions. 一个多功能合一的提供操作Python对象底层工具的Python包, 支持几乎所有Python 3版本。
|
|
5
5
|
Home-page: https://github.com/qfcy/pyobject
|
|
6
6
|
Author: qfcy
|
|
7
7
|
Author-email: 3076711200@qq.com
|
|
8
|
-
Keywords: pyobject,python,object,utility,object browser,bytecode,reflect,object search,OOP
|
|
8
|
+
Keywords: pyobject,python,object,utility,object browser,bytecode,reflect,object search,OOP,reverse,对象,字节码,逆向
|
|
9
9
|
Classifier: Programming Language :: Python
|
|
10
10
|
Classifier: Topic :: Utilities
|
|
11
11
|
Classifier: Topic :: Software Development :: Bug Tracking
|
|
12
12
|
Classifier: Topic :: Software Development :: Debuggers
|
|
13
|
+
Classifier: Topic :: Software Development :: Object Brokering
|
|
13
14
|
Classifier: Topic :: Software Development :: Testing
|
|
14
15
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
16
|
License-File: LICENSE
|
|
@@ -21,19 +22,19 @@ versions.
|
|
|
21
22
|
|
|
22
23
|
**The English introduction is shown below the Chinese version.**
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
子模块
|
|
26
|
+
------
|
|
26
27
|
|
|
27
28
|
pyobject.\__init\_\_ - 显示和输出Python对象的各个属性值
|
|
28
29
|
|
|
29
30
|
pyobject.browser - 调用tkinter,浏览Python对象的图形界面
|
|
30
31
|
|
|
31
|
-
pyobject.code
|
|
32
|
+
pyobject.code - Python 底层字节码(bytecode)的操作工具
|
|
32
33
|
|
|
33
|
-
pyobject.search -
|
|
34
|
+
pyobject.search - 以一个对象为起点,查找和搜索能到达的所有python对象
|
|
34
35
|
|
|
35
36
|
pyobject.objproxy -
|
|
36
|
-
|
|
37
|
+
实现一个通用的对象代理,能够代理任意Python对象,包括模块,函数和类
|
|
37
38
|
|
|
38
39
|
pyobject.pyobj_extension - C扩展模块, 提供操作Python对象底层的函数
|
|
39
40
|
|
|
@@ -197,7 +198,7 @@ Python内部的字节码对象\ ``CodeType``\ ,如\ ``func.__code__``\ ,是
|
|
|
197
198
|
|
|
198
199
|
- 属性\ ``co_lnotab``\ :在3.10以上的版本中,如果尝试设置\ ``co_lnotab``\ 属性,会自动转换成设置\ ``co_linetable``\ 。
|
|
199
200
|
|
|
200
|
-
示例用法: (
|
|
201
|
+
示例用法: (从doctest中摘取):
|
|
201
202
|
|
|
202
203
|
.. code:: python
|
|
203
204
|
|
|
@@ -244,7 +245,7 @@ Python内部的字节码对象\ ``CodeType``\ ,如\ ``func.__code__``\ ,是
|
|
|
244
245
|
plt = chain.new_object("import matplotlib.pyplot as plt","plt",
|
|
245
246
|
export_funcs = ["show"])
|
|
246
247
|
|
|
247
|
-
#
|
|
248
|
+
# 测试调用代理后的numpy, matplotlib模块
|
|
248
249
|
arr = np.array(range(1,11))
|
|
249
250
|
arr_squared = arr ** 2
|
|
250
251
|
print(np.mean(arr)) # 输出平均值
|
|
@@ -393,11 +394,12 @@ Python内部的字节码对象\ ``CodeType``\ ,如\ ``func.__code__``\ ,是
|
|
|
393
394
|
lst调用多次==运算符(``__eq__``)相比,
|
|
394
395
|
本函数直接比较对象的指针,提高了效率。
|
|
395
396
|
|
|
396
|
-
**``pyobject``\ 当前版本**: 1.2.
|
|
397
|
+
**``pyobject``\ 当前版本**: 1.2.9
|
|
397
398
|
|
|
398
399
|
更新日志:
|
|
399
400
|
---------
|
|
400
401
|
|
|
402
|
+
| 2025-4-30(v1.2.9):改进和增强了子模块pyobject.objproxy,重命名子模块pyobject.code_为pyobject.code。
|
|
401
403
|
| 2025-3-31(v1.2.8):将pyobject.super_proxy重命名为pyobject.objproxy,并正式发布;修改了pyobject.pyobj_extension模块。
|
|
402
404
|
| 2025-3-6(v1.2.7):为pyobject.browser新增了\ ``dir()``\ 中不存在的类属性(如\ ``__flags__``,
|
|
403
405
|
``__mro__``\ ),修改了pyobj_extension模块。
|
|
@@ -412,6 +414,8 @@ lst调用多次==运算符(``__eq__``)相比,
|
|
|
412
414
|
code_中增加了Code类, browser中增加编辑属性功能,
|
|
413
415
|
增加了Code类的doctest。
|
|
414
416
|
|
|
417
|
+
--------------
|
|
418
|
+
|
|
415
419
|
Submodules:
|
|
416
420
|
-----------
|
|
417
421
|
|
|
@@ -421,8 +425,7 @@ objects.
|
|
|
421
425
|
pyobject.browser - Provides a visual interface to browse Python objects
|
|
422
426
|
using tkinter.
|
|
423
427
|
|
|
424
|
-
pyobject.code
|
|
425
|
-
bytecode.
|
|
428
|
+
pyobject.code - Provides tools for manipulating Python native bytecode.
|
|
426
429
|
|
|
427
430
|
pyobject.search - Implements the utility for locating the path to a
|
|
428
431
|
specific object.
|
|
@@ -625,7 +628,7 @@ Compatibility Details
|
|
|
625
628
|
the ``co_lnotab`` attribute will automatically be converted into
|
|
626
629
|
setting the ``co_linetable`` attribute.
|
|
627
630
|
|
|
628
|
-
Example usage: (excerpted from the
|
|
631
|
+
Example usage: (excerpted from the doctest):
|
|
629
632
|
|
|
630
633
|
.. code:: python
|
|
631
634
|
|
|
@@ -883,11 +886,14 @@ Python call “obj in lst” that invokes the “==” operator (``__eq__``)
|
|
|
883
886
|
multiple times, this function directly compares the pointers to improve
|
|
884
887
|
efficiency.
|
|
885
888
|
|
|
886
|
-
**Current Version of ``pyobject``**: 1.2.
|
|
889
|
+
**Current Version of ``pyobject``**: 1.2.9
|
|
887
890
|
|
|
888
891
|
Change Log
|
|
889
892
|
----------
|
|
890
893
|
|
|
894
|
+
| 2025-4-30(v1.2.9): Improved and enhanced the sub-module
|
|
895
|
+
``pyobject.objproxy``, and renamed the sub-module ``pyobject.code_``
|
|
896
|
+
to ``pyobject.code``.
|
|
891
897
|
| 2025-3-31(v1.2.8): Renamed pyobject.super_proxy to pyobject.objproxy
|
|
892
898
|
and officially released it; modified the pyobject.pyobj_extension
|
|
893
899
|
module.
|
|
@@ -5,19 +5,19 @@ versions.
|
|
|
5
5
|
|
|
6
6
|
**The English introduction is shown below the Chinese version.**
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
子模块
|
|
9
|
+
------
|
|
10
10
|
|
|
11
11
|
pyobject.\__init\_\_ - 显示和输出Python对象的各个属性值
|
|
12
12
|
|
|
13
13
|
pyobject.browser - 调用tkinter,浏览Python对象的图形界面
|
|
14
14
|
|
|
15
|
-
pyobject.code
|
|
15
|
+
pyobject.code - Python 底层字节码(bytecode)的操作工具
|
|
16
16
|
|
|
17
|
-
pyobject.search -
|
|
17
|
+
pyobject.search - 以一个对象为起点,查找和搜索能到达的所有python对象
|
|
18
18
|
|
|
19
19
|
pyobject.objproxy -
|
|
20
|
-
|
|
20
|
+
实现一个通用的对象代理,能够代理任意Python对象,包括模块,函数和类
|
|
21
21
|
|
|
22
22
|
pyobject.pyobj_extension - C扩展模块, 提供操作Python对象底层的函数
|
|
23
23
|
|
|
@@ -181,7 +181,7 @@ Python内部的字节码对象\ ``CodeType``\ ,如\ ``func.__code__``\ ,是
|
|
|
181
181
|
|
|
182
182
|
- 属性\ ``co_lnotab``\ :在3.10以上的版本中,如果尝试设置\ ``co_lnotab``\ 属性,会自动转换成设置\ ``co_linetable``\ 。
|
|
183
183
|
|
|
184
|
-
示例用法: (
|
|
184
|
+
示例用法: (从doctest中摘取):
|
|
185
185
|
|
|
186
186
|
.. code:: python
|
|
187
187
|
|
|
@@ -228,7 +228,7 @@ Python内部的字节码对象\ ``CodeType``\ ,如\ ``func.__code__``\ ,是
|
|
|
228
228
|
plt = chain.new_object("import matplotlib.pyplot as plt","plt",
|
|
229
229
|
export_funcs = ["show"])
|
|
230
230
|
|
|
231
|
-
#
|
|
231
|
+
# 测试调用代理后的numpy, matplotlib模块
|
|
232
232
|
arr = np.array(range(1,11))
|
|
233
233
|
arr_squared = arr ** 2
|
|
234
234
|
print(np.mean(arr)) # 输出平均值
|
|
@@ -377,11 +377,12 @@ Python内部的字节码对象\ ``CodeType``\ ,如\ ``func.__code__``\ ,是
|
|
|
377
377
|
lst调用多次==运算符(``__eq__``)相比,
|
|
378
378
|
本函数直接比较对象的指针,提高了效率。
|
|
379
379
|
|
|
380
|
-
**``pyobject``\ 当前版本**: 1.2.
|
|
380
|
+
**``pyobject``\ 当前版本**: 1.2.9
|
|
381
381
|
|
|
382
382
|
更新日志:
|
|
383
383
|
---------
|
|
384
384
|
|
|
385
|
+
| 2025-4-30(v1.2.9):改进和增强了子模块pyobject.objproxy,重命名子模块pyobject.code_为pyobject.code。
|
|
385
386
|
| 2025-3-31(v1.2.8):将pyobject.super_proxy重命名为pyobject.objproxy,并正式发布;修改了pyobject.pyobj_extension模块。
|
|
386
387
|
| 2025-3-6(v1.2.7):为pyobject.browser新增了\ ``dir()``\ 中不存在的类属性(如\ ``__flags__``,
|
|
387
388
|
``__mro__``\ ),修改了pyobj_extension模块。
|
|
@@ -396,6 +397,8 @@ lst调用多次==运算符(``__eq__``)相比,
|
|
|
396
397
|
code_中增加了Code类, browser中增加编辑属性功能,
|
|
397
398
|
增加了Code类的doctest。
|
|
398
399
|
|
|
400
|
+
--------------
|
|
401
|
+
|
|
399
402
|
Submodules:
|
|
400
403
|
-----------
|
|
401
404
|
|
|
@@ -405,8 +408,7 @@ objects.
|
|
|
405
408
|
pyobject.browser - Provides a visual interface to browse Python objects
|
|
406
409
|
using tkinter.
|
|
407
410
|
|
|
408
|
-
pyobject.code
|
|
409
|
-
bytecode.
|
|
411
|
+
pyobject.code - Provides tools for manipulating Python native bytecode.
|
|
410
412
|
|
|
411
413
|
pyobject.search - Implements the utility for locating the path to a
|
|
412
414
|
specific object.
|
|
@@ -609,7 +611,7 @@ Compatibility Details
|
|
|
609
611
|
the ``co_lnotab`` attribute will automatically be converted into
|
|
610
612
|
setting the ``co_linetable`` attribute.
|
|
611
613
|
|
|
612
|
-
Example usage: (excerpted from the
|
|
614
|
+
Example usage: (excerpted from the doctest):
|
|
613
615
|
|
|
614
616
|
.. code:: python
|
|
615
617
|
|
|
@@ -867,11 +869,14 @@ Python call “obj in lst” that invokes the “==” operator (``__eq__``)
|
|
|
867
869
|
multiple times, this function directly compares the pointers to improve
|
|
868
870
|
efficiency.
|
|
869
871
|
|
|
870
|
-
**Current Version of ``pyobject``**: 1.2.
|
|
872
|
+
**Current Version of ``pyobject``**: 1.2.9
|
|
871
873
|
|
|
872
874
|
Change Log
|
|
873
875
|
----------
|
|
874
876
|
|
|
877
|
+
| 2025-4-30(v1.2.9): Improved and enhanced the sub-module
|
|
878
|
+
``pyobject.objproxy``, and renamed the sub-module ``pyobject.code_``
|
|
879
|
+
to ``pyobject.code``.
|
|
875
880
|
| 2025-3-31(v1.2.8): Renamed pyobject.super_proxy to pyobject.objproxy
|
|
876
881
|
and officially released it; modified the pyobject.pyobj_extension
|
|
877
882
|
module.
|
|
@@ -6,14 +6,15 @@ import sys
|
|
|
6
6
|
from warnings import warn
|
|
7
7
|
from pprint import pprint
|
|
8
8
|
|
|
9
|
-
__version__="1.2.
|
|
9
|
+
__version__="1.2.9"
|
|
10
10
|
|
|
11
11
|
__all__=["objectname","bases","describe","desc"]
|
|
12
12
|
_ignore_names=["__builtins__","__doc__"]
|
|
13
13
|
|
|
14
|
+
MAXLENGTH=150
|
|
15
|
+
|
|
14
16
|
def objectname(obj):
|
|
15
|
-
|
|
16
|
-
For example: objectname(int) -> 'builtins.int'."""
|
|
17
|
+
# 返回对象的全名,类似__qualname__属性
|
|
17
18
|
# if hasattr(obj,"__qualname__"):return obj.__qualname__
|
|
18
19
|
if not obj.__class__==type:obj=obj.__class__
|
|
19
20
|
if not hasattr(obj,"__module__") or obj.__module__=="__main__":
|
|
@@ -21,8 +22,7 @@ For example: objectname(int) -> 'builtins.int'."""
|
|
|
21
22
|
return "{}.{}".format(obj.__module__,obj.__name__)
|
|
22
23
|
|
|
23
24
|
def bases(obj,level=0,tab=4):
|
|
24
|
-
|
|
25
|
-
tab: The number of spaces for indentation, default is 4.'''
|
|
25
|
+
# 打印对象的基类
|
|
26
26
|
if not obj.__class__==type:obj=obj.__class__
|
|
27
27
|
if obj.__bases__:
|
|
28
28
|
if level:print(' '*(level*tab),end='')
|
|
@@ -31,8 +31,9 @@ tab: The number of spaces for indentation, default is 4.'''
|
|
|
31
31
|
bases(cls,level,tab)
|
|
32
32
|
|
|
33
33
|
_trans_table=str.maketrans("\n\t"," ") # 替换特殊字符为空格
|
|
34
|
-
def shortrepr(obj,maxlength=
|
|
35
|
-
|
|
34
|
+
def shortrepr(obj,maxlength=MAXLENGTH,repr_func=None):
|
|
35
|
+
if repr_func is None:repr_func = repr
|
|
36
|
+
result=repr_func(obj).translate(_trans_table)
|
|
36
37
|
if len(result)>maxlength:
|
|
37
38
|
return result[:maxlength]+"..."
|
|
38
39
|
return result
|
|
@@ -53,7 +54,7 @@ file: A file-like object for printing output.
|
|
|
53
54
|
elif level>maxlevel:raise ValueError(
|
|
54
55
|
"Argument level is larger than maxlevel")
|
|
55
56
|
else:
|
|
56
|
-
print(
|
|
57
|
+
print(shortrepr(obj)+': ',file=file)
|
|
57
58
|
if type(obj) is type:
|
|
58
59
|
print("Base classes of the object:",file=file)
|
|
59
60
|
bases(obj,level+1,tab)
|
|
@@ -65,7 +66,7 @@ file: A file-like object for printing output.
|
|
|
65
66
|
if not attr in _ignore_names:
|
|
66
67
|
describe(getattr(obj,attr),level+1,maxlevel,
|
|
67
68
|
tab,verbose,file)
|
|
68
|
-
else:print(
|
|
69
|
+
else:print(shortrepr(getattr(obj,attr)),file=file)
|
|
69
70
|
except AttributeError:
|
|
70
71
|
print("<AttributeError!>",file=file)
|
|
71
72
|
|
|
@@ -84,9 +85,9 @@ try:
|
|
|
84
85
|
except (ImportError,SystemError):warn("Failed to import pyobject.search.")
|
|
85
86
|
|
|
86
87
|
try:
|
|
87
|
-
from pyobject.
|
|
88
|
+
from pyobject.code import Code
|
|
88
89
|
__all__.append("Code")
|
|
89
|
-
except (ImportError,SystemError):warn("Failed to import pyobject.
|
|
90
|
+
except (ImportError,SystemError):warn("Failed to import pyobject.code.")
|
|
90
91
|
try:
|
|
91
92
|
from pyobject.pyobj_extension import *
|
|
92
93
|
__all__.extend(["convptr","py_incref","py_decref","getrealrefcount",
|
|
@@ -96,17 +97,16 @@ try:
|
|
|
96
97
|
"set_type_subclasses_by_cls"])
|
|
97
98
|
except ImportError:warn("Failed to import pyobject.pyobj_extension.")
|
|
98
99
|
try:
|
|
99
|
-
from pyobject.objproxy import DynObj,ObjChain,ProxiedObj
|
|
100
|
-
__all__.extend(["DynObj","ObjChain","ProxiedObj"])
|
|
101
|
-
except ImportError
|
|
100
|
+
from pyobject.objproxy import DynObj,ObjChain,ProxiedObj,accept_raw_obj
|
|
101
|
+
__all__.extend(["DynObj","ObjChain","ProxiedObj","accept_raw_obj"])
|
|
102
|
+
except (ImportError, SyntaxError):
|
|
103
|
+
warn("Failed to import pyobject.objproxy.") # SyntaxError: Python 3.5及以下不支持f-string
|
|
102
104
|
|
|
103
|
-
def
|
|
105
|
+
def desc_demo():
|
|
104
106
|
try:
|
|
105
107
|
describe(type,verbose=True)
|
|
106
108
|
except BaseException as err:
|
|
107
109
|
print("STOPPED!",file=sys.stderr)
|
|
108
|
-
if
|
|
109
|
-
return 1
|
|
110
|
-
else:return 0
|
|
110
|
+
if type(err) is not KeyboardInterrupt:raise
|
|
111
111
|
|
|
112
|
-
if __name__=="__main__":
|
|
112
|
+
if __name__=="__main__":desc_demo()
|