Skip to content

Commit 5cd4316

Browse files
committed
CPU (X86): uses normalized cpu brand name for pattern matching
1 parent e946861 commit 5cd4316

1 file changed

Lines changed: 8 additions & 20 deletions

File tree

src/detection/cpu/cpu_x86.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,25 +1284,13 @@ bool ffCPUDetectX86Specific(FFCPUResult* cpu) {
12841284
return false;
12851285
}
12861286

1287-
ffStrbufClear(&cpu->vendor);
1288-
ffStrbufEnsureFixedLengthFree(&cpu->vendor, 12);
1289-
memcpy(cpu->vendor.chars + 0, &ebx, 4);
1290-
memcpy(cpu->vendor.chars + 4, &edx, 4);
1291-
memcpy(cpu->vendor.chars + 8, &ecx, 4);
1292-
cpu->vendor.chars[12] = '\0';
1293-
cpu->vendor.length = 12;
1294-
1295-
// Brand String (CPUID Leaves 0x80000002 - 0x80000004)
1296-
char brand[49] = {};
1297-
unsigned int ext_eax;
1298-
if (__get_cpuid(0x80000000, &ext_eax, &ebx, &ecx, &edx)) {
1299-
if (ext_eax >= 0x80000004) {
1300-
unsigned int* brand_ptr = (unsigned int*) brand;
1301-
__get_cpuid(0x80000002, &brand_ptr[0], &brand_ptr[1], &brand_ptr[2], &brand_ptr[3]);
1302-
__get_cpuid(0x80000003, &brand_ptr[4], &brand_ptr[5], &brand_ptr[6], &brand_ptr[7]);
1303-
__get_cpuid(0x80000004, &brand_ptr[8], &brand_ptr[9], &brand_ptr[10], &brand_ptr[11]);
1304-
brand[48] = '\0';
1305-
}
1287+
if (!cpu->vendor.length) {
1288+
ffStrbufEnsureFixedLengthFree(&cpu->vendor, 12);
1289+
memcpy(cpu->vendor.chars + 0, &ebx, 4);
1290+
memcpy(cpu->vendor.chars + 4, &edx, 4);
1291+
memcpy(cpu->vendor.chars + 8, &ecx, 4);
1292+
cpu->vendor.chars[12] = '\0';
1293+
cpu->vendor.length = 12;
13061294
}
13071295

13081296
// CPU Version Info (CPUID Leaf 1)
@@ -1375,7 +1363,7 @@ bool ffCPUDetectX86Specific(FFCPUResult* cpu) {
13751363
}
13761364

13771365
if (entry->brand.pattern[0] != '\0') {
1378-
if (match_brand_pattern(entry->brand.pattern, brand)) {
1366+
if (match_brand_pattern(entry->brand.pattern, cpu->name.chars)) {
13791367
score += entry->brand.score;
13801368
} else {
13811369
continue;

0 commit comments

Comments
 (0)