#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <strings.h>
#include <string.h>
#include <unistd.h>
#include "rsb-lz.h"
#include "filesystem.h"
-struct file_entry* get_next_file(unsigned char *fw, int len)
+struct file_entry* get_next_file(uint8_t *fw, int32_t len)
{
- static unsigned char *pos;
- static unsigned char *start;
- static unsigned char *end;
+ static uint8_t *pos;
+ static uint8_t *start;
+ static uint8_t *end;
static struct file_entry fent;
- int name_length;
+ int32_t name_length;
if (fw != NULL && len != 0) {
pos = fw + 0x28;
#if 0
- printf("Start of filesystem: 0x%08x\n", *((unsigned int*)pos));
+ printf("Start of filesystem: 0x%08x\n", *((uint32_t*)pos));
#endif
start = fw;
- pos = fw + *((unsigned int*)pos);
+ pos = fw + *((uint32_t*)pos);
end = fw + len;
}
if (fent.unknown == 0x00) {
/* EOF */
- int fill = (4 - ((pos - start) % 4)) % 4;
- int i;
+ int32_t fill = (4 - ((pos - start) % 4)) % 4;
+ int32_t i;
for (i = 0; i < fill; i++) {
if (*pos != 0xff) {
}
- name_length = *((unsigned int*)pos);
+ name_length = *((uint32_t*)pos);
pos += 4;
- fent.length = *((unsigned int*)pos);
+ fent.length = *((uint32_t*)pos);
pos += 4;
if ((fent.length > (end - pos)) ||
return &fent;
}
-void extract_files(unsigned char *fw, int len)
+void extract_files(uint8_t *fw, int32_t len)
{
struct file_entry *fent;
if (fent->length > 0) {
write_file(extracted_file(fent->name), fent->start, fent->length);
- if (*((unsigned int*)fent->start) == LZ_MAGIC) {
+ if (*((uint32_t*)fent->start) == LZ_MAGIC) {
char *lzname;
- unsigned char *outbuf;
- unsigned int outlen;
+ uint8_t *outbuf;
+ uint32_t outlen;
if ((lzname = strdup(fent->name)) == NULL) {
perror("strdup");
free(outbuf);
free(lzname);
} else if (!strcmp(fent->name, "firmware")) {
- unsigned char *lzpos;
+ uint8_t *lzpos;
char lzname[128];
bzero(lzname, sizeof(lzname));
strcpy(lzname, "firmware.");
- lzpos = fent->start + *((unsigned int*)(fent->start + 0x20));
+ lzpos = fent->start + *((uint32_t*)(fent->start + 0x20));
memcpy(lzname + strlen(lzname), lzpos - 4, 4);
lzpos += 4;
- if (*((unsigned int*)(lzpos)) == LZ_MAGIC) {
- unsigned char *outbuf;
- unsigned int outlen;
+ if (*((uint32_t*)(lzpos)) == LZ_MAGIC) {
+ uint8_t *outbuf;
+ uint32_t outlen;
printf("%s: compressed firmware part found", lzname);
outbuf = extract_lz_file(lzpos, &outlen, 1);
}
}
-void replace_add_file(unsigned char *fw, int len, char *fwname, char *lname)
+void replace_add_file(uint8_t *fw, int32_t len, char *fwname, char *lname)
{
fprintf(stderr, "%s: Implement me!\n", __func__);
exit(1);
}
-void list_files(unsigned char *fw, int len)
+void list_files(uint8_t *fw, int32_t len)
{
struct file_entry *fent;
void mkdir_p(char *dir)
{
char *parent;
+ char *tmpdir;
if ((dir == NULL) || (!strcmp(dir, ".")))
return;
- parent = strdup(dirname(dir));
+ tmpdir = strdup(dir);
+ if (tmpdir == NULL) {
+ perror("strdup");
+ exit(1);
+ }
+
+ parent = strdup(dirname(tmpdir));
+ free(tmpdir);
if (parent == NULL) {
perror("strdup");
exit(1);
free(parent);
}
-void write_file(char *fname, unsigned char *buf, int len)
+void write_file(char *fname, uint8_t *buf, int32_t len)
{
char *filename_c, *dirn;
- int fd;
- int remaining;
- int ret;
+ int32_t fd;
+ int32_t remaining;
+ int32_t ret;
if ((filename_c = strdup(fname)) == NULL) {
perror("strdup");