|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.Collections.Generic; |
|
19 using System.Text; |
|
20 using System.IO; |
|
21 using SymbianStructuresLib.Version; |
|
22 |
|
23 namespace SymbianImageLib.ROM.Structures |
|
24 { |
|
25 internal class SRomPageInfo |
|
26 { |
|
27 #region Enumerations |
|
28 public enum TSymbianCompressionType |
|
29 { |
|
30 ENoCompression = 0, |
|
31 EBytePair, |
|
32 } |
|
33 #endregion |
|
34 |
|
35 #region Static constructors |
|
36 public static SRomPageInfo New( Stream aStream, uint aOffsetToStartOfRomData ) |
|
37 { |
|
38 byte[] data = new byte[ Size ]; |
|
39 aStream.Read( data, 0, data.Length ); |
|
40 return new SRomPageInfo( data, aOffsetToStartOfRomData ); |
|
41 } |
|
42 #endregion |
|
43 |
|
44 #region Constructors |
|
45 private SRomPageInfo( byte[] aArray, uint aOffsetToStartOfRomData ) |
|
46 { |
|
47 uint delta = 0; |
|
48 // |
|
49 iDataStart = aOffsetToStartOfRomData + ReadUint( aArray, ref delta ); |
|
50 iDataSize = ReadUshort( aArray, ref delta ); |
|
51 iCompressionType = (TSymbianCompressionType) aArray[ delta++ ]; |
|
52 iPagingAttributes = (TAttributes) aArray[ delta++ ]; |
|
53 } |
|
54 #endregion |
|
55 |
|
56 #region Constants |
|
57 public const int KPageSize = 0x1000; |
|
58 #endregion |
|
59 |
|
60 #region Properties |
|
61 public static uint Size |
|
62 { |
|
63 get { return 8; } |
|
64 } |
|
65 |
|
66 public bool IsPageable |
|
67 { |
|
68 get { return ( iPagingAttributes & TAttributes.EPageable ) == TAttributes.EPageable; } |
|
69 } |
|
70 |
|
71 public TSymbianCompressionType CompressionType |
|
72 { |
|
73 get |
|
74 { |
|
75 // Rather frustratingly, even unpageable areas of the ROM still report their |
|
76 // compression type as "byte pair". We must zero this out, since they are |
|
77 // definitely not compressed. |
|
78 if ( !IsPageable ) |
|
79 { |
|
80 return TSymbianCompressionType.ENoCompression; |
|
81 } |
|
82 // |
|
83 return iCompressionType; |
|
84 } |
|
85 } |
|
86 |
|
87 public uint DataStart |
|
88 { |
|
89 get { return iDataStart; } |
|
90 } |
|
91 |
|
92 public uint DataSize |
|
93 { |
|
94 get { return iDataSize; } |
|
95 } |
|
96 #endregion |
|
97 |
|
98 #region Internal enumerations |
|
99 [Flags] |
|
100 private enum TAttributes |
|
101 { |
|
102 EPageable = 1 << 0 |
|
103 } |
|
104 #endregion |
|
105 |
|
106 #region Internal methods |
|
107 private static uint ReadUint( byte[] aArray, ref uint aOffset ) |
|
108 { |
|
109 uint ret = 0; |
|
110 // |
|
111 ret += (uint) ( aArray[ aOffset + 0 ] << 00 ); |
|
112 ret += (uint) ( aArray[ aOffset + 1 ] << 08 ); |
|
113 ret += (uint) ( aArray[ aOffset + 2 ] << 16 ); |
|
114 ret += (uint) ( aArray[ aOffset + 3 ] << 24 ); |
|
115 // |
|
116 aOffset += 4; |
|
117 // |
|
118 return ret; |
|
119 } |
|
120 |
|
121 private static ushort ReadUshort( byte[] aArray, ref uint aOffset ) |
|
122 { |
|
123 ushort ret = 0; |
|
124 // |
|
125 ret += (ushort) ( aArray[ aOffset + 0 ] << 00 ); |
|
126 ret += (ushort) ( aArray[ aOffset + 1 ] << 08 ); |
|
127 // |
|
128 aOffset += 2; |
|
129 // |
|
130 return ret; |
|
131 } |
|
132 #endregion |
|
133 |
|
134 #region Data members |
|
135 private uint iDataStart; |
|
136 private ushort iDataSize; |
|
137 private TSymbianCompressionType iCompressionType; |
|
138 private TAttributes iPagingAttributes; |
|
139 #endregion |
|
140 } |
|
141 } |