forked from iH8sn0w/iDove
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.c
executable file
·150 lines (131 loc) · 4.27 KB
/
image.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* GreenPois0n Cynanide - image.c
* Copyright (C) 2010 Chronic-Dev Team
* Copyright (C) 2010 Joshua Hill
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
#include <stdio.h>
#include "bdev.h"
#include "lock.h"
#include "task.h"
#include "image.h"
#include "common.h"
#include "device.h"
LinkedList* gImageList = NULL;
void* find_image_list() {
if(strstr((char*) (TARGET_BASEADDR + 0x200), "n88ap")) {
unsigned int ref = find_string(TARGET_BASEADDR, TARGET_BASEADDR, 0x50000, "blli");
ImageDescriptor* image = (ImageDescriptor*)(ref-0x1C);
return image->list.prev;
} else if(strstr((char*) (TARGET_BASEADDR + 0x200), "n72ap")) {
unsigned int ref = find_string(TARGET_BASEADDR, TARGET_BASEADDR, 0x50000, "blli");
ImageDescriptor* image = (ImageDescriptor*)(ref-0x1C);
return image->list.prev;
} else if(strstr((char*) (TARGET_BASEADDR + 0x200), "n82ap")) {
unsigned int ref = find_string(TARGET_BASEADDR, TARGET_BASEADDR, 0x50000, "blli");
ImageDescriptor* image = (ImageDescriptor*)(ref-0x1C);
return image->list.prev;
} else {
unsigned int ref = find_string(TARGET_BASEADDR, TARGET_BASEADDR, 0x50000, "tobi");
ImageDescriptor* image = (ImageDescriptor*)(ref-0x1C);
return image->list.prev;
}
}
int image_init() {
gImageList = find_image_list();
if(gImageList == NULL) {
puts("Unable to find gImageList\n");
} else {
//printf("Found gImageList at 0x%x\n", gImageList);
cmd_add("image", &image_cmd, "display and operate on for firmware images");
}
return 0;
}
int image_cmd(int argc, CmdArg* argv) {
unsigned int image = 0;
void* address = NULL;
char* action = NULL;
if(argc < 2) {
puts("usage: image <list/load> [options]\n");
puts(" list \t\tdisplay list of bdev images\n");
puts(" load <image> <address> \t\tload an img3 from bdev\n");
return 0;
}
action = argv[1].string;
if(!strcmp(action, "list")) {
image_display_list();
}
if(argc == 4) {
if(!strcmp(action, "load")) {
image = argv[2].uinteger;
address = (void*) argv[3].uinteger;
return image_load(image, address, 0x100000);
}
}
return 0;
}
void image_display_list() {
char type[] = "type";
LinkedList* list = gImageList->next;
enter_critical_section();
printf("Images:\n");
while(list != gImageList) {
ImageDescriptor* image = (ImageDescriptor*)list;
type[0] = (image->info.imageIdentifier & 0xFF000000) >> 24;
type[1] = (image->info.imageIdentifier & 0xFF0000) >> 16;
type[2] = (image->info.imageIdentifier & 0xFF00) >> 8;
type[3] = (image->info.imageIdentifier & 0xFF);
type[4] = '\0';
char* pigs = (char*)malloc;
sprintf(pigs, " %p: bdev: %p type: %s offset: 0x%05x len: 0x%x\n", image, image->device, type, image->startAddress, image->info.imageSize);
puts(pigs);
list = image->list.next;
}
printf("\n");
exit_critical_section();
}
void* image_find_tag(void* image, unsigned int tag, unsigned int size) {
unsigned int i = 0;
unsigned int* current = image;
current = image;
for (i = 0; i < size; i++) {
if (*current == tag) {
return current;
}
if(i % 0x1000) task_yield();
current++;
}
return 0;
}
ImageDescriptor* image_find(unsigned int signature) {
LinkedList* list = gImageList->next;
while(list != gImageList) {
ImageDescriptor* image = (ImageDescriptor*) list;
if(image->info.imageIdentifier == signature) {
return image;
}
list = image->list.next;
}
return NULL;
}
int image_load(unsigned int signature, void* dataout, unsigned int maxsize) {
ImageDescriptor* image = image_find(signature);
if(image == NULL) {
puts("unable to find requested image\n");
return -1;
}
image->device->read(image->device, dataout,
(void*) image->startAddress, 0, image->info.imageSize);
}