This file is indexed.

/usr/lib/python2.7/dist-packages/pyaff4/aff4.py is in python-aff4 0.24.post1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 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
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License.  You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
# License for the specific language governing permissions and limitations under
# the License.

"""This is the python AFF4 library."""
import platform
import sys
import time
import uuid
import weakref

from pyaff4 import rdfvalue


class NoneObject(object):
    """ A magical object which is like None but swallows bad
    dereferences, __getattr__, iterators etc to return itself.

    Instantiate with the reason for the error.
    """

    def __init__(self, reason="", *args, **_):
        # Often None objects are instantiated on purpose so its not really that
        # important to see their reason.
        self.reason = reason
        self.args = args

    def __str__(self):
        return unicode(self).encode('utf-8')

    def __unicode__(self):
        return self.FormatReason()

    def FormatReason(self):
        if "%" in self.reason:
            return self.reason % self.args
        else:
            return self.reason.format(*self.args)

    def __repr__(self):
        return "<%s>" % self.FormatReason()

    ## Behave like an empty set
    def __iter__(self):
        return iter([])

    def __len__(self):
        return 0

    def __getattr__(self, attr):
        # By returning self for any unknown attribute and ensuring the self is
        # callable, we cover both properties and methods Override NotImplemented
        # functions in object with self
        return self

    def __bool__(self):
        return False

    def __nonzero__(self):
        return False

    # Comparisons.
    def __eq__(self, other):
        return other is None

    def __ne__(self, other):
        return other is not None

    def __gt__(self, _):
        return False

    __lt__ = __gt__
    __le__ = __gt__
    __ge__ = __gt__

    ## Make us subscriptable obj[j]
    def __getitem__(self, item):
        return self

    def __call__(self, *arg, **kwargs):
        return self

    def __int__(self):
        return -1

    __add__ = __call__
    __sub__ = __call__
    __mul__ = __call__
    __floordiv__ = __call__
    __mod__ = __call__
    __div__ = __call__
    __divmod__ = __call__
    __pow__ = __call__
    __lshift__ = __call__
    __rshift__ = __call__
    __and__ = __call__
    __xor__ = __call__
    __or__ = __call__

    __radd__ = __call__
    __rsub__ = __call__
    __rmul__ = __call__
    __rfloordiv__ = __call__
    __rmod__ = __call__
    __rdivmod__ = __call__
    __rpow__ = __call__
    __rlshift__ = __call__
    __rrshift__ = __call__
    __rand__ = __call__
    __rxor__ = __call__
    __ror__ = __call__

    # Override these methods too.
    dereference_as = __call__
    __getitem__ = __call__

    def __enter__(self):
        return self
    def __exit__(self, exc_type, exc_value, traceback):
        # Do not allow exceptions to be propagated through us.
        return True


# Keep track of all the AFF4 objects which are alive right now. This helps in
# debugging memory leaks.
AFF4_OBJECT_REFS = {}


class AFF4StreamProperties(object):
    seekable = True
    sizeable = True
    writable = False

class AFF4VolumeProperties(object):
    supports_compression = True
    writable = False
    files_are_directories = True


class AFF4Object(object):
    def __init__(self, resolver, urn=None):
        self.resolver = resolver
        self._dirty = False
        if urn is None:
            urn = "aff4://%s" % uuid.uuid4()

        self.urn = rdfvalue.URN(urn)
        AFF4_OBJECT_REFS[id(self)] = weakref.proxy(
            self, lambda _, id=id(self), ref=AFF4_OBJECT_REFS: ref.pop(id))

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        # Return ourselves to the resolver cache.
        self.resolver.Return(self)

    def LoadFromURN(self):
        raise NotImplementedError

    def Prepare(self):
        pass

    def Flush(self):
        self._dirty = False

    def IsDirty(self):
        return self._dirty

    def MarkDirty(self):
        self._dirty = True


class AFF4Volume(AFF4Object):
    def __init__(self, *args, **kwargs):
        super(AFF4Volume, self).__init__(*args, **kwargs)
        self.properties = AFF4VolumeProperties()

    def CreateMember(self, child):
        raise NotImplementedError


SEEK_SET = 0
SEEK_CUR = 1
SEEK_END = 2


class AFF4Stream(AFF4Object):
    readptr = 0
    size = 0

    def __init__(self, *args, **kwargs):
        super(AFF4Stream, self).__init__(*args, **kwargs)
        self.properties = AFF4StreamProperties()

    def Read(self, length):
        raise NotImplementedError()

    def Write(self, data):
        raise NotImplementedError()

    def WriteStream(self, source):
        """Writes into this stream from a stream.

        The stream is a file-like object with read and tell() methods.
        """
        raise NotImplementedError()

    def Seek(self, offset, whence=0):
        if whence == SEEK_SET:
            self.readptr = offset
        elif whence == SEEK_CUR:
            self.readptr += offset
        elif whence == SEEK_END:
            self.readptr = offset + self.Size()

        if self.readptr < 0:
            self.readptr = 0

    def Tell(self):
        return self.readptr

    def Size(self):
        return self.size

    def read(self, length=1024*1024):
        return self.Read(length)

    def seek(self, offset, whence=0):
        self.Seek(offset, whence=whence)

    def write(self, data):
        self.Write(data)

    def tell(self):
        return self.Tell()

    def flush(self):
        self.Flush()

    def Prepare(self):
        self.Seek(0)


class ProgressContext(object):
    last_time = 0
    last_offset = 0

    # The following are set in advance by users in order to get accurate
    # progress reports.

    # Start offset of this current range.
    start = 0
    length = 0

    def __init__(self, length=0):
        self.length = length
        self.last_time = self.now()

    def now(self):
        return time.time() * 1e6

    def Report(self, readptr):
        """This will be called periodically to report the progress.

        Note that readptr is specified relative to the start of the range
        operation (WriteStream and CopyToStream)
        """
        readptr = readptr + self.start
        now = self.now()
        if now > self.last_time + 1000000/4:
            # Rate in MB/s.
            rate = ((readptr - self.last_offset) /
                    (now - self.last_time) * 1000000 / 1024/1024)

            sys.stdout.write(" Reading %sMiB / %sMiB  %s MiB/s\r\n" % (
                readptr/1024/1024,
                self.length/1024/1024,
                rate))
            sys.stdout.flush()

            self.last_time = now
            self.last_offset = readptr

        if aff4_abort_signaled:
            sys.stdout.write("\n\nAborted!\n")
            raise RuntimeError("Aborted")

aff4_abort_signaled = False


class EmptyProgressContext(ProgressContext):
    def Report(self, _):
        pass

DEFAULT_PROGRESS = ProgressContext()
EMPTY_PROGRESS = EmptyProgressContext()


WIN32 = platform.system() == "Windows"