Kaydet (Commit) 06ab74b7 authored tarafından Batuhan Osman TASKAYA's avatar Batuhan Osman TASKAYA

ceviri

üst 9b8281ec
.PHONY: clean
hookify.so: hookify.c lpyhook.c
gcc `python-config --cflags` `python-config --includes` -Wl,--export-dynamic -fPIC -shared -o $@ $^ -ldl `python-config --libs`
lpyhook.c:
python lpyhook.py
clean:
rm hookify.so lpyhook.c lpyhook.h
#include <Python.h>
#include "lpyhook.h"
extern PyObject* PyObject_GetAttr(PyObject *v, PyObject *name);
PyObject *
translated_PyObject_GetAttr(PyObject *v, PyObject *name)
{
__asm__("NOP");
PyTypeObject *tp = Py_TYPE(v);
printf("%s", PyUnicode_AsUTF8(name));
if (!PyUnicode_Check(name)) {
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
name->ob_type->tp_name);
return NULL;
}
if (tp->tp_getattro != NULL)
return (*tp->tp_getattro)(v, name);
if (tp->tp_getattr != NULL) {
const char *name_str = PyUnicode_AsUTF8(name);
if (name_str == NULL)
return NULL;
return (*tp->tp_getattr)(v, (char *)name_str);
}
PyErr_Format(PyExc_AttributeError,
"'%.50s' object has no attribute '%U'",
tp->tp_name, name);
return NULL;
}
static PyMethodDef module_methods[] = {
{NULL}
};
static struct PyModuleDef ceviri =
{
PyModuleDef_HEAD_INIT,
"ceviri",
NULL,
-1,
module_methods
};
PyMODINIT_FUNC PyInit_ceviri(void) {
__asm__("");
lpyhook(PyObject_GetAttr, &translated_PyObject_GetAttr);
return PyModule_Create(&ceviri);
}
def try_to_guess(attr, possible_words, language):
if language == "tr":
pass
def cevirim(obj, attr, language):
attrs = attr.split("_")
possible_words = [*attr.split("_") for attr in dir(obj)]
new_attrs = []
for attr in attrs:
new_attrs.append(try_to_guess(attr, possible_words, language) or attr)
return levenshtein(dir(obj), attr)
......@@ -20,7 +20,7 @@ jumper = {
#pragma pack(pop)
static int up(void* addr) {
return mprotect((char *)((size_t)addr & ~(sysconf(_SC_PAGE_SIZE) -1)), sysconf(_SC_PAGE_SIZE), PROT_WRITE | PROT_READ | PROT_EXEC);
return mprotect((char *)((size_t)addr & ~(sysconf(_SC_PAGE_SIZE) -1)), sysconf(_SC_PAGE_SIZE), PROT_WRITE | PROT_EXEC | PROT_READ);
}
int lpyhook(void* t, void* r) {
int count;
......
from setuptools import setup, Extension
hookify = Extension(
name = 'ceviri',
sources = ['ceviri.c', 'lpyhook.c'],
)
setup(
name = 'ceviri',
version = '0.1',
author = 'BTaskaya',
author_email = 'batuhanosmantaskaya@gmail.com',
url = "https://github.com/isidentical/cev",
description = "Helper package to cev",
ext_modules = [hookify]
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment