angr.storage.file¶
- class angr.storage.file.Flags¶
Bases:
object- O_RDONLY = 0¶
- O_WRONLY = 1¶
- O_RDWR = 2¶
- O_ACCMODE = 3¶
- O_APPEND = 1024¶
- O_ASYNC = 8192¶
- O_CLOEXEC = 524288¶
- O_CREAT = 64¶
- O_DIRECT = 16384¶
- O_DIRECTORY = 65536¶
- O_DSYNC = 4096¶
- O_EXCL = 128¶
- O_LARGEFILE = 32768¶
- O_NOATIME = 262144¶
- O_NOCTTY = 256¶
- O_NOFOLLOW = 131072¶
- O_NONBLOCK = 2048¶
- O_NDELAY = 2048¶
- O_PATH = 2097152¶
- O_SYNC = 1052672¶
- O_TMPFILE = 4259840¶
- O_TRUNC = 512¶
- class angr.storage.file.SimFileBase¶
Bases:
SimStatePluginSimFiles are the storage mechanisms used by SimFileDescriptors.
Different types of SimFiles can have drastically different interfaces, and as a result there’s not much that can be specified on this base class. All the read and write methods take a
posargument, which may have different semantics per-class.0will always be a valid position to use, though, and the next position you should use is part of the return tuple.Some simfiles are “streams”, meaning that the position that reads come from is determined not by the position you pass in (it will in fact be ignored), but by an internal variable. This is stored as
.posif you care to read it. Don’t write to it. The same lack-of-semantics applies to this field as well.- Variables:
name – The name of the file. Purely for cosmetic purposes
ident – The identifier of the file, typically autogenerated from the name and a nonce. Purely for cosmetic purposes, but does appear in symbolic values autogenerated in the file.
seekable – Bool indicating whether seek operations on this file should succeed. If this is True, then
posmust be a number of bytes from the start of the file.writable – Bool indicating whether writing to this file is allowed.
pos – If the file is a stream, this will be the current position. Otherwise, None.
concrete – Whether or not this file contains mostly concrete data. Will be used by some SimProcedures to choose how to handle variable-length operations like fgets.
file_exists – Set to False, if file does not exists, set to a claripy Bool if unknown, default True.
- seekable = False¶
- pos = None¶
- __init__(name=None, writable=True, ident=None, concrete=False, file_exists=True, **kwargs)¶
- static make_ident(name)¶
- concretize(**kwargs)¶
Return a concretization of the contents of the file. The type of the return value of this method will vary depending on which kind of SimFile you’re using.
- read(pos, size, **kwargs)¶
Read some data from the file.
- Parameters:
pos – The offset in the file to read from.
size – The size to read. May be symbolic.
- Returns:
A tuple of the data read (a bitvector of the length that is the maximum length of the read), the actual size of the read, and the new file position pointer.
- write(pos, data, size=None, **kwargs)¶
Write some data to the file.
- Parameters:
pos – The offset in the file to write to. May be ignored if the file is a stream or device.
data – The data to write as a bitvector
size – The optional size of the data to write. If not provided will default to the length of the data. Must be constrained to less than or equal to the size of the data.
- Returns:
The new file position pointer.
- property size¶
The number of data bytes stored by the file at present. May be a symbolic value.
- class angr.storage.file.SimFile¶
Bases:
SimFileBase,DefaultMemoryThe normal SimFile is meant to model files on disk. It subclasses SimSymbolicMemory so loads and stores to/from it are very simple.
- Parameters:
name – The name of the file
content – Optional initial content for the file as a string or bitvector
size – Optional size of the file. If content is not specified, it defaults to zero
has_end – Whether the size boundary is treated as the end of the file or a frontier at which new content will be generated. If unspecified, will pick its value based on options.FILES_HAVE_EOF. Another caveat is that if the size is also unspecified this value will default to False.
seekable – Optional bool indicating whether seek operations on this file should succeed, default True.
writable – Whether writing to this file is allowed
concrete – Whether or not this file contains mostly concrete data. Will be used by some SimProcedures to choose how to handle variable-length operations like fgets.
- Variables:
has_end – Whether this file has an EOF
- __init__(name=None, content=None, size=None, has_end=None, seekable=True, writable=True, ident=None, concrete=None, **kwargs)¶
- property category¶
reg, mem, or file.
- Type:
Return the category of this SimMemory instance. It can be one of the three following categories
- property size¶
The number of data bytes stored by the file at present. May be a symbolic value.
- concretize(**kwargs)¶
Return a concretization of the contents of the file, as a flat bytestring.
- class angr.storage.file.SimFileStream¶
Bases:
SimFileA specialized SimFile that uses a flat memory backing, but functions as a stream, tracking its position internally.
The pos argument to the read and write methods will be ignored, and will return None. Instead, there is an attribute
poson the file itself, which will give you what you want.- Parameters:
name – The name of the file, for cosmetic purposes
pos – The initial position of the file, default zero
kwargs – Any other keyword arguments will go on to the SimFile constructor.
- Variables:
pos – The current position in the file.
- __init__(name=None, content=None, pos=0, **kwargs)¶
- class angr.storage.file.SimPackets¶
Bases:
SimFileBaseThe SimPackets is meant to model inputs whose content is delivered a series of asynchronous chunks. The data is stored as a list of read or write results. For symbolic sizes, state.libc.max_packet_size will be respected. If the SHORT_READS option is enabled, reads will return a symbolic size constrained to be less than or equal to the requested size.
A SimPackets cannot be used for both reading and writing - for socket objects that can be both read and written to you should use a file descriptor to multiplex the read and write operations into two separate file storage mechanisms.
- Parameters:
name – The name of the file, for cosmetic purposes
write_mode – Whether this file is opened in read or write mode. If this is unspecified it will be autodetected.
content – Some initial content to use for the file. Can be a list of bytestrings or a list of tuples of content ASTs and size ASTs.
- Variables:
write_mode – See the eponymous parameter
content – A list of packets, as tuples of content ASTs and size ASTs.
- __init__(name, write_mode=None, content=None, writable=True, ident=None, **kwargs)¶
- property size¶
The number of data bytes stored by the file at present. May be a symbolic value.
- concretize(**kwargs)¶
Returns a list of the packets read or written as bytestrings.
- read(pos, size, **kwargs)¶
Read a packet from the stream.
- Parameters:
pos (int) – The packet number to read from the sequence of the stream. May be None to append to the stream.
size – The size to read. May be symbolic.
short_reads – Whether to replace the size with a symbolic value constrained to less than or equal to the original size. If unspecified, will be chosen based on the state option.
- Returns:
A tuple of the data read (a bitvector of the length that is the maximum length of the read) and the actual size of the read.
- write(pos, data, size=None, events=True, **kwargs)¶
Write a packet to the stream.
- Parameters:
pos (int) – The packet number to write in the sequence of the stream. May be None to append to the stream.
data – The data to write, as a string or bitvector.
size – The optional size to write. May be symbolic; must be constrained to at most the size of data.
- Returns:
The next packet to use after this
- class angr.storage.file.SimPacketsStream¶
Bases:
SimPacketsA specialized SimPackets that tracks its position internally.
The pos argument to the read and write methods will be ignored, and will return None. Instead, there is an attribute
poson the file itself, which will give you what you want.- Parameters:
name – The name of the file, for cosmetic purposes
pos – The initial position of the file, default zero
kwargs – Any other keyword arguments will go on to the SimPackets constructor.
- Variables:
pos – The current position in the file.
- __init__(name, pos=0, **kwargs)¶
- class angr.storage.file.SimFileDescriptorBase¶
Bases:
SimStatePluginThe base class for implementations of POSIX file descriptors.
All file descriptors should respect the CONCRETIZE_SYMBOLIC_{READ,WRITE}_SIZES state options.
- read(pos, size, **kwargs)¶
Reads some data from the file, storing it into memory.
- Parameters:
pos – The address to read data from file
size – The requested length of the read
- Returns:
The real length of the read
- write(pos, size, **kwargs)¶
Writes some data, loaded from the state, into the file.
- Parameters:
pos – The address to read the data to write from in memory
size – The requested size of the write
- Returns:
The real length of the write
- read_data(size, **kwargs)¶
Reads some data from the file, returning the data.
- Parameters:
size – The requested length of the read
- Returns:
A tuple of the data read and the real length of the read
- write_data(data, size=None, **kwargs)¶
Write some data, provided as an argument into the file.
- Parameters:
data – A bitvector to write into the file
size – The requested size of the write (may be symbolic)
- Returns:
The real length of the write
- seek(offset, whence='start')¶
Seek the file descriptor to a different position in the file.
- Parameters:
offset – The offset to seek to, interpreted according to whence
whence – What the offset is relative to; one of the strings “start”, “current”, or “end”
- Returns:
A symbolic boolean describing whether the seek succeeded or not
- tell()¶
Return the current position, or None if the concept doesn’t make sense for the given file.
- eof()¶
Return the EOF status. May be a symbolic boolean.
- size()¶
Return the size of the data stored in the file in bytes, or None if the concept doesn’t make sense for the given file.
- property read_storage¶
Return the SimFile backing reads from this fd
- property write_storage¶
Return the SimFile backing writes to this fd
- property read_pos¶
Return the current position of the read file pointer.
If the underlying read file is a stream, this will return the position of the stream. Otherwise, will return the position of the file descriptor in the file.
- property write_pos¶
Return the current position of the read file pointer.
If the underlying read file is a stream, this will return the position of the stream. Otherwise, will return the position of the file descriptor in the file.
- concretize(**kwargs)¶
Return a concretizeation of the data in the underlying file. Has different return types to represent different data structures on a per-class basis.
Any arguments passed to this will be passed onto state.solver.eval.
- property file_exists¶
This should be True in most cases. Only if we opened an fd of unknown existence, ALL_FILES_EXIST is False and ANY_FILE_MIGHT_EXIST is True, this is a symbolic boolean.
- class angr.storage.file.SimFileDescriptor¶
Bases:
SimFileDescriptorBaseA simple file descriptor forwarding reads and writes to a SimFile. Contains information about the current opened state of the file, such as the flags or (if relevant) the current position.
- Variables:
file – The SimFile described to by this descriptor
flags – The mode that the file descriptor was opened with, a bitfield of flags
- __init__(simfile, flags=0)¶
- concretize(**kwargs)¶
Return a concretization of the underlying file. Returns whatever format is preferred by the file.
- property file_exists¶
This should be True in most cases. Only if we opened an fd of unknown existence, ALL_FILES_EXIST is False and ANY_FILE_MIGHT_EXIST is True, this is a symbolic boolean.
- property read_storage¶
Return the SimFile backing reads from this fd
- property write_storage¶
Return the SimFile backing writes to this fd
- property read_pos¶
Return the current position of the read file pointer.
If the underlying read file is a stream, this will return the position of the stream. Otherwise, will return the position of the file descriptor in the file.
- property write_pos¶
Return the current position of the read file pointer.
If the underlying read file is a stream, this will return the position of the stream. Otherwise, will return the position of the file descriptor in the file.
- class angr.storage.file.SimFileDescriptorDuplex¶
Bases:
SimFileDescriptorBaseA file descriptor that refers to two file storage mechanisms, one to read from and one to write to. As a result, operations like seek, eof, etc no longer make sense.
- Parameters:
read_file – The SimFile to read from
write_file – The SimFile to write to
- __init__(read_file, write_file)¶
- concretize(**kwargs)¶
Return a concretization of the underlying files, as a tuple of (read file, write file).
- property read_storage¶
Return the SimFile backing reads from this fd
- property write_storage¶
Return the SimFile backing writes to this fd
- property read_pos¶
Return the current position of the read file pointer.
If the underlying read file is a stream, this will return the position of the stream. Otherwise, will return the position of the file descriptor in the file.
- property write_pos¶
Return the current position of the read file pointer.
If the underlying read file is a stream, this will return the position of the stream. Otherwise, will return the position of the file descriptor in the file.
- class angr.storage.file.SimPacketsSlots¶
Bases:
SimFileBaseSimPacketsSlots is the new SimDialogue, if you’ve ever seen that before.
The idea is that in some cases, the only thing you really care about is getting the lengths of reads right, and some of them should be short reads, and some of them should be truncated. You provide to this class a list of read lengths, and it figures out the length of each read, and delivers some content.
This class will NOT respect the position argument you pass it - this storage is not stateless.
- seekable = False¶
- __init__(name, read_sizes, ident=None, **kwargs)¶
- property size¶
The number of data bytes stored by the file at present. May be a symbolic value.