-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add handling of hex encoded key to realm-trawler #6264
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,9 @@ void consolidate_lists(std::vector<T>& list, std::vector<T>& list2) | |
list.insert(list.end(), list2.begin(), list2.end()); | ||
list2.clear(); | ||
if (list.size() > 1) { | ||
std::sort(begin(list), end(list), [](T& a, T& b) { return a.start < b.start; }); | ||
std::sort(begin(list), end(list), [](T& a, T& b) { | ||
return a.start < b.start; | ||
}); | ||
|
||
auto prev = list.begin(); | ||
for (auto it = list.begin() + 1; it != list.end(); ++it) { | ||
|
@@ -79,7 +81,11 @@ void consolidate_lists(std::vector<T>& list, std::vector<T>& list2) | |
} | ||
|
||
// Remove all of the now zero-size chunks from the free list | ||
list.erase(std::remove_if(begin(list), end(list), [](T& chunk) { return chunk.length == 0; }), end(list)); | ||
list.erase(std::remove_if(begin(list), end(list), | ||
[](T& chunk) { | ||
return chunk.length == 0; | ||
}), | ||
end(list)); | ||
} | ||
} | ||
|
||
|
@@ -507,7 +513,9 @@ std::string human_readable(uint64_t val) | |
uint64_t get_size(const std::vector<Entry>& list) | ||
{ | ||
uint64_t sz = 0; | ||
std::for_each(list.begin(), list.end(), [&](const Entry& e) { sz += e.length; }); | ||
std::for_each(list.begin(), list.end(), [&](const Entry& e) { | ||
sz += e.length; | ||
}); | ||
return sz; | ||
} | ||
|
||
|
@@ -1036,6 +1044,42 @@ void RealmFile::changes() const | |
} | ||
} | ||
|
||
bool is_hex(char c) | ||
{ | ||
if (c >= '0' && c <= '9') | ||
return true; | ||
if (c >= 'a' && c <= 'f') | ||
return true; | ||
if (c >= 'A' && c <= 'F') | ||
return true; | ||
return false; | ||
} | ||
|
||
unsigned int hex_char_to_bin(char c) | ||
{ | ||
if (c >= '0' && c <= '9') | ||
return c - '0'; | ||
if (c >= 'a' && c <= 'f') | ||
return c - 'a' + 10; | ||
if (c >= 'A' && c <= 'F') | ||
return c - 'A' + 10; | ||
exit(-1); | ||
} | ||
|
||
unsigned int hex_to_bin(char first, char second) | ||
{ | ||
return (hex_char_to_bin(first) << 4) | hex_char_to_bin(second); | ||
} | ||
|
||
char to_hex_char(char c) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not used |
||
{ | ||
if (c < 10) | ||
return c + '0'; | ||
if (c < 16) | ||
return c - 10 + 'a'; | ||
return '!'; | ||
} | ||
|
||
int main(int argc, const char* argv[]) | ||
{ | ||
if (argc > 1) { | ||
|
@@ -1049,12 +1093,20 @@ int main(int argc, const char* argv[]) | |
const char* key_ptr = nullptr; | ||
char key[64]; | ||
for (int curr_arg = 1; curr_arg < argc; curr_arg++) { | ||
if (strcmp(argv[curr_arg], "--key") == 0) { | ||
if (strcmp(argv[curr_arg], "--keyfile") == 0) { | ||
std::ifstream key_file(argv[curr_arg + 1]); | ||
key_file.read(key, sizeof(key)); | ||
key_ptr = key; | ||
curr_arg++; | ||
} | ||
else if (strcmp(argv[curr_arg], "--hexkey") == 0) { | ||
curr_arg++; | ||
const char* chars = argv[curr_arg]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should have a check on the length here. |
||
for (int idx = 0; idx < 64; ++idx) { | ||
key[idx] = hex_to_bin(chars[idx * 2], chars[idx * 2 + 1]); | ||
} | ||
key_ptr = key; | ||
} | ||
else if (strcmp(argv[curr_arg], "--top") == 0) { | ||
char* end; | ||
curr_arg++; | ||
|
@@ -1112,7 +1164,10 @@ int main(int argc, const char* argv[]) | |
} | ||
} | ||
else { | ||
std::cout << "Usage: realm-trawler [-afmsw] [--key crypt_key] [--top top_ref] <realmfile>" << std::endl; | ||
std::cout << "Usage: realm-trawler [-afmsw] [--keyfile file-with-binary-crypt-key] [--hexkey " | ||
"crypt-key-in-hex] [--top " | ||
"top_ref] <realmfile>" | ||
<< std::endl; | ||
std::cout << " f : free list analysis" << std::endl; | ||
std::cout << " m : memory leak check" << std::endl; | ||
std::cout << " s : schema dump" << std::endl; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used