forked from Mirror/GodMode9
Speedup hexviewer search operations
This commit is contained in:
parent
9466fe37d1
commit
a74897c0fb
@ -194,21 +194,37 @@ bool FileGetSha256(const char* path, u8* sha256) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 FileFindData(const char* path, u8* data, u32 size, u32 offset) {
|
u32 FileFindData(const char* path, u8* data, u32 size_data, u32 offset_file) {
|
||||||
|
int drvtype = DriveType(path);
|
||||||
u32 found = (u32) -1;
|
u32 found = (u32) -1;
|
||||||
u32 fsize = FileGetSize(path);
|
u32 fsize = FileGetSize(path);
|
||||||
|
|
||||||
|
// open FAT / virtual file
|
||||||
|
FIL file; // only used on FAT drives
|
||||||
|
VirtualFile vfile; // only used on virtual drives
|
||||||
|
if (((drvtype & DRV_FAT) && (fx_open(&file, path, FA_READ | FA_OPEN_EXISTING) != FR_OK)) ||
|
||||||
|
((drvtype & DRV_VIRTUAL) && !GetVirtualFile(&vfile, path))) return found;
|
||||||
|
|
||||||
|
// main routine
|
||||||
for (u32 pass = 0; pass < 2; pass++) {
|
for (u32 pass = 0; pass < 2; pass++) {
|
||||||
bool show_progress = false;
|
bool show_progress = false;
|
||||||
u32 pos = (pass == 0) ? offset : 0;
|
u32 pos = (pass == 0) ? offset_file : 0;
|
||||||
u32 search_end = (pass == 0) ? fsize : offset + size;
|
u32 search_end = (pass == 0) ? fsize : offset_file + size_data;
|
||||||
search_end = (search_end > fsize) ? fsize : search_end;
|
search_end = (search_end > fsize) ? fsize : search_end;
|
||||||
for (; (pos < search_end) && (found == (u32) -1); pos += MAIN_BUFFER_SIZE - (size - 1)) {
|
for (; (pos < search_end) && (found == (u32) -1); pos += MAIN_BUFFER_SIZE - (size_data - 1)) {
|
||||||
UINT read_bytes = min(MAIN_BUFFER_SIZE, search_end - pos);
|
UINT read_bytes = min(MAIN_BUFFER_SIZE, search_end - pos);
|
||||||
if (FileGetData(path, MAIN_BUFFER, read_bytes, pos) != read_bytes)
|
if (drvtype & DRV_FAT) {
|
||||||
break;
|
UINT btr;
|
||||||
for (u32 i = 0; i + size <= read_bytes; i++) {
|
f_lseek(&file, pos);
|
||||||
if (memcmp(MAIN_BUFFER + i, data, size) == 0) {
|
if ((fx_read(&file, MAIN_BUFFER, read_bytes, &btr) != FR_OK) || (btr != read_bytes))
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
u32 btr;
|
||||||
|
if ((ReadVirtualFile(&vfile, MAIN_BUFFER, pos, read_bytes, &btr) != 0) || (btr != read_bytes))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (u32 i = 0; i + size_data <= read_bytes; i++) {
|
||||||
|
if (memcmp(MAIN_BUFFER + i, data, size_data) == 0) {
|
||||||
found = pos + i;
|
found = pos + i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -221,6 +237,7 @@ u32 FileFindData(const char* path, u8* data, u32 size, u32 offset) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (drvtype & DRV_FAT) fx_close(&file);
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ size_t FileGetSize(const char* path);
|
|||||||
bool FileGetSha256(const char* path, u8* sha256);
|
bool FileGetSha256(const char* path, u8* sha256);
|
||||||
|
|
||||||
/** Find data in file **/
|
/** Find data in file **/
|
||||||
u32 FileFindData(const char* path, u8* data, u32 size, u32 offset);
|
u32 FileFindData(const char* path, u8* data, u32 size_data, u32 offset_file);
|
||||||
|
|
||||||
/** Inject file into file @offset **/
|
/** Inject file into file @offset **/
|
||||||
bool FileInjectFile(const char* dest, const char* orig, u32 offset);
|
bool FileInjectFile(const char* dest, const char* orig, u32 offset);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user