Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF201 signed blob support #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions shared/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
// Previous unknown fields grabbed from
// http://nv-tegra.nvidia.com/gitweb/?p=android/platform/build.git;a=commitdiff;h=0adc4478615891636d8b7c476c20c2014b788537

#define SIGNBLOB "\x2d\x53\x49\x47\x4e\x45\x44\x2d\x42\x59\x2d\x53\x49\x47\x4e\x42\x4c\x4f\x42\x2d\x29\xc3\x94\x20\x00\x01\x00\x00" //"-SIGNED-BY-SIGNBLOB-)� "
#define SIGNBLOB_SIZE 28
#define MAGIC "MSM-RADIO-UPDATE"
#define MAGIC_SIZE 16
#define PART_NAME_LEN 4

typedef struct
{
unsigned char signblob[SIGNBLOB_SIZE];
unsigned char magic[MAGIC_SIZE];
unsigned int version; // Always 0x00010000
unsigned int size; // Size of header
Expand Down
38 changes: 27 additions & 11 deletions src/blobpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string.h>

#include "blob.h"

typedef struct
{
char *part_name;
Expand All @@ -24,16 +25,24 @@ main (int argc, char **argv)

memset (&hdr, 0, sizeof (header_type));

if (argc < (GENERIC_ARGS+2)) // Require at least one partition
int nGenericArgs = GENERIC_ARGS;
bool bSignOffset = false;
if(0 == memcmp (argv[1], "-s", 2))
{
bSignOffset = true;
++nGenericArgs;
}

if (argc < (nGenericArgs+2)) // Require at least one partition
{
fprintf (stderr,"Usage: %s <outfile> <partitionname> <partitionfile> ...\n", argv[0]);
fprintf (stderr,"Usage: %s <-s> <outfile> <partitionname> <partitionfile> ...\n", argv[0]);
fprintf(stderr, "Any number of partitionname partitionfilename entries can be entered\n");
return -1;
}

outname = argv[1];
partnums = argc - GENERIC_ARGS;
outname = argv[nGenericArgs-1];

partnums = argc - nGenericArgs;
if(partnums <= 0 || partnums % 2 != 0)
{
fprintf(stderr, "Error in parameters. There needs to be equal partition names and partition filenames.");
Expand All @@ -45,28 +54,35 @@ main (int argc, char **argv)
printf("Found %d partitions as commandline arguments\n", partnums);
partitions = (partition_item*)calloc(partnums, sizeof(partition_item));
curr_part = partitions;
for(i=GENERIC_ARGS; i<argc; i+=2)
for(i=nGenericArgs; i<argc; i+=2)
{
printf("Partname: %s Filename: %s\n", argv[i], argv[i+1]);
curr_part->part_name = argv[i];
curr_part->filename = argv[i+1];
curr_part++;
++curr_part;
};

memcpy(hdr.signblob, SIGNBLOB, SIGNBLOB_SIZE);
memcpy(hdr.magic, MAGIC, MAGIC_SIZE);
hdr.version = 0x00010000; // Taken from
hdr.size = hdr.part_offset = sizeof(header_type);
hdr.size = hdr.part_offset = sizeof(header_type)-SIGNBLOB_SIZE;
hdr.num_parts = partnums;

outfile = fopen (outname, "wb");
fwrite (&hdr, sizeof (header_type), 1, outfile);
if(bSignOffset)
{
fwrite (&hdr, sizeof (header_type), 1, outfile); //Write the new way (write the sign as part of the header)
}
else
{
fwrite (&hdr.magic, sizeof (header_type)-SIGNBLOB_SIZE, 1, outfile); //Write the original way (ignore the new variable)
}
printf ("Size: %d\n", hdr.size);
printf ("%d partitions starting at offset 0x%X\n", hdr.num_parts,
hdr.part_offset);
printf ("%d partitions starting at offset 0x%X\n", hdr.num_parts, hdr.part_offset);

parts = (part_type *)calloc (hdr.num_parts, sizeof (part_type));
memset(parts, 0, sizeof(part_type)*hdr.num_parts);
int currentOffset = sizeof(header_type)+sizeof(part_type)*hdr.num_parts;
int currentOffset = hdr.part_offset+sizeof(part_type)*hdr.num_parts;
printf("Offset: %d\n", currentOffset);
for (i = 0; i < (int)hdr.num_parts; i++)
{
Expand Down
36 changes: 24 additions & 12 deletions src/blobunpack.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "blob.h"

#ifdef _WIN32
#define snprintf _snprintf
#endif
void dumpPartition (FILE * file, char *basename, part_type part);
void dumpPartition (FILE * file, char *basename, part_type part, bool bSignOffset);
#define BUFFER_SIZE 2048

int
Expand All @@ -30,16 +32,24 @@ main (int argc, char **argv)
fprintf (stderr, "Unable to open \"%s\"\n", argv[1]);
return -1;
}
fread (&hdr, sizeof (header_type), 1, file);

bool bSignOffset = false;
fread (&hdr.magic, sizeof (header_type)-SIGNBLOB_SIZE, 1, file); //Read the original way (ignore the new variable)
if (memcmp (hdr.magic, MAGIC, MAGIC_SIZE))
{
fprintf (stderr, "File \"%s\" is not a valid blob file\n", argv[1]);
return -1;
fseek (file, 0, SEEK_SET);
fread (&hdr, sizeof (header_type), 1, file); //Read the new way (read in the sign so it is skipped)
if (memcmp (hdr.magic, MAGIC, MAGIC_SIZE))
{
fprintf (stderr, "File \"%s\" is not a valid blob file\n", argv[1]);
return -1;
}
printf ("Header contains SIGNBLOB\n");
bSignOffset = true;
}
printf ("Header size: %d\n", hdr.size);
printf ("%d partitions starting at offset 0x%X\n", hdr.num_parts,
hdr.part_offset);
printf ("Blob version: %d\n", hdr.version);
printf ("%d partitions starting at offset 0x%X\n", hdr.num_parts, hdr.part_offset);
printf ("Blob version: %d\n", hdr.version/0x10000);
for(i=0; i<7; i++)
{
printf ("Blob 'unknown' %d: %d\n", i, hdr.unknown[i]);
Expand All @@ -51,7 +61,7 @@ main (int argc, char **argv)
fclose (hdrfile);*/


fseek (file, hdr.part_offset, SEEK_SET);
fseek (file, hdr.part_offset+(bSignOffset?SIGNBLOB_SIZE:0), SEEK_SET);
parts = (part_type *)calloc (hdr.num_parts, sizeof (part_type));
fread (parts, sizeof (part_type), hdr.num_parts, file);

Expand All @@ -61,16 +71,16 @@ main (int argc, char **argv)
printf ("Name: %s\n", parts[i].name);
printf ("Offset: %d (0x%X)\n", parts[i].offset, parts[i].offset);
printf ("Size: %d (0x%X)\n", parts[i].size, parts[i].size);
dumpPartition (file, argv[1], parts[i]);
dumpPartition (file, argv[1], parts[i], bSignOffset);
}
fclose (file);
return 0;
}

void
dumpPartition (FILE * file, char *basename, part_type part)
dumpPartition (FILE * file, char *basename, part_type part, bool bSignOffset)
{
fseek (file, part.offset, SEEK_SET);
fseek (file, part.offset+(bSignOffset?SIGNBLOB_SIZE:0), SEEK_SET);
int dataleft = part.size;
char buffer[BUFFER_SIZE];
char filename[1024];
Expand All @@ -84,8 +94,10 @@ dumpPartition (FILE * file, char *basename, part_type part)
int toRead = dataleft > BUFFER_SIZE ? BUFFER_SIZE : dataleft;
int dataread = fread (buffer, 1, toRead, file);
int datawritten = fwrite (buffer, 1, dataread, outfile);
if (dataread != datawritten)
if (dataread != datawritten || (0 == dataread && 0 < dataleft))
{
abort ();
}
dataleft -= dataread;
}
fclose (outfile);
Expand Down