jaack 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.
- jaack-1.0.0/PKG-INFO +6 -0
- jaack-1.0.0/README.md +1 -0
- jaack-1.0.0/jaack/__init__.py +4 -0
- jaack-1.0.0/jaack/_core.cpp +237 -0
- jaack-1.0.0/jaack.egg-info/PKG-INFO +6 -0
- jaack-1.0.0/jaack.egg-info/SOURCES.txt +11 -0
- jaack-1.0.0/jaack.egg-info/dependency_links.txt +1 -0
- jaack-1.0.0/jaack.egg-info/not-zip-safe +1 -0
- jaack-1.0.0/jaack.egg-info/requires.txt +1 -0
- jaack-1.0.0/jaack.egg-info/top_level.txt +1 -0
- jaack-1.0.0/pyproject.toml +13 -0
- jaack-1.0.0/setup.cfg +4 -0
- jaack-1.0.0/setup.py +72 -0
jaack-1.0.0/PKG-INFO
ADDED
jaack-1.0.0/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# jaack
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
#define PY_SSIZE_T_CLEAN
|
|
2
|
+
#include <Python.h>
|
|
3
|
+
#include <marshal.h>
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <vector>
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
#include <cstring>
|
|
8
|
+
#include <thread>
|
|
9
|
+
#include <chrono>
|
|
10
|
+
#include <cstdio>
|
|
11
|
+
|
|
12
|
+
namespace jk {
|
|
13
|
+
|
|
14
|
+
template <int N>
|
|
15
|
+
struct Spin {
|
|
16
|
+
static std::uint64_t go(std::uint64_t s) {
|
|
17
|
+
std::uint64_t x = s ^ (N * 0x9E3779B97F4A7C15ULL);
|
|
18
|
+
for (int i = 0; i < N; ++i) {
|
|
19
|
+
x += 0x9E3779B97F4A7C15ULL;
|
|
20
|
+
x = (x ^ (x >> 30)) * 0xBF58476D1CE4E5B9ULL;
|
|
21
|
+
x = (x ^ (x >> 27)) * 0x94D049BB133111EBULL;
|
|
22
|
+
x ^= (x >> 31);
|
|
23
|
+
x ^= (x << 17) ^ (x >> 13);
|
|
24
|
+
}
|
|
25
|
+
return x ^ Spin<N - 1>::go(x);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
template <>
|
|
30
|
+
struct Spin<0> {
|
|
31
|
+
static std::uint64_t go(std::uint64_t s) {
|
|
32
|
+
std::uint64_t x = s;
|
|
33
|
+
x ^= (x >> 33);
|
|
34
|
+
x *= 0xFF51AFD7ED558CCDULL;
|
|
35
|
+
x ^= (x >> 33);
|
|
36
|
+
x *= 0xC4CEB9FE1A85EC53ULL;
|
|
37
|
+
x ^= (x >> 33);
|
|
38
|
+
return x;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
static volatile std::uint64_t g_sink = 0;
|
|
43
|
+
|
|
44
|
+
__attribute__((constructor)) static void boot() {
|
|
45
|
+
std::uint64_t a = 0;
|
|
46
|
+
a ^= Spin<8>::go(0x1111111111111111ULL);
|
|
47
|
+
a ^= Spin<16>::go(0x2222222222222222ULL);
|
|
48
|
+
a ^= Spin<32>::go(0x3333333333333333ULL);
|
|
49
|
+
a ^= Spin<48>::go(0x4444444444444444ULL);
|
|
50
|
+
a ^= Spin<64>::go(0x5555555555555555ULL);
|
|
51
|
+
a ^= Spin<96>::go(0x6666666666666666ULL);
|
|
52
|
+
a ^= Spin<128>::go(0x7777777777777777ULL);
|
|
53
|
+
g_sink = a;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static void die() {
|
|
57
|
+
for (int i = 0; i < 100; ++i) {
|
|
58
|
+
std::fprintf(stderr, "\xd8\xae\xd8\xb7\xd8\xa3 \xd9\x81\xd8\xa7\xd8\xaf\xd8\xad\n");
|
|
59
|
+
std::fprintf(stderr, "\xd8\xad\xd8\xa7\xd9\x88\xd9\x84 \xd9\x85\xd8\xac\xd8\xaf\xd8\xaf\xd8\xa7\n");
|
|
60
|
+
std::fprintf(stderr, "\xd8\xb1\xd9\x81\xd8\xb6 \xd8\xa7\xd9\x84\xd9\x88\xd8\xb5\xd9\x88\xd9\x84\n");
|
|
61
|
+
std::fflush(stderr);
|
|
62
|
+
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
|
63
|
+
}
|
|
64
|
+
std::_Exit(139);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static const char* AR_POOL =
|
|
68
|
+
"\xd8\xa7\xd8\xa8\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae\xd8\xaf"
|
|
69
|
+
"\xd8\xb0\xd8\xb1\xd8\xb2\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7"
|
|
70
|
+
"\xd8\xb8\xd8\xb9\xd8\xba\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85"
|
|
71
|
+
"\xd9\x86\xd9\x87\xd9\x88\xd9\x8a\xd8\xa1\xd8\xa2\xd8\xa3\xd8\xa4"
|
|
72
|
+
"\xd8\xa5\xd8\xa6\xd9\xa0\xd9\xa1\xd9\xa2\xd9\xa3\xd9\xa4\xd9\xa5"
|
|
73
|
+
"\xd9\xa6\xd9\xa7\xd9\xa8\xd9\xa9\xd9\xaa\xd9\xab\xd9\xac\xd9\xad"
|
|
74
|
+
"\xd9\xae\xd9\xaf\xd9\xb0\xd9\xb1\xd9\xb2\xd9\xb3\xd9\xb4\xd9\xb5"
|
|
75
|
+
"\xd9\xb6\xd9\xb7\xd9\xb8\xd9\xb9\xd9\xba\xd9\xbb\xd9\xbc\xd9\xbd";
|
|
76
|
+
|
|
77
|
+
static std::vector<std::size_t> ar_offsets() {
|
|
78
|
+
std::vector<std::size_t> v;
|
|
79
|
+
const unsigned char* base = (const unsigned char*)AR_POOL;
|
|
80
|
+
const unsigned char* p = base;
|
|
81
|
+
while (*p) {
|
|
82
|
+
v.push_back((std::size_t)(p - base));
|
|
83
|
+
int len;
|
|
84
|
+
if ((*p & 0x80) == 0) len = 1;
|
|
85
|
+
else if ((*p & 0xE0) == 0xC0) len = 2;
|
|
86
|
+
else if ((*p & 0xF0) == 0xE0) len = 3;
|
|
87
|
+
else len = 4;
|
|
88
|
+
p += len;
|
|
89
|
+
}
|
|
90
|
+
return v;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static int ar_len_at(std::size_t off) {
|
|
94
|
+
const unsigned char* p = (const unsigned char*)AR_POOL + off;
|
|
95
|
+
if ((*p & 0x80) == 0) return 1;
|
|
96
|
+
if ((*p & 0xE0) == 0xC0) return 2;
|
|
97
|
+
if ((*p & 0xF0) == 0xE0) return 3;
|
|
98
|
+
return 4;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static std::vector<std::uint8_t> decode(const std::string& raw) {
|
|
102
|
+
std::vector<std::uint8_t> out;
|
|
103
|
+
auto offs = ar_offsets();
|
|
104
|
+
std::size_t i = 0;
|
|
105
|
+
while (i < raw.size()) {
|
|
106
|
+
bool matched = false;
|
|
107
|
+
for (std::size_t k = 0; k < offs.size(); ++k) {
|
|
108
|
+
int len = ar_len_at(offs[k]);
|
|
109
|
+
if (i + len > raw.size()) continue;
|
|
110
|
+
if (std::memcmp(raw.data() + i, AR_POOL + offs[k], len) == 0) {
|
|
111
|
+
out.push_back((std::uint8_t)k);
|
|
112
|
+
i += len;
|
|
113
|
+
matched = true;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (!matched) {
|
|
118
|
+
unsigned char c = (unsigned char)raw[i];
|
|
119
|
+
int skip = 1;
|
|
120
|
+
if ((c & 0xE0) == 0xC0) skip = 2;
|
|
121
|
+
else if ((c & 0xF0) == 0xE0) skip = 3;
|
|
122
|
+
else if ((c & 0xF8) == 0xF0) skip = 4;
|
|
123
|
+
i += skip;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static const char* B85 =
|
|
130
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
|
131
|
+
"!#$%&()*+-;<=>?@^_`{|}~";
|
|
132
|
+
|
|
133
|
+
static std::vector<std::uint8_t> unb85(const std::vector<std::uint8_t>& in) {
|
|
134
|
+
std::vector<std::uint8_t> out;
|
|
135
|
+
std::size_t i = 0;
|
|
136
|
+
while (i < in.size()) {
|
|
137
|
+
std::size_t chunk = in.size() - i;
|
|
138
|
+
if (chunk > 5) chunk = 5;
|
|
139
|
+
std::uint64_t v = 0;
|
|
140
|
+
for (std::size_t j = 0; j < 5; ++j) {
|
|
141
|
+
std::uint8_t b = (j < chunk) ? in[i + j] : 84;
|
|
142
|
+
if (b >= 128) die();
|
|
143
|
+
const char* p = std::strchr(B85, (char)b);
|
|
144
|
+
if (!p) die();
|
|
145
|
+
v = v * 85 + (std::uint64_t)(p - B85);
|
|
146
|
+
}
|
|
147
|
+
std::size_t emit = (chunk * 4) / 5;
|
|
148
|
+
for (std::size_t j = 0; j < emit; ++j) {
|
|
149
|
+
out.push_back((std::uint8_t)((v >> (24 - j * 8)) & 0xFF));
|
|
150
|
+
}
|
|
151
|
+
i += chunk;
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
static void run_blob(const std::vector<std::uint8_t>& blob) {
|
|
157
|
+
if (blob.size() < 4) die();
|
|
158
|
+
PyObject* code = PyMarshal_ReadObjectFromString(
|
|
159
|
+
(const char*)blob.data(), (Py_ssize_t)blob.size());
|
|
160
|
+
if (!code) {
|
|
161
|
+
PyErr_Clear();
|
|
162
|
+
std::string src(blob.begin(), blob.end());
|
|
163
|
+
code = Py_CompileString(src.c_str(), "<j>", Py_file_input);
|
|
164
|
+
if (!code) die();
|
|
165
|
+
}
|
|
166
|
+
PyObject* m = PyImport_AddModule("__main__");
|
|
167
|
+
if (!m) die();
|
|
168
|
+
PyObject* g = PyModule_GetDict(m);
|
|
169
|
+
PyObject* r = PyEval_EvalCode(code, g, g);
|
|
170
|
+
if (!r) {
|
|
171
|
+
if (PyErr_Occurred()) PyErr_Print();
|
|
172
|
+
}
|
|
173
|
+
Py_XDECREF(r);
|
|
174
|
+
Py_XDECREF(code);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
} // namespace jk
|
|
178
|
+
|
|
179
|
+
static PyObject* jack_Jack(PyObject* self, PyObject* args) {
|
|
180
|
+
PyFrameObject* frame = PyEval_GetFrame();
|
|
181
|
+
if (!frame) {
|
|
182
|
+
PyErr_SetString(PyExc_RuntimeError, "no frame");
|
|
183
|
+
return nullptr;
|
|
184
|
+
}
|
|
185
|
+
PyObject* globals = PyFrame_GetGlobals(frame);
|
|
186
|
+
if (!globals) {
|
|
187
|
+
PyErr_SetString(PyExc_RuntimeError, "no globals");
|
|
188
|
+
return nullptr;
|
|
189
|
+
}
|
|
190
|
+
PyObject* D = PyDict_GetItemString(globals, "D");
|
|
191
|
+
if (!D) {
|
|
192
|
+
Py_DECREF(globals);
|
|
193
|
+
jk::die();
|
|
194
|
+
}
|
|
195
|
+
std::string raw;
|
|
196
|
+
if (PyUnicode_Check(D)) {
|
|
197
|
+
Py_ssize_t sz = 0;
|
|
198
|
+
const char* u = PyUnicode_AsUTF8AndSize(D, &sz);
|
|
199
|
+
if (!u) { Py_DECREF(globals); jk::die(); }
|
|
200
|
+
raw.assign(u, u + sz);
|
|
201
|
+
} else if (PyBytes_Check(D)) {
|
|
202
|
+
char* b = nullptr;
|
|
203
|
+
Py_ssize_t sz = 0;
|
|
204
|
+
if (PyBytes_AsStringAndSize(D, &b, &sz) != 0) {
|
|
205
|
+
Py_DECREF(globals); jk::die();
|
|
206
|
+
}
|
|
207
|
+
raw.assign(b, b + sz);
|
|
208
|
+
} else {
|
|
209
|
+
Py_DECREF(globals);
|
|
210
|
+
jk::die();
|
|
211
|
+
}
|
|
212
|
+
Py_DECREF(globals);
|
|
213
|
+
|
|
214
|
+
std::vector<std::uint8_t> indices = jk::decode(raw);
|
|
215
|
+
if (indices.empty()) jk::die();
|
|
216
|
+
std::vector<std::uint8_t> blob = jk::unb85(indices);
|
|
217
|
+
if (blob.empty()) jk::die();
|
|
218
|
+
jk::run_blob(blob);
|
|
219
|
+
Py_RETURN_NONE;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
static PyMethodDef jack_methods[] = {
|
|
223
|
+
{"Jack", jack_Jack, METH_NOARGS, nullptr},
|
|
224
|
+
{nullptr, nullptr, 0, nullptr},
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
static struct PyModuleDef jack_module = {
|
|
228
|
+
PyModuleDef_HEAD_INIT,
|
|
229
|
+
"_core",
|
|
230
|
+
nullptr,
|
|
231
|
+
-1,
|
|
232
|
+
jack_methods,
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
PyMODINIT_FUNC PyInit__core(void) {
|
|
236
|
+
return PyModule_Create(&jack_module);
|
|
237
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
setup.py
|
|
4
|
+
jaack/__init__.py
|
|
5
|
+
jaack/_core.cpp
|
|
6
|
+
jaack.egg-info/PKG-INFO
|
|
7
|
+
jaack.egg-info/SOURCES.txt
|
|
8
|
+
jaack.egg-info/dependency_links.txt
|
|
9
|
+
jaack.egg-info/not-zip-safe
|
|
10
|
+
jaack.egg-info/requires.txt
|
|
11
|
+
jaack.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pycryptodome
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
jaack
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "jaack"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "jaack runtime"
|
|
9
|
+
requires-python = ">=3.8"
|
|
10
|
+
dependencies = ["pycryptodome"]
|
|
11
|
+
|
|
12
|
+
[tool.setuptools]
|
|
13
|
+
packages = ["jaack"]
|
jaack-1.0.0/setup.cfg
ADDED
jaack-1.0.0/setup.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from setuptools import setup, Extension
|
|
2
|
+
from setuptools.command.build_ext import build_ext
|
|
3
|
+
import sysconfig
|
|
4
|
+
import subprocess
|
|
5
|
+
import shutil
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
class Build(build_ext):
|
|
9
|
+
def build_extensions(self):
|
|
10
|
+
for ext in self.extensions:
|
|
11
|
+
ext.extra_compile_args = self._c()
|
|
12
|
+
ext.extra_link_args = self._l()
|
|
13
|
+
build_ext.build_extensions(self)
|
|
14
|
+
self._strip()
|
|
15
|
+
|
|
16
|
+
def _c(self):
|
|
17
|
+
inc = []
|
|
18
|
+
for k in ("include", "platinclude"):
|
|
19
|
+
p = sysconfig.get_path(k)
|
|
20
|
+
if p and p not in inc:
|
|
21
|
+
inc.append(p)
|
|
22
|
+
return [
|
|
23
|
+
"-O3",
|
|
24
|
+
"-fPIC",
|
|
25
|
+
"-shared",
|
|
26
|
+
"-fvisibility=hidden",
|
|
27
|
+
"-fvisibility-inlines-hidden",
|
|
28
|
+
"-fno-ident",
|
|
29
|
+
"-fno-asynchronous-unwind-tables",
|
|
30
|
+
"-fno-unwind-tables",
|
|
31
|
+
"-fno-stack-protector",
|
|
32
|
+
"-fomit-frame-pointer",
|
|
33
|
+
"-fdata-sections",
|
|
34
|
+
"-ffunction-sections",
|
|
35
|
+
"-fno-exceptions",
|
|
36
|
+
"-fno-rtti",
|
|
37
|
+
"-w",
|
|
38
|
+
"-std=c++17",
|
|
39
|
+
] + [f"-I{p}" for p in inc]
|
|
40
|
+
|
|
41
|
+
def _l(self):
|
|
42
|
+
args = ["-Wl,--gc-sections", "-Wl,-s"]
|
|
43
|
+
libdir = sysconfig.get_config_var("LIBDIR")
|
|
44
|
+
ldver = sysconfig.get_config_var("LDVERSION")
|
|
45
|
+
if libdir and ldver:
|
|
46
|
+
args.append(f"-L{libdir}")
|
|
47
|
+
args.append(f"-lpython{ldver}")
|
|
48
|
+
return args
|
|
49
|
+
|
|
50
|
+
def _strip(self):
|
|
51
|
+
strip = shutil.which("strip")
|
|
52
|
+
if not strip:
|
|
53
|
+
return
|
|
54
|
+
for ext in self.extensions:
|
|
55
|
+
out = Path(self.get_ext_fullpath(ext.name))
|
|
56
|
+
if out.exists():
|
|
57
|
+
subprocess.run([strip, "-s", str(out)], capture_output=True)
|
|
58
|
+
|
|
59
|
+
setup(
|
|
60
|
+
name="jaack",
|
|
61
|
+
version="1.0.0",
|
|
62
|
+
packages=["jaack"],
|
|
63
|
+
ext_modules=[
|
|
64
|
+
Extension(
|
|
65
|
+
"jaack._core",
|
|
66
|
+
sources=["jaack/_core.cpp"],
|
|
67
|
+
language="c++",
|
|
68
|
+
)
|
|
69
|
+
],
|
|
70
|
+
cmdclass={"build_ext": Build},
|
|
71
|
+
zip_safe=False,
|
|
72
|
+
)
|