Class: Arachni::Snapshot
Overview
Stores and provides access to the state of the system.
Defined Under Namespace
Classes: Error
Class Attribute Summary collapse
-
.location ⇒ String
Location of the loaded snapshot.
-
.metadata ⇒ Hash
Metadata associated with the loaded snapshot.
Class Method Summary collapse
-
.dump(location) ⇒ String
Location of the snapshot.
-
.load(snapshot) ⇒ Snapshot
`self`.
-
.read_metadata(snapshot) ⇒ Hash
Metadata associated with the given snapshot.
- .reset ⇒ Object
-
.restored? ⇒ Bool
`true` if this is a restored snapshot, `false` otherwise.
-
.summary ⇒ Hash
Snapshot summary information.
Class Attribute Details
Class Method Details
.dump(location) ⇒ String
Returns Location of the snapshot.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/arachni/snapshot.rb', line 71 def dump( location ) FileUtils.rm_rf( location ) directory = get_temporary_directory FileUtils.rm_rf( directory ) FileUtils.mkdir_p( directory ) begin Data.dump( "#{directory}/data/" ) State.dump( "#{directory}/state/" ) compress directory, location # Append metadata to the end of the file. = Marshal.dump( ) File.open( location, 'ab' ) do |f| f.write [, .size].pack( 'a*N' ) end location ensure FileUtils.rm_rf( directory ) end end |
.load(snapshot) ⇒ Snapshot
Returns `self`.
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/arachni/snapshot.rb', line 105 def load( snapshot ) directory = get_temporary_directory @location = snapshot @metadata = ( snapshot ) extract( snapshot, directory ) Data.load( "#{directory}/data/" ) State.load( "#{directory}/state/" ) self end |
.read_metadata(snapshot) ⇒ Hash
Returns Metadata associated with the given snapshot.
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/arachni/snapshot.rb', line 127 def ( snapshot ) File.open( snapshot, 'rb' ) do |f| f.seek -4, IO::SEEK_END = f.read( 4 ).unpack( 'N' ).first f.seek --4, IO::SEEK_END Marshal.load( f.read( ) ) end rescue => e ne = Error::InvalidFile.new( "Invalid snapshot: #{snapshot} (#{e})" ) ne.set_backtrace e.backtrace raise ne end |
.reset ⇒ Object
46 47 48 49 |
# File 'lib/arachni/snapshot.rb', line 46 def reset @metadata = nil @location = nil end |
.restored? ⇒ Bool
Returns `true` if this is a restored snapshot, `false` otherwise.
53 54 55 |
# File 'lib/arachni/snapshot.rb', line 53 def restored? !!location end |
.summary ⇒ Hash
Returns Snapshot summary information.
59 60 61 62 63 64 |
# File 'lib/arachni/snapshot.rb', line 59 def summary { data: Data.statistics, state: State.statistics } end |