# SPDX-FileCopyrightText: 2021 RizinOrg <info@rizin.re>
# SPDX-License-Identifier: LGPL-3.0-only
---
name: cmd_open
commands:
  - name: o
    cname: open
    summary: Open <file>
    args:
      - name: file
        type: RZ_CMD_ARG_TYPE_FILE
      - name: addr
        type: RZ_CMD_ARG_TYPE_RZNUM
        optional: true
      - name: perm
        type: RZ_CMD_ARG_TYPE_STRING
        optional: true
  - name: o+
    cname: open_write
    summary: Open <file> in write mode
    args:
      - name: file
        type: RZ_CMD_ARG_TYPE_FILE
      - name: addr
        type: RZ_CMD_ARG_TYPE_RZNUM
        optional: true
      - name: perm
        type: RZ_CMD_ARG_TYPE_STRING
        optional: true
  - name: ol
    cname: open_list
    summary: List opened files
    args: []
    type: RZ_CMD_DESC_TYPE_ARGV_STATE
    modes:
      - RZ_OUTPUT_MODE_STANDARD
      - RZ_OUTPUT_MODE_QUIET
      - RZ_OUTPUT_MODE_JSON
      - RZ_OUTPUT_MODE_TABLE
  - name: ol.
    cname: open_show_current
    summary: Show currently opened file
    args: []
    type: RZ_CMD_DESC_TYPE_ARGV_STATE
    modes:
      - RZ_OUTPUT_MODE_STANDARD
      - RZ_OUTPUT_MODE_QUIET
      - RZ_OUTPUT_MODE_JSON
      - RZ_OUTPUT_MODE_TABLE
  - name: o-
    cname: open_close
    summary: Close file descriptor
    args:
      - name: fd
        type: RZ_CMD_ARG_TYPE_NUM
  - name: o--
    cname: open_close_all
    summary: Close all files
    args: []
  - name: oc
    cname: open_core_file
    summary: Close all opened files and open <file>, like relaunching rizin
    args:
      - name: file
        type: RZ_CMD_ARG_TYPE_FILE
  - name: oC
    cname: open_malloc
    summary: Open a 'malloc://<len>' file, copying the bytes from current offset
    args:
      - name: len
        type: RZ_CMD_ARG_TYPE_RZNUM
  - name: "on"
    summary: Open files without parsing binary info
    subcommands:
      - name: "on"
        cname: open_nobin
        summary: Open <file> without parsing binary info
        args:
          - name: file
            type: RZ_CMD_ARG_TYPE_FILE
          - name: addr
            type: RZ_CMD_ARG_TYPE_RZNUM
            optional: true
          - name: perm
            type: RZ_CMD_ARG_TYPE_STRING
            optional: true
      - name: on+
        cname: open_nobin_write
        summary: Open <file> in write mode, without parsing binary info
        args:
          - name: file
            type: RZ_CMD_ARG_TYPE_FILE
          - name: addr
            type: RZ_CMD_ARG_TYPE_RZNUM
            optional: true
          - name: perm
            type: RZ_CMD_ARG_TYPE_STRING
            optional: true
  - name: oo
    summary: Reopen current file
    subcommands:
      - name: oo
        cname: reopen
        summary: Reopen current file or file <fd>
        args:
          - name: fd
            type: RZ_CMD_ARG_TYPE_NUM
            optional: true
      - name: oo+
        cname: reopen_write
        summary: Reopen current file or file <fd> in write mode
        args:
          - name: fd
            type: RZ_CMD_ARG_TYPE_NUM
            optional: true
      - name: oob
        cname: reopen_binary
        summary: Reopen current file and reload binary information
        args:
          - name: baddr
            type: RZ_CMD_ARG_TYPE_RZNUM
            optional: true
      - name: ooc
        cname: reopen_core
        summary: Reopen current file as if restarting rizin
        args: []
      - name: ood
        summary: Reopen current file in debug mode
        subcommands:
          - name: ood
            cname: reopen_debug
            summary: Reopen current file in debug mode
            args:
              - name: args
                type: RZ_CMD_ARG_TYPE_STRING
                flags: RZ_CMD_ARG_FLAG_ARRAY
                optional: true
          - name: oodf
            cname: reopen_debug_file
            summary: Open <uri> in debug mode
            args:
              - name: uri
                type: RZ_CMD_ARG_TYPE_STRING
              - name: addr
                type: RZ_CMD_ARG_TYPE_RZNUM
                optional: true
          - name: oodr
            cname: reopen_debug_rzrun
            summary: Reopen current file in debug mode with given rz-run directives
            args:
              - name: rz-run-directives
                type: RZ_CMD_ARG_TYPE_STRING
      - name: oom
        cname: reopen_malloc
        summary: Reopen curent file in malloc://
        args: []
      - name: oon
        cname: reopen_nobin
        summary: Reopen curent file without loading binary information
        args: []
      - name: oon+
        cname: reopen_nobin_write
        summary: Reopen curent file in write-mode without loading binary information
        args: []
      - name: oonn
        cname: reopen_nobin_headers
        summary: Reopen curent file without loading binary information but with header flags
        args: []
      - name: oonn+
        cname: reopen_nobin_write_headers
        summary: Reopen curent file in write-mode without loading binary information but with header flags
        args: []
  - name: oL
    cname: open_plugins
    handler: plugins_io_print
    summary: List all IO plugins / Register IO plugin from <path>
    type: RZ_CMD_DESC_TYPE_ARGV_STATE
    args:
      - name: path
        type: RZ_CMD_ARG_TYPE_FILE
        optional: true
    default_mode: RZ_OUTPUT_MODE_TABLE
    modes:
      - RZ_OUTPUT_MODE_TABLE
      - RZ_OUTPUT_MODE_JSON
      - RZ_OUTPUT_MODE_QUIET
  - name: o=
    cname: open_list_ascii
    summary: List opened files in ASCII-art bars
    args: []
  - name: oa
    cname: open_arch_bits
    summary: Specify <arch> and <bits> for the file <filename> or the current one if none is specified
    args:
      - name: arch
        type: RZ_CMD_ARG_TYPE_STRING
      - name: bits
        type: RZ_CMD_ARG_TYPE_RZNUM
      - name: filename
        type: RZ_CMD_ARG_TYPE_FILE
        optional: true
  - name: ob
    summary: Handle binary files
    subcommands:
      - name: ob
        cname: open_binary_select_id
        summary: Switch to binary file with the given <id>
        args:
          - name: id
            type: RZ_CMD_ARG_TYPE_NUM
      - name: obo
        cname: open_binary_select_fd
        summary: Switch to binary file with the given <fd>
        args:
          - name: fd
            type: RZ_CMD_ARG_TYPE_NUM
      - name: ob-
        cname: open_binary_del
        summary: Delete binary file with the given <id>
        args:
          - name: id
            type: RZ_CMD_ARG_TYPE_NUM
      - name: ob-*
        cname: open_binary_del_all
        summary: Delete all binary files
        args: []
      - name: obl
        cname: open_binary_list
        summary: List opened binary files
        type: RZ_CMD_DESC_TYPE_ARGV_STATE
        modes:
          - RZ_OUTPUT_MODE_STANDARD
          - RZ_OUTPUT_MODE_JSON
          - RZ_OUTPUT_MODE_QUIET
          - RZ_OUTPUT_MODE_TABLE
        args: []
      - name: obl=
        cname: open_binary_list_ascii
        summary: List opened binary files in ASCII art
        args: []
      - name: ob.
        cname: open_binary_show
        summary: Show id of binary file current address
        args: []
      - name: oba
        cname: open_binary_add
        summary: Open binary file for current file and load binary info with baseaddr at current offset
        args:
          - name: loadaddr
            type: RZ_CMD_ARG_TYPE_RZNUM
            default_value: 0
      - name: obf
        cname: open_binary_file
        summary: Load binary info for the given file or current one with baseaddr at current offset
        args:
          - name: file
            type: RZ_CMD_ARG_TYPE_FILE
            optional: true
      - name: obs
        cname: open_binary_select
        summary: Select the binary version for the specified architecture from the fat binary.
        args:
          - name: arch
            type: RZ_CMD_ARG_TYPE_STRING
            optional: true
        details:
          - name: Examples
            entries:
              - text: "obs"
                comment: "List all architectures the fat binary supports contains."
              - text: "obs sparc"
                comment: "Select and load the binary for Sparc"
      - name: obR
        cname: open_binary_reload
        summary: Reload the current buffer for setting of the bin (use once only)
        args:
          - name: baddr
            type: RZ_CMD_ARG_TYPE_RZNUM
            default_value: 0
  - name: ou
    cname: open_use
    summary: Use specified <fd>
    args:
      - name: fd
        type: RZ_CMD_ARG_TYPE_NUM
  - name: op
    summary: Select prioritized file
    subcommands:
      - name: op
        cname: open_prioritize
        summary: Prioritize file with file descriptor <fd>
        args:
          - name: fd
            type: RZ_CMD_ARG_TYPE_NUM
      - name: opn
        cname: open_prioritize_next
        summary: Prioritize next file in the list
        args: []
      - name: opp
        cname: open_prioritize_prev
        summary: Prioritize previous file in the list
        args: []
      - name: opr
        cname: open_prioritize_next_rotate
        summary: Prioritize next file in the list (go back to first if on the last)
        args: []
  - name: om
    summary: Handle IO maps
    subcommands:
      - name: om
        cname: open_maps_map
        summary: Create a new map
        args:
          - name: fd
            type: RZ_CMD_ARG_TYPE_NUM
          - name: vaddr
            type: RZ_CMD_ARG_TYPE_RZNUM
          - name: size
            type: RZ_CMD_ARG_TYPE_RZNUM
            optional: true
          - name: paddr
            type: RZ_CMD_ARG_TYPE_RZNUM
            optional: true
          - name: flags
            type: RZ_CMD_ARG_TYPE_STRING
            optional: true
          - name: name
            type: RZ_CMD_ARG_TYPE_STRING
            optional: true
      - name: oml
        cname: open_maps_list
        summary: List maps of all file descriptor or only the specified <fd>
        type: RZ_CMD_DESC_TYPE_ARGV_STATE
        modes:
          - RZ_OUTPUT_MODE_QUIET
          - RZ_OUTPUT_MODE_QUIETEST
          - RZ_OUTPUT_MODE_STANDARD
          - RZ_OUTPUT_MODE_TABLE
          - RZ_OUTPUT_MODE_JSON
        args:
          - name: fd
            type: RZ_CMD_ARG_TYPE_NUM
            optional: true
      - name: oml.
        cname: open_maps_list_cur
        summary: Show map at the current offset
        type: RZ_CMD_DESC_TYPE_ARGV_STATE
        modes:
          - RZ_OUTPUT_MODE_QUIET
          - RZ_OUTPUT_MODE_QUIETEST
          - RZ_OUTPUT_MODE_STANDARD
          - RZ_OUTPUT_MODE_TABLE
          - RZ_OUTPUT_MODE_JSON
        args: []
      - name: oml=
        cname: open_maps_list_ascii
        summary: List IO maps in ASCII art
        args: []
      - name: om-
        cname: open_maps_remove
        summary: Remove the IO map with corresponding <id>
        args:
          - name: id
            type: RZ_CMD_ARG_TYPE_NUM
      - name: om-*
        cname: open_maps_remove_all
        summary: Remove all IO maps
        args: []
      - name: oma
        cname: open_maps_all_fd
        summary: Create a IO map covering all VA for given <fd> or current one if not provided
        args:
          - name: fd
            type: RZ_CMD_ARG_TYPE_NUM
            optional: true
      - name: omb
        cname: open_maps_relocate
        summary: Relocate map with corresponding <id> to <addr>
        args:
          - name: id
            type: RZ_CMD_ARG_TYPE_NUM
          - name: addr
            type: RZ_CMD_ARG_TYPE_RZNUM
      - name: omb.
        cname: open_maps_relocate_current
        summary: Relocate map at current offset to <addr>
        args:
          - name: addr
            type: RZ_CMD_ARG_TYPE_RZNUM
      - name: omf
        cname: open_maps_flags
        summary: Change flags/perms for map with given <id> or current one
        args:
          - name: flags
            type: RZ_CMD_ARG_TYPE_STRING
          - name: id
            type: RZ_CMD_ARG_TYPE_NUM
            optional: true
      - name: omfg
        cname: open_maps_flags_global
        summary: Change flags/perms for all maps
        description: >
          Update flags of all maps. If <flags> starts with a +, the specified flags
          are added to the maps. If <flags> starts with a -, the specified flags
          are removed from the maps. Otherwise, the exact <flags> are set for
          each map.
        args:
          - name: flags
            type: RZ_CMD_ARG_TYPE_STRING
      - name: omm
        cname: open_maps_map_fd
        summary: Create default map for given <fd> or current one
        args:
          - name: fd
            type: RZ_CMD_ARG_TYPE_NUM
            optional: true
      - name: omn
        summary: Handle maps names
        subcommands:
          - name: omn
            cname: open_maps_name
            summary: Set name of map which spans current seek
            args:
              - name: name
                type: RZ_CMD_ARG_TYPE_STRING
          - name: omn-
            cname: open_maps_name_del
            summary: Delete name of map which spans current seek
            args: []
          - name: omni
            cname: open_maps_name_id
            summary: Set name of map with map <id>
            args:
              - name: id
                type: RZ_CMD_ARG_TYPE_NUM
              - name: name
                type: RZ_CMD_ARG_TYPE_STRING
          - name: omni-
            cname: open_maps_name_id_del
            summary: Delete name of map with map <id>
            args:
              - name: id
                type: RZ_CMD_ARG_TYPE_NUM
      - name: omr
        cname: open_maps_resize
        summary: Resize map with corresponding <id>
        args:
          - name: id
            type: RZ_CMD_ARG_TYPE_NUM
          - name: newsize
            type: RZ_CMD_ARG_TYPE_RZNUM
      - name: omp
        summary: Prioritize maps
        subcommands:
          - name: omp
            cname: open_maps_prioritize
            summary: Prioritize map with the corresponding id
            args:
              - name: id
                type: RZ_CMD_ARG_TYPE_NUM
          - name: ompb
            cname: open_maps_prioritize_binid
            summary: Prioritize maps of the bin associated with the binid
            args:
              - name: fd
                type: RZ_CMD_ARG_TYPE_NUM
          - name: ompd
            cname: open_maps_deprioritize
            summary: Deprioritize map with the corresponding id
            args:
              - name: id
                type: RZ_CMD_ARG_TYPE_NUM
          - name: ompf
            cname: open_maps_prioritize_fd
            summary: Prioritize map by fd
            args:
              - name: fd
                type: RZ_CMD_ARG_TYPE_NUM
  - name: ox
    cname: open_exchange
    summary: Exchange the descs of <fd> and <fdx> and keep the mapping
    args:
      - name: fd
        type: RZ_CMD_ARG_TYPE_NUM
      - name: fdx
        type: RZ_CMD_ARG_TYPE_NUM
