|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU Lesser General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU Lesser General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #include <fcntl.h> |
|
20 #include <sys/types.h> |
|
21 #include <unistd.h> |
|
22 #include <cstring> |
|
23 |
|
24 #include "elfromerror.h" |
|
25 #include "e32romimage.h" |
|
26 |
|
27 |
|
28 void E32RomImage::SetupRomData(){ |
|
29 // see if there's a header on the image. |
|
30 iRomFile.GetData(&iE32RomHeader, sizeof(iE32RomHeader)); |
|
31 |
|
32 // In general the 'name' is of the form EPOC*ROM. |
|
33 // We are looking for ARM roms for the moment so check for EPOCARM and error on anything |
|
34 // else which matches EPOC*ROM |
|
35 bool isEPOCHeader = !strncmp((const char *)&iE32RomHeader.name[0], "EPOC", 4) && |
|
36 (strstr((const char *)&iE32RomHeader.name[0], "ROM") != NULL); |
|
37 bool isARMHeader = !strncmp((const char *)&iE32RomHeader.name[0], "EPOCARM", 7); |
|
38 |
|
39 if(isARMHeader) |
|
40 iRomFile.SetOffset(sizeof(iE32RomHeader)); |
|
41 else if (isEPOCHeader) |
|
42 errx(EX_NOINPUT, "unsupported rom type: %s\n", (const char *)&iE32RomHeader.name[0]); |
|
43 } |
|
44 |
|
45 void E32RomImage::GetFileFragmentData(FileFragmentData & aFileFragmentData ){ |
|
46 assert(iRomFile.Size() > 0); |
|
47 if (!iData) |
|
48 iData = iRomFile.GetData(); |
|
49 SetFileFragmentData(aFileFragmentData, Size(), reinterpret_cast<char *>(iData)); |
|
50 } |
|
51 |
|
52 void E32RomImage::DeleteFileFragmentData(){ |
|
53 if (iData) { |
|
54 char * d = iData; |
|
55 iData = NULL; |
|
56 delete [] d; |
|
57 } |
|
58 } |