diff options
| author | Santosh Sivaraj <santosiv@in.ibm.com> | 2015-04-28 20:40:13 +0530 |
|---|---|---|
| committer | Santosh Sivaraj <santosiv@in.ibm.com> | 2016-11-09 19:42:34 +0530 |
| commit | 3b21283808f3cf6685c01f754fd1d270a06e6d7d (patch) | |
| tree | f070771d4d23eb8f2ed447922774ab0525d02e7b /catalog/catalog.py | |
| parent | 9d1bd89a8c1f98da49588d174c691c0257b5d24e (diff) | |
| download | ima-catalog-3b21283808f3cf6685c01f754fd1d270a06e6d7d.tar.gz ima-catalog-3b21283808f3cf6685c01f754fd1d270a06e6d7d.zip | |
Some folder structure re-arrangement
Signed-off-by: Santosh Sivaraj <santosiv@in.ibm.com>
Diffstat (limited to 'catalog/catalog.py')
| -rw-r--r-- | catalog/catalog.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/catalog/catalog.py b/catalog/catalog.py new file mode 100644 index 0000000..be20a24 --- /dev/null +++ b/catalog/catalog.py @@ -0,0 +1,56 @@ +import struct +import time +import sys +from datetime import datetime +from common import * +from events import pack_events +from groups import pack_groups +from formulae import pack_formulae + +def dump_schema(cat_file): + f = open(cat_file) + f.seek(0x1000) + s = f.read(PAGE_SIZE) + f.close() + + return s + +def create_catalog(version, old_lid): + events, enum = pack_events('events.csv') + groups, gnum = pack_groups('groups.csv') + formulae, fnum = pack_formulae('formulae.csv') + # we will not create the schema now, will extract the schema from the + # existing catalog file. + schema = dump_schema(old_lid) + + schema_offset = 1 + events_offset = schema_offset + len(schema) / PAGE_SIZE + events_length = len(events) / PAGE_SIZE + groups_offset = events_offset + len(events) / PAGE_SIZE + groups_length = len(groups) / PAGE_SIZE + formulae_offset = groups_offset + len(groups) / PAGE_SIZE + formulae_length = len(formulae) / PAGE_SIZE + # WARNING: schema len and offset is hardcoded here + header = struct.pack(">IIQ16s32xHHHxxHHHxxHHHxxHHHxx", 0x32347837, 64, + version, + datetime.fromtimestamp(time.time()).strftime('%Y%m%d%H%M%S'), + 1, 1, 4, events_offset, events_length, enum, + groups_offset, groups_length, gnum, formulae_offset, + formulae_length, fnum) + + return pad_page(header, PAGE_SIZE) + schema + events + groups + formulae + +if __name__ == "__main__": + if len(sys.argv) <= 3: + print "Usage: ./%s version old_lid out_file" % (sys.argv[0]) + exit(1) + + # get the version for the new build, and older catalog file to extract the + # schema data + c = create_catalog(int(sys.argv[1]), sys.argv[2]) + padlen = 64 - len(c) / PAGE_SIZE + c += struct.pack('%dx' % (padlen * PAGE_SIZE)) + + f = open(sys.argv[3], 'wt') + f.write(c) + f.close() |

