sbtools: fix handling of raw mode, have elf_write looks like elf_read, fix uninitiliazed offset of bss sections, add real key override on decrypt
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30858 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
fd187ad14c
commit
4cab9f26b6
3 changed files with 32 additions and 3 deletions
|
@ -19,6 +19,7 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
#include "elf.h"
|
||||
#include "misc.h"
|
||||
|
||||
/**
|
||||
* Definitions
|
||||
|
@ -219,7 +220,8 @@ void elf_add_fill_section(struct elf_params_t *params,
|
|||
sec->pattern = pattern;
|
||||
}
|
||||
|
||||
void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, void *user)
|
||||
void elf_write_file(struct elf_params_t *params, elf_write_fn_t write,
|
||||
elf_printf_fn_t printf, void *user)
|
||||
{
|
||||
Elf32_Ehdr ehdr;
|
||||
uint32_t phnum = 0;
|
||||
|
@ -236,6 +238,10 @@ void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, void *use
|
|||
sec->offset = offset;
|
||||
offset += sec->size;
|
||||
}
|
||||
else
|
||||
{
|
||||
sec->offset = 0;
|
||||
}
|
||||
|
||||
phnum++;
|
||||
sec = sec->next;
|
||||
|
|
|
@ -82,7 +82,7 @@ void elf_add_fill_section(struct elf_params_t *params,
|
|||
uint32_t fill_addr, uint32_t size, uint32_t pattern);
|
||||
uint32_t elf_translate_virtual_address(struct elf_params_t *params, uint32_t addr);
|
||||
void elf_translate_addresses(struct elf_params_t *params);
|
||||
void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, void *user);
|
||||
void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, elf_printf_fn_t printf, void *user);
|
||||
bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, elf_printf_fn_t printf,
|
||||
void *user);
|
||||
bool elf_is_empty(struct elf_params_t *params);
|
||||
|
|
|
@ -86,6 +86,17 @@ static uint8_t instruction_checksum(struct sb_instruction_header_t *hdr)
|
|||
return sum;
|
||||
}
|
||||
|
||||
static void elf_printf(void *user, bool error, const char *fmt, ...)
|
||||
{
|
||||
if(!g_debug && !error)
|
||||
return;
|
||||
(void) user;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vprintf(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static void elf_write(void *user, uint32_t addr, const void *buf, size_t count)
|
||||
{
|
||||
FILE *f = user;
|
||||
|
@ -105,7 +116,7 @@ static void extract_elf_section(struct elf_params_t *elf, int count, const char
|
|||
|
||||
if(fd == NULL)
|
||||
return ;
|
||||
elf_write_file(elf, elf_write, fd);
|
||||
elf_write_file(elf, elf_write, elf_printf, fd);
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
|
@ -481,6 +492,15 @@ static void extract(unsigned long filesize)
|
|||
}
|
||||
}
|
||||
|
||||
if(getenv("SB_REAL_KEY") != 0)
|
||||
{
|
||||
struct crypto_key_t k;
|
||||
char *env = getenv("SB_REAL_KEY");
|
||||
if(!parse_key(&env, &k) || *env)
|
||||
bug("Invalid SB_REAL_KEY");
|
||||
memcpy(real_key, k.u.key, 16);
|
||||
}
|
||||
|
||||
color(RED);
|
||||
printf(" Summary:\n");
|
||||
color(GREEN);
|
||||
|
@ -751,6 +771,9 @@ int main(int argc, char **argv)
|
|||
add_keys(&g_zero_key, 1);
|
||||
break;
|
||||
}
|
||||
case 'r':
|
||||
g_raw_mode = true;
|
||||
break;
|
||||
case 'a':
|
||||
{
|
||||
struct crypto_key_t key;
|
||||
|
|
Loading…
Reference in a new issue