Last active
March 9, 2020 23:49
-
-
Save mouseroot/21491779d723ad946bf791d824e9876a to your computer and use it in GitHub Desktop.
Build and Assemble a program to print a message, using python (self contained script)
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
import subprocess | |
asm_code = """ | |
.global _start | |
.text | |
_start: | |
mov $1,%rax | |
mov $1,%rdi | |
mov $msg, %rsi | |
mov $?size?, %rdx | |
syscall | |
mov $60, %rax | |
xor %rdi,%rdi | |
syscall | |
msg: | |
.ascii "?message?" | |
""" | |
with open("_main.s","w") as _code: | |
_code.write(asm_code) | |
line = raw_input("Message:") | |
sz = len(line) | |
with open("_main.s","r") as f: | |
data = f.read() | |
result = data.replace("?size?",str(sz)) | |
result = result.replace("?message?",line.replace("\n",'')) | |
with open("patch_main.s","w") as _out: | |
_out.write(result) | |
subprocess.call(["gcc","-c","patch_main.s","-o","patch.o"]) | |
subprocess.call(["ld","patch.o","-o","app"]) | |
print("Complete") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment