· 6 years ago · Jan 01, 2020, 02:18 PM
1-- Synapse X-Sanctioned Development Compatibility Layer (DCL)
2-- https://github.com/LoukaMB/SynapseX/script/compatibility_layer.lua
3-- Usage: loadstring(game:HttpGet("https://raw.githubusercontent.com/LoukaMB/SynapseX/master/script/compatibility_layer.lua"))()
4
5-- This script provides a standardized API for Lua scripts with environment extensions.
6-- Definitions are written in corcondance with https://loukamb.github.io/SynapseX/
7-- (Functions start with api.* instead of syn_)
8
9-- Last Update: October 22, 2019
10
11--[[
12 COMPATIBILITY PERCENTAGES (estimates)
13 Synapse X (post-Holiday update): 100%
14 Synapse X (pre-Holiday update): 98%
15 Calamari: 95%
16 ProtoSmh: 75%
17 Elysian: 50%
18 SirHurt: ?
19
20 DOCUMENTATION SOURCES (to be updated regularly)
21 Calamari: /compatibility_layer_docs/calamari_docs.html
22 ProtoSm.: /compatibility_layer_docs/ps_docs.html
23 Elysian: /compatibility_layer_docs/elysian_docs.html
24 Synapse: https://loukamb.github.io/SynapseX/
25 SirHurt: ?
26
27 DISCLAIMER
28 This script is offered FREE OF CHARGE by the folks at Synapse GP. You can use this for
29 ANYTHING and I (Louka) don't really care but it'd be nice if you kept this disclaimer or
30 something (and a link to my website) so people know who wrote most of it <3
31
32 DISCLAIMER #2
33 The main reason why I decided to write this is because of the many API changes in the
34 Synapse X Holiday update, which changes (almost) every single definition out here. I
35 doubt other exploits will immediately rush to implement Synapse X compatibility so this
36 should come in handy. Also, this should solve most of your cross-compatibility problems
37 and many "or X or Y or Z" statements :P
38
39 DISCLAIMER #3
40 This is supposed to work with most exploits out here, but things may break if you run some
41 private thing or your exploit goes lengths to break this script (which it shouldn't because
42 this is for compatibility and supporting this is 100% GREAT FOR SCRIPT DEVELOPERS!), so if
43 something doesn't work just open an issue case on the GitHub or something thank you
44--]]
45
46--[[ macalamari funcs: (according to https://v3rmillion.net/showthread.php?tid=897918)
47loadstring
48game:GetObjects
49game:HttpGet
50writefile
51readfile
52getrawmetatable
53setreadonly
54getnamecallmethod
55make_writeable
56newcclosure
57]]
58
59local function flag_to_name(software_flag)
60 return
61 ({
62
63 ["unk"] = "Unknown exploit";
64 ["ps"] = "ProtoSmasher";
65 ["synx"] = "Synapse X";
66 ["synx_old"] = "Synapse X (pre-Holiday update)";
67 ["sh"] = "SirHurt";
68 ["cl"] = "Calamari (Windows)";
69 ["clx"] = "Calamari (macOS)";
70 ["ely"] = "Elysian";
71
72 })[software_flag]
73end
74
75local function unsupported(feature, flag)
76 return function() error(("api::%s is not supported by %s"):format(feature, flag_to_name(flag))) end
77end
78
79local function idxparse(src_table, statement)
80 local current_kv
81 for key in statement:gmatch("([^%.]+)") do
82 if not current_kv then
83 current_kv = src_table[key]
84 else
85 current_kv = current_kv[key]
86 if current_kv == nil then
87 return -- cannot parse any further
88 end
89 end
90 end
91 return current_kv
92end
93
94local function lookup(src_table, ...)
95 local alias_list = {...}
96 for k, v in pairs(src_table) do
97 local s, tv = pcall(idxparse, src_table, v)
98 if s and tv then
99 return tv
100 end
101 end
102 return -- not existing
103end
104
105local prev_global
106local function globals() -- look up prefered global table
107 if prev_global then
108 return prev_global
109 end
110 -- getgenv is pretty much universal
111 local a, b, c = _G, getfenv(), getgenv()
112 local lookupk = "_VERSION"
113 -- in order of preference
114 if c[lookupk] then
115 -- prefered
116 if not prev_global then
117 prev_global = a
118 end
119 return a
120 elseif b[lookupk] then
121 -- should only be the case in minimal exploits
122 if not prev_global then
123 prev_global = b
124 end
125 return b
126 elseif a[lookupk] then
127 -- should only be the case in lua wrappers
128 if not prev_global then
129 prev_global = c
130 end
131 return c
132 end
133end
134
135return function()
136 local api = {}
137 local flags = {}
138
139 do -- Calculate Flags
140 if pebc_load then -- is ProtoSmasher
141 flags.software = "ps"
142 end
143
144 if not flags.software and getnspval then -- is Elysian
145 flags.software = "ely"
146 end
147
148 if not flags.software and writefileas then -- is Calamari
149 flags.software = "cl"
150 end
151
152 if not flags.software and syn or syn_context_get then -- is Synapse X (unknown version)
153 if syn_context_get then -- is Synapse X (post Holiday update)
154 flags.software = "synx"
155 else -- is Synapse X (pre Holiday update)
156 flags.software = "synx_old"
157 end
158 end
159
160 if not flags.software and make_writeable then -- is Calamari (macOS)
161 -- note to calamri devs: if you want a more accurate way of
162 -- detecting whether your software is its mac os version please
163 -- include some sort of constant or something
164 flags.software = "clx"
165 end
166
167 if not flags.software then
168 flags.software = "unk" -- Unknown exploit
169 end
170 end
171
172 do -- Create Clipboard Library
173 if flags.software == "synx" then
174 api.clipboard_get = syn_clipboard_get
175 api.clipboard_set = syn_clipboard_set
176 elseif flags.software == "cl" then
177 api.clipboard_get = getclipboard
178 api.clipboard_set = setclipboard
179 elseif flags.software == "ely" then
180 api.clipboard_get = unsupported("clipboard_get", flags.software)
181 api.clipboard_set = Clipboard.set
182 elseif flags.software == "synx_old" or flags.software == "ps" then
183 api.clipboard_get = unsupported("clipboard_get", flags.software)
184 api.clipboard_set = setclipboard
185 else
186 local globals = globals()
187 api.clipboard_get = lookup(globals, "getclipboard", "get_clipboard", "Clipboard.get")
188 or unsupported("clipboard_get", flags.software)
189 api.clipboard_set = lookup(globals, "setclipboard", "set_clipboard", "Clipboard.set")
190 or unsupported("clipboard_set", flags.software)
191 end
192 end
193
194 do -- Create Environment Functions
195 if flags.software == "synx" then
196 api.getgenv = syn_getgenv
197 api.getrenv = syn_getrenv
198 api.getsenv = syn_getsenv
199 api.getreg = syn_getreg
200 api.getgc = syn_getgc
201 api.getinstances = syn_getinstances
202 api.getnilinstances = syn_getnilinstances
203 api.getloadedmodules = syn_getloadedmodules
204 api.getconnections = syn_getconnections -- NOTE: unsure if fixed on post Holiday
205 api.getscripts = syn_getscripts
206 api.getcallingscript = syn_getcallingscript
207 elseif flags.software == "synx_old" then
208 api.getgenv = getgenv
209 api.getrenv = getrenv
210 api.getsenv = getsenv
211 api.getreg = getreg
212 api.getgc = getgc
213 api.getinstances = getinstances
214 api.getnilinstances = getnilinstances
215 api.getscripts = getscripts
216 api.getloadedmodules = getloadedmodules
217 api.getconnections = getconnections -- broken afaik, load anyway just in case
218 elseif flags.software == "ps" then
219 api.getgenv = getgenv
220 api.getrenv = getrenv
221 api.getsenv = getsenv
222 api.getreg = getregistry
223 api.getgc = get_gc_objects
224 api.getinstances = unsupported("getinstances", flags.software)
225 api.getnilinstances = get_nil_instances
226 api.getloadedmodules = get_loaded_modules
227 api.getconnections = get_signal_connections -- unsure if still unimplemented, not on api list
228 or unsupported("getconnections", flags.software)
229 function api.getscripts()
230 -- manually reimplement
231 local rest = {}
232 local scre = getscriptenvs()
233 for k, _ in next, scre do
234 rest[#rest + 1] = k
235 end
236 return rest
237 end
238 elseif flags.software == "ely" then
239 api.getgenv = getgenv
240 api.getrenv = getrenv
241 api.getsenv = getsenv
242 api.getreg = getreg
243 api.getgc = getgc
244 api.getinstances = getinstances
245 api.getnilinstances = getnilinstances
246 api.getscripts = unsupported("getscripts", flags.software) -- reimpl using getinstances would be too performance heavy
247 api.getloadedmodules = unsupported("getloadedmodules", flags.software) -- ditto
248 api.getconnections = getconnections
249 elseif flags.software == "cl" then
250 api.getgenv = getgenv
251 api.getrenv = getrenv
252 api.getsenv = getsenv
253 api.getreg = getreg
254 api.getgc = getgc
255 api.getinstances = getinstances
256 api.getnilinstances = getnilinstances
257 api.getscripts = getscripts
258 api.getloadedmodules = unsupported("getloadedmodules", flags.software)
259 api.getconnections = unsupported("getconnections", flags.software)
260 else
261 local globals = globals()
262 api.getgenv = lookup(globals, "getgenv", "get_genv") or unsupported("getgenv", flags.software)
263 api.getrenv = lookup(globals, "getrenv", "get_renv") or unsupported("getrenv", flags.software)
264 api.getsenv = lookup(globals, "getsenv", "get_senv") or unsupported("getsenv", flags.software)
265 api.getreg = lookup(globals, "getreg", "getregistry", "get_registry") or unsupported("getreg", flags.software)
266 api.getgc = lookup(globals, "getgc", "get_gc", "gclist") or unsupported("getgc", flags.software)
267 api.getinstances = lookup(globals, "getinstances", "get_instances", "get_instance_list") or unsupported("getinstances", flags.software)
268 end
269 end
270
271 do -- Create Context library
272 if flags.software == "synx" then
273 api.context_get = syn_context_get
274 api.context_set = syn_context_set
275 elseif flags.software == "synx_old" then
276 api.context_get = syn.get_thread_identity
277 api.context_get = syn.set_thread_identity
278 elseif flags.software == "ps" then
279 api.context_get = get_thread_context
280 api.context_set = unsupported("context_set", flags.software)
281 elseif flags.software == "ely" then
282 api.context_get = unsupported("context_get", flags.software)
283 api.context_set = unsupported("context_set", flags.software)
284 elseif flags.software == "cl" then
285 api.context_get = getcontext
286 api.context_set = setcontext
287 else
288 api.context_get = lookup(globals())
289 end
290 end
291
292 do -- Create IO library
293 if flags.software == "synx" then
294 api.io_write = syn_io_write
295 api.io_read = syn_io_read
296 api.io_append = syn_io_append
297 elseif flags.software == "synx_old" then
298 api.io_write = writefile
299 api.io_read = readfile
300 api.io_append = appendfile
301 end
302
303 return api
304 end
305end