|
12 | 12 | # |
13 | 13 | # We would appreciate acknowledgement if the software is used. |
14 | 14 |
|
| 15 | +import argparse |
15 | 16 | import json |
16 | 17 | import codecs |
17 | 18 | import sys |
|
20 | 21 | from PyQt5.QtWidgets import * |
21 | 22 | from PyQt5.QtGui import * |
22 | 23 | from PyQt5 import QtCore |
23 | | -#import logging |
| 24 | +import logging |
24 | 25 |
|
25 | | -from lib import JSONLD, get_attribute, get_optional_integer_attribute, \ |
| 26 | +from .lib import JSONLD, get_attribute, get_optional_integer_attribute, \ |
26 | 27 | get_optional_string_attribute, get_optional_dict_attribute, \ |
27 | 28 | get_optional_list_attribute |
28 | 29 |
|
@@ -293,6 +294,7 @@ def buildDataCellSites(self, idObject): |
293 | 294 |
|
294 | 295 |
|
295 | 296 | def buildDataWirelessNet(self, idObject: str) -> list[list[str]]: |
| 297 | + global wireless_net |
296 | 298 | tData = [] |
297 | 299 | if idObject == ':WirelessNet': |
298 | 300 | self.headers = ["SSID", "BSID"] |
@@ -1085,7 +1087,7 @@ def processRelationConnectedTo(jsonObj): |
1085 | 1087 | { |
1086 | 1088 | "uco-core:source":id_connected_source, |
1087 | 1089 | "uco-core:target":id_connected_target, |
1088 | | - "uco-observable:starTime": startTime, |
| 1090 | + "uco-observable:startTime": startTime, |
1089 | 1091 | "uco-observable:endTime": endTime |
1090 | 1092 | }) |
1091 | 1093 | except Exception as e: |
@@ -1873,62 +1875,76 @@ def number_with_dots(n: Union[int, str]) -> str: |
1873 | 1875 | else: |
1874 | 1876 | raise TypeError('Parameter must be either integer or string') |
1875 | 1877 |
|
1876 | | -if __name__ == '__main__': |
1877 | 1878 | #--- Gobal variables |
| 1879 | +chatMessages: list[dict[str, str]] = [] |
| 1880 | +chatThreads: list[dict[str, str]] = [] |
| 1881 | +#chatMessageAttachments = [] |
| 1882 | +cookies: list[dict[str, str]] = [] |
| 1883 | +geo_coordinates: list[dict[str, str]] = [] |
| 1884 | +cell_sites: list[dict[str, str]] = [] |
| 1885 | +bluetooths: list[dict[str, str]] = [] |
| 1886 | +searched_items: list[dict[str, str]] = [] |
| 1887 | +social_media_activities: list[dict[str, str]] = [] |
| 1888 | +events: list[dict[str, str]] = [] |
| 1889 | +relationAttachmentsTo: list[dict[str, str]] = [] |
| 1890 | +relationMappedBy: list[dict[str, str]] = [] |
| 1891 | +relationConnectedTo: list[dict[str, str]] = [] |
| 1892 | +smsMessages: list[dict[str, str]] = [] |
| 1893 | +accounts: list[dict[str, str]] = [] |
| 1894 | +emailAddresses: list[dict[str, str]] = [] |
| 1895 | +emailAccounts: list[dict[str, str]] = [] |
| 1896 | +applications: list[dict[str, str]] = [] |
| 1897 | +phoneCalls: list[dict[str, str]] = [] |
| 1898 | +calendars: list[dict[str, str]] = [] |
| 1899 | +emailMessages: list[dict[str, str]] = [] |
| 1900 | +filesUncategorized: list[dict[str, str]] = [] |
| 1901 | +filesImage: list[dict[str, str]] = [] |
| 1902 | +filesAudio: list[dict[str, str]] = [] |
| 1903 | +filesText: list[dict[str, str]] = [] |
| 1904 | +filesPDF: list[dict[str, str]] = [] |
| 1905 | +filesWord: list[dict[str, str]] = [] |
| 1906 | +filesRTF: list[dict[str, str]] = [] |
| 1907 | +filesVideo: list[dict[str, str]] = [] |
| 1908 | +filesArchive: list[dict[str, str]] = [] |
| 1909 | +filesDatabase: list[dict[str, str]] = [] |
| 1910 | +filesApplication: list[dict[str, str]] = [] |
| 1911 | +webURLs: list[dict[str, str]] = [] |
| 1912 | +webURLHistory: list[dict[str, str]] = [] |
| 1913 | +webSearchTerm: list[dict[str, str]] = [] |
| 1914 | +webBookmark: list[dict[str, str]] = [] |
| 1915 | +wireless_net: list[dict[str, str]] = [] |
| 1916 | + |
| 1917 | +tableData: list[list[str]] = [[]] |
| 1918 | +treeData: list[dict[str,str]] = [] |
| 1919 | + |
| 1920 | +def main(): |
1878 | 1921 | C_GREEN = '\033[32m' |
1879 | 1922 | C_RED = '\033[31m' |
1880 | 1923 | C_BLACK = '\033[0m' |
1881 | 1924 | C_CYAN = '\033[36m' |
1882 | 1925 | EMPTY_DATA = "1900-01-01T00:00:00" |
1883 | 1926 |
|
1884 | | - chatThreads: list[dict[str, str]] = [] |
1885 | | - chatMessages: list[dict[str, str]] = [] |
1886 | | - #chatMessageAttachments = [] |
1887 | | - cookies: list[dict[str, str]] = [] |
1888 | | - geo_coordinates: list[dict[str, str]] = [] |
1889 | | - cell_sites: list[dict[str, str]] = [] |
1890 | | - bluetooths: list[dict[str, str]] = [] |
1891 | | - searched_items: list[dict[str, str]] = [] |
1892 | | - social_media_activities: list[dict[str, str]] = [] |
1893 | | - events: list[dict[str, str]] = [] |
1894 | | - wireless_net: list[dict[str, str]] = [] |
1895 | | - relationAttachmentsTo: list[dict[str, str]] = [] |
1896 | | - relationMappedBy: list[dict[str, str]] = [] |
1897 | | - relationConnectedTo: list[dict[str, str]] = [] |
1898 | | - smsMessages: list[dict[str, str]] = [] |
1899 | | - accounts: list[dict[str, str]] = [] |
1900 | | - emailAddresses: list[dict[str, str]] = [] |
1901 | | - emailAccounts: list[dict[str, str]] = [] |
1902 | | - applications: list[dict[str, str]] = [] |
1903 | | - phoneCalls: list[dict[str, str]] = [] |
1904 | | - calendars: list[dict[str, str]] = [] |
1905 | | - emailMessages: list[dict[str, str]] = [] |
1906 | | - filesUncategorized: list[dict[str, str]] = [] |
1907 | | - filesImage: list[dict[str, str]] = [] |
1908 | | - filesAudio: list[dict[str, str]] = [] |
1909 | | - filesText: list[dict[str, str]] = [] |
1910 | | - filesPDF: list[dict[str, str]] = [] |
1911 | | - filesWord: list[dict[str, str]] = [] |
1912 | | - filesRTF: list[dict[str, str]] = [] |
1913 | | - filesVideo: list[dict[str, str]] = [] |
1914 | | - filesArchive: list[dict[str, str]] = [] |
1915 | | - filesDatabase: list[dict[str, str]] = [] |
1916 | | - filesApplication: list[dict[str, str]] = [] |
1917 | | - webURLs: list[dict[str, str]] = [] |
1918 | | - webURLHistory: list[dict[str, str]] = [] |
1919 | | - webSearchTerm: list[dict[str, str]] = [] |
1920 | | - webBookmark: list[dict[str, str]] = [] |
| 1927 | + parser = argparse.ArgumentParser() |
| 1928 | + parser.add_argument("--debug", action="store_true") |
| 1929 | + parser.add_argument("--dry-run", action="store_true", help="Run application, exiting without initiating GUI.") |
| 1930 | + parser.add_argument("input_jsonld") |
| 1931 | + args = parser.parse_args() |
| 1932 | + |
| 1933 | + logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO) |
1921 | 1934 |
|
1922 | 1935 | #--- Read input file in CASE-JSON format |
1923 | 1936 | try: |
1924 | | - f = codecs.open(sys.argv[1], 'r', encoding='utf-8') |
| 1937 | + f = codecs.open(args.input_jsonld, 'r', encoding='utf-8') |
1925 | 1938 | except Exception as e: |
1926 | | - print(C_RED + '\n' + "ERROR in trying to open the file " + sys.argv[1]) |
| 1939 | + print(C_RED + '\n' + "ERROR in trying to open the file " + args.input_jsonld) |
1927 | 1940 | print (e) |
1928 | 1941 | sys.exit('Open file failed.') |
1929 | 1942 | try: |
1930 | 1943 | print(C_CYAN + "Load JSON structure, it might take some time, please wait ...\n") |
1931 | 1944 | json_obj = json.load(f) |
| 1945 | + if args.dry_run: |
| 1946 | + logging.info("Exiting dry run.") |
| 1947 | + sys.exit(0) |
1932 | 1948 | app = QApplication([]) |
1933 | 1949 | _widget=QWidget() |
1934 | 1950 | msgBox = QMessageBox() |
@@ -1975,9 +1991,11 @@ def number_with_dots(n: Union[int, str]) -> str: |
1975 | 1991 | for facet in dataFacets: |
1976 | 1992 | assert isinstance(facet, dict) |
1977 | 1993 | facet_type = facet["@type"] |
| 1994 | + objectType: str |
1978 | 1995 | if isinstance(facet_type, str): |
1979 | 1996 | objectType = facet_type |
1980 | 1997 | elif isinstance(facet_type, list): |
| 1998 | + assert isinstance(facet_type[0], str) |
1981 | 1999 | objectType = facet_type[0] # SocialMediaActivityFacet |
1982 | 2000 | else: |
1983 | 2001 | raise TypeError("Unexpected type for property %r: %r." % (facet_type, type(facet_type))) |
@@ -2043,8 +2061,6 @@ def number_with_dots(n: Union[int, str]) -> str: |
2043 | 2061 | f.close() |
2044 | 2062 | print(C_CYAN + "\n\nEnd Observables processing!" + C_BLACK + "\n\n") |
2045 | 2063 |
|
2046 | | - tableData: list[list[str]] = [[]] |
2047 | | - treeData: list[dict[str,str]] = [] |
2048 | 2064 | i = 1 |
2049 | 2065 | totMessages = 0 |
2050 | 2066 |
|
@@ -2210,6 +2226,10 @@ def number_with_dots(n: Union[int, str]) -> str: |
2210 | 2226 | #--- Set the UI layout |
2211 | 2227 | _view = view(treeData, tableData) |
2212 | 2228 | _view.setGeometry(50, 50, 1400, 800) |
2213 | | - _view.setWindowTitle('Cyber items view - ' + sys.argv[1] + ' (n. Observables: ' + number_with_dots(nObjects) + ')') |
| 2229 | + _view.setWindowTitle('Cyber items view - ' + args.input_jsonld + ' (n. Observables: ' + number_with_dots(nObjects) + ')') |
2214 | 2230 | _view.show() |
2215 | 2231 | sys.exit(app.exec_()) |
| 2232 | + |
| 2233 | + |
| 2234 | +if __name__ == '__main__': |
| 2235 | + main() |
0 commit comments