Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
H
hookify
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
hookify
Commits
628f53e3
Kaydet (Commit)
628f53e3
authored
Mar 02, 2019
tarafından
Batuhan Taşkaya
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
init
üst
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
359 additions
and
0 deletions
+359
-0
.gitignore
.gitignore
+185
-0
Makefile
Makefile
+7
-0
README.md
README.md
+1
-0
hookify.c
hookify.c
+150
-0
setup.py
setup.py
+16
-0
No files found.
.gitignore
0 → 100644
Dosyayı görüntüle @
628f53e3
# Created by https://www.gitignore.io/api/python
# Edit at https://www.gitignore.io/?templates=python
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
### Python Patch ###
.venv/
# End of https://www.gitignore.io/api/python
# Created by https://www.gitignore.io/api/c
# Edit at https://www.gitignore.io/?templates=c
### C ###
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
# End of https://www.gitignore.io/api/c
Makefile
0 → 100644
Dosyayı görüntüle @
628f53e3
.PHONY
:
clean
hookify.so
:
hookify.c
gcc
`
python-config
--cflags
`
`
python-config
--includes
`
-Wl
,--export-dynamic
-fPIC
-shared
-o
$@
$^
-ldl
`
python-config
--libs
`
clean
:
rm
hookify.so
README.md
0 → 100644
Dosyayı görüntüle @
628f53e3
Helper package to
[
catlizor
](
https://github.com/btaskaya/catlizor
)
hookify.c
0 → 100644
Dosyayı görüntüle @
628f53e3
#include <Python.h>
#include <sys/mman.h>
#pragma pack(push, 1)
static
struct
{
char
push_rax
;
char
mov_rax
[
2
];
char
addr
[
8
];
char
jmp_rax
[
2
];
}
jumper
=
{
.
push_rax
=
0x50
,
.
mov_rax
=
{
0x48
,
0xb8
},
.
jmp_rax
=
{
0xff
,
0xe0
}
};
#pragma pack(pop)
#define CATLIZED_SIGN "__catlized"
#define CAPI_METHOD "exc_capi"
extern
PyObject
*
_PyFunction_FastCallKeywords
(
PyObject
*
func
,
PyObject
*
const
*
stack
,
Py_ssize_t
nargs
,
PyObject
*
kwnames
);
static
int
unprotect_page
(
void
*
addr
)
{
return
mprotect
((
char
*
)((
size_t
)
addr
&
~
(
sysconf
(
_SC_PAGE_SIZE
)
-
1
)),
sysconf
(
_SC_PAGE_SIZE
),
PROT_READ
|
PROT_WRITE
|
PROT_EXEC
);
}
int
hookifier
(
void
*
target
,
void
*
replace
)
{
/* Some parts based on libhook */
int
count
;
if
(
unprotect_page
(
replace
)
||
unprotect_page
(
target
))
{
return
1
;
}
for
(
count
=
0
;
count
<
255
&&
((
unsigned
char
*
)
replace
)[
count
]
!=
0x90
;
++
count
);
if
(
count
==
255
)
{
return
1
;
}
memmove
(
replace
+
1
,
replace
,
count
);
*
((
unsigned
char
*
)
replace
)
=
0x58
;
memcpy
(
jumper
.
addr
,
&
replace
,
sizeof
(
void
*
));
memcpy
(
target
,
&
jumper
,
sizeof
jumper
);
return
0
;
}
PyObject
*
hookify_PyFunction_FastCallKeywords
(
PyObject
*
func
,
PyObject
*
const
*
stack
,
Py_ssize_t
nargs
,
PyObject
*
kwnames
)
{
__asm__
(
"NOP"
);
PyCodeObject
*
co
=
(
PyCodeObject
*
)
PyFunction_GET_CODE
(
func
);
PyObject
*
globals
=
PyFunction_GET_GLOBALS
(
func
);
PyObject
*
argdefs
=
PyFunction_GET_DEFAULTS
(
func
);
PyObject
*
kwdefs
,
*
closure
,
*
name
,
*
qualname
;
PyObject
**
d
;
Py_ssize_t
nkwargs
=
(
kwnames
==
NULL
)
?
0
:
PyTuple_GET_SIZE
(
kwnames
);
Py_ssize_t
nd
;
PyObject
*
w
,
*
args
,
*
instance
,
*
catlizor
,
*
meth_name
,
*
tracked
,
*
hooks
;
int
i
,
n
,
pre
=
0
,
on_call
=
0
,
post
=
0
;
assert
(
PyFunction_Check
(
func
));
assert
(
nargs
>=
0
);
assert
(
kwnames
==
NULL
||
PyTuple_CheckExact
(
kwnames
));
assert
((
nargs
==
0
&&
nkwargs
==
0
)
||
stack
!=
NULL
);
kwdefs
=
PyFunction_GET_KW_DEFAULTS
(
func
);
closure
=
PyFunction_GET_CLOSURE
(
func
);
name
=
((
PyFunctionObject
*
)
func
)
->
func_name
;
qualname
=
((
PyFunctionObject
*
)
func
)
->
func_qualname
;
if
(
argdefs
!=
NULL
)
{
d
=
&
PyTuple_GET_ITEM
(
argdefs
,
0
);
nd
=
PyTuple_GET_SIZE
(
argdefs
);
}
else
{
d
=
NULL
;
nd
=
0
;
}
if
(
nargs
>
co
->
co_argcount
)
{
n
=
co
->
co_argcount
;
}
else
{
n
=
nargs
;
}
args
=
PyList_New
(
n
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
w
=
stack
[
i
];
Py_INCREF
(
w
);
PyList_SetItem
(
args
,
i
,
w
);
}
instance
=
PyList_GetItem
(
args
,
0
);
if
(
PyObject_HasAttrString
(
instance
,
CATLIZED_SIGN
)){
catlizor
=
PyObject_GetAttrString
(
instance
,
CATLIZED_SIGN
);
meth_name
=
PyObject_GetAttrString
(
func
,
"__name__"
);
tracked
=
PyObject_CallMethod
(
catlizor
,
"tracked"
,
"(OO)"
,
meth_name
,
Py_True
);
if
(
PySet_Check
(
tracked
)
&&
PySet_Size
(
tracked
)
>
0
){
pre
=
PySet_Contains
(
tracked
,
PyLong_FromLong
(
0
));
on_call
=
PySet_Contains
(
tracked
,
PyLong_FromLong
(
1
));
post
=
PySet_Contains
(
tracked
,
PyLong_FromLong
(
2
));
}
}
if
(
pre
)
PyObject_CallMethod
(
catlizor
,
CAPI_METHOD
,
"(iOOO)"
,
0
,
func
,
args
,
Py_None
);
PyObject
*
result
=
_PyEval_EvalCodeWithName
((
PyObject
*
)
co
,
globals
,
(
PyObject
*
)
NULL
,
stack
,
nargs
,
nkwargs
?
&
PyTuple_GET_ITEM
(
kwnames
,
0
)
:
NULL
,
stack
+
nargs
,
nkwargs
,
1
,
d
,
(
int
)
nd
,
kwdefs
,
closure
,
name
,
qualname
);
if
(
on_call
)
PyObject_CallMethod
(
catlizor
,
CAPI_METHOD
,
"(iOOO)"
,
1
,
func
,
args
,
result
);
if
(
post
)
PyObject_CallMethod
(
catlizor
,
CAPI_METHOD
,
"(iOOO)"
,
2
,
func
,
args
,
Py_None
);
return
result
;
}
static
PyMethodDef
module_methods
[]
=
{
{
NULL
}
};
static
struct
PyModuleDef
hookify
=
{
PyModuleDef_HEAD_INIT
,
"hookify"
,
NULL
,
-
1
,
module_methods
};
PyMODINIT_FUNC
PyInit_hookify
(
void
)
{
__asm__
(
""
);
hookifier
(
_PyFunction_FastCallKeywords
,
&
hookify_PyFunction_FastCallKeywords
);
return
PyModule_Create
(
&
hookify
);
}
setup.py
0 → 100644
Dosyayı görüntüle @
628f53e3
from
setuptools
import
setup
,
Extension
hookify
=
Extension
(
name
=
'hookify'
,
sources
=
[
'hookify.c'
],
)
setup
(
name
=
'hookify'
,
version
=
'1.0.0'
,
author
=
'BTaskaya'
,
author_email
=
'batuhanosmantaskaya@gmail.com'
,
url
=
"https://github.com/btaskaya/hookify"
,
description
=
"Helper package to catlizor v1-extended series."
,
ext_modules
=
[
hookify
]
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment