fishhook 0.3.1__tar.gz → 0.3.3__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.
@@ -1,18 +1,19 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: fishhook
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: Allows for runtime hooking of static class functions
5
- Home-page: https://github.com/chilaxan/fishhook
6
- Author: chilaxan
7
- Author-email: chilaxan@gmail.com
5
+ Author-email: chilaxan <chilaxan@gmail.com>
6
+ License: MIT
7
+ Project-URL: repository, https://github.com/chilaxan/fishhook
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
11
11
  Requires-Python: >=3.8
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
- Requires-Dist: capstone
15
- Requires-Dist: keystone-engine
14
+ Requires-Dist: capstone; os_name != "nt"
15
+ Requires-Dist: keystone-engine; os_name != "nt"
16
+ Dynamic: license-file
16
17
 
17
18
  # Fishhook
18
19
 
@@ -50,14 +50,16 @@ void changeProts(Py_buffer buffer, int prots) {
50
50
  }
51
51
 
52
52
  void invalidateInstructionCache(void *addr, size_t length) {
53
- #if defined(__x86_64__) || defined(_M_X64)
54
- // x86 invalidates cache for us
53
+ #if defined(_WIN32)
54
+ FlushInstructionCache(GetCurrentProcess(), (unsigned char*)addr, length);
55
55
  #elif defined(__has_builtin)
56
56
  #if __has_builtin(__builtin___clear_cache)
57
57
  __builtin___clear_cache((char*)addr, (char*)(addr + length));
58
58
  #endif
59
59
  #else
60
- #error "cannot determine way to clear instruction cache (required on arm64, otherwise make an issue here: https://github.com/chilaxan/fishhook)"
60
+ // cannot determine way to clear instruction cache
61
+ // things might work, and might not
62
+ // If you get weird crashes, make an issue: https://github.com/chilaxan/fishhook
61
63
  #endif
62
64
  }
63
65
 
@@ -81,7 +83,7 @@ static PyObject *method_writeExecutableMemory(PyObject *self, PyObject *args, Py
81
83
  }
82
84
 
83
85
  if (target_buf.len != src_buf.len) {
84
- PyErr_SetString(PyExc_ValueError, "target and dest must be the same length");
86
+ PyErr_SetString(PyExc_ValueError, "target and src must be the same length");
85
87
  return NULL;
86
88
  }
87
89
 
@@ -1,13 +1,10 @@
1
1
  from ctypes import *
2
2
  import platform
3
+ import weakref
3
4
 
4
5
  if platform.system() == 'Windows':
5
6
  raise RuntimeError('fishhook.asm does not currently work on Windows')
6
7
 
7
- import sys
8
- import weakref
9
- import capstone as CS
10
- import keystone as KS
11
8
  from ._asm import writeExecutableMemory
12
9
  from .fishhook import getmem
13
10
  from .jit import TRAMPOLINE
@@ -212,7 +212,7 @@ def build_orig():
212
212
  int_add = int.__add__
213
213
  int_and = int.__and__
214
214
  int_bool = int.__bool__
215
- dict_get = dict.get
215
+ locals_get = type(get_locals(getframe())).get # this enables compat with >= 3.13 FrameLocalsProxy
216
216
  flags = {v: k for k, v in dis.COMPILER_FLAG_NAMES.items()}.get
217
217
  new_slice = slice.__call__
218
218
  get_class = vars(object)['__class__'].__get__
@@ -248,7 +248,7 @@ def build_orig():
248
248
  varargs = None
249
249
  if int_bool(int_and(get_flags(co), flags('VARARGS'))):
250
250
  varargs = tuple_getitem(names, nargs)
251
- argvals = (*(dict_get(locals, arg, NULL) for arg in tuple_iter(args)), *dict_get(locals, varargs, ()))
251
+ argvals = (*(locals_get(locals, arg, NULL) for arg in tuple_iter(args)), *locals_get(locals, varargs, ()))
252
252
  if int_bool(tuple_len(argvals)) and (self := tuple_getitem(argvals, 0)) is not NULL:
253
253
  return self
254
254
  raise RuntimeError('unable to bind self')
@@ -2,7 +2,24 @@ from ctypes import *
2
2
  import sys
3
3
  import platform
4
4
 
5
- import capstone as CS
5
+ try:
6
+ import capstone as CS
7
+ except ModuleNotFoundError as err:
8
+ if err.name == 'distutils':
9
+ # capstone depends on distutils and pkg_resources, but in most configs does not need them
10
+ # 3.12+ has deprecated these modules
11
+ # we can stub them out and re-attempt the import
12
+ class stub:
13
+ def __getattr__(self, attr):
14
+ return self
15
+ def __call__(self, *args):
16
+ return ''
17
+
18
+ sys.modules['distutils'] = stub()
19
+ sys.modules['distutils.sysconfig'] = stub()
20
+ sys.modules['pkg_resources'] = stub()
21
+ import capstone as CS
22
+
6
23
  import keystone as KS
7
24
 
8
25
  ENDIAN = 'LITTLE' if memoryview(b'\1\0').cast('h')[0]==1 else 'BIG'
@@ -63,7 +80,7 @@ def size_to_typ(n):
63
80
  elif n == 8:
64
81
  return 'QWORD'
65
82
  else:
66
- raise RuntimeError(f'x86 memory size {n} is unsupported')
83
+ raise RuntimeError(f'x86 register memory size {n} is unsupported')
67
84
 
68
85
  def inst(n, *args):
69
86
  return fragements[ARCH][n].format(*args)
@@ -77,8 +94,8 @@ def TRAMPOLINE(address, storage=None, registers=()):
77
94
  field = getattr(type(storage), register)
78
95
  offset = field.offset
79
96
  typ = size_to_typ(field.size)
80
- header += inst('store_mem', register, TMP_REG, offset, *((typ,) if typ else ()))
81
- footer += inst('read_mem', register, TMP_REG, offset, *((typ,) if typ else ()))
97
+ header += inst('store_mem', register, TMP_REG, offset, typ)
98
+ footer += inst('read_mem', register, TMP_REG, offset, typ)
82
99
  else:
83
100
  header = footer = ''
84
101
 
@@ -1,18 +1,19 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: fishhook
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: Allows for runtime hooking of static class functions
5
- Home-page: https://github.com/chilaxan/fishhook
6
- Author: chilaxan
7
- Author-email: chilaxan@gmail.com
5
+ Author-email: chilaxan <chilaxan@gmail.com>
6
+ License: MIT
7
+ Project-URL: repository, https://github.com/chilaxan/fishhook
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
11
11
  Requires-Python: >=3.8
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
- Requires-Dist: capstone
15
- Requires-Dist: keystone-engine
14
+ Requires-Dist: capstone; os_name != "nt"
15
+ Requires-Dist: keystone-engine; os_name != "nt"
16
+ Dynamic: license-file
16
17
 
17
18
  # Fishhook
18
19
 
@@ -1,5 +1,6 @@
1
1
  LICENSE
2
2
  README.md
3
+ pyproject.toml
3
4
  setup.py
4
5
  fishhook/__init__.py
5
6
  fishhook/_asmmodule.c
@@ -1,2 +1,4 @@
1
+
2
+ [:os_name != "nt"]
1
3
  capstone
2
4
  keystone-engine
@@ -0,0 +1,29 @@
1
+ [project]
2
+ name = "fishhook"
3
+ version = "0.3.3"
4
+ description = "Allows for runtime hooking of static class functions"
5
+ authors = [
6
+ { name = "chilaxan", email = "chilaxan@gmail.com" },
7
+ ]
8
+ license = { text = "MIT" }
9
+ readme = "README.md"
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "License :: OSI Approved :: MIT License",
13
+ "Operating System :: OS Independent",
14
+ ]
15
+ requires-python = ">=3.8"
16
+ dependencies = [
17
+ "capstone; os_name != 'nt'",
18
+ "keystone-engine; os_name != 'nt'",
19
+ ]
20
+
21
+ [project.urls]
22
+ repository = "https://github.com/chilaxan/fishhook"
23
+
24
+ [build-system]
25
+ requires = ["setuptools"]
26
+ build-backend = "setuptools.build_meta"
27
+
28
+ [tool.setuptools]
29
+ packages = ["fishhook"]
@@ -0,0 +1,7 @@
1
+ import setuptools
2
+
3
+ setuptools.setup(
4
+ ext_modules=[
5
+ setuptools.Extension("fishhook._asm", sources=["fishhook/_asmmodule.c"])
6
+ ],
7
+ )
fishhook-0.3.1/setup.py DELETED
@@ -1,24 +0,0 @@
1
- import setuptools
2
-
3
- with open("README.md", "r") as fh:
4
- long_description = fh.read()
5
-
6
- setuptools.setup(
7
- name="fishhook",
8
- version="0.3.1",
9
- author="chilaxan",
10
- author_email="chilaxan@gmail.com",
11
- description="Allows for runtime hooking of static class functions",
12
- long_description=long_description,
13
- long_description_content_type="text/markdown",
14
- url="https://github.com/chilaxan/fishhook",
15
- packages=['fishhook'],
16
- classifiers=[
17
- "Programming Language :: Python :: 3",
18
- "License :: OSI Approved :: MIT License",
19
- "Operating System :: OS Independent",
20
- ],
21
- python_requires='>=3.8',
22
- ext_modules=[setuptools.Extension('fishhook._asm', sources=['fishhook/_asmmodule.c'])],
23
- install_requires=['capstone', 'keystone-engine']
24
- )
File without changes
File without changes
File without changes
File without changes
File without changes