From 227dd9f4cd795ba01f375c138349c5936d35eefc Mon Sep 17 00:00:00 2001 From: Greg Back Date: Tue, 30 Apr 2013 14:09:38 -0400 Subject: [PATCH 1/5] Update README in cybox1.0 branch [ci skip] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 90cde04a..72517d30 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# python-cybox [![Build Status](https://travis-ci.org/CybOXProject/python-cybox.png?branch=master)](https://travis-ci.org/CybOXProject/python-cybox) +# python-cybox [![Build Status](https://travis-ci.org/CybOXProject/python-cybox.png?branch=cybox1.0)](https://travis-ci.org/CybOXProject/python-cybox) A Python library for parsing, manipulating, and generating CybOX content. For more information about CybOX, see http://cybox.mitre.org. From 477f627009cdccd40656b1bb09a2779bc7ffc9e1 Mon Sep 17 00:00:00 2001 From: Greg Back Date: Tue, 30 Apr 2013 14:20:31 -0400 Subject: [PATCH 2/5] Revert "Made all fields in RegistryValue.from_dict optional" This reverts commit 42035efebc604e78cafb7d49a7a9f80ae752c9dd. I talked to Andrew and we both agreed this change is unneccessary. --- cybox/objects/win_registry_key_object.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cybox/objects/win_registry_key_object.py b/cybox/objects/win_registry_key_object.py index c65177e5..af348654 100644 --- a/cybox/objects/win_registry_key_object.py +++ b/cybox/objects/win_registry_key_object.py @@ -165,9 +165,9 @@ def from_dict(registry_value_dict): return None registry_value_ = RegistryValue() - if 'name' in registry_value_dict: registry_value_.name = String.from_dict(registry_value_dict.get('name')) - if 'data' in registry_value_dict: registry_value_.data = String.from_dict(registry_value_dict.get('data')) - if 'datatype' in registry_value_dict: registry_value_.datatype = String.from_dict(registry_value_dict.get('datatype')) + registry_value_.name = String.from_dict(registry_value_dict.get('name')) + registry_value_.data = String.from_dict(registry_value_dict.get('data')) + registry_value_.datatype = String.from_dict(registry_value_dict.get('datatype')) #registry_value_.byte_runs = ByteRuns.from_dict(registry_value_dict.get('byte_runs')) return registry_value_ \ No newline at end of file From aaf505c85d47c6d87990d9ec04cd236c9d21582b Mon Sep 17 00:00:00 2001 From: Andrew Sillers Date: Tue, 30 Apr 2013 12:55:06 -0400 Subject: [PATCH 3/5] Added vendor to ToolInformation object --- cybox/common/toolinformation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cybox/common/toolinformation.py b/cybox/common/toolinformation.py index 9ead6f73..a63ba419 100644 --- a/cybox/common/toolinformation.py +++ b/cybox/common/toolinformation.py @@ -24,6 +24,7 @@ def to_obj(self): if self.idref is not None : tool_information_obj.set_idref(self.idref) if self.description is not None : pass if self.name is not None : tool_information_obj.set_Name(self.name) + if self.vendor is not None : tool_information_obj.set_Vendor(self.vendor) if self.version is not None : tool_information_obj.set_Version(self.version) if self.service_pack is not None : tool_information_obj.set_Service_Pack(self.service_pack) if self.tool_specific_data is not None : pass From 11a2672783dde1dc5238c0c37ae08af7149639c8 Mon Sep 17 00:00:00 2001 From: Greg Back Date: Wed, 4 Sep 2013 15:05:03 -0400 Subject: [PATCH 4/5] Add new shortcut import. Makes some code a bit more 1.0-2.0 compatible. --- cybox/common/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cybox/common/__init__.py b/cybox/common/__init__.py index 78ef6cb6..aa9e2da8 100644 --- a/cybox/common/__init__.py +++ b/cybox/common/__init__.py @@ -6,3 +6,4 @@ from personnel import Personnel from time import Time from structured_text import StructuredText, Block, StructuredGroup +from toolinformation import ToolInformationList From e934048ad5e75e740a2ea221b390937e9b21aef8 Mon Sep 17 00:00:00 2001 From: Greg Back Date: Wed, 2 Jul 2014 17:46:43 -0500 Subject: [PATCH 5/5] Add a from_json() function. --- cybox/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cybox/__init__.py b/cybox/__init__.py index 03352acb..9cc0af0d 100644 --- a/cybox/__init__.py +++ b/cybox/__init__.py @@ -15,8 +15,19 @@ def to_xml(self): return s.getvalue() def to_json(self): + """Export an object as a JSON String.""" return json.dumps(self.to_dict()) + @classmethod + def from_json(cls, json_doc): + """Parse a JSON string and build an entity.""" + try: + d = json.load(json_doc) + except AttributeError: # catch the read() error + d = json.loads(json_doc) + + return cls.from_dict(d) + @classmethod def object_from_dict(cls, entity_dict): """Convert from dict representation to object representation."""