Module ida_dirtree

The dirtree_t class is used to organize a directory tree on top of any collection that allows for accessing its elements by an id (inode).

No requirements are imposed on the inodes apart from the forbidden value -1 (it is used ot denote a bad inode).

The dirspec_t class is used to specialize the dirtree. It can be used to introduce a directory structure for:

  • local types

  • structs

  • enums

  • functions

  • names

  • etc

@note: you should be manipulating dirtree_t (and, if implementing a new tree backend, dirspec_t) instances, not calling top-level functions in this file directly.

Global Variables

DIRTREE_BPTS

DIRTREE_BPTS = 5

DIRTREE_END

DIRTREE_END = 7

DIRTREE_FUNCS

DIRTREE_FUNCS = 1

DIRTREE_IDAPLACE_BOOKMARKS

DIRTREE_IDAPLACE_BOOKMARKS = 4

DIRTREE_IMPORTS

DIRTREE_IMPORTS = 3

DIRTREE_LOCAL_TYPES

DIRTREE_LOCAL_TYPES = 0

DIRTREE_LTYPES_BOOKMARKS

DIRTREE_LTYPES_BOOKMARKS = 6

DIRTREE_NAMES

DIRTREE_NAMES = 2

DTE_ALREADY_EXISTS

DTE_ALREADY_EXISTS = 1

DTE_BAD_PATH

DTE_BAD_PATH = 5

DTE_CANT_RENAME

DTE_CANT_RENAME = 6

DTE_LAST

DTE_LAST = 9

DTE_MAX_DIR

DTE_MAX_DIR = 8

DTE_NOT_DIRECTORY

DTE_NOT_DIRECTORY = 3

DTE_NOT_EMPTY

DTE_NOT_EMPTY = 4

DTE_NOT_FOUND

DTE_NOT_FOUND = 2

DTE_OK

DTE_OK = 0

DTE_OWN_CHILD

DTE_OWN_CHILD = 7

DTN_DISPLAY_NAME

DTN_DISPLAY_NAME = 1

DTN_FULL_NAME

DTN_FULL_NAME = 0

Functions

get_std_dirtree(id: dirtree_id_t) ‑> dirtree_t *

get_std_dirtree(id) -> dirtree_t

id: enum dirtree_id_t

Classes

direntry_t(*args)

: Proxy of C++ direntry_t class.

__init__(self, i=BADIDX, d=False) -> direntry_t

 i: uval_t
 d: bool

Class variables

  • BADIDX


  • ROOTIDX


Instance variables

  • idx: uval_t idx


  • isdir: bool isdir


Methods

  • valid(self) ‑> bool valid(self) -> bool


direntry_vec_t(*args)

: Proxy of C++ qvector< direntry_t > class.

__init__(self) -> direntry_vec_t
__init__(self, x) -> direntry_vec_t

 x: qvector< direntry_t > const &

Methods

  • add_unique(self, x: direntry_t) ‑> bool add_unique(self, x) -> bool

    x: direntry_t const &


  • at(self, _idx: size_t) ‑> direntry_t const & at(self, _idx) -> direntry_t

    _idx: size_t


  • back(self)


  • begin(self, *args) ‑> qvector< direntry_t >::const_iterator begin(self) -> direntry_t


  • capacity(self) ‑> size_t capacity(self) -> size_t


  • clear(self) ‑> void clear(self)


  • empty(self) ‑> bool empty(self) -> bool


  • end(self, *args) ‑> qvector< direntry_t >::const_iterator end(self) -> direntry_t


  • erase(self, *args) ‑> qvector< direntry_t >::iterator erase(self, it) -> direntry_t

    it: qvector< direntry_t >::iterator

    erase(self, first, last) -> direntry_t

    first: qvector< direntry_t >::iterator last: qvector< direntry_t >::iterator


  • extract(self) ‑> direntry_t * extract(self) -> direntry_t


  • find(self, *args) ‑> qvector< direntry_t >::const_iterator find(self, x) -> direntry_t

    x: direntry_t const &


  • front(self)


  • grow(self, *args) ‑> void grow(self, x=direntry_t())

    x: direntry_t const &


  • has(self, x: direntry_t) ‑> bool has(self, x) -> bool

    x: direntry_t const &


  • inject(self, s: direntry_t, len: size_t) ‑> void inject(self, s, len)

    s: direntry_t * len: size_t


  • insert(self, it: direntry_t, x: direntry_t) ‑> qvector< direntry_t >::iterator insert(self, it, x) -> direntry_t

    it: qvector< direntry_t >::iterator x: direntry_t const &


  • pop_back(self) ‑> void pop_back(self)


  • push_back(self, *args) ‑> direntry_t & push_back(self, x)

    x: direntry_t const &

    push_back(self) -> direntry_t


  • qclear(self) ‑> void qclear(self)


  • reserve(self, cnt: size_t) ‑> void reserve(self, cnt)

    cnt: size_t


  • resize(self, *args) ‑> void resize(self, _newsize, x)

    _newsize: size_t x: direntry_t const &

    resize(self, _newsize)

    _newsize: size_t


  • size(self) ‑> size_t size(self) -> size_t


  • swap(self, r: direntry_vec_t) ‑> void swap(self, r)

    r: qvector< direntry_t > &


  • truncate(self) ‑> void truncate(self)


dirspec_t(nm: char const * = None, f: uint32 = 0)

: Proxy of C++ dirspec_t class.

__init__(self, nm=None, f=0) -> dirspec_t

 nm: char const *
 f: uint32

Class variables

  • DSF_INODE_EA


  • DSF_ORDERABLE


  • DSF_PRIVRANGE


Instance variables

  • flags: uint32 flags


  • id: qstring id


  • nodename id


Methods

  • get_attrs(self, inode: inode_t) ‑> qstring get_attrs(self, inode) -> qstring

    inode: inode_t


  • get_inode(self, dirpath: char const *, name: char const *) ‑> inode_t get_inode(self, dirpath, name) -> inode_t get the entry inode in the specified directory

    dirpath: (C++: const char *) the absolute directory path with trailing slash name: (C++: const char *) the entry name in the directory return: the entry inode


  • get_name(self, inode: inode_t, name_flags: uint32 = 0) ‑> bool get_name(self, inode, name_flags=DTN_FULL_NAME) -> bool get the entry name. for example, the structure name

    inode: (C++: inode_t) inode number of the entry name_flags: (C++: uint32) how exactly the name should be retrieved. combination of bits for get_...name() methods bits return: false if the entry does not exist.


  • is_orderable(self) ‑> bool is_orderable(self) -> bool


  • rename_inode(self, inode: inode_t, newname: char const *) ‑> bool rename_inode(self, inode, newname) -> bool rename the entry

    inode: (C++: inode_t) newname: (C++: const char *) return: success


  • unlink_inode(self, inode: inode_t) ‑> void unlink_inode(self, inode)

    inode: (C++: inode_t)


dirtree_cursor_t(*args)

: Proxy of C++ dirtree_cursor_t class.

__init__(self, _parent=BADIDX, _rank=size_t(-1)) -> dirtree_cursor_t

 _parent: diridx_t
 _rank: size_t

Static methods

  • root_cursor() ‑> ida_dirtree.dirtree_cursor_t root_cursor() -> dirtree_cursor_t


Instance variables

  • parent: diridx_t parent


  • rank: size_t rank


Methods

  • compare(self, r: dirtree_cursor_t) ‑> int compare(self, r) -> int

    r: dirtree_cursor_t const &


  • is_root_cursor(self) ‑> bool is_root_cursor(self) -> bool


  • set_root_cursor(self) ‑> void set_root_cursor(self)


  • valid(self) ‑> bool valid(self) -> bool


dirtree_cursor_vec_t(*args)

: Proxy of C++ qvector< dirtree_cursor_t > class.

__init__(self) -> dirtree_cursor_vec_t
__init__(self, x) -> dirtree_cursor_vec_t

 x: qvector< dirtree_cursor_t > const &

Descendants

* ida_dirtree.dirtree_selection_t

Methods

  • add_unique(self, x: dirtree_cursor_t) ‑> bool add_unique(self, x) -> bool

    x: dirtree_cursor_t const &


  • at(self, _idx: size_t) ‑> dirtree_cursor_t const & at(self, _idx) -> dirtree_cursor_t

    _idx: size_t


  • back(self)


  • begin(self, *args) ‑> qvector< dirtree_cursor_t >::const_iterator begin(self) -> dirtree_cursor_t


  • capacity(self) ‑> size_t capacity(self) -> size_t


  • clear(self) ‑> void clear(self)


  • empty(self) ‑> bool empty(self) -> bool


  • end(self, *args) ‑> qvector< dirtree_cursor_t >::const_iterator end(self) -> dirtree_cursor_t


  • erase(self, *args) ‑> qvector< dirtree_cursor_t >::iterator erase(self, it) -> dirtree_cursor_t

    it: qvector< dirtree_cursor_t >::iterator

    erase(self, first, last) -> dirtree_cursor_t

    first: qvector< dirtree_cursor_t >::iterator last: qvector< dirtree_cursor_t >::iterator


  • extract(self) ‑> dirtree_cursor_t * extract(self) -> dirtree_cursor_t


  • find(self, *args) ‑> qvector< dirtree_cursor_t >::const_iterator find(self, x) -> dirtree_cursor_t

    x: dirtree_cursor_t const &


  • front(self)


  • grow(self, *args) ‑> void grow(self, x=dirtree_cursor_t())

    x: dirtree_cursor_t const &


  • has(self, x: dirtree_cursor_t) ‑> bool has(self, x) -> bool

    x: dirtree_cursor_t const &


  • inject(self, s: dirtree_cursor_t, len: size_t) ‑> void inject(self, s, len)

    s: dirtree_cursor_t * len: size_t


  • insert(self, it: dirtree_cursor_t, x: dirtree_cursor_t) ‑> qvector< dirtree_cursor_t >::iterator insert(self, it, x) -> dirtree_cursor_t

    it: qvector< dirtree_cursor_t >::iterator x: dirtree_cursor_t const &


  • pop_back(self) ‑> void pop_back(self)


  • push_back(self, *args) ‑> dirtree_cursor_t & push_back(self, x)

    x: dirtree_cursor_t const &

    push_back(self) -> dirtree_cursor_t


  • qclear(self) ‑> void qclear(self)


  • reserve(self, cnt: size_t) ‑> void reserve(self, cnt)

    cnt: size_t


  • resize(self, *args) ‑> void resize(self, _newsize, x)

    _newsize: size_t x: dirtree_cursor_t const &

    resize(self, _newsize)

    _newsize: size_t


  • size(self) ‑> size_t size(self) -> size_t


  • swap(self, r: dirtree_cursor_vec_t) ‑> void swap(self, r)

    r: qvector< dirtree_cursor_t > &


  • truncate(self) ‑> void truncate(self)


dirtree_iterator_t()

: Proxy of C++ dirtree_iterator_t class.

__init__(self) -> dirtree_iterator_t

Instance variables

  • cursor: dirtree_cursor_t cursor


  • pattern: qstring pattern


dirtree_selection_t()

: Proxy of C++ dirtree_selection_t class.

__init__(self) -> dirtree_selection_t

Ancestors (in MRO)

* ida_dirtree.dirtree_cursor_vec_t

dirtree_t(ds: dirspec_t)

: Proxy of C++ dirtree_t class.

__init__(self, ds) -> dirtree_t

 ds: dirspec_t *

Static methods

  • errstr(err: dterr_t) ‑> char const * errstr(err) -> char const * Get textual representation of the error code.

    err: (C++: dterr_t) enum dterr_t


Methods

  • change_rank(self, path: char const *, rank_delta: ssize_t) ‑> dterr_t change_rank(self, path, rank_delta) -> dterr_t Change ordering rank of an item.

    path: (C++: const char *) path to the item rank_delta: (C++: ssize_t) the amount of the change. positive numbers mean to move down in the list; negative numbers mean to move up. return: dterr_t error code note: this function may disable natural ordering of the parent folder @see: set_natural_order()


  • chdir(self, path: char const *) ‑> dterr_t chdir(self, path) -> dterr_t Change current directory

    path: (C++: const char *) new current directory return: dterr_t error code


  • find_entry(self, de: direntry_t) ‑> ida_dirtree.dirtree_cursor_t find_entry(self, de) -> dirtree_cursor_t Find the cursor corresponding to an entry of a directory

    de: (C++: const direntry_t &) directory entry return: cursor corresponding to the directory entry


  • findfirst(self, ff: dirtree_iterator_t, pattern: char const *) ‑> bool findfirst(self, ff, pattern) -> bool Start iterating over files in a directory

    ff: (C++: dirtree_iterator_t *) directory iterator. it will be initialized by the function pattern: (C++: const char *) pattern to search for return: success


  • findnext(self, ff: dirtree_iterator_t) ‑> bool findnext(self, ff) -> bool Continue iterating over files in a directory

    ff: (C++: dirtree_iterator_t *) directory iterator return: success


  • get_abspath(self, *args) ‑> qstring get_abspath(self, cursor, name_flags=DTN_FULL_NAME) -> qstring Construct an absolute path from the specified relative path. This function verifies the directory part of the specified path. The last component of the specified path is not verified.

    cursor: dirtree_cursor_t const & name_flags: uint32

    return: path. empty path means wrong directory part of RELPATH get_abspath(self, relpath) -> qstring

    relpath: char const *


  • get_dir_size(self, diridx: diridx_t) ‑> ssize_t get_dir_size(self, diridx) -> ssize_t Get dir size

    diridx: (C++: diridx_t) directory index return: number of entries under this directory; if error, return -1


  • get_entry_attrs(self, de: direntry_t) ‑> qstring get_entry_attrs(self, de) -> qstring Get entry attributes

    de: (C++: const direntry_t &) directory entry return: name


  • get_entry_name(self, de: direntry_t, name_flags: uint32 = 0) ‑> qstring get_entry_name(self, de, name_flags=DTN_FULL_NAME) -> qstring Get entry name

    de: (C++: const direntry_t &) directory entry name_flags: (C++: uint32) how exactly the name should be retrieved. combination of bits for get_...name() methods bits return: name


  • get_id(self) ‑> char const * get_id(self) -> char const * netnode name


  • get_nodename(self) ‑> char const * get_id(self) -> char const * netnode name


  • get_parent_cursor(self, cursor: dirtree_cursor_t) ‑> ida_dirtree.dirtree_cursor_t get_parent_cursor(self, cursor) -> dirtree_cursor_t Get parent cursor.

    cursor: (C++: const dirtree_cursor_t &) a valid ditree cursor return: cursor's parent


  • get_rank(self, diridx: diridx_t, de: direntry_t) ‑> ssize_t get_rank(self, diridx, de) -> ssize_t Get ordering rank of an item.

    diridx: (C++: diridx_t) index of the parent directory de: (C++: const direntry_t &) directory entry return: number in a range of [0..n) where n is the number of entries in the parent directory. -1 if error


  • getcwd(self) ‑> qstring getcwd(self) -> qstring Get current directory

    return: the current working directory


  • is_dir_ordered(self, diridx: diridx_t) ‑> bool is_dir_ordered(self, diridx) -> bool Is dir ordered?

    diridx: (C++: diridx_t) return: true if the dirtree has natural ordering


  • is_orderable(self) ‑> bool is_orderable(self) -> bool Is dirtree orderable?

    return: true if the dirtree is orderable


  • isdir(self, *args) ‑> bool isdir(self, de) -> bool

    de: direntry_t const &

    isdir(self, path) -> bool

    path: char const *


  • isfile(self, *args) ‑> bool isfile(self, de) -> bool

    de: direntry_t const &

    isfile(self, path) -> bool

    path: char const *


  • link(self, *args) ‑> dterr_t link(self, path) -> dterr_t Add an inode into the current directory

    path: char const *

    return: dterr_t error code link(self, inode) -> dterr_t

    inode: inode_t


  • load(self) ‑> bool load(self) -> bool Load the tree structure from the netnode. If dirspec_t::id is empty, the operation will be considered a success. In addition, calling load() more than once will not do anything, and will be considered a success.

    return: success @see: dirspec_t::id.


  • mkdir(self, path: char const *) ‑> dterr_t mkdir(self, path) -> dterr_t Create a directory.

    path: (C++: const char *) directory to create return: dterr_t error code


  • notify_dirtree(self, added: bool, inode: inode_t) ‑> void notify_dirtree(self, added, inode) Notify dirtree about a change of an inode.

    added: (C++: bool) are we adding or deleting an inode? inode: (C++: inode_t) inode in question


  • rename(self, _from: char const *, to: char const *) ‑> dterr_t rename(self, _from, to) -> dterr_t Rename a directory entry.

    from: (C++: const char *) source path to: (C++: const char *) destination path return: dterr_t error code note: This function can also rename the item


  • resolve_cursor(self, cursor: dirtree_cursor_t) ‑> ida_dirtree.direntry_t resolve_cursor(self, cursor) -> direntry_t Resolve cursor

    cursor: (C++: const dirtree_cursor_t &) to analyze return: directory entry; if the cursor is bad, the resolved entry will be invalid. note: see also get_abspath()


  • resolve_path(self, path: char const *) ‑> direntry_t resolve_path(self, path) -> direntry_t Resolve path

    path: (C++: const char *) to analyze return: directory entry


  • rmdir(self, path: char const *) ‑> dterr_t rmdir(self, path) -> dterr_t Remove a directory.

    path: (C++: const char *) directory to delete return: dterr_t error code


  • save(self) ‑> bool save(self) -> bool Save the tree structure to the netnode.

    return: success @see: dirspec_t::id.


  • set_id(self, nm: char const *) ‑> void set_id(self, nm)

    nm: char const *


  • set_natural_order(self, diridx: diridx_t, enable: bool) ‑> bool set_natural_order(self, diridx, enable) -> bool Enable/disable natural inode order in a directory.

    diridx: (C++: diridx_t) directory index enable: (C++: bool) action to do TRUE - enable ordering: re-order existing entries so that all subdirs are at the to beginning of the list, file entries are sorted and placed after the subdirs FALSE - disable ordering, no changes to existing entries return: SUCCESS


  • set_nodename(self, nm: char const *) ‑> void set_id(self, nm)

    nm: char const *


  • traverse(self, v: dirtree_visitor_t) ‑> ssize_t traverse(self, v) -> ssize_t Traverse dirtree, and be notified at each entry If the the visitor returns anything other than 0, iteration will stop, and that value returned. The tree is traversed using a depth-first algorithm. It is forbidden to modify the dirtree_t during traversal; doing so will result in undefined behavior.

    v: (C++: dirtree_visitor_t &) the callback return: 0, or whatever the visitor returned


  • unlink(self, *args) ‑> dterr_t unlink(self, path) -> dterr_t Remove an inode from the current directory

    path: char const *

    return: dterr_t error code unlink(self, inode) -> dterr_t

    inode: inode_t


dirtree_visitor_t()

: Proxy of C++ dirtree_visitor_t class.

__init__(self) -> dirtree_visitor_t

 self: PyObject *

Methods

  • visit(self, c: dirtree_cursor_t, de: direntry_t) ‑> ssize_t visit(self, c, de) -> ssize_t Will be called for each entry in the dirtree_t If something other than 0 is returned, iteration will stop.

    c: (C++: const dirtree_cursor_t &) the current cursor de: (C++: const direntry_t &) the current entry return: 0 to keep iterating, or anything else to stop


Last updated