Mercurial > libpst
comparison src/libpst.c @ 87:3ec5ad97e926
Use inttypes.h for portable printing of 64 bit items.
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Sun, 03 Aug 2008 15:42:37 -0700 |
parents | 582e927756d3 |
children | cb14583c119a |
comparison
equal
deleted
inserted
replaced
86:7d8cc1712221 | 87:3ec5ad97e926 |
---|---|
213 DEBUG_INFO(("encrypt = %i\n", pf->encryption)); | 213 DEBUG_INFO(("encrypt = %i\n", pf->encryption)); |
214 | 214 |
215 pf->index2_back = pst_getIntAtPos(pf, SECOND_BACK); | 215 pf->index2_back = pst_getIntAtPos(pf, SECOND_BACK); |
216 pf->index2 = pst_getIntAtPos(pf, SECOND_POINTER); | 216 pf->index2 = pst_getIntAtPos(pf, SECOND_POINTER); |
217 pf->size = pst_getIntAtPos(pf, FILE_SIZE_POINTER); | 217 pf->size = pst_getIntAtPos(pf, FILE_SIZE_POINTER); |
218 DEBUG_INFO(("Pointer2 is %#llx, back pointer2 is %#llx\n", pf->index2, pf->index2_back)); | 218 DEBUG_INFO(("Pointer2 is %#"PRIx64", back pointer2 is %#"PRIx64"\n", pf->index2, pf->index2_back)); |
219 | 219 |
220 pf->index1_back = pst_getIntAtPos(pf, INDEX_BACK); | 220 pf->index1_back = pst_getIntAtPos(pf, INDEX_BACK); |
221 pf->index1 = pst_getIntAtPos(pf, INDEX_POINTER); | 221 pf->index1 = pst_getIntAtPos(pf, INDEX_POINTER); |
222 DEBUG_INFO(("Pointer1 is %#llx, back pointer2 is %#llx\n", pf->index1, pf->index1_back)); | 222 DEBUG_INFO(("Pointer1 is %#"PRIx64", back pointer2 is %#"PRIx64"\n", pf->index1, pf->index1_back)); |
223 | 223 |
224 DEBUG_RET(); | 224 DEBUG_RET(); |
225 return 0; | 225 return 0; |
226 } | 226 } |
227 | 227 |
709 int32_t x, item_count; | 709 int32_t x, item_count; |
710 uint64_t old = start_val; | 710 uint64_t old = start_val; |
711 char *buf = NULL, *bptr; | 711 char *buf = NULL, *bptr; |
712 | 712 |
713 DEBUG_ENT("pst_build_id_ptr"); | 713 DEBUG_ENT("pst_build_id_ptr"); |
714 DEBUG_INDEX(("offset %llx depth %i linku1 %llx start %llx end %llx\n", offset, depth, linku1, start_val, end_val)); | 714 DEBUG_INDEX(("offset %#"PRIx64" depth %i linku1 %#"PRIx64" start %#"PRIx64" end %#"PRIx64"\n", offset, depth, linku1, start_val, end_val)); |
715 if (end_val <= start_val) { | 715 if (end_val <= start_val) { |
716 DEBUG_WARN(("The end value is BEFORE the start value. This function will quit. Soz. [start:%#llx, end:%#llx]\n", start_val, end_val)); | 716 DEBUG_WARN(("The end value is BEFORE the start value. This function will quit. Soz. [start:%#"PRIx64", end:%#"PRIx64"]\n", start_val, end_val)); |
717 DEBUG_RET(); | 717 DEBUG_RET(); |
718 return -1; | 718 return -1; |
719 } | 719 } |
720 DEBUG_INDEX(("Reading index block\n")); | 720 DEBUG_INDEX(("Reading index block\n")); |
721 if (pst_read_block_size(pf, offset, BLOCK_SIZE, &buf) < BLOCK_SIZE) { | 721 if (pst_read_block_size(pf, offset, BLOCK_SIZE, &buf) < BLOCK_SIZE) { |
733 DEBUG_RET(); | 733 DEBUG_RET(); |
734 return -1; | 734 return -1; |
735 } | 735 } |
736 index.id = pst_getIntAt(pf, buf+BACKLINK_OFFSET); | 736 index.id = pst_getIntAt(pf, buf+BACKLINK_OFFSET); |
737 if (index.id != linku1) { | 737 if (index.id != linku1) { |
738 DEBUG_WARN(("Backlink %#llx in this node does not match required %#llx\n", index.id, linku1)); | 738 DEBUG_WARN(("Backlink %#"PRIx64" in this node does not match required %#"PRIx64"\n", index.id, linku1)); |
739 if (buf) free(buf); | 739 if (buf) free(buf); |
740 DEBUG_RET(); | 740 DEBUG_RET(); |
741 return -1; | 741 return -1; |
742 } | 742 } |
743 | 743 |
746 x = 0; | 746 x = 0; |
747 while (x < item_count) { | 747 while (x < item_count) { |
748 bptr += pst_decode_index(pf, &index, bptr); | 748 bptr += pst_decode_index(pf, &index, bptr); |
749 x++; | 749 x++; |
750 if (index.id == 0) break; | 750 if (index.id == 0) break; |
751 DEBUG_INDEX(("[%i]%i Item [id = %#llx, offset = %#llx, u1 = %#x, size = %i(%#x)]\n", | 751 DEBUG_INDEX(("[%i]%i Item [id = %#"PRIx64", offset = %#"PRIx64", u1 = %#x, size = %i(%#x)]\n", |
752 depth, x, index.id, index.offset, index.u1, index.size, index.size)); | 752 depth, x, index.id, index.offset, index.u1, index.size, index.size)); |
753 // if (index.id & 0x02) DEBUG_INDEX(("two-bit set!!\n")); | 753 // if (index.id & 0x02) DEBUG_INDEX(("two-bit set!!\n")); |
754 if ((index.id >= end_val) || (index.id < old)) { | 754 if ((index.id >= end_val) || (index.id < old)) { |
755 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n")); | 755 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n")); |
756 if (buf) free(buf); | 756 if (buf) free(buf); |
787 (void)pst_decode_table(pf, &table2, bptr); | 787 (void)pst_decode_table(pf, &table2, bptr); |
788 } | 788 } |
789 else { | 789 else { |
790 table2.start = end_val; | 790 table2.start = end_val; |
791 } | 791 } |
792 DEBUG_INDEX(("[%i] %i Index Table [start id = %#llx, u1 = %#llx, offset = %#llx, end id = %#llx]\n", | 792 DEBUG_INDEX(("[%i] %i Index Table [start id = %#"PRIx64", u1 = %#"PRIx64", offset = %#"PRIx64", end id = %#"PRIx64"]\n", |
793 depth, x, table.start, table.u1, table.offset, table2.start)); | 793 depth, x, table.start, table.u1, table.offset, table2.start)); |
794 if ((table.start >= end_val) || (table.start < old)) { | 794 if ((table.start >= end_val) || (table.start < old)) { |
795 DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n")); | 795 DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n")); |
796 if (buf) free(buf); | 796 if (buf) free(buf); |
797 DEBUG_RET(); | 797 DEBUG_RET(); |
866 lostfound_ptr = lostfound_head; | 866 lostfound_ptr = lostfound_head; |
867 while (lostfound_ptr && (lostfound_ptr->ptr->id != parent_id)) { | 867 while (lostfound_ptr && (lostfound_ptr->ptr->id != parent_id)) { |
868 lostfound_ptr = lostfound_ptr->next; | 868 lostfound_ptr = lostfound_ptr->next; |
869 } | 869 } |
870 if (!lostfound_ptr) { | 870 if (!lostfound_ptr) { |
871 DEBUG_WARN(("ERROR -- cannot find parent with id %#llx. Adding to lost/found\n", parent_id)); | 871 DEBUG_WARN(("ERROR -- cannot find parent with id %#"PRIx64". Adding to lost/found\n", parent_id)); |
872 lostfound_ptr = (struct cache_list_node*) xmalloc(sizeof(struct cache_list_node)); | 872 lostfound_ptr = (struct cache_list_node*) xmalloc(sizeof(struct cache_list_node)); |
873 lostfound_ptr->prev = NULL; | 873 lostfound_ptr->prev = NULL; |
874 lostfound_ptr->next = lostfound_head; | 874 lostfound_ptr->next = lostfound_head; |
875 lostfound_ptr->parent = parent_id; | 875 lostfound_ptr->parent = parent_id; |
876 lostfound_ptr->ptr = d_ptr; | 876 lostfound_ptr->ptr = d_ptr; |
877 lostfound_head = lostfound_ptr; | 877 lostfound_head = lostfound_ptr; |
878 } else { | 878 } else { |
879 parent = lostfound_ptr->ptr; | 879 parent = lostfound_ptr->ptr; |
880 DEBUG_INDEX(("Found parent (%#llx) in Lost and Found\n", parent->id)); | 880 DEBUG_INDEX(("Found parent (%#"PRIx64") in Lost and Found\n", parent->id)); |
881 } | 881 } |
882 } | 882 } |
883 | 883 |
884 if (cache_ptr || parent) { | 884 if (cache_ptr || parent) { |
885 if (cache_ptr) | 885 if (cache_ptr) |
936 lostfound_head = NULL; | 936 lostfound_head = NULL; |
937 cache_count = 0; | 937 cache_count = 0; |
938 } | 938 } |
939 | 939 |
940 DEBUG_ENT("pst_build_desc_ptr"); | 940 DEBUG_ENT("pst_build_desc_ptr"); |
941 DEBUG_INDEX(("offset %llx depth %i linku1 %llx start %llx end %llx\n", offset, depth, linku1, start_val, end_val)); | 941 DEBUG_INDEX(("offset %#"PRIx64" depth %i linku1 %#"PRIx64" start %#"PRIx64" end %#"PRIx64"\n", offset, depth, linku1, start_val, end_val)); |
942 if (end_val <= start_val) { | 942 if (end_val <= start_val) { |
943 DEBUG_WARN(("The end value is BEFORE the start value. This function will quit. Soz. [start:%#llx, end:%#llx]\n", start_val, end_val)); | 943 DEBUG_WARN(("The end value is BEFORE the start value. This function will quit. Soz. [start:%#"PRIx64", end:%#"PRIx64"]\n", start_val, end_val)); |
944 DEBUG_RET(); | 944 DEBUG_RET(); |
945 return -1; | 945 return -1; |
946 } | 946 } |
947 DEBUG_INDEX(("Reading desc block\n")); | 947 DEBUG_INDEX(("Reading desc block\n")); |
948 if (pst_read_block_size(pf, offset, DESC_BLOCK_SIZE, &buf) < DESC_BLOCK_SIZE) { | 948 if (pst_read_block_size(pf, offset, DESC_BLOCK_SIZE, &buf) < DESC_BLOCK_SIZE) { |
954 bptr = buf; | 954 bptr = buf; |
955 item_count = (int32_t)(unsigned)(buf[ITEM_COUNT_OFFSET]); | 955 item_count = (int32_t)(unsigned)(buf[ITEM_COUNT_OFFSET]); |
956 | 956 |
957 desc_rec.d_id = pst_getIntAt(pf, buf+BACKLINK_OFFSET); | 957 desc_rec.d_id = pst_getIntAt(pf, buf+BACKLINK_OFFSET); |
958 if (desc_rec.d_id != linku1) { | 958 if (desc_rec.d_id != linku1) { |
959 DEBUG_WARN(("Backlink %#llx in this node does not match required %#llx\n", desc_rec.d_id, linku1)); | 959 DEBUG_WARN(("Backlink %#"PRIx64" in this node does not match required %#"PRIx64"\n", desc_rec.d_id, linku1)); |
960 if (buf) free(buf); | 960 if (buf) free(buf); |
961 DEBUG_RET(); | 961 DEBUG_RET(); |
962 return -1; | 962 return -1; |
963 } | 963 } |
964 if (buf[LEVEL_INDICATOR_OFFSET] == '\0') { | 964 if (buf[LEVEL_INDICATOR_OFFSET] == '\0') { |
973 x = 0; | 973 x = 0; |
974 while (x < item_count) { | 974 while (x < item_count) { |
975 bptr += pst_decode_desc(pf, &desc_rec, bptr); | 975 bptr += pst_decode_desc(pf, &desc_rec, bptr); |
976 x++; | 976 x++; |
977 if (desc_rec.d_id == 0) break; | 977 if (desc_rec.d_id == 0) break; |
978 DEBUG_INDEX(("[%i] Item(%#x) = [d_id = %#llx, desc_id = %#llx, list_id = %#llx, parent_id = %#x]\n", | 978 DEBUG_INDEX(("[%i] Item(%#x) = [d_id = %#"PRIx64", desc_id = %#"PRIx64", list_id = %#"PRIx64", parent_id = %#x]\n", |
979 depth, x, desc_rec.d_id, desc_rec.desc_id, desc_rec.list_id, desc_rec.parent_id)); | 979 depth, x, desc_rec.d_id, desc_rec.desc_id, desc_rec.list_id, desc_rec.parent_id)); |
980 if ((desc_rec.d_id >= end_val) || (desc_rec.d_id < old)) { | 980 if ((desc_rec.d_id >= end_val) || (desc_rec.d_id < old)) { |
981 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n")); | 981 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n")); |
982 DEBUG_HEXDUMPC(buf, DESC_BLOCK_SIZE, 16); | 982 DEBUG_HEXDUMPC(buf, DESC_BLOCK_SIZE, 16); |
983 if (buf) free(buf); | 983 if (buf) free(buf); |
998 if (desc_rec.d_id <= *high_id && (d_ptr = pst_getDptr(pf, desc_rec.d_id))) { | 998 if (desc_rec.d_id <= *high_id && (d_ptr = pst_getDptr(pf, desc_rec.d_id))) { |
999 uint64_t bigzero = 0; | 999 uint64_t bigzero = 0; |
1000 DEBUG_INDEX(("Updating Existing Values\n")); | 1000 DEBUG_INDEX(("Updating Existing Values\n")); |
1001 d_ptr->list_index = pst_getID(pf, desc_rec.list_id); | 1001 d_ptr->list_index = pst_getID(pf, desc_rec.list_id); |
1002 d_ptr->desc = pst_getID(pf, desc_rec.desc_id); | 1002 d_ptr->desc = pst_getID(pf, desc_rec.desc_id); |
1003 DEBUG_INDEX(("\tdesc = %#llx\tlist_index=%#llx\n", | 1003 DEBUG_INDEX(("\tdesc = %#"PRIx64"\tlist_index=%#"PRIx64"\n", |
1004 (d_ptr->desc==NULL ? bigzero : d_ptr->desc->id), | 1004 (d_ptr->desc==NULL ? bigzero : d_ptr->desc->id), |
1005 (d_ptr->list_index==NULL ? bigzero : d_ptr->list_index->id))); | 1005 (d_ptr->list_index==NULL ? bigzero : d_ptr->list_index->id))); |
1006 if (d_ptr->parent && desc_rec.parent_id != d_ptr->parent->id) { | 1006 if (d_ptr->parent && desc_rec.parent_id != d_ptr->parent->id) { |
1007 DEBUG_INDEX(("WARNING -- Parent of record has changed. Moving it\n")); | 1007 DEBUG_INDEX(("WARNING -- Parent of record has changed. Moving it\n")); |
1008 //hmmm, we must move the record. | 1008 //hmmm, we must move the record. |
1054 // check here to see if d_ptr is the parent of any of the items in the lost / found list | 1054 // check here to see if d_ptr is the parent of any of the items in the lost / found list |
1055 lostfound_ptr = lostfound_head; | 1055 lostfound_ptr = lostfound_head; |
1056 lostfound_shd = NULL; | 1056 lostfound_shd = NULL; |
1057 while (lostfound_ptr) { | 1057 while (lostfound_ptr) { |
1058 if (lostfound_ptr->parent == d_ptr->id) { | 1058 if (lostfound_ptr->parent == d_ptr->id) { |
1059 DEBUG_INDEX(("Found a child (%#llx) of the current record. Joining to main structure.\n", lostfound_ptr->ptr->id)); | 1059 DEBUG_INDEX(("Found a child (%#"PRIx64") of the current record. Joining to main structure.\n", lostfound_ptr->ptr->id)); |
1060 parent = d_ptr; | 1060 parent = d_ptr; |
1061 d_ptr = lostfound_ptr->ptr; | 1061 d_ptr = lostfound_ptr->ptr; |
1062 parent->no_child++; | 1062 parent->no_child++; |
1063 d_ptr->parent = parent; | 1063 d_ptr->parent = parent; |
1064 if (parent->child_tail) parent->child_tail->next = d_ptr; | 1064 if (parent->child_tail) parent->child_tail->next = d_ptr; |
1094 (void)pst_decode_table(pf, &table2, bptr); | 1094 (void)pst_decode_table(pf, &table2, bptr); |
1095 } | 1095 } |
1096 else { | 1096 else { |
1097 table2.start = end_val; | 1097 table2.start = end_val; |
1098 } | 1098 } |
1099 DEBUG_INDEX(("[%i] %i Descriptor Table [start id = %#llx, u1 = %#llx, offset = %#llx, end id = %#llx]\n", | 1099 DEBUG_INDEX(("[%i] %i Descriptor Table [start id = %#"PRIx64", u1 = %#"PRIx64", offset = %#"PRIx64", end id = %#"PRIx64"]\n", |
1100 depth, x, table.start, table.u1, table.offset, table2.start)); | 1100 depth, x, table.start, table.u1, table.offset, table2.start)); |
1101 if ((table.start >= end_val) || (table.start < old)) { | 1101 if ((table.start >= end_val) || (table.start < old)) { |
1102 DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n")); | 1102 DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n")); |
1103 if (buf) free(buf); | 1103 if (buf) free(buf); |
1104 DEBUG_RET(); | 1104 DEBUG_RET(); |
1124 cache_head = cache_ptr; | 1124 cache_head = cache_ptr; |
1125 } | 1125 } |
1126 // free the lost and found | 1126 // free the lost and found |
1127 while (lostfound_head) { | 1127 while (lostfound_head) { |
1128 lostfound_ptr = lostfound_head->next; | 1128 lostfound_ptr = lostfound_head->next; |
1129 WARN(("unused lost/found item with parent %lld))", lostfound_head->parent)); | 1129 WARN(("unused lost/found item with parent %#"PRIx64"))", lostfound_head->parent)); |
1130 free(lostfound_head); | 1130 free(lostfound_head); |
1131 lostfound_head = lostfound_ptr; | 1131 lostfound_head = lostfound_ptr; |
1132 } | 1132 } |
1133 } | 1133 } |
1134 if (buf) free(buf); | 1134 if (buf) free(buf); |
1164 DEBUG_WARN(("Have not been able to fetch any id2 values for this item. Brace yourself!\n")); | 1164 DEBUG_WARN(("Have not been able to fetch any id2 values for this item. Brace yourself!\n")); |
1165 } | 1165 } |
1166 | 1166 |
1167 list = pst_parse_block(pf, d_ptr->desc->id, id2_head, NULL); | 1167 list = pst_parse_block(pf, d_ptr->desc->id, id2_head, NULL); |
1168 if (!list) { | 1168 if (!list) { |
1169 DEBUG_WARN(("pst_parse_block() returned an error for d_ptr->desc->id [%#llx]\n", d_ptr->desc->id)); | 1169 DEBUG_WARN(("pst_parse_block() returned an error for d_ptr->desc->id [%#"PRIx64"]\n", d_ptr->desc->id)); |
1170 if (id2_head) pst_free_id2(id2_head); | 1170 if (id2_head) pst_free_id2(id2_head); |
1171 DEBUG_RET(); | 1171 DEBUG_RET(); |
1172 return NULL; | 1172 return NULL; |
1173 } | 1173 } |
1174 | 1174 |
1251 if (id_ptr) { | 1251 if (id_ptr) { |
1252 // id2_val has been updated to the ID2 value of the datablock containing the | 1252 // id2_val has been updated to the ID2 value of the datablock containing the |
1253 // attachment data | 1253 // attachment data |
1254 attach->id_val = id_ptr->id; | 1254 attach->id_val = id_ptr->id; |
1255 } else { | 1255 } else { |
1256 DEBUG_WARN(("have not located the correct value for the attachment [%#llx]\n", attach->id2_val)); | 1256 DEBUG_WARN(("have not located the correct value for the attachment [%#"PRIx64"]\n", attach->id2_val)); |
1257 } | 1257 } |
1258 } else { | 1258 } else { |
1259 DEBUG_WARN(("ERROR cannot locate id2 value %#llx\n", attach->id2_val)); | 1259 DEBUG_WARN(("ERROR cannot locate id2 value %#"PRIx64"\n", attach->id2_val)); |
1260 } | 1260 } |
1261 attach = attach->next; | 1261 attach = attach->next; |
1262 } | 1262 } |
1263 } | 1263 } |
1264 } | 1264 } |
1358 uint8_t slot; | 1358 uint8_t slot; |
1359 } table2_rec; //for type 2 (0x7CEC) blocks | 1359 } table2_rec; //for type 2 (0x7CEC) blocks |
1360 | 1360 |
1361 DEBUG_ENT("pst_parse_block"); | 1361 DEBUG_ENT("pst_parse_block"); |
1362 if ((read_size = pst_ff_getIDblock_dec(pf, block_id, &buf)) == 0) { | 1362 if ((read_size = pst_ff_getIDblock_dec(pf, block_id, &buf)) == 0) { |
1363 WARN(("Error reading block id %#llx\n", block_id)); | 1363 WARN(("Error reading block id %#"PRIx64"\n", block_id)); |
1364 if (buf) free (buf); | 1364 if (buf) free (buf); |
1365 DEBUG_RET(); | 1365 DEBUG_RET(); |
1366 return NULL; | 1366 return NULL; |
1367 } | 1367 } |
1368 | 1368 |
1429 LE16_CPU(table_rec.ref_type); | 1429 LE16_CPU(table_rec.ref_type); |
1430 LE32_CPU(table_rec.value); | 1430 LE32_CPU(table_rec.value); |
1431 DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value)); | 1431 DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value)); |
1432 | 1432 |
1433 if ((table_rec.type != (uint16_t)0x02B5) || (table_rec.ref_type != 6)) { | 1433 if ((table_rec.type != (uint16_t)0x02B5) || (table_rec.ref_type != 6)) { |
1434 WARN(("Unknown second block constant - %#hx %#hx for id %#llx\n", table_rec.type, table_rec.ref_type, block_id)); | 1434 WARN(("Unknown second block constant - %#hx %#hx for id %#"PRIx64"\n", table_rec.type, table_rec.ref_type, block_id)); |
1435 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | 1435 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); |
1436 DEBUG_RET(); | 1436 DEBUG_RET(); |
1437 return NULL; | 1437 return NULL; |
1438 } | 1438 } |
1439 | 1439 |
1492 LE16_CPU(table_rec.ref_type); | 1492 LE16_CPU(table_rec.ref_type); |
1493 LE32_CPU(table_rec.value); | 1493 LE32_CPU(table_rec.value); |
1494 DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value)); | 1494 DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value)); |
1495 | 1495 |
1496 if (table_rec.type != (uint16_t)0x04B5) { // different constant than a type 1 record | 1496 if (table_rec.type != (uint16_t)0x04B5) { // different constant than a type 1 record |
1497 WARN(("Unknown second block constant - %#hx for id %#llx\n", table_rec.type, block_id)); | 1497 WARN(("Unknown second block constant - %#hx for id %#"PRIx64"\n", table_rec.type, block_id)); |
1498 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | 1498 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); |
1499 DEBUG_RET(); | 1499 DEBUG_RET(); |
1500 return NULL; | 1500 return NULL; |
1501 } | 1501 } |
1502 | 1502 |
1503 if (pst_getBlockOffsetPointer(pf, i2_head, &subblocks, table_rec.value, &block_offset5)) { | 1503 if (pst_getBlockOffsetPointer(pf, i2_head, &subblocks, table_rec.value, &block_offset5)) { |
1504 DEBUG_WARN(("internal error (7c.b5.desc offset %#x) in reading block id %#llx\n", table_rec.value, block_id)); | 1504 DEBUG_WARN(("internal error (7c.b5.desc offset %#x) in reading block id %#"PRIx64"\n", table_rec.value, block_id)); |
1505 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | 1505 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); |
1506 DEBUG_RET(); | 1506 DEBUG_RET(); |
1507 return NULL; | 1507 return NULL; |
1508 } | 1508 } |
1509 | 1509 |
1518 } | 1518 } |
1519 ind2_ptr = block_offset6.from; | 1519 ind2_ptr = block_offset6.from; |
1520 ind2_end = block_offset6.to; | 1520 ind2_end = block_offset6.to; |
1521 } | 1521 } |
1522 else { | 1522 else { |
1523 WARN(("ERROR: Unknown block constant - %#hx for id %#llx\n", block_hdr.type, block_id)); | 1523 WARN(("ERROR: Unknown block constant - %#hx for id %#"PRIx64"\n", block_hdr.type, block_id)); |
1524 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | 1524 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); |
1525 DEBUG_RET(); | 1525 DEBUG_RET(); |
1526 return NULL; | 1526 return NULL; |
1527 } | 1527 } |
1528 | 1528 |
2543 DEBUG_EMAIL(("Binary Data [Size %i] - ", list->items[x]->size)); | 2543 DEBUG_EMAIL(("Binary Data [Size %i] - ", list->items[x]->size)); |
2544 NULL_CHECK(attach); | 2544 NULL_CHECK(attach); |
2545 MOVE_NEXT(attach); | 2545 MOVE_NEXT(attach); |
2546 if (!list->items[x]->data) { //special case | 2546 if (!list->items[x]->data) { //special case |
2547 attach->id2_val = list->items[x]->type; | 2547 attach->id2_val = list->items[x]->type; |
2548 DEBUG_EMAIL(("Seen a Reference. The data hasn't been loaded yet. [%#llx][%#x]\n", | 2548 DEBUG_EMAIL(("Seen a Reference. The data hasn't been loaded yet. [%#"PRIx64"][%#x]\n", |
2549 attach->id2_val, list->items[x]->type)); | 2549 attach->id2_val, list->items[x]->type)); |
2550 } else { | 2550 } else { |
2551 LIST_COPY(attach->data, (char*)); | 2551 LIST_COPY(attach->data, (char*)); |
2552 attach->size = list->items[x]->size; | 2552 attach->size = list->items[x]->size; |
2553 DEBUG_EMAIL(("NOT PRINTED\n")); | 2553 DEBUG_EMAIL(("NOT PRINTED\n")); |
3117 uint32_t tempid; | 3117 uint32_t tempid; |
3118 MOVE_NEXT(attach); | 3118 MOVE_NEXT(attach); |
3119 memcpy(&(tempid), list->items[x]->data, sizeof(tempid)); | 3119 memcpy(&(tempid), list->items[x]->data, sizeof(tempid)); |
3120 LE32_CPU(tempid); | 3120 LE32_CPU(tempid); |
3121 attach->id2_val = tempid; | 3121 attach->id2_val = tempid; |
3122 DEBUG_EMAIL(("%#llx\n", attach->id2_val)); | 3122 DEBUG_EMAIL(("%#"PRIx64"\n", attach->id2_val)); |
3123 } else { | 3123 } else { |
3124 DEBUG_EMAIL(("NOT AN ATTACHMENT: %#x\n", list->items[x]->id)); | 3124 DEBUG_EMAIL(("NOT AN ATTACHMENT: %#x\n", list->items[x]->id)); |
3125 } | 3125 } |
3126 break; | 3126 break; |
3127 case 0x67FF: // Extra Property Identifier (Password CheckSum) | 3127 case 0x67FF: // Extra Property Identifier (Password CheckSum) |
3720 head = head_ptr; | 3720 head = head_ptr; |
3721 while (head_ptr) head_ptr = (tail = head_ptr)->next; | 3721 while (head_ptr) head_ptr = (tail = head_ptr)->next; |
3722 } | 3722 } |
3723 if (pst_read_block_size(pf, list->offset, list->size, &buf) < list->size) { | 3723 if (pst_read_block_size(pf, list->offset, list->size, &buf) < list->size) { |
3724 //an error occured in block read | 3724 //an error occured in block read |
3725 WARN(("block read error occured. offset = %#llx, size = %#llx\n", list->offset, list->size)); | 3725 WARN(("block read error occured. offset = %#"PRIx64", size = %#"PRIx64"\n", list->offset, list->size)); |
3726 if (buf) free(buf); | 3726 if (buf) free(buf); |
3727 DEBUG_RET(); | 3727 DEBUG_RET(); |
3728 return NULL; | 3728 return NULL; |
3729 } | 3729 } |
3730 DEBUG_HEXDUMPC(buf, list->size, 16); | 3730 DEBUG_HEXDUMPC(buf, list->size, 16); |
3732 memcpy(&block_head, buf, sizeof(block_head)); | 3732 memcpy(&block_head, buf, sizeof(block_head)); |
3733 LE16_CPU(block_head.type); | 3733 LE16_CPU(block_head.type); |
3734 LE16_CPU(block_head.count); | 3734 LE16_CPU(block_head.count); |
3735 | 3735 |
3736 if (block_head.type != (uint16_t)0x0002) { // some sort of constant? | 3736 if (block_head.type != (uint16_t)0x0002) { // some sort of constant? |
3737 WARN(("Unknown constant [%#hx] at start of id2 values [offset %#llx].\n", block_head.type, list->offset)); | 3737 WARN(("Unknown constant [%#hx] at start of id2 values [offset %#"PRIx64"].\n", block_head.type, list->offset)); |
3738 if (buf) free(buf); | 3738 if (buf) free(buf); |
3739 DEBUG_RET(); | 3739 DEBUG_RET(); |
3740 return NULL; | 3740 return NULL; |
3741 } | 3741 } |
3742 | 3742 |
3743 DEBUG_INDEX(("ID %#llx is likely to be a description record. Count is %i (offset %#llx)\n", | 3743 DEBUG_INDEX(("ID %#"PRIx64" is likely to be a description record. Count is %i (offset %#"PRIx64")\n", |
3744 list->id, block_head.count, list->offset)); | 3744 list->id, block_head.count, list->offset)); |
3745 x = 0; | 3745 x = 0; |
3746 b_ptr = buf + ((pf->do_read64) ? 0x08 : 0x04); | 3746 b_ptr = buf + ((pf->do_read64) ? 0x08 : 0x04); |
3747 while (x < block_head.count) { | 3747 while (x < block_head.count) { |
3748 b_ptr += pst_decode_assoc(pf, &id2_rec, b_ptr); | 3748 b_ptr += pst_decode_assoc(pf, &id2_rec, b_ptr); |
3749 DEBUG_INDEX(("\tid2 = %#x, id = %#llx, table2 = %#llx\n", id2_rec.id2, id2_rec.id, id2_rec.table2)); | 3749 DEBUG_INDEX(("\tid2 = %#x, id = %#"PRIx64", table2 = %#"PRIx64"\n", id2_rec.id2, id2_rec.id, id2_rec.table2)); |
3750 if ((i_ptr = pst_getID(pf, id2_rec.id)) == NULL) { | 3750 if ((i_ptr = pst_getID(pf, id2_rec.id)) == NULL) { |
3751 DEBUG_WARN(("\t\t%#llx - Not Found\n", id2_rec.id)); | 3751 DEBUG_WARN(("\t\t%#"PRIx64" - Not Found\n", id2_rec.id)); |
3752 } else { | 3752 } else { |
3753 DEBUG_INDEX(("\t\t%#llx - Offset %#llx, u1 %#llx, Size %lli(%#llx)\n", i_ptr->id, i_ptr->offset, i_ptr->u1, i_ptr->size, i_ptr->size)); | 3753 DEBUG_INDEX(("\t\t%#"PRIx64" - Offset %#"PRIx64", u1 %#"PRIx64", Size %lli(%#"PRIx64")\n", i_ptr->id, i_ptr->offset, i_ptr->u1, i_ptr->size, i_ptr->size)); |
3754 // add it to the linked list | 3754 // add it to the linked list |
3755 i2_ptr = (pst_index2_ll*) xmalloc(sizeof(pst_index2_ll)); | 3755 i2_ptr = (pst_index2_ll*) xmalloc(sizeof(pst_index2_ll)); |
3756 i2_ptr->id2 = id2_rec.id2; | 3756 i2_ptr->id2 = id2_rec.id2; |
3757 i2_ptr->id = i_ptr; | 3757 i2_ptr->id = i_ptr; |
3758 i2_ptr->next = NULL; | 3758 i2_ptr->next = NULL; |
4082 if (id == 0) { | 4082 if (id == 0) { |
4083 DEBUG_RET(); | 4083 DEBUG_RET(); |
4084 return NULL; | 4084 return NULL; |
4085 } | 4085 } |
4086 | 4086 |
4087 //if (id & 1) DEBUG_INDEX(("have odd id bit %#llx\n", id)); | 4087 //if (id & 1) DEBUG_INDEX(("have odd id bit %#"PRIx64"\n", id)); |
4088 //if (id & 2) DEBUG_INDEX(("have two id bit %#llx\n", id)); | 4088 //if (id & 2) DEBUG_INDEX(("have two id bit %#"PRIx64"\n", id)); |
4089 id -= (id & 1); | 4089 id -= (id & 1); |
4090 | 4090 |
4091 DEBUG_INDEX(("Trying to find %#llx\n", id)); | 4091 DEBUG_INDEX(("Trying to find %#"PRIx64"\n", id)); |
4092 ptr = pf->i_head; | 4092 ptr = pf->i_head; |
4093 while (ptr && (ptr->id != id)) { | 4093 while (ptr && (ptr->id != id)) { |
4094 ptr = ptr->next; | 4094 ptr = ptr->next; |
4095 } | 4095 } |
4096 if (ptr) {DEBUG_INDEX(("Found Value %#llx\n", id)); } | 4096 if (ptr) {DEBUG_INDEX(("Found Value %#"PRIx64"\n", id)); } |
4097 else {DEBUG_INDEX(("ERROR: Value %#llx not found\n", id)); } | 4097 else {DEBUG_INDEX(("ERROR: Value %#"PRIx64" not found\n", id)); } |
4098 DEBUG_RET(); | 4098 DEBUG_RET(); |
4099 return ptr; | 4099 return ptr; |
4100 } | 4100 } |
4101 | 4101 |
4102 | 4102 |
4103 pst_index_ll * pst_getID2(pst_index2_ll *ptr, uint64_t id) { | 4103 pst_index_ll * pst_getID2(pst_index2_ll *ptr, uint64_t id) { |
4104 DEBUG_ENT("pst_getID2"); | 4104 DEBUG_ENT("pst_getID2"); |
4105 DEBUG_INDEX(("Head = %p id = %#llx\n", ptr, id)); | 4105 DEBUG_INDEX(("Head = %p id = %#"PRIx64"\n", ptr, id)); |
4106 while (ptr && (ptr->id2 != id)) { | 4106 while (ptr && (ptr->id2 != id)) { |
4107 ptr = ptr->next; | 4107 ptr = ptr->next; |
4108 } | 4108 } |
4109 if (ptr) { | 4109 if (ptr) { |
4110 if (ptr->id) {DEBUG_INDEX(("Found value %#llx\n", ptr->id->id)); } | 4110 if (ptr->id) {DEBUG_INDEX(("Found value %#"PRIx64"\n", ptr->id->id)); } |
4111 else {DEBUG_INDEX(("Found value, though it is NULL!\n"));} | 4111 else {DEBUG_INDEX(("Found value, though it is NULL!\n"));} |
4112 DEBUG_RET(); | 4112 DEBUG_RET(); |
4113 return ptr->id; | 4113 return ptr->id; |
4114 } | 4114 } |
4115 DEBUG_INDEX(("ERROR Not Found\n")); | 4115 DEBUG_INDEX(("ERROR Not Found\n")); |
4190 * @return size of block read into memory | 4190 * @return size of block read into memory |
4191 */ | 4191 */ |
4192 size_t pst_read_block_size(pst_file *pf, off_t offset, size_t size, char **buf) { | 4192 size_t pst_read_block_size(pst_file *pf, off_t offset, size_t size, char **buf) { |
4193 size_t rsize; | 4193 size_t rsize; |
4194 DEBUG_ENT("pst_read_block_size"); | 4194 DEBUG_ENT("pst_read_block_size"); |
4195 DEBUG_READ(("Reading block from %#llx, %x bytes\n", offset, size)); | 4195 DEBUG_READ(("Reading block from %#"PRIx64", %x bytes\n", offset, size)); |
4196 | 4196 |
4197 if (*buf) { | 4197 if (*buf) { |
4198 DEBUG_READ(("Freeing old memory\n")); | 4198 DEBUG_READ(("Freeing old memory\n")); |
4199 free(*buf); | 4199 free(*buf); |
4200 } | 4200 } |
4202 | 4202 |
4203 rsize = pst_getAtPos(pf, offset, *buf, size); | 4203 rsize = pst_getAtPos(pf, offset, *buf, size); |
4204 if (rsize != size) { | 4204 if (rsize != size) { |
4205 DEBUG_WARN(("Didn't read all the data. fread returned less [%i instead of %i]\n", rsize, size)); | 4205 DEBUG_WARN(("Didn't read all the data. fread returned less [%i instead of %i]\n", rsize, size)); |
4206 if (feof(pf->fp)) { | 4206 if (feof(pf->fp)) { |
4207 DEBUG_WARN(("We tried to read past the end of the file at [offset %#llx, size %#x]\n", offset, size)); | 4207 DEBUG_WARN(("We tried to read past the end of the file at [offset %#"PRIx64", size %#x]\n", offset, size)); |
4208 } else if (ferror(pf->fp)) { | 4208 } else if (ferror(pf->fp)) { |
4209 DEBUG_WARN(("Error is set on file stream.\n")); | 4209 DEBUG_WARN(("Error is set on file stream.\n")); |
4210 } else { | 4210 } else { |
4211 DEBUG_WARN(("I can't tell why it failed\n")); | 4211 DEBUG_WARN(("I can't tell why it failed\n")); |
4212 } | 4212 } |
4326 // p->next = tail; | 4326 // p->next = tail; |
4327 // p->offset = pos; | 4327 // p->offset = pos; |
4328 // p->size = size; | 4328 // p->size = size; |
4329 // p->readcount = 1; | 4329 // p->readcount = 1; |
4330 // } | 4330 // } |
4331 // DEBUG_MAIN(("pst file old offset %#llx old size %#x read count %i offset %#llx size %#x\n", | 4331 // DEBUG_MAIN(("pst file old offset %#"PRIx64" old size %#x read count %i offset %#"PRIx64" size %#x\n", |
4332 // p->offset, p->size, p->readcount, pos, size)); | 4332 // p->offset, p->size, p->readcount, pos, size)); |
4333 | 4333 |
4334 if (fseeko(pf->fp, pos, SEEK_SET) == -1) { | 4334 if (fseeko(pf->fp, pos, SEEK_SET) == -1) { |
4335 DEBUG_RET(); | 4335 DEBUG_RET(); |
4336 return 0; | 4336 return 0; |
4377 pst_index_ll *rec; | 4377 pst_index_ll *rec; |
4378 size_t rsize; | 4378 size_t rsize; |
4379 DEBUG_ENT("pst_ff_getIDblock"); | 4379 DEBUG_ENT("pst_ff_getIDblock"); |
4380 rec = pst_getID(pf, id); | 4380 rec = pst_getID(pf, id); |
4381 if (!rec) { | 4381 if (!rec) { |
4382 DEBUG_INDEX(("Cannot find ID %#llx\n", id)); | 4382 DEBUG_INDEX(("Cannot find ID %#"PRIx64"\n", id)); |
4383 DEBUG_RET(); | 4383 DEBUG_RET(); |
4384 return 0; | 4384 return 0; |
4385 } | 4385 } |
4386 DEBUG_INDEX(("id = %#llx, record size = %#x, offset = %#x\n", id, rec->size, rec->offset)); | 4386 DEBUG_INDEX(("id = %#"PRIx64", record size = %#x, offset = %#x\n", id, rec->size, rec->offset)); |
4387 rsize = pst_read_block_size(pf, rec->offset, rec->size, buf); | 4387 rsize = pst_read_block_size(pf, rec->offset, rec->size, buf); |
4388 DEBUG_RET(); | 4388 DEBUG_RET(); |
4389 return rsize; | 4389 return rsize; |
4390 } | 4390 } |
4391 | 4391 |