Chromium Code Reviews| Index: components/webdata/encryptor/ie7_password.cc |
| diff --git a/components/webdata/encryptor/ie7_password.cc b/components/webdata/encryptor/ie7_password.cc |
| index e7db3ab3be0268842fc8415417668b81b4524a7b..a2d8b6ce71dd55f609422c502766638094366aeb 100644 |
| --- a/components/webdata/encryptor/ie7_password.cc |
| +++ b/components/webdata/encryptor/ie7_password.cc |
| @@ -28,8 +28,7 @@ struct Header { |
| char wick[4]; // The string "WICK". I don't know what it means. |
| DWORD fixed_header_size; // The size of this structure without the entries: |
| // sizeof(Header). |
| - DWORD item_count; // Number of entries. It should always be 2. One for |
| - // the username, and one for the password. |
| + DWORD item_count; // Number of entries. Should be even. |
| wchar_t two_letters[2]; // Two unknown bytes. |
| DWORD unknown[2]; // Two unknown DWORDs. |
| }; |
| @@ -45,17 +44,16 @@ struct Entry { |
| struct PasswordEntry { |
| PreHeader pre_header; // Contains the size of the different sections. |
| Header header; // Contains the number of items. |
| - Entry entry[1]; // List of entries containing a string. The first one |
| - // is the username, the second one if the password. |
| + Entry entry[1]; // List of entries containing a string. Even-indexed |
| + // are usernames, odd are passwords. There may be |
| + // several sets saved for a single url hash. |
| }; |
| - |
| } // namespace |
| namespace ie7_password { |
| bool GetUserPassFromData(const std::vector<unsigned char>& data, |
| - std::wstring* username, |
| - std::wstring* password) { |
| + std::vector<DecryptedCredentials>* credentials) { |
| const PasswordEntry* information = |
| reinterpret_cast<const PasswordEntry*>(&data.front()); |
| @@ -64,23 +62,28 @@ bool GetUserPassFromData(const std::vector<unsigned char>& data, |
| if (information->pre_header.pre_header_size != sizeof(PreHeader)) |
| return false; |
| - if (information->header.item_count != 2) // Username and Password |
| + const int entry_count = information->header.item_count; |
| + if (entry_count % 2) // Usernames and Passwords |
| return false; |
| if (information->header.fixed_header_size != sizeof(Header)) |
| return false; |
| - const uint8* ptr = &data.front(); |
| - const uint8* offset_to_data = ptr + information->pre_header.header_size + |
| - information->pre_header.pre_header_size; |
| + for (int i = 0; i < entry_count / 2; ++i) { |
| + const uint8* offset_to_data = &data[0] + |
|
Lei Zhang
2013/10/09 07:59:09
Ok, you got rid of |ptr|, but isn't |offset_to_dat
|
| + information->pre_header.header_size + |
| + information->pre_header.pre_header_size; |
| - const Entry* user_entry = information->entry; |
| - const Entry* pass_entry = user_entry+1; |
| + const Entry* user_entry = &information->entry[2*i]; |
| + const Entry* pass_entry = user_entry+1; |
| - *username = reinterpret_cast<const wchar_t*>(offset_to_data + |
| - user_entry->offset); |
| - *password = reinterpret_cast<const wchar_t*>(offset_to_data + |
| - pass_entry->offset); |
| + DecryptedCredentials c; |
| + c.username = reinterpret_cast<const wchar_t*>(offset_to_data + |
| + user_entry->offset); |
| + c.password = reinterpret_cast<const wchar_t*>(offset_to_data + |
| + pass_entry->offset); |
| + credentials->push_back(c); |
| + } |
| return true; |
| } |
| @@ -108,9 +111,9 @@ std::wstring GetUrlHash(const std::wstring& url) { |
| return url_hash; |
| } |
| -bool DecryptPassword(const std::wstring& url, |
| - const std::vector<unsigned char>& data, |
| - std::wstring* username, std::wstring* password) { |
| +bool DecryptPasswords(const std::wstring& url, |
| + const std::vector<unsigned char>& data, |
| + std::vector<DecryptedCredentials>* credentials) { |
| std::wstring lower_case_url = StringToLowerASCII(url); |
| DATA_BLOB input = {0}; |
| DATA_BLOB output = {0}; |
| @@ -132,7 +135,7 @@ bool DecryptPassword(const std::wstring& url, |
| decrypted_data.resize(output.cbData); |
| memcpy(&decrypted_data.front(), output.pbData, output.cbData); |
| - GetUserPassFromData(decrypted_data, username, password); |
| + GetUserPassFromData(decrypted_data, credentials); |
| LocalFree(output.pbData); |
| return true; |