NetHook2: Refactor duplicated string comparison code