<commit_before>'''
   Copyright (c) 2017 <NAME> 

   This file is part of mac_apt (macOS Artifact Parsing Tool).
   Usage or distribution of this software/code is subject to the 
   terms of the MIT License.
   
'''

import os
import biplist
import sys
import logging

from biplist import *
from enum import IntEnum
from binascii import unhexlify
from plugins.helpers.macinfo import *
from plugins.helpers.writer import *


__Plugin_Name = "WIFI"
__Plugin_Friendly_Name = "Wifi-Airport Preferences"
__Plugin_Version = "1.1"
__Plugin_Description = "Gets wifi network information from the com.apple.airport.preferences.plist file"
__Plugin_Author = "<NAME>, <NAME>"
__Plugin_Author_Email = "<EMAIL>, <EMAIL>"

__Plugin_Standalone = True
__Plugin_Standalone_Usage = 'Provide the airport wifi plist file found at /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist'

log = logging.getLogger('MAIN.' + __Plugin_Name) # Do not rename or remove this ! This is the logger object

#---- Do not change the variable names in above section ----#

class NetType(IntEnum):
    UNKNOWN = 0
    KNOWN = 1
    PREVIOUSREMEMBERED = 2 # Perhaps after an update ?

    def __str__(self):
        return self.name # This returns 'KNOWN' instead of 'NetType.KNOWN'

class Network: 
    
    def __init__(self, version):
        self.Name = ''
        self.Order = None
        self.Type = NetType.UNKNOWN
        self.Version = version
        self.Disabled = False
        self.SystemMode = False
        self.PossiblyHiddenNetwork = False
        self.TemporarilyDisabled = False
        self.Closed = False
        self.SecurityType = ""
        self.SSIDString = ""
        self.SPRoaming = False
        self.Passpoint = False
        self.AutoLogin = False
        self.Captive = False
        self.LastConnected = None
        self.PersonalHotspot = False
        self.CollocatedGroup = ""
        self.RoamingProfileType = ""
        self.lastChannelHistory = ""
        self.ChannelHistory = ""
        self.BSSIDHistory = None
    
    def ReadNetworkInfo(self, dictionary, net_type):
        self.Type = net_type
        self.AutoLogin = dictionary.get('AutoLogin', '')
        self.Captive = dictionary.get('Captive', '')
        self.Closed = dictionary.get('Closed', '')
        self.CollocatedGroup = dictionary.get('CollocatedGroup', '')
        self.Disabled = dictionary.get('Disabled', '')
        self.LastConnected = dictionary.get('LastConnected', '')
        self.Passpoint = dictionary.get('Passpoint', '')
        self.PersonalHotspot = dictionary.get('PersonalHotspot', '')
        self.PossiblyHiddenNetwork = dictionary.get('PossiblyHiddenNetwork', '')
        self.RoamingProfileType = dictionary.get('RoamingProfileType', '')
        self.SPRoaming = dictionary.get('SPRoaming', '')
        #self.SSID = dictionary.get('SSID')
        self.SSIDString = dictionary.get('SSIDString', '')
        self.SecurityType = dictionary.get('SecurityType', '')
        self.SystemMode = dictionary.get('SystemMode', '')
        self.TemporarilyDisabled = dictionary.get('TemporarilyDisabled')
        self.ChannelHistory = dictionary.get('ChannelHistory')
        bssid_history = dictionary.get('BSSIDHistory', None) # Present if version=1900
        if bssid_history and len(bssid_history) > 0:
            self.BSSIDHistory = ''
            for history_item in bssid_history:
                self.BSSIDHistory += '[MAC={}, {}]'.format(
                                        history_item.get('BSSID',''), 
                                        str(history_item.get('Timestamp', '')) )

def GetReadableSSID(ssid, wifi_plist_ver):
    try:
        if (wifi_plist_ver == 2500):
            ssid = ssid[10:]
        else:
            ssid = ssid[11:-1]
            ssid = ssid.replace(" ", "")
        ssid = unhexlify(ssid).decode('utf-8', 'backslashreplace')
    except (ValueError, IndexError) as e:
        log.error ('Error in GetReadableSSID() Details: ' + str(e))
    return ssid
    
def GetSSIDs(ssids, wifi_plist_ver):
    list = []
    for ssid in ssids:
        ssid_readable = GetReadableSSID(ssid, wifi_plist_ver)
        if ssid_readable:
            list.append(ssid_readable)
    return list
<commit_msg>fix wifi plist handling for reading ssid<commit_after>'''
   Copyright (c) 2017 <NAME> 

   This file is part of mac_apt (macOS Artifact Parsing Tool).
   Usage or distribution of this software/code is subject to the 
   terms of the MIT License.
   
'''

import os
import biplist
import sys
import logging

from biplist import *
from enum import IntEnum
from binascii import unhexlify
from plugins.helpers.macinfo import *
from plugins.helpers.writer import *


__Plugin_Name = "WIFI"
__Plugin_Friendly_Name = "Wifi-Airport Preferences"
__Plugin_Version = "1.1"
__Plugin_Description = "Gets wifi network information from the com.apple.airport.preferences.plist file"
__Plugin_Author = "<NAME>, <NAME>"
__Plugin_Author_Email = "<EMAIL>, <EMAIL>"

__Plugin_Standalone = True
__Plugin_Standalone_Usage = 'Provide the airport wifi plist file found at /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist'

log = logging.getLogger('MAIN.' + __Plugin_Name) # Do not rename or remove this ! This is the logger object

#---- Do not change the variable names in above section ----#

class NetType(IntEnum):
    UNKNOWN = 0
    KNOWN = 1
    PREVIOUSREMEMBERED = 2 # Perhaps after an update ?

    def __str__(self):
        return self.name # This returns 'KNOWN' instead of 'NetType.KNOWN'

class Network: 
    
    def __init__(self, version):
        self.Name = ''
        self.Order = None
        self.Type = NetType.UNKNOWN
        self.Version = version
        self.Disabled = False
        self.SystemMode = False
        self.PossiblyHiddenNetwork = False
        self.TemporarilyDisabled = False
        self.Closed = False
        self.SecurityType = ""
        self.SSIDString = ""
        self.SPRoaming = False
        self.Passpoint = False
        self.AutoLogin = False
        self.Captive = False
        self.LastConnected = None
        self.PersonalHotspot = False
        self.CollocatedGroup = ""
        self.RoamingProfileType = ""
        self.lastChannelHistory = ""
        self.ChannelHistory = ""
        self.BSSIDHistory = None
    
    def ReadNetworkInfo(self, dictionary, net_type):
        self.Type = net_type
        self.AutoLogin = dictionary.get('AutoLogin', '')
        self.Captive = dictionary.get('Captive', '')
        self.Closed = dictionary.get('Closed', '')
        self.CollocatedGroup = dictionary.get('CollocatedGroup', '')
        self.Disabled = dictionary.get('Disabled', '')
        self.LastConnected = dictionary.get('LastConnected', '')
        self.Passpoint = dictionary.get('Passpoint', '')
        self.PersonalHotspot = dictionary.get('PersonalHotspot', '')
        self.PossiblyHiddenNetwork = dictionary.get('PossiblyHiddenNetwork', '')
        self.RoamingProfileType = dictionary.get('RoamingProfileType', '')
        self.SPRoaming = dictionary.get('SPRoaming', '')
        #self.SSID = dictionary.get('SSID')
        self.SSIDString = dictionary.get('SSIDString', '')
        self.SecurityType = dictionary.get('SecurityType', '')
        self.SystemMode = dictionary.get('SystemMode', '')
        self.TemporarilyDisabled = dictionary.get('TemporarilyDisabled')
        self.ChannelHistory = dictionary.get('ChannelHistory')
        bssid_history = dictionary.get('BSSIDHistory', None) # Present if version=1900
        if bssid_history and len(bssid_history) > 0:
            self.BSSIDHistory = ''
            for history_item in bssid_history:
                self.BSSIDHistory += '[MAC={}, {}]'.format(
                                        history_item.get('BSSID',''), 
                                        str(history_item.get('Timestamp', '')) )

def GetReadableSSID(ssid, wifi_plist_ver):
    try:
        if (wifi_plist_ver == 2500):
            ssid = ssid[10:]
        else:
            ssid = ssid[11:-1]
        ssid = ssid.replace(" ", "").replace("<", "").replace(">", "")
        ssid = unhexlify(ssid).decode('utf-8', 'backslashreplace')
    except (ValueError, IndexError) as e:
        log.error ('Error in GetReadableSSID() Details: ' + str(e))
    return ssid
    
def GetSSIDs(ssids, wifi_plist_ver):
    list = []
    for ssid in ssids:
        ssid_readable = GetReadableSSID(ssid, wifi_plist_ver)
        if ssid_readable:
            list.append(ssid_readable)
    return list

{'fraction_non_alphanumeric': 0.11143626360763198, 'fraction_numerical': 0.005618635139880604, 'mean_word_length': 2.7163984341017833, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3805389', 'n_tokens_mistral': 2546, 'n_tokens_neox': 2437, 'n_words': 574}