#!/usr/bin/env python
from vagd import {dependencies}, Box
from pwn import *

GDB_OFF = 0x555555555000
IP = '{ip}'
PORT = {port}
BINARY = '{binary}'
ARGS = []
ENV = {}
GDB = f"""

c"""

context.binary = exe = ELF(BINARY, checksec=False)
libc = ELF('{libc}', checksec=False)
context.aslr = {aslr}

byt = lambda x: str(x).encode()
phex = lambda x, y='': print(y + hex(x))
lhex = lambda x, y='': log.info(y + hex(x))

t = None
gt = lambda at=None: at if at else t
sl = lambda x, t=None: gt(t).sendline(x)
se = lambda x, t=None: gt(t).send(x)
sla = lambda x, y, t=None: gt(t).sendlineafter(x, y)
sa = lambda x, y, t=None: gt(t).sendafter(x, y)
ra = lambda t=None: gt(t).recvall()
rl = lambda t=None: gt(t).recvline()
re = lambda x, t=None: gt(t).recv(x)
ru = lambda x, t=None: gt(t).recvuntil(x)
it = lambda t=None: gt(t).interactive()
cl = lambda t=None: gt(t).close()

vm = None
def get_target(**kw):
    global vm

    if args.REMOTE:
        context.log_level = 'debug'
        return remote(IP, PORT)

    if not vm:
        {vms}
    return vm.start(argv=ARGS, env=ENV, gdbscript=GDB, **kw)


t = get_target()

it() # or t.interactive()
