@@ -148,39 +148,36 @@ hook_BYTES_int2bytes(SortInt len, SortInt i, SortEndianness endianness_ptr) {
148
148
return result;
149
149
}
150
150
151
- string *bytes2string (string *b, size_t len) {
152
- auto *result = static_cast <string *>(kore_alloc_token (sizeof (string) + len));
153
- memcpy (result->data , b->data , len);
154
- init_with_len (result, len);
155
- return result;
156
- }
157
-
158
151
SortString hook_BYTES_bytes2string (SortBytes b) {
159
- return bytes2string (b, len (b));
152
+ auto len_b = len (b);
153
+ auto *result = static_cast <string *>(kore_alloc_token (sizeof (string) + len_b));
154
+ memcpy (result->data , b->data , len_b);
155
+ init_with_len (result, len_b);
156
+ return result;
160
157
}
161
158
162
159
SortBytes hook_BYTES_string2bytes (SortString s) {
163
160
return hook_BYTES_bytes2string (s);
164
161
}
165
162
166
- string *bytes2hexstring (string *b, size_t len) {
163
+ // Convert a bytes array to its hexadecimal string representation
164
+ // For example, the bytes array b'\x01\xef' becomes the string "01ef"
165
+ // syntax String ::= Bytes2Hex( Bytes )
166
+ SortString hook_BYTES_bytes2hex (SortBytes b) {
167
167
static const std::array<char , 16 > hexchars
168
168
= {' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' ,
169
169
' 8' , ' 9' , ' a' , ' b' , ' c' , ' d' , ' e' , ' f' };
170
+ auto len_b = len (b);
170
171
auto *result
171
- = static_cast <string *>(kore_alloc_token (sizeof (string) + len * 2 ));
172
- for (size_t i = 0 ; i < len ; i++) {
172
+ = static_cast <string *>(kore_alloc_token (sizeof (string) + len_b * 2 ));
173
+ for (size_t i = 0 ; i < len_b ; i++) {
173
174
result->data [i * 2 ] = hexchars.at ((b->data [i] >> 4 ) & 0xf );
174
175
result->data [i * 2 + 1 ] = hexchars.at (b->data [i] & 0xf );
175
176
}
176
- init_with_len (result, len * 2 );
177
+ init_with_len (result, len_b * 2 );
177
178
return result;
178
179
}
179
180
180
- SortString hook_BYTES_bytes2hexstring (SortBytes b) {
181
- return bytes2hexstring (b, len (b));
182
- }
183
-
184
181
SortBytes hook_BYTES_substr (SortBytes input, SortInt start, SortInt end) {
185
182
uint64_t ustart = GET_UI (start);
186
183
uint64_t uend = GET_UI (end);
0 commit comments