OLD | NEW |
1 // Copyright (c) 2006, 2009, Google Inc. | 1 // Copyright (c) 2006, 2009, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 16 matching lines...) Expand all Loading... |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 // | 29 // |
30 // file_id.cc: Return a unique identifier for a file | 30 // file_id.cc: Return a unique identifier for a file |
31 // | 31 // |
32 // See file_id.h for documentation | 32 // See file_id.h for documentation |
33 // | 33 // |
34 | 34 |
35 #include "breakpad/linux/file_id.h" | 35 #include "breakpad/linux/file_id.h" |
36 | 36 |
| 37 #include <arpa/inet.h> |
37 #include <elf.h> | 38 #include <elf.h> |
38 #include <fcntl.h> | 39 #include <fcntl.h> |
39 #include <link.h> | 40 #include <link.h> |
40 #include <string.h> | 41 #include <string.h> |
41 #include <sys/mman.h> | 42 #include <sys/mman.h> |
42 #include <unistd.h> | 43 #include <unistd.h> |
43 | 44 |
44 #include <cassert> | 45 #include <cassert> |
45 #include <cstdio> | 46 #include <cstdio> |
46 | 47 |
(...skipping 28 matching lines...) Expand all Loading... |
75 ptr += kMDGUIDSize; | 76 ptr += kMDGUIDSize; |
76 } | 77 } |
77 | 78 |
78 munmap(base, mapped_len); | 79 munmap(base, mapped_len); |
79 return true; | 80 return true; |
80 } | 81 } |
81 | 82 |
82 // static | 83 // static |
83 void FileID::ConvertIdentifierToString(const uint8_t identifier[kMDGUIDSize], | 84 void FileID::ConvertIdentifierToString(const uint8_t identifier[kMDGUIDSize], |
84 char* buffer, int buffer_length) { | 85 char* buffer, int buffer_length) { |
| 86 uint8_t identifier_swapped[kMDGUIDSize]; |
| 87 |
| 88 // Endian-ness swap to match dump processor expectation. |
| 89 memcpy(identifier_swapped, identifier, kMDGUIDSize); |
| 90 uint32_t* data1 = reinterpret_cast<uint32_t*>(identifier_swapped); |
| 91 *data1 = htonl(*data1); |
| 92 uint16_t* data2 = reinterpret_cast<uint16_t*>(identifier_swapped + 4); |
| 93 *data2 = htons(*data2); |
| 94 uint16_t* data3 = reinterpret_cast<uint16_t*>(identifier_swapped + 6); |
| 95 *data3 = htons(*data3); |
| 96 |
85 int buffer_idx = 0; | 97 int buffer_idx = 0; |
86 for (int idx = 0; | 98 for (int idx = 0; |
87 (buffer_idx < buffer_length) && (idx < kMDGUIDSize); | 99 (buffer_idx < buffer_length) && (idx < kMDGUIDSize); |
88 ++idx) { | 100 ++idx) { |
89 int hi = (identifier[idx] >> 4) & 0x0F; | 101 int hi = (identifier_swapped[idx] >> 4) & 0x0F; |
90 int lo = (identifier[idx]) & 0x0F; | 102 int lo = (identifier_swapped[idx]) & 0x0F; |
91 | 103 |
92 if (idx == 4 || idx == 6 || idx == 8 || idx == 10) | 104 if (idx == 4 || idx == 6 || idx == 8 || idx == 10) |
93 buffer[buffer_idx++] = '-'; | 105 buffer[buffer_idx++] = '-'; |
94 | 106 |
95 buffer[buffer_idx++] = (hi >= 10) ? 'A' + hi - 10 : '0' + hi; | 107 buffer[buffer_idx++] = (hi >= 10) ? 'A' + hi - 10 : '0' + hi; |
96 buffer[buffer_idx++] = (lo >= 10) ? 'A' + lo - 10 : '0' + lo; | 108 buffer[buffer_idx++] = (lo >= 10) ? 'A' + lo - 10 : '0' + lo; |
97 } | 109 } |
98 | 110 |
99 // NULL terminate | 111 // NULL terminate |
100 buffer[(buffer_idx < buffer_length) ? buffer_idx : buffer_idx - 1] = 0; | 112 buffer[(buffer_idx < buffer_length) ? buffer_idx : buffer_idx - 1] = 0; |
101 } | 113 } |
102 | 114 |
103 } // namespace google_breakpad | 115 } // namespace google_breakpad |
OLD | NEW |