diff options
author | Richard Jones <rjones@redhat.com> | 2010-01-18 17:56:13 +0000 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2010-01-28 11:25:30 +0000 |
commit | 5fe4d4718cf00876d8de20f4c297dc4ca69db1a4 (patch) | |
tree | a3fa0314fa332b9c71a5cfcadf98fd6753105c51 /hivex/hivex.c | |
parent | f1dc74b8d605c07f4b8d4ca0b8dcf3db8c18edd1 (diff) | |
download | libguestfs-5fe4d4718cf00876d8de20f4c297dc4ca69db1a4.tar.gz libguestfs-5fe4d4718cf00876d8de20f4c297dc4ca69db1a4.tar.xz libguestfs-5fe4d4718cf00876d8de20f4c297dc4ca69db1a4.zip |
hivex: Move header checksum code into a function.
This function can be reused later.
Diffstat (limited to 'hivex/hivex.c')
-rw-r--r-- | hivex/hivex.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/hivex/hivex.c b/hivex/hivex.c index fd65f8cc..9799ddc6 100644 --- a/hivex/hivex.c +++ b/hivex/hivex.c @@ -255,6 +255,21 @@ struct ntreg_vk_record { char name[1]; /* key name follows here */ } __attribute__((__packed__)); +static uint32_t +header_checksum (hive_h *h) +{ + uint32_t *daddr = (uint32_t *) h->addr; + size_t i; + uint32_t sum = 0; + + for (i = 0; i < 0x1fc / 4; ++i) { + sum ^= le32toh (*daddr); + daddr++; + } + + return sum; +} + hive_h * hivex_open (const char *filename, int flags) { @@ -323,14 +338,7 @@ hivex_open (const char *filename, int flags) goto error; /* Header checksum. */ - uint32_t *daddr = (uint32_t *) h->addr; - size_t i; - uint32_t sum = 0; - for (i = 0; i < 0x1fc / 4; ++i) { - sum ^= le32toh (*daddr); - daddr++; - } - + uint32_t sum = header_checksum (h); if (sum != le32toh (h->hdr->csum)) { fprintf (stderr, "hivex: %s: bad checksum in hive header\n", filename); errno = EINVAL; |