@@ -28,19 +28,44 @@ std::string verbosity_to_string(const VerbosityLevel lvl) {
28
28
return " Unknwon" ;
29
29
}
30
30
31
+ // Get the size of an open file without changing its position
31
32
std::streampos get_file_size (std::ifstream &file) {
32
- std::streampos backup = file.tellg ();
33
33
34
- file. seekg ( 0 , std::ios::beg);
35
- std::streampos fsize = file.tellg ();
34
+ // Save the current file ptr position
35
+ std::streampos backup = file.tellg ();
36
36
37
+ // Move the ptr to the end
37
38
file.seekg (0 , std::ios::end);
38
- fsize = file.tellg () - fsize;
39
39
40
+ // Get the current file ptr position ( start = 0 + EOF )
41
+ std::streampos fsize = file.tellg ();
42
+
43
+ // Restore the previous ptr position
40
44
file.seekg (backup);
45
+
41
46
return fsize;
42
47
}
43
48
49
+ // Helper function to check if va has prefix (0x) or not
50
+ bool has_prefix (const std::string &va) {
51
+ return va.size () > 2 && va[0 ] == ' 0' && (va[1 ] == ' x' || va[1 ] == ' X' );
52
+ }
53
+
54
+ /*
55
+ * Sanitize VA copied from WinDbg (removes backticks)
56
+ * Ensures "0x" prefix exists when needed
57
+ */
58
+ std::string sanitize_va (std::string va) {
59
+
60
+ bool needs_prefix = !has_prefix (va);
61
+
62
+ // Remove backticks if present
63
+ va.erase (std::remove (va.begin (), va.end (), ' `' ), va.end ());
64
+
65
+ return needs_prefix ? " 0x" + va : va;
66
+
67
+ }
68
+
44
69
// this function is completely inspirated from the previous work of jonathan
45
70
// salwan
46
71
bool is_matching (const std::string &str, const std::string &pattern) {
@@ -49,10 +74,10 @@ bool is_matching(const std::string &str, const std::string &pattern) {
49
74
return false ;
50
75
}
51
76
52
- size_t i = 0 , max = std::min (str.length (), pattern.length ());
77
+ size_t i = 0 , maxLen = ( std::min) (str.length (), pattern.length ());
53
78
bool it_matches = true ;
54
79
55
- while (i < max ) {
80
+ while (i < maxLen ) {
56
81
if (pattern.at (i) != ' ?' && pattern.at (i) != str.at (i)) {
57
82
it_matches = false ;
58
83
break ;
0 commit comments