+struct file_entry* get_next_file(unsigned char *fw, int len)
+{
+ static unsigned char *pos;
+ static unsigned char *end;
+ static struct file_entry fent;
+ int name_length;
+
+ if (fw != NULL && len != 0) {
+ pos = fw + 0x28;
+
+ printf("Start of filesystem: 0x%08x\n", *((unsigned int*)pos));
+ pos = fw + *((unsigned int*)pos);
+ end = fw + len;
+ }
+
+ fent.unknown = *pos;
+ pos++;
+
+ name_length = *((unsigned int*)pos);
+ pos += 4;
+
+ fent.length = *((unsigned int*)pos);
+ pos += 4;
+
+ if ((fent.length > (end - pos)) ||
+ (name_length > (end - pos))) {
+ printf("EOF reached\n");
+ return NULL;
+ }
+
+ fent.name = (char*)pos;
+ pos += name_length;
+
+ fent.start = pos;
+ pos += fent.length;
+
+ return &fent;
+}
+