Example #1
0
def ql_syscall_faccessat(ql: Qiling, dfd: int, filename: int, mode: int):
    access_path = ql.os.utils.read_cstring(filename)
    real_path = ql.os.path.transform_to_real_path(access_path)

    if not os.path.exists(real_path):
        regreturn = -1

    elif stat.S_ISFIFO(Stat(real_path).st_mode):
        regreturn = 0

    else:
        regreturn = -1

    if regreturn == -1:
        ql.log.debug(f'File not found or skipped: {access_path}')
    else:
        ql.log.debug(f'File found: {access_path}')

    return regreturn
Example #2
0
def ql_syscall_newfstatat(ql: Qiling, dirfd: int, path: int, buf_ptr: int,
                          flag: int):
    # FIXME: dirfd(relative path) not implement.
    file_path = ql.os.utils.read_cstring(path)
    real_path = ql.os.path.transform_to_real_path(file_path)
    relative_path = ql.os.path.transform_to_relative_path(file_path)

    if os.path.exists(real_path):
        buf = pack_stat_struct(ql, Stat(real_path))
        ql.mem.write(buf_ptr, buf)

        regreturn = 0
    else:
        regreturn = -1

    ql.log.debug(
        f'Directory {"found" if regreturn == 0 else "not found"}: {relative_path}'
    )

    return regreturn
Example #3
0
def ql_syscall_ftruncate(ql: Qiling, fd: int, length: int):
    real_path = ql.os.fd[fd].name
    st_size = Stat(real_path).st_size

    try:
        if st_size >= length:
            os.truncate(real_path, length)

        else:
            padding = length - st_size

            with open(real_path, 'a+b') as ofile:
                ofile.write(b'\x00' * padding)
    except:
        regreturn = -1
    else:
        regreturn = 0

    ql.log.debug("ftruncate(%d, 0x%x) = %d" % (fd, length, regreturn))

    return regreturn
Example #4
0
def ql_syscall_truncate(ql: Qiling, path: int, length: int):
    file_path = ql.os.utils.read_cstring(path)
    real_path = ql.os.path.transform_to_real_path(file_path)
    st_size = Stat(real_path).st_size

    try:
        if st_size >= length:
            os.truncate(real_path, length)

        else:
            padding = length - st_size

            with open(real_path, 'a+b') as ofile:
                ofile.write(b'\x00' * padding)
    except:
        regreturn = -1
    else:
        regreturn = 0

    ql.log.debug('truncate(%s, 0x%x) = %d' % (file_path, length, regreturn))

    return regreturn