Skip to content

Commit

Permalink
[0.2.2] Properly load blobs from boot images with prepended data
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasssadar committed Jan 8, 2015
1 parent abdae88 commit 6607d1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions include/libbootimg.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ extern "C" {
#include <stdio.h>
#include "boot_img_hdr.h"

#define LIBBOOTIMG_VERSION 0x000201 // 0xMMNNPP
#define LIBBOOTIMG_VERSION_STR "0.2.1"
#define LIBBOOTIMG_VERSION 0x000202 // 0xMMNNPP
#define LIBBOOTIMG_VERSION_STR "0.2.2"

/**
* Enum containing possible blob types in a boot image.
Expand Down Expand Up @@ -85,6 +85,7 @@ struct bootimg
{
struct boot_img_hdr hdr; /*!< Boot image header */
struct bootimg_blob blobs[LIBBOOTIMG_BLOB_CNT]; /*!< Blobs packed in the boot image. */
int start_offset; /*!< Offset of the boot image structure from the start of the file. Only used when loading blobs from boot.img file. */
};

/**
Expand All @@ -109,7 +110,7 @@ int libbootimg_init_load(struct bootimg *img, const char *path, int load_blob_ma
* Loads boot_img_hdr from file on disk
* @param hdr pointer to boot_img_hdr structure
* @param path path to boot.img to load header from
* @return zero if successful, negative value from libbootimg_error if failed.
* @return positive offset of the header from the start of the file if successful, negative value from libbootimg_error if failed.
*/
int libbootimg_load_header(struct boot_img_hdr *hdr, const char *path);

Expand Down
8 changes: 5 additions & 3 deletions src/libbootimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ int libbootimg_init_load(struct bootimg *img, const char *path, int load_blob_ma
return res;
}

img->start_offset = res;

f = fopen(path, "r");
if(!f)
return translate_errnum(errno);

addr = img->hdr.page_size;
addr = img->start_offset + img->hdr.page_size;

for(i = 0; i < LIBBOOTIMG_BLOB_CNT; ++i)
{
Expand Down Expand Up @@ -174,7 +176,7 @@ int libbootimg_load_header(struct boot_img_hdr *hdr, const char *path)
int res = 0;
FILE *f;
size_t i;
static const uint32_t known_magic_pos[] = {
static const int known_magic_pos[] = {
0x0, // default
0x100, // HTC signed boot images
};
Expand All @@ -191,7 +193,7 @@ int libbootimg_load_header(struct boot_img_hdr *hdr, const char *path)
{
if(memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE) == 0)
{
res = 0;
res = known_magic_pos[i];
break;
}
}
Expand Down

0 comments on commit 6607d1c

Please sign in to comment.