-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringPrinter.py
More file actions
executable file
·52 lines (41 loc) · 1.26 KB
/
stringPrinter.py
File metadata and controls
executable file
·52 lines (41 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
import sys
# A simple script to convert strings to lasm syntax
def convert(s):
# Append 0x00 then Split string up into 8 byte parts
# The packs stay at the right position, only inside they get reversed in
# endianness
s = (bytes(s,"utf-8")+b"\x00")
res = ""
packs = []
for i in range(0,len(s)-1,8):
pack = s[i:i+8]
packs.append(pack)
print(packs)
for i in packs:
res += "0x"
for j in i[::-1]:
res += hex(j)[2:].zfill(2)
res += "\n"
return res
def fullStringPrint(s):
# Get all the right byte codes
result = ""
codes = [i for i in convert(s).split("\n") if i != ""]
print("codes:",codes)
result += "# Auto-Generated Print Function\n"
for i in codes:
result += f"mov rbf, {i}\n"
result += "push rbf\n"
result += "mov rax,0x86\n"
result += f"mov rbf,{hex(len(codes)*8)}\n"
result += "mov rcx,rsp\n"
result += "sub rcx,rbf\n"
result += "mov rdi,rcx\n"
result += "syscall\n"
return result
if __name__ == "__main__":
if len(sys.argv) <2:
print("You have to supply the string to be converted!")
exit(1)
print(fullStringPrint("Adding all the numbers from 0-20 results in:\n"))