532 *next++ = '.'; 533 strncpy(next, extension, length); next += length; 534 } 535 // Make sure there is no buffer overflow. 536 assert((size_t)(next - path) < max && "buffer overflow"); 537 // Terminate string. 538 *next = '\0'; 539 } 540 541 // Verify that a found location matches the supplied path (without copying.) 542 bool ImageFileReader::verify_location(ImageLocation& location, const char* path) const { 543 // Manage the image string table. 544 ImageStrings strings(_string_bytes, _header.strings_size(_endian)); 545 // Position to first character of the path string. 546 const char* next = path; 547 // Get module name string. 548 const char* module = location.get_attribute(ImageLocation::ATTRIBUTE_MODULE, strings); 549 // If module string is not empty. 550 if (*module != '\0') { 551 // Compare '/module/' . 552 if (*next++ != '/') return false; 553 if (!(next = ImageStrings::starts_with(next, module))) return false; 554 if (*next++ != '/') return false; 555 } 556 // Get parent (package) string 557 const char* parent = location.get_attribute(ImageLocation::ATTRIBUTE_PARENT, strings); 558 // If parent string is not empty string. 559 if (*parent != '\0') { 560 // Compare 'parent/' . 561 if (!(next = ImageStrings::starts_with(next, parent))) return false; 562 if (*next++ != '/') return false; 563 } 564 // Get base name string. 565 const char* base = location.get_attribute(ImageLocation::ATTRIBUTE_BASE, strings); 566 // Compare with basne name. 567 if (!(next = ImageStrings::starts_with(next, base))) return false; 568 // Get extension string. 569 const char* extension = location.get_attribute(ImageLocation::ATTRIBUTE_EXTENSION, strings); 570 // If extension is not empty. 571 if (*extension != '\0') { 572 // Compare '.extension' . 573 if (*next++ != '.') return false; 574 if (!(next = ImageStrings::starts_with(next, extension))) return false; 575 } 576 // True only if complete match and no more characters. 577 return *next == '\0'; 578 } 579 580 // Return the resource for the supplied location offset. 581 void ImageFileReader::get_resource(u4 offset, u1* uncompressed_data) const { 582 // Get address of first byte of location attribute stream. 583 u1* data = get_location_offset_data(offset); 584 // Expand location attributes. 585 ImageLocation location(data); 586 // Read the data 587 get_resource(location, uncompressed_data); 588 } 589 590 // Return the resource for the supplied location. 591 void ImageFileReader::get_resource(ImageLocation& location, u1* uncompressed_data) const { 592 // Retrieve the byte offset and size of the resource. 593 u8 offset = location.get_attribute(ImageLocation::ATTRIBUTE_OFFSET); | 532 *next++ = '.'; 533 strncpy(next, extension, length); next += length; 534 } 535 // Make sure there is no buffer overflow. 536 assert((size_t)(next - path) < max && "buffer overflow"); 537 // Terminate string. 538 *next = '\0'; 539 } 540 541 // Verify that a found location matches the supplied path (without copying.) 542 bool ImageFileReader::verify_location(ImageLocation& location, const char* path) const { 543 // Manage the image string table. 544 ImageStrings strings(_string_bytes, _header.strings_size(_endian)); 545 // Position to first character of the path string. 546 const char* next = path; 547 // Get module name string. 548 const char* module = location.get_attribute(ImageLocation::ATTRIBUTE_MODULE, strings); 549 // If module string is not empty. 550 if (*module != '\0') { 551 // Compare '/module/' . 552 if (*next != '/') return false; 553 next++; 554 if (!(next = ImageStrings::starts_with(next, module))) return false; 555 if (*next != '/') return false; 556 next++; 557 } 558 // Get parent (package) string 559 const char* parent = location.get_attribute(ImageLocation::ATTRIBUTE_PARENT, strings); 560 // If parent string is not empty string. 561 if (*parent != '\0') { 562 // Compare 'parent/' . 563 if (!(next = ImageStrings::starts_with(next, parent))) return false; 564 if (*next != '/') return false; 565 next++; 566 } 567 // Get base name string. 568 const char* base = location.get_attribute(ImageLocation::ATTRIBUTE_BASE, strings); 569 // Compare with basne name. 570 if (!(next = ImageStrings::starts_with(next, base))) return false; 571 // Get extension string. 572 const char* extension = location.get_attribute(ImageLocation::ATTRIBUTE_EXTENSION, strings); 573 // If extension is not empty. 574 if (*extension != '\0') { 575 // Compare '.extension' . 576 if (*next != '.') return false; 577 next++; 578 if (!(next = ImageStrings::starts_with(next, extension))) return false; 579 } 580 // True only if complete match and no more characters. 581 return *next == '\0'; 582 } 583 584 // Return the resource for the supplied location offset. 585 void ImageFileReader::get_resource(u4 offset, u1* uncompressed_data) const { 586 // Get address of first byte of location attribute stream. 587 u1* data = get_location_offset_data(offset); 588 // Expand location attributes. 589 ImageLocation location(data); 590 // Read the data 591 get_resource(location, uncompressed_data); 592 } 593 594 // Return the resource for the supplied location. 595 void ImageFileReader::get_resource(ImageLocation& location, u1* uncompressed_data) const { 596 // Retrieve the byte offset and size of the resource. 597 u8 offset = location.get_attribute(ImageLocation::ATTRIBUTE_OFFSET); |