-
-
Save tekknolagi/3df691ad6f48e85e26bd995f6ec5c900 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sizeof_ptr = 8 | |
length_hex_ptr = 2 * sizeof_ptr | |
idx = 0 | |
idx_map = {} | |
def splitn(s, n): | |
for i in range(0, len(s), n): | |
yield s[i : i + n] | |
def clean(s): | |
result = "" | |
for c in s: | |
result += c if c.isalnum() else "_" | |
return result | |
def zeropad(s): | |
return s + "\x00" * (sizeof_ptr - (len(s))) | |
def alloc(s): | |
global idx | |
idx_map[clean(s)] = idx | |
result = [] | |
splits = list(splitn(s, sizeof_ptr)) | |
for group in splits: | |
enc = "0x" + "".join([hex(ord(c))[2:] for c in group[::-1]]) | |
# .zfill(length_hex_ptr) | |
result.append(enc + ",") | |
idx += 1 | |
return result | |
strings = [ | |
"Hello, ", | |
"this is a message from ", | |
"your friendly Scrapscript team", | |
] | |
arrcontents = [] | |
for s in strings: | |
arrcontents.extend(alloc(s)) | |
length = len(arrcontents) | |
print(f"uint64_t stack_strings[{length+1}] = {{") | |
print("\n".join(arrcontents)) | |
print("};") | |
print(f"stack_strings[{length}] = 1337;") | |
for k, v in idx_map.items(): | |
print(f"char* str_{k} = (char*)&stack_strings[{v}];") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment