ida_dirtree
Types involved in grouping of item into folders.
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 (used to 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
Attributes
use long form of the entry name. That name is unique. |
|
use short, displayable form of the entry name. for example, 'std::string' instead of 'std::basic_string<char, ...>'. Note that more than one "full name" can have the same displayable name. |
|
ok |
|
item already exists |
|
item not found |
|
item is not a directory |
|
directory is not empty |
|
invalid path |
|
failed to rename an item |
|
moving inside subdirectory of itself |
|
maximum directory count achieved |
|
Classes
Functions
|
Module Contents
- ida_dirtree.SWIG_PYTHON_LEGACY_BOOL
- class ida_dirtree.direntry_vec_t(*args)
Bases:
object
- thisown
- push_back(*args) direntry_t &
- pop_back() None
- size() size_t
- empty() bool
- at(_idx: size_t) direntry_t const &
- qclear() None
- clear() None
- resize(*args) None
- grow(*args) None
- capacity() size_t
- reserve(cnt: size_t) None
- truncate() None
- swap(r: direntry_vec_t) None
- extract() direntry_t *
- inject(s: direntry_t, len: size_t) None
- begin(*args) qvector< direntry_t >::const_iterator
- end(*args) qvector< direntry_t >::const_iterator
- insert(it: direntry_t, x: direntry_t) qvector< direntry_t >::iterator
- erase(*args) qvector< direntry_t >::iterator
- find(*args) qvector< direntry_t >::const_iterator
- has(x: direntry_t) bool
- add_unique(x: direntry_t) bool
- append(x: direntry_t) None
- extend(x: direntry_vec_t) None
- front
- back
- class ida_dirtree.dirtree_cursor_vec_t(*args)
Bases:
object
- thisown
- push_back(*args) dirtree_cursor_t &
- pop_back() None
- size() size_t
- empty() bool
- at(_idx: size_t) dirtree_cursor_t const &
- qclear() None
- clear() None
- resize(*args) None
- grow(*args) None
- capacity() size_t
- reserve(cnt: size_t) None
- truncate() None
- swap(r: dirtree_cursor_vec_t) None
- extract() dirtree_cursor_t *
- inject(s: dirtree_cursor_t, len: size_t) None
- begin(*args) qvector< dirtree_cursor_t >::const_iterator
- end(*args) qvector< dirtree_cursor_t >::const_iterator
- insert(it: dirtree_cursor_t, x: dirtree_cursor_t) qvector< dirtree_cursor_t >::iterator
- erase(*args) qvector< dirtree_cursor_t >::iterator
- find(*args) qvector< dirtree_cursor_t >::const_iterator
- has(x: dirtree_cursor_t) bool
- add_unique(x: dirtree_cursor_t) bool
- append(x: dirtree_cursor_t) None
- extend(x: dirtree_cursor_vec_t) None
- front
- back
- class ida_dirtree.direntry_t(*args)
Bases:
object
- thisown
- idx: int
diridx_t or inode_t
- isdir: bool
is ‘idx’ a diridx_t, or an inode_t
- BADIDX
- ROOTIDX
- valid() bool
- ida_dirtree.DTN_FULL_NAME
use long form of the entry name. That name is unique.
- ida_dirtree.DTN_DISPLAY_NAME
use short, displayable form of the entry name. for example, ‘std::string’ instead of ‘std::basic_string<char, …>’. Note that more than one “full name” can have the same displayable name.
- class ida_dirtree.dirspec_t(nm: str = None, f: int = 0)
Bases:
object
- thisown
- flags: int
- DSF_INODE_EA
- DSF_PRIVRANGE
- DSF_ORDERABLE
- id: str
- get_name(inode: inode_t, name_flags: int = DTN_FULL_NAME) bool
get the entry name. for example, the structure name
- Parameters:
inode – inode number of the entry
name_flags – how exactly the name should be retrieved. combination of bits for get_…name() methods bits
- Returns:
false if the entry does not exist.
- get_inode(dirpath: str, name: str) inode_t
get the entry inode in the specified directory
- Parameters:
dirpath – the absolute directory path with trailing slash
name – the entry name in the directory
- Returns:
the entry inode
- get_attrs(inode: inode_t) str
- rename_inode(inode: inode_t, newname: str) bool
rename the entry
- Returns:
success
- unlink_inode(inode: inode_t) None
event: unlinked an inode
- is_orderable() bool
- nodename
- class ida_dirtree.dirtree_cursor_t(*args)
Bases:
object
- thisown
- parent: diridx_t
the parent directory
- rank: size_t
the index into the parent directory
- valid() bool
- is_root_cursor() bool
- set_root_cursor() None
- static root_cursor() dirtree_cursor_t
- compare(r: dirtree_cursor_t) int
- class ida_dirtree.dirtree_selection_t
Bases:
dirtree_cursor_vec_t
- thisown
- class ida_dirtree.dirtree_iterator_t
Bases:
object
- thisown
- pattern: str
- cursor: dirtree_cursor_t
- ida_dirtree.DTE_OK
ok
- ida_dirtree.DTE_ALREADY_EXISTS
item already exists
- ida_dirtree.DTE_NOT_FOUND
item not found
- ida_dirtree.DTE_NOT_DIRECTORY
item is not a directory
- ida_dirtree.DTE_NOT_EMPTY
directory is not empty
- ida_dirtree.DTE_BAD_PATH
invalid path
- ida_dirtree.DTE_CANT_RENAME
failed to rename an item
- ida_dirtree.DTE_OWN_CHILD
moving inside subdirectory of itself
- ida_dirtree.DTE_MAX_DIR
maximum directory count achieved
- ida_dirtree.DTE_LAST
- class ida_dirtree.dirtree_visitor_t
Bases:
object
- thisown
- visit(c: dirtree_cursor_t, de: direntry_t) ssize_t
Will be called for each entry in the dirtree_t If something other than 0 is returned, iteration will stop.
- Parameters:
c – the current cursor
de – the current entry
- Returns:
0 to keep iterating, or anything else to stop
- class ida_dirtree.dirtree_t(ds: dirspec_t)
Bases:
object
- thisown
- static errstr(err: dterr_t) str
Get textual representation of the error code.
- is_orderable() bool
Is dirtree orderable?
- Returns:
true if the dirtree is orderable
- chdir(path: str) dterr_t
Change current directory
- Parameters:
path – new current directory
- Returns:
dterr_t error code
- getcwd() str
Get current directory
- Returns:
the current working directory
- get_abspath(*args) str
This function has the following signatures:
get_abspath(cursor: const dirtree_cursor_t &, name_flags: int=DTN_FULL_NAME) -> str
get_abspath(relpath: str) -> str
# 0: get_abspath(cursor: const dirtree_cursor_t &, name_flags: int=DTN_FULL_NAME) -> str
Get absolute path pointed by the cursor
- Returns:
path; empty string if error
# 1: get_abspath(relpath: str) -> str
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.
- Returns:
path. empty path means wrong directory part of RELPATH
- resolve_cursor(cursor: dirtree_cursor_t) direntry_t
Resolve cursor
- Parameters:
cursor – to analyze
- Returns:
directory entry; if the cursor is bad, the resolved entry will be invalid.
- resolve_path(path: str) direntry_t
Resolve path
- Parameters:
path – to analyze
- Returns:
directory entry
- isdir(*args) bool
This function has the following signatures:
isdir(path: str) -> bool
isdir(de: const direntry_t &) -> bool
# 0: isdir(path: str) -> bool
Is a directory?
- Returns:
true if the specified path is a directory
# 1: isdir(de: const direntry_t &) -> bool
- isfile(*args) bool
This function has the following signatures:
isfile(path: str) -> bool
isfile(de: const direntry_t &) -> bool
# 0: isfile(path: str) -> bool
Is a file?
- Returns:
true if the specified path is a file
# 1: isfile(de: const direntry_t &) -> bool
- get_entry_name(de: direntry_t, name_flags: int = DTN_FULL_NAME) str
Get entry name
- Parameters:
de – directory entry
name_flags – how exactly the name should be retrieved. combination of bits for get_…name() methods bits
- Returns:
name
- is_dir_ordered(diridx: diridx_t) bool
Is dir ordered?
- Returns:
true if the dirtree has natural ordering
- set_natural_order(diridx: diridx_t, enable: bool) bool
Enable/disable natural inode order in a directory.
- Parameters:
diridx – directory index
enable – 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
- Returns:
SUCCESS
- get_dir_size(diridx: diridx_t) ssize_t
Get dir size
- Parameters:
diridx – directory index
- Returns:
number of entries under this directory; if error, return -1
- get_entry_attrs(de: direntry_t) str
Get entry attributes
- Parameters:
de – directory entry
- Returns:
name
- findfirst(ff: dirtree_iterator_t, pattern: str) bool
Start iterating over files in a directory
- Parameters:
ff – directory iterator. it will be initialized by the function
pattern – pattern to search for
- Returns:
success
- findnext(ff: dirtree_iterator_t) bool
Continue iterating over files in a directory
- Parameters:
ff – directory iterator
- Returns:
success
- mkdir(path: str) dterr_t
Create a directory.
- Parameters:
path – directory to create
- Returns:
dterr_t error code
- rmdir(path: str) dterr_t
Remove a directory.
- Parameters:
path – directory to delete
- Returns:
dterr_t error code
- link(*args) dterr_t
This function has the following signatures:
link(path: str) -> dterr_t
link(inode: inode_t) -> dterr_t
# 0: link(path: str) -> dterr_t
Add a file item into a directory.
- Returns:
dterr_t error code
# 1: link(inode: inode_t) -> dterr_t
Add an inode into the current directory
- Returns:
dterr_t error code
- unlink(*args) dterr_t
This function has the following signatures:
unlink(path: str) -> dterr_t
unlink(inode: inode_t) -> dterr_t
# 0: unlink(path: str) -> dterr_t
Remove a file item from a directory.
- Returns:
dterr_t error code
# 1: unlink(inode: inode_t) -> dterr_t
Remove an inode from the current directory
- Returns:
dterr_t error code
- rename(_from: str, to: str) dterr_t
Rename a directory entry.
- Parameters:
to – destination path
- Returns:
dterr_t error code
- get_rank(diridx: diridx_t, de: direntry_t) ssize_t
Get ordering rank of an item.
- Parameters:
diridx – index of the parent directory
de – directory entry
- Returns:
number in a range of [0..n) where n is the number of entries in the parent directory. -1 if error
- change_rank(path: str, rank_delta: ssize_t) dterr_t
Change ordering rank of an item.
- Parameters:
path – path to the item
rank_delta – the amount of the change. positive numbers mean to move down in the list; negative numbers mean to move up.
- Returns:
dterr_t error code
- get_parent_cursor(cursor: dirtree_cursor_t) dirtree_cursor_t
Get parent cursor.
- Parameters:
cursor – a valid ditree cursor
- Returns:
cursor’s parent
- load() 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.
- Returns:
success
- save() bool
Save the tree structure to the netnode.
- Returns:
success
- get_id() str
netnode name
- set_id(nm: str) None
- notify_dirtree(added: bool, inode: inode_t) None
Notify dirtree about a change of an inode.
- Parameters:
added – are we adding or deleting an inode?
inode – inode in question
- traverse(v: dirtree_visitor_t) 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.
- Parameters:
v – the callback
- Returns:
0, or whatever the visitor returned
- find_entry(de: direntry_t) dirtree_cursor_t
Find the cursor corresponding to an entry of a directory
- Parameters:
de – directory entry
- Returns:
cursor corresponding to the directory entry
- get_nodename
- set_nodename
- ida_dirtree.DIRTREE_LOCAL_TYPES
- ida_dirtree.DIRTREE_FUNCS
- ida_dirtree.DIRTREE_NAMES
- ida_dirtree.DIRTREE_IMPORTS
- ida_dirtree.DIRTREE_IDAPLACE_BOOKMARKS
- ida_dirtree.DIRTREE_BPTS
- ida_dirtree.DIRTREE_LTYPES_BOOKMARKS
- ida_dirtree.DIRTREE_END
- ida_dirtree.get_std_dirtree(id: dirtree_id_t) dirtree_t *