byt3d4nc3-linux64 0.2.3__py3-none-any.whl
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.
- byt3d4nc3/__init__.py +5 -0
- byt3d4nc3/data/abi +1 -0
- byt3d4nc3/data/magic +1 -0
- byt3d4nc3/data/run +0 -0
- byt3d4nc3/loader.py +216 -0
- byt3d4nc3_linux64-0.2.3.dist-info/METADATA +10 -0
- byt3d4nc3_linux64-0.2.3.dist-info/RECORD +10 -0
- byt3d4nc3_linux64-0.2.3.dist-info/WHEEL +5 -0
- byt3d4nc3_linux64-0.2.3.dist-info/entry_points.txt +2 -0
- byt3d4nc3_linux64-0.2.3.dist-info/top_level.txt +1 -0
byt3d4nc3/__init__.py
ADDED
byt3d4nc3/data/abi
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
linux64
|
byt3d4nc3/data/magic
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
063b7170
|
byt3d4nc3/data/run
ADDED
|
Binary file
|
byt3d4nc3/loader.py
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import sys as _sy
|
|
2
|
+
|
|
3
|
+
_SCRIPT = _sy.argv and _sy.argv[0] and _sy.argv[0].endswith(
|
|
4
|
+
("byt3d4nc3", "byt3d4nc3.exe", "runnerx", "runnerx.exe", "loader.py",
|
|
5
|
+
"loader.exe", "python", "python3"))
|
|
6
|
+
_OD = ''
|
|
7
|
+
if _SCRIPT and _sy.argv[0]:
|
|
8
|
+
_a = _sy.argv[0]
|
|
9
|
+
_OD = _a.rsplit('/', 1)[0] if '/' in _a else ''
|
|
10
|
+
_sy.path[:] = [p for p in _sy.path if p not in ('', '.', _OD)]
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import platform
|
|
14
|
+
import shutil
|
|
15
|
+
import subprocess
|
|
16
|
+
import tempfile
|
|
17
|
+
|
|
18
|
+
_SHADOW = []
|
|
19
|
+
for _m in (os, platform, shutil, subprocess, tempfile):
|
|
20
|
+
_f = getattr(_m, '__file__', '') or ''
|
|
21
|
+
if _OD and _f.startswith(_OD):
|
|
22
|
+
_SHADOW.append(_f)
|
|
23
|
+
|
|
24
|
+
_DATA = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
|
|
25
|
+
|
|
26
|
+
_SCRATCH = os.path.join(
|
|
27
|
+
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
|
|
28
|
+
"tmp")
|
|
29
|
+
if os.path.isdir(_SCRATCH):
|
|
30
|
+
tempfile.tempdir = _SCRATCH
|
|
31
|
+
else:
|
|
32
|
+
_SCRATCH = None
|
|
33
|
+
|
|
34
|
+
_TARGETS = {
|
|
35
|
+
"linux64": ("linux64", "x86_64"),
|
|
36
|
+
"armv8": ("armv8", "aarch64/arm64"),
|
|
37
|
+
"armv7": ("armv7", "armv6l/armv7l"),
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
PROTOCOL = 2
|
|
41
|
+
|
|
42
|
+
_MACHINE_ABI = (
|
|
43
|
+
("linux64", ("x86_64", "amd64", "x64")),
|
|
44
|
+
("armv8", ("aarch64", "arm64", "arm64-v8a", "aarch64_be", "armv9", "armv9l")),
|
|
45
|
+
("armv7", ("armv6l", "armv6", "armv7l", "armv7", "arm", "armeabi",
|
|
46
|
+
"armeabi-v7a", "armeabi-v6", "armv7a", "armv8l")),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
def _host_abi():
|
|
50
|
+
machine = platform.machine().lower()
|
|
51
|
+
for abi, names in _MACHINE_ABI:
|
|
52
|
+
if machine in names:
|
|
53
|
+
return abi
|
|
54
|
+
raise RuntimeError(
|
|
55
|
+
"no shipped runtime for this machine (%s). This build carries %s; run "
|
|
56
|
+
"the artifact on a supported host, or add a runtime for it."
|
|
57
|
+
% (platform.machine(),
|
|
58
|
+
", ".join(sorted(_TARGETS))))
|
|
59
|
+
|
|
60
|
+
def _bundled_abis():
|
|
61
|
+
if os.path.isfile(os.path.join(_DATA, "run")):
|
|
62
|
+
try:
|
|
63
|
+
with open(os.path.join(_DATA, "abi"), "r", encoding="utf-8") as fh:
|
|
64
|
+
abi = fh.read().strip()
|
|
65
|
+
except OSError:
|
|
66
|
+
abi = ""
|
|
67
|
+
if abi in _TARGETS:
|
|
68
|
+
return [abi]
|
|
69
|
+
try:
|
|
70
|
+
return [_host_abi()]
|
|
71
|
+
except RuntimeError:
|
|
72
|
+
return []
|
|
73
|
+
return [abi for abi in sorted(_TARGETS)
|
|
74
|
+
if os.path.isfile(os.path.join(_DATA, abi, "run"))]
|
|
75
|
+
|
|
76
|
+
def targets():
|
|
77
|
+
have = _bundled_abis()
|
|
78
|
+
if have:
|
|
79
|
+
return {abi: _TARGETS[abi][1] for abi in have}
|
|
80
|
+
return dict(_TARGETS)
|
|
81
|
+
|
|
82
|
+
def abi_for_host():
|
|
83
|
+
return _host_abi()
|
|
84
|
+
|
|
85
|
+
def binary_path(abi=None):
|
|
86
|
+
want = abi or _host_abi()
|
|
87
|
+
if want not in _TARGETS:
|
|
88
|
+
raise ValueError("unknown ABI %r; choose from %s"
|
|
89
|
+
% (want, ", ".join(sorted(_TARGETS))))
|
|
90
|
+
single = os.path.join(_DATA, "run")
|
|
91
|
+
if os.path.isfile(single):
|
|
92
|
+
return single
|
|
93
|
+
return os.path.join(_DATA, want, "run")
|
|
94
|
+
|
|
95
|
+
def runtime_magic(abi=None):
|
|
96
|
+
want = abi or _host_abi()
|
|
97
|
+
if os.path.isfile(os.path.join(_DATA, "run")):
|
|
98
|
+
try:
|
|
99
|
+
with open(os.path.join(_DATA, "magic"), "r", encoding="utf-8") as fh:
|
|
100
|
+
return fh.read().strip()
|
|
101
|
+
except OSError:
|
|
102
|
+
return ""
|
|
103
|
+
try:
|
|
104
|
+
with open(os.path.join(_DATA, want, "magic"), "r", encoding="utf-8") as fh:
|
|
105
|
+
return fh.read().strip()
|
|
106
|
+
except OSError:
|
|
107
|
+
return ""
|
|
108
|
+
|
|
109
|
+
def match_arch(abi=None):
|
|
110
|
+
host = _host_abi()
|
|
111
|
+
want = abi or host
|
|
112
|
+
have = _bundled_abis()
|
|
113
|
+
if have and want not in have:
|
|
114
|
+
raise RuntimeError(
|
|
115
|
+
"this package ships the %s runtime, but this host is %s; install "
|
|
116
|
+
"byt3d4nc3-%s instead" % (", ".join(have), host, host))
|
|
117
|
+
path = binary_path(want)
|
|
118
|
+
if not os.path.isfile(path):
|
|
119
|
+
raise RuntimeError("missing runtime for %s" % want)
|
|
120
|
+
return path
|
|
121
|
+
|
|
122
|
+
def host_site_dirs():
|
|
123
|
+
import sys
|
|
124
|
+
out, seen = [], set()
|
|
125
|
+
try:
|
|
126
|
+
import sysconfig
|
|
127
|
+
for key in ("purelib", "platlib"):
|
|
128
|
+
p = sysconfig.get_paths().get(key)
|
|
129
|
+
if p and os.path.isdir(p) and p not in seen:
|
|
130
|
+
seen.add(p)
|
|
131
|
+
out.append(p)
|
|
132
|
+
except Exception:
|
|
133
|
+
pass
|
|
134
|
+
for p in sys.path:
|
|
135
|
+
if os.path.isdir(p) and (
|
|
136
|
+
p.endswith(("site-packages", "dist-packages"))
|
|
137
|
+
or "site-packages" in p or "dist-packages" in p
|
|
138
|
+
) and p not in seen:
|
|
139
|
+
seen.add(p)
|
|
140
|
+
out.append(p)
|
|
141
|
+
return out
|
|
142
|
+
|
|
143
|
+
def _scrub_site_env(spawn_env):
|
|
144
|
+
for key in [k for k in spawn_env if k.upper().startswith("BYT3D4NC3_SITE")]:
|
|
145
|
+
del spawn_env[key]
|
|
146
|
+
for key in ("MODRUNTIME_PATH",):
|
|
147
|
+
spawn_env.pop(key, None)
|
|
148
|
+
spawn_env.pop("PYTHONPATH", None)
|
|
149
|
+
return spawn_env
|
|
150
|
+
|
|
151
|
+
def run(payload, binary=None, env=None, timeout=None, site_packages=None,
|
|
152
|
+
quiet=False):
|
|
153
|
+
prog = shutil.which(binary) if binary else match_arch()
|
|
154
|
+
if not prog:
|
|
155
|
+
raise RuntimeError("no usable runtime for %s" % _host_abi())
|
|
156
|
+
if isinstance(payload, str):
|
|
157
|
+
if os.path.isfile(payload):
|
|
158
|
+
raise RuntimeError(
|
|
159
|
+
"stale loader: this file passes a script path, but the "
|
|
160
|
+
"runtime only accepts a sealed stream on stdin; re-mint with "
|
|
161
|
+
"the byt3d4nc3 release matching this package")
|
|
162
|
+
payload = payload.encode("utf-8")
|
|
163
|
+
|
|
164
|
+
spawn_env = _scrub_site_env(dict(os.environ if env is None else env))
|
|
165
|
+
dirs = list(site_packages) if site_packages is not None else host_site_dirs()
|
|
166
|
+
if dirs:
|
|
167
|
+
spawn_env["BYT3D4NC3_SITEPACKAGES"] = os.pathsep.join(dirs)
|
|
168
|
+
if _SCRATCH and os.path.isdir(_SCRATCH):
|
|
169
|
+
spawn_env["TMPDIR"] = _SCRATCH
|
|
170
|
+
out = subprocess.DEVNULL if quiet else None
|
|
171
|
+
return subprocess.run(
|
|
172
|
+
[prog],
|
|
173
|
+
input=payload,
|
|
174
|
+
env=spawn_env, timeout=timeout, check=False,
|
|
175
|
+
stdout=out, stderr=out,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
def main(argv=None):
|
|
179
|
+
if _SHADOW:
|
|
180
|
+
raise SystemExit(
|
|
181
|
+
'byt3d4nc3: refusing to run -- these modules resolved from the '
|
|
182
|
+
'launcher directory and may have executed already: '
|
|
183
|
+
+ ', '.join(_SHADOW))
|
|
184
|
+
import argparse
|
|
185
|
+
ap = argparse.ArgumentParser(prog="byt3d4nc3")
|
|
186
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
187
|
+
|
|
188
|
+
p_targets = sub.add_parser("targets")
|
|
189
|
+
_ = p_targets
|
|
190
|
+
|
|
191
|
+
p_arch = sub.add_parser("arch")
|
|
192
|
+
_ = p_arch
|
|
193
|
+
|
|
194
|
+
p_path = sub.add_parser("path")
|
|
195
|
+
p_path.add_argument("abi", nargs="?", default=None)
|
|
196
|
+
|
|
197
|
+
p_run = sub.add_parser("run")
|
|
198
|
+
p_run.add_argument("script", help="file holding a sealed payload stream")
|
|
199
|
+
|
|
200
|
+
args = ap.parse_args(argv)
|
|
201
|
+
|
|
202
|
+
if args.cmd == "targets":
|
|
203
|
+
for abi in sorted(targets()):
|
|
204
|
+
print("%-8s %s" % (abi, _TARGETS[abi][1]))
|
|
205
|
+
elif args.cmd == "arch":
|
|
206
|
+
print(_host_abi())
|
|
207
|
+
elif args.cmd == "path":
|
|
208
|
+
print(match_arch(args.abi))
|
|
209
|
+
else:
|
|
210
|
+
with open(args.script, "rb") as fh:
|
|
211
|
+
cp = run(fh.read())
|
|
212
|
+
return cp.returncode
|
|
213
|
+
return 0
|
|
214
|
+
|
|
215
|
+
if __name__ == "__main__":
|
|
216
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: byt3d4nc3-linux64
|
|
3
|
+
Version: 0.2.3
|
|
4
|
+
Summary: byt3d4nc3 runtime for linux64 (one bundled interpreter, host stdlib)
|
|
5
|
+
License: Proprietary
|
|
6
|
+
Keywords: runtime,binary,platform,linux64
|
|
7
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
10
|
+
Requires-Python: >=3.8
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
byt3d4nc3/__init__.py,sha256=4TlT9y9Ym_g4lnktl3M4YEpGuxVBK2t9BAqSy0eZTFo,65
|
|
2
|
+
byt3d4nc3/loader.py,sha256=OdukN_8J957VJsyo9drM_sxHIHNCi8LNcKbhFpiCrdM,6824
|
|
3
|
+
byt3d4nc3/data/abi,sha256=lhD2ec92p39zgcA0UPT4-B61MRbB8UxkAoEFXjZ1Vwc,8
|
|
4
|
+
byt3d4nc3/data/magic,sha256=dqW3xT3vAQ9klx7nJLRZczo7bhYyYxzoASxeKSeXZ2k,9
|
|
5
|
+
byt3d4nc3/data/run,sha256=ysbCsqjk9ksPHBZIJRr-RFCnbMpNdcFV88zdPyoqJ_4,5731316
|
|
6
|
+
byt3d4nc3_linux64-0.2.3.dist-info/METADATA,sha256=d6ZtGUm0blA6CKZtEjr3Z_aj2eD43rxwxnWut7I56Ik,377
|
|
7
|
+
byt3d4nc3_linux64-0.2.3.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
8
|
+
byt3d4nc3_linux64-0.2.3.dist-info/entry_points.txt,sha256=qlIv8T35PHZXEthRzFBarssArF3u00z2TcTBQHJBgCk,52
|
|
9
|
+
byt3d4nc3_linux64-0.2.3.dist-info/top_level.txt,sha256=-EcSJmylpvWMhUWlIslheGq9fkg5BCqzjX5nYQjDvRY,10
|
|
10
|
+
byt3d4nc3_linux64-0.2.3.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
byt3d4nc3
|