Class: Arachni::Snapshot

Inherits:
Object show all
Defined in:
lib/arachni/snapshot.rb

Overview

Stores and provides access to the state of the system.

Author:

Defined Under Namespace

Classes: Error

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.locationString

Returns Location of the loaded snapshot.

Returns:



44
45
46
# File 'lib/arachni/snapshot.rb', line 44

def location
  @location
end

.metadataHash

Returns Metadata associated with the loaded snapshot.

Returns:

  • (Hash)

    Metadata associated with the loaded snapshot.



40
41
42
# File 'lib/arachni/snapshot.rb', line 40

def 
  @metadata
end

Class Method Details

.dump(location) ⇒ String

Returns Location of the snapshot.

Parameters:

  • location (String)

    Location of the snapshot.

Returns:

  • (String)

    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, 'a' ) do |f|
            f.write [, .size].pack( 'a*N' )
        end

        location
    ensure
        FileUtils.rm_rf( directory )
    end
end

.load(snapshot) ⇒ Snapshot

Returns ‘self`.

Parameters:

  • snapshot (String)

    Location of the snapshot to load.

Returns:

Raises:



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.

Parameters:

  • snapshot (String)

    Location of the snapshot.

Returns:

  • (Hash)

    Metadata associated with the given snapshot.

Raises:



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 ) 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

.resetObject



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.

Returns:

  • (Bool)

    ‘true` if this is a restored snapshot, `false` otherwise.



53
54
55
# File 'lib/arachni/snapshot.rb', line 53

def restored?
    !!location
end

.summaryHash

Returns Snapshot summary information.

Returns:

  • (Hash)

    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