mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 13:11:28 +00:00
Change the static functions getattrbyname and gettestbyname into public
methods of AVal and FingerTest, respectively.
This commit is contained in:
@@ -171,6 +171,7 @@ struct OS_Classification {
|
|||||||
struct FingerTest {
|
struct FingerTest {
|
||||||
const char *name;
|
const char *name;
|
||||||
std::vector<struct AVal> results;
|
std::vector<struct AVal> results;
|
||||||
|
const struct AVal *getattrbyname(const char *name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FingerPrint {
|
struct FingerPrint {
|
||||||
@@ -178,6 +179,7 @@ struct FingerPrint {
|
|||||||
char *OS_name;
|
char *OS_name;
|
||||||
std::vector<OS_Classification> OS_class;
|
std::vector<OS_Classification> OS_class;
|
||||||
std::vector<FingerTest> tests;
|
std::vector<FingerTest> tests;
|
||||||
|
const FingerTest *gettestbyname(const char *name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This structure contains the important data from the fingerprint
|
/* This structure contains the important data from the fingerprint
|
||||||
|
|||||||
33
osscan.cc
33
osscan.cc
@@ -188,12 +188,10 @@ FingerPrintDB::~FingerPrintDB() {
|
|||||||
delete *current;
|
delete *current;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct AVal *getattrbyname(const FingerTest *test, const char *name) {
|
const struct AVal *FingerTest::getattrbyname(const char *name) const {
|
||||||
std::vector<struct AVal>::const_iterator i;
|
std::vector<struct AVal>::const_iterator i;
|
||||||
|
|
||||||
if (test == NULL)
|
for (i = results.begin(); i != results.end(); i++) {
|
||||||
return NULL;
|
|
||||||
for (i = test->results.begin(); i != test->results.end(); i++) {
|
|
||||||
if (strcmp(i->attribute, name) == 0)
|
if (strcmp(i->attribute, name) == 0)
|
||||||
return &*i;
|
return &*i;
|
||||||
}
|
}
|
||||||
@@ -201,11 +199,10 @@ static const struct AVal *getattrbyname(const FingerTest *test, const char *name
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FingerTest *gettestbyname(FingerPrint *FP, const char *name) {
|
const FingerTest *FingerPrint::gettestbyname(const char *name) const {
|
||||||
std::vector<FingerTest>::iterator i;
|
std::vector<FingerTest>::const_iterator i;
|
||||||
|
|
||||||
if (!FP) return NULL;
|
for (i = tests.begin(); i != tests.end(); i++) {
|
||||||
for (i = FP->tests.begin(); i != FP->tests.end(); i++) {
|
|
||||||
if (strcmp(i->name, name) == 0)
|
if (strcmp(i->name, name) == 0)
|
||||||
return &*i;
|
return &*i;
|
||||||
};
|
};
|
||||||
@@ -226,11 +223,11 @@ static FingerTest *gettestbyname(FingerPrint *FP, const char *name) {
|
|||||||
case, you may also pass in the group name (SEQ, T1, etc) to have
|
case, you may also pass in the group name (SEQ, T1, etc) to have
|
||||||
that extra info printed. If you pass 0 for verbose, you might as
|
that extra info printed. If you pass 0 for verbose, you might as
|
||||||
well pass NULL for testGroupName as it won't be used. */
|
well pass NULL for testGroupName as it won't be used. */
|
||||||
static int AVal_match(FingerTest *reference, FingerTest *fprint, FingerTest *points,
|
static int AVal_match(const FingerTest *reference, const FingerTest *fprint, const FingerTest *points,
|
||||||
unsigned long *num_subtests,
|
unsigned long *num_subtests,
|
||||||
unsigned long *num_subtests_succeeded, int shortcut,
|
unsigned long *num_subtests_succeeded, int shortcut,
|
||||||
int verbose, const char *testGroupName) {
|
int verbose, const char *testGroupName) {
|
||||||
std::vector<struct AVal>::iterator current_ref;
|
std::vector<struct AVal>::const_iterator current_ref;
|
||||||
const struct AVal *current_fp;
|
const struct AVal *current_fp;
|
||||||
const struct AVal *current_points;
|
const struct AVal *current_points;
|
||||||
unsigned int number, number1;
|
unsigned int number, number1;
|
||||||
@@ -246,7 +243,7 @@ static int AVal_match(FingerTest *reference, FingerTest *fprint, FingerTest *poi
|
|||||||
for (current_ref = reference->results.begin();
|
for (current_ref = reference->results.begin();
|
||||||
current_ref != reference->results.end();
|
current_ref != reference->results.end();
|
||||||
current_ref++) {
|
current_ref++) {
|
||||||
current_fp = getattrbyname(fprint, current_ref->attribute);
|
current_fp = fprint->getattrbyname(current_ref->attribute);
|
||||||
if (!current_fp) continue;
|
if (!current_fp) continue;
|
||||||
/* OK, we compare an attribute value in current_fp->value to a
|
/* OK, we compare an attribute value in current_fp->value to a
|
||||||
potentially large expression in current_ref->value. The syntax
|
potentially large expression in current_ref->value. The syntax
|
||||||
@@ -301,7 +298,7 @@ static int AVal_match(FingerTest *reference, FingerTest *fprint, FingerTest *poi
|
|||||||
} while(q);
|
} while(q);
|
||||||
if (numtrue == 0) testfailed=1;
|
if (numtrue == 0) testfailed=1;
|
||||||
if (points) {
|
if (points) {
|
||||||
current_points = getattrbyname(points, current_ref->attribute);
|
current_points = points->getattrbyname(current_ref->attribute);
|
||||||
if (!current_points) fatal("%s: Failed to find point amount for test %s.%s", __func__, testGroupName? testGroupName : "", current_ref->attribute);
|
if (!current_points) fatal("%s: Failed to find point amount for test %s.%s", __func__, testGroupName? testGroupName : "", current_ref->attribute);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
pointsThisTest = strtol(current_points->value, &endptr, 10);
|
pointsThisTest = strtol(current_points->value, &endptr, 10);
|
||||||
@@ -334,8 +331,8 @@ static int AVal_match(FingerTest *reference, FingerTest *fprint, FingerTest *poi
|
|||||||
double compare_fingerprints(FingerPrint *referenceFP, FingerPrint *observedFP,
|
double compare_fingerprints(FingerPrint *referenceFP, FingerPrint *observedFP,
|
||||||
FingerPrint *MatchPoints, int verbose) {
|
FingerPrint *MatchPoints, int verbose) {
|
||||||
std::vector<FingerTest>::iterator currentReferenceTest;
|
std::vector<FingerTest>::iterator currentReferenceTest;
|
||||||
FingerTest *currentObservedTest;
|
const FingerTest *currentObservedTest;
|
||||||
FingerTest *currentTestMatchPoints;
|
const FingerTest *currentTestMatchPoints;
|
||||||
unsigned long num_subtests = 0, num_subtests_succeeded = 0;
|
unsigned long num_subtests = 0, num_subtests_succeeded = 0;
|
||||||
unsigned long new_subtests, new_subtests_succeeded;
|
unsigned long new_subtests, new_subtests_succeeded;
|
||||||
assert(referenceFP);
|
assert(referenceFP);
|
||||||
@@ -344,11 +341,11 @@ double compare_fingerprints(FingerPrint *referenceFP, FingerPrint *observedFP,
|
|||||||
for (currentReferenceTest = referenceFP->tests.begin();
|
for (currentReferenceTest = referenceFP->tests.begin();
|
||||||
currentReferenceTest != referenceFP->tests.end();
|
currentReferenceTest != referenceFP->tests.end();
|
||||||
currentReferenceTest++) {
|
currentReferenceTest++) {
|
||||||
currentObservedTest = gettestbyname(observedFP, currentReferenceTest->name);
|
currentObservedTest = observedFP->gettestbyname(currentReferenceTest->name);
|
||||||
if (currentObservedTest) {
|
if (currentObservedTest) {
|
||||||
new_subtests = new_subtests_succeeded = 0;
|
new_subtests = new_subtests_succeeded = 0;
|
||||||
if (MatchPoints) {
|
if (MatchPoints) {
|
||||||
currentTestMatchPoints = gettestbyname(MatchPoints, currentReferenceTest->name);
|
currentTestMatchPoints = MatchPoints->gettestbyname(currentReferenceTest->name);
|
||||||
if (!currentTestMatchPoints)
|
if (!currentTestMatchPoints)
|
||||||
fatal("%s: Failed to locate test %s in MatchPoints directive of fingerprint file", __func__, currentReferenceTest->name);
|
fatal("%s: Failed to locate test %s in MatchPoints directive of fingerprint file", __func__, currentReferenceTest->name);
|
||||||
} else currentTestMatchPoints = NULL;
|
} else currentTestMatchPoints = NULL;
|
||||||
@@ -654,14 +651,14 @@ static bool test_match_literal(const FingerTest *a, const FingerTest *b) {
|
|||||||
|
|
||||||
/* Check that b contains all the AVals in a, with the same values. */
|
/* Check that b contains all the AVals in a, with the same values. */
|
||||||
for (i = a->results.begin(); i != a->results.end(); i++) {
|
for (i = a->results.begin(); i != a->results.end(); i++) {
|
||||||
av = getattrbyname(b, i->attribute);
|
av = b->getattrbyname(i->attribute);
|
||||||
if (av == NULL || strcmp(i->value, av->value) != 0)
|
if (av == NULL || strcmp(i->value, av->value) != 0)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that a contains all the AVals in b, with the same values. */
|
/* Check that a contains all the AVals in b, with the same values. */
|
||||||
for (i = b->results.begin(); i != b->results.end(); i++) {
|
for (i = b->results.begin(); i != b->results.end(); i++) {
|
||||||
av = getattrbyname(a, i->attribute);
|
av = a->getattrbyname(i->attribute);
|
||||||
if (av == NULL || strcmp(i->value, av->value) != 0)
|
if (av == NULL || strcmp(i->value, av->value) != 0)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user