| 284 | } |
| 285 | |
| 286 | std::vector<std::string> Explorer::ReadFileFormatHex(const std::string &path, const u32 line_offset, const u32 line_count) { |
| 287 | std::vector<std::string> str_data; |
| 288 | const auto full_path = this->MakeFull(path); |
| 289 | const auto file_size = this->GetFileSize(full_path); |
| 290 | const auto offset = 16 * line_offset; |
| 291 | const u64 read_size = 16 * line_count; |
| 292 | if(offset >= file_size) { |
| 293 | return str_data; |
| 294 | } |
| 295 | auto data_read_size = std::min(file_size, read_size); |
| 296 | if((offset + read_size) > file_size) { |
| 297 | data_read_size = read_size - ((offset + read_size) - file_size); |
| 298 | } |
| 299 | auto work_buf = AllocateWorkBuffer(); |
| 300 | this->ReadFile(full_path, offset, data_read_size, work_buf); |
| 301 | u32 count = 0; |
| 302 | std::string tmp_line; |
| 303 | std::string tmp_chr; |
| 304 | u32 tmp_offset = 0; |
| 305 | for(u32 i = 0; i < (data_read_size + 1); i++) { |
| 306 | if(count == 16) { |
| 307 | std::stringstream strm; |
| 308 | strm << std::hex << std::setw(8) << std::uppercase << std::setfill('0') << (offset + tmp_offset); |
| 309 | const auto def = " " + strm.str() + " " + tmp_line + " " + tmp_chr; |
| 310 | str_data.push_back(def); |
| 311 | tmp_offset += 16; |
| 312 | count = 0; |
| 313 | tmp_line = ""; |
| 314 | tmp_chr = ""; |
| 315 | } |
| 316 | else if(i == data_read_size) { |
| 317 | if((data_read_size % 16) != 0) { |
| 318 | const auto miss = 16 - count; |
| 319 | for(u32 i = 0; i < miss; i++) { |
| 320 | tmp_line += " "; |
| 321 | tmp_chr += " "; |
| 322 | } |
| 323 | } |
| 324 | std::stringstream strm; |
| 325 | strm << std::hex << std::setw(8) << std::uppercase << std::setfill('0') << (offset + tmp_offset); |
| 326 | const auto def = " " + strm.str() + " " + tmp_line + " " + tmp_chr; |
| 327 | str_data.push_back(def); |
| 328 | break; |
| 329 | } |
| 330 | const auto cur_byte = work_buf[i]; |
| 331 | std::stringstream strm; |
| 332 | strm << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << static_cast<u32>(cur_byte); |
| 333 | tmp_line += strm.str() + " "; |
| 334 | if(isprint(cur_byte)) { |
| 335 | tmp_chr += static_cast<char>(cur_byte); |
| 336 | } |
| 337 | else { |
| 338 | tmp_chr += "."; |
| 339 | } |
| 340 | count++; |
| 341 | } |
| 342 | DeleteWorkBuffer(work_buf); |
| 343 | return str_data; |
no test coverage detected