OLD | NEW |
1 # Rekall Memory Forensics | 1 # Rekall Memory Forensics |
2 # | 2 # |
3 # Copyright 2013 Google Inc. All Rights Reserved. | 3 # Copyright 2013 Google Inc. All Rights Reserved. |
4 # | 4 # |
5 # Authors: | 5 # Authors: |
6 # Copyright (C) 2012 Michael Cohen <scudette@users.sourceforge.net> | 6 # Copyright (C) 2012 Michael Cohen <scudette@users.sourceforge.net> |
7 # Mike Auty <mike.auty@gmail.com> | 7 # Mike Auty <mike.auty@gmail.com> |
8 # | 8 # |
9 # This program is free software; you can redistribute it and/or modify | 9 # This program is free software; you can redistribute it and/or modify |
10 # it under the terms of the GNU General Public License as published by | 10 # it under the terms of the GNU General Public License as published by |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 """ Return an object to be proxied """ | 98 """ Return an object to be proxied """ |
99 return str(self) | 99 return str(self) |
100 | 100 |
101 def __str__(self): | 101 def __str__(self): |
102 # Remove any null termination chars. | 102 # Remove any null termination chars. |
103 return self.v().rstrip("\x00") | 103 return self.v().rstrip("\x00") |
104 | 104 |
105 def __unicode__(self): | 105 def __unicode__(self): |
106 return self.v().decode("utf8", "replace").split("\x00")[0] or u"" | 106 return self.v().decode("utf8", "replace").split("\x00")[0] or u"" |
107 | 107 |
| 108 def __len__(self): |
| 109 return len(str(self)) |
| 110 |
108 @property | 111 @property |
109 def indices(self): | 112 def indices(self): |
110 return (str(self),) | 113 return (str(self),) |
111 | 114 |
112 def __getitem__(self, *args): | 115 def __getitem__(self, *args): |
113 return unicode(self).__getitem__(*args) | 116 return unicode(self).__getitem__(*args) |
114 | 117 |
115 def __add__(self, other): | 118 def __add__(self, other): |
116 """Set up mappings for concat""" | 119 """Set up mappings for concat""" |
117 return str(self) + other | 120 return str(self) + other |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 left, sep, _ = data.partition(self.term) | 171 left, sep, _ = data.partition(self.term) |
169 data = left + sep | 172 data = left + sep |
170 | 173 |
171 return data | 174 return data |
172 | 175 |
173 def proxied(self): | 176 def proxied(self): |
174 return unicode(self) | 177 return unicode(self) |
175 | 178 |
176 def __unicode__(self): | 179 def __unicode__(self): |
177 return self.v().split("\x00")[0] or u"" | 180 return self.v().split("\x00")[0] or u"" |
| 181 ···· |
| 182 def __len__(self): |
| 183 return len(unicode(self)) |
178 | 184 |
179 def __repr__(self): | 185 def __repr__(self): |
180 value = utils.SmartStr(self) | 186 value = utils.SmartStr(self) |
181 elide = "" | 187 elide = "" |
182 if len(value) > 50: | 188 if len(value) > 50: |
183 elide = "..." | 189 elide = "..." |
184 value = value[:50] | 190 value = value[:50] |
185 | 191 |
186 return "%s (%s%s)" % (super(UnicodeString, self).__repr__(), | 192 return "%s (%s%s)" % (super(UnicodeString, self).__repr__(), |
187 value, elide) | 193 value, elide) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 # This return an instance of the target type. | 332 # This return an instance of the target type. |
327 return self.value | 333 return self.value |
328 | 334 |
329 def write(self, data): | 335 def write(self, data): |
330 if data in self.reverse_choices: | 336 if data in self.reverse_choices: |
331 data = self.reverse_choices.get(data) | 337 data = self.reverse_choices.get(data) |
332 | 338 |
333 return self.target_obj.write(data) | 339 return self.target_obj.write(data) |
334 | 340 |
335 def __hash__(self): | 341 def __hash__(self): |
| 342 # TODO: This hash function is dangerous, because the Enum compares |
| 343 # as string or int, but hashes only as int. We need to implement a |
| 344 # version of dict that supports multiple hash entries and then uncomment |
| 345 # the exception: |
| 346 # raise NotImplementedError("Enumerations are not hashable.") |
336 return hash(self.v()) | 347 return hash(self.v()) |
337 | 348 |
338 def __unicode__(self): | 349 def __unicode__(self): |
339 value = self.v() | 350 value = self.v() |
340 # Choices dict keys are always strings. | 351 # Choices dict keys are always strings. |
341 return self.choices.get(utils.SmartStr(value), self.default) or ( | 352 return self.choices.get(utils.SmartStr(value), self.default) or ( |
342 u"UNKNOWN (%s)" % utils.SmartUnicode(value)) | 353 u"UNKNOWN (%s)" % utils.SmartUnicode(value)) |
343 | 354 |
344 def __eq__(self, other): | 355 def __eq__(self, other): |
345 if isinstance(other, (int, long)): | 356 if isinstance(other, (int, long)): |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 profile.add_overlay(common_overlay) | 962 profile.add_overlay(common_overlay) |
952 | 963 |
953 | 964 |
954 def container_of(ptr, type, member): | 965 def container_of(ptr, type, member): |
955 """cast a member of a structure out to the containing structure. | 966 """cast a member of a structure out to the containing structure. |
956 | 967 |
957 http://lxr.free-electrons.com/source/include/linux/kernel.h?v=3.7#L677 | 968 http://lxr.free-electrons.com/source/include/linux/kernel.h?v=3.7#L677 |
958 """ | 969 """ |
959 offset = ptr.v() - ptr.obj_profile.get_obj_offset(type, member) | 970 offset = ptr.v() - ptr.obj_profile.get_obj_offset(type, member) |
960 return ptr.obj_profile.Object(type, offset=offset, vm=ptr.obj_vm) | 971 return ptr.obj_profile.Object(type, offset=offset, vm=ptr.obj_vm) |
OLD | NEW |