1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . IO ;
4+
5+ namespace RegawMOD . Android
6+ {
7+ public partial class AAPT
8+ {
9+ /// <summary>
10+ /// Contains Apk Badging Dump Information
11+ /// </summary>
12+ public class Badging
13+ {
14+ #region Constants
15+ private const string APOSTROPHE = "'" ;
16+
17+ private const string PACKAGE = "package:" ;
18+ private const string PACKAGE_NAME = "name='" ;
19+ private const string PACKAGE_VERSION_CODE = "versionCode='" ;
20+ private const string PACKAGE_VERSION_NAME = "versionName='" ;
21+
22+ private const string APPLICATION = "application:" ;
23+ private const string APPLICATION_LABEL = "label='" ;
24+ private const string APPLICATION_ICON = "icon='" ;
25+
26+ private const string ACTIVITY = "launchable-activity:" ;
27+ private const string ACTIVITY_NAME = "name='" ;
28+ private const string ACTIVITY_LABEL = "label='" ;
29+ private const string ACTIVITY_ICON = "icon='" ;
30+
31+ private const string SDK_VERSION = "sdkVersion:'" ;
32+ private const string SDK_TARGET = "targetSdkVersion:'" ;
33+
34+ private const string USES_PERMISSION = "uses-permission:'" ;
35+
36+ private const string DENSITIES = "densities:" ;
37+ #endregion
38+
39+ #region Fields
40+ private FileInfo source ;
41+
42+ private PackageInfo package ;
43+ private ApplicationInfo application ;
44+ private LaunchableActivity activity ;
45+
46+ private string sdkVersion ;
47+ private string targetSdkVersion ;
48+
49+ private List < string > usesPermission ;
50+ private List < int > densities ;
51+ #endregion
52+
53+ #region Properties
54+ /// <summary>
55+ /// Gets a <c>FileInfo</c> containing information about the source Apk
56+ /// </summary>
57+ public FileInfo Source { get { return this . source ; } }
58+
59+ /// <summary>
60+ /// Gets a <see cref="PackageInfo"/> containing infomation about the Apk
61+ /// </summary>
62+ public PackageInfo Package { get { return this . package ; } }
63+
64+ /// <summary>
65+ /// Gets a <see cref="ApplicationInfo"/> containing infomation about the Apk
66+ /// </summary>
67+ public ApplicationInfo Application { get { return this . application ; } }
68+
69+ /// <summary>
70+ /// Gets a <see cref="LaunchableActivity"/> containing infomation about the Apk
71+ /// </summary>
72+ public LaunchableActivity Activity { get { return this . activity ; } }
73+
74+ /// <summary>
75+ /// Gets a value indicating the Android Sdk Version of the Apk
76+ /// </summary>
77+ public string SdkVersion { get { return this . sdkVersion ; } }
78+
79+ /// <summary>
80+ /// Gets a value indicating the Target Android Sdk Version of the Apk
81+ /// </summary>
82+ public string TargetSdkVersion { get { return this . targetSdkVersion ; } }
83+
84+ /// <summary>
85+ /// Gets a <c>List<string></c> containing the Android Permissions used by the Apk
86+ /// </summary>
87+ public List < string > Permissions { get { return this . usesPermission ; } }
88+
89+ /// <summary>
90+ /// Gets a <c>List<int></c> containing the supported screen densities of the Apk
91+ /// </summary>
92+ public List < int > ScreenDensities { get { return this . densities ; } }
93+ #endregion
94+
95+ internal Badging ( FileInfo source , string dump )
96+ {
97+ this . source = source ;
98+
99+ this . package = new PackageInfo ( ) ;
100+ this . application = new ApplicationInfo ( ) ;
101+ this . activity = new LaunchableActivity ( ) ;
102+
103+ this . sdkVersion = "" ;
104+ this . targetSdkVersion = "" ;
105+
106+ this . usesPermission = new List < string > ( ) ;
107+ this . densities = new List < int > ( ) ;
108+
109+ ProcessDump ( dump ) ;
110+ }
111+
112+ private void ProcessDump ( string dump )
113+ {
114+ using ( StringReader r = new StringReader ( dump ) )
115+ {
116+ string line ;
117+
118+ while ( r . Peek ( ) != - 1 )
119+ {
120+ line = r . ReadLine ( ) ;
121+
122+ if ( line . StartsWith ( PACKAGE ) )
123+ {
124+ //find name
125+ int nameStart = line . IndexOf ( PACKAGE_NAME ) + PACKAGE_NAME . Length ;
126+ int nameLength = line . IndexOf ( APOSTROPHE , nameStart ) - nameStart ;
127+ string name = line . Substring ( nameStart , nameLength ) ;
128+
129+ //find versionCode
130+ int versionCodeStart = line . IndexOf ( PACKAGE_VERSION_CODE ) + PACKAGE_VERSION_CODE . Length ;
131+ int versionCodeLength = line . IndexOf ( APOSTROPHE , versionCodeStart ) - versionCodeStart ;
132+ string versionCode = line . Substring ( versionCodeStart , versionCodeLength ) ;
133+
134+ //find versionName
135+ int versionNameStart = line . IndexOf ( PACKAGE_VERSION_NAME ) + PACKAGE_VERSION_NAME . Length ;
136+ int versionNameLength = line . IndexOf ( APOSTROPHE , versionNameStart ) - versionNameStart ;
137+ string versionName = line . Substring ( versionNameStart , versionNameLength ) ;
138+
139+ this . package = new PackageInfo ( name , versionCode , versionName ) ;
140+ }
141+ else if ( line . StartsWith ( APPLICATION ) )
142+ {
143+ //find label
144+ int labelStart = line . IndexOf ( APPLICATION_LABEL ) + APPLICATION_LABEL . Length ;
145+ int labelLength = line . IndexOf ( APOSTROPHE , labelStart ) - labelStart ;
146+ string label = line . Substring ( labelStart , labelLength ) ;
147+
148+ //find icon
149+ int iconStart = line . IndexOf ( APPLICATION_ICON ) + APPLICATION_ICON . Length ;
150+ int iconLength = line . IndexOf ( APOSTROPHE , iconStart ) - iconStart ;
151+ string icon = line . Substring ( iconStart , iconLength ) ;
152+
153+ this . application = new ApplicationInfo ( label , icon ) ;
154+ }
155+ else if ( line . StartsWith ( ACTIVITY ) )
156+ {
157+ //find name
158+ int nameStart = line . IndexOf ( ACTIVITY_NAME ) + ACTIVITY_NAME . Length ;
159+ int nameLength = line . IndexOf ( APOSTROPHE , nameStart ) - nameStart ;
160+ string name = line . Substring ( nameStart , nameLength ) ;
161+
162+ //find label
163+ int labelStart = line . IndexOf ( ACTIVITY_LABEL ) + ACTIVITY_LABEL . Length ;
164+ int labelLength = line . IndexOf ( APOSTROPHE , labelStart ) - labelStart ;
165+ string label = line . Substring ( labelStart , labelLength ) ;
166+
167+ //find icon
168+ int iconStart = line . IndexOf ( ACTIVITY_ICON ) + ACTIVITY_ICON . Length ;
169+ int iconLength = line . IndexOf ( APOSTROPHE , iconStart ) - iconStart ;
170+ string icon = line . Substring ( iconStart , iconLength ) ;
171+
172+ this . activity = new LaunchableActivity ( name , label , icon ) ;
173+ }
174+ else if ( line . StartsWith ( SDK_VERSION ) )
175+ {
176+ this . sdkVersion = line . Substring ( SDK_VERSION . Length ) . Replace ( APOSTROPHE , "" ) ;
177+ }
178+ else if ( line . StartsWith ( SDK_TARGET ) )
179+ {
180+ this . targetSdkVersion = line . Substring ( SDK_TARGET . Length ) . Replace ( APOSTROPHE , "" ) ;
181+ }
182+ else if ( line . StartsWith ( USES_PERMISSION ) )
183+ {
184+ this . usesPermission . Add ( line . Substring ( USES_PERMISSION . Length ) . Replace ( APOSTROPHE , "" ) ) ;
185+ }
186+ else if ( line . StartsWith ( DENSITIES ) )
187+ {
188+ string [ ] densities = line . Substring ( DENSITIES . Length + 2 ) . Split ( new char [ ] { '\' ' , ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
189+
190+ for ( int i = 0 ; i < densities . Length ; i ++ )
191+ this . densities . Add ( int . Parse ( densities [ i ] ) ) ;
192+ }
193+ }
194+ }
195+ }
196+
197+ /// <summary>
198+ /// Contains information about an Apk's package
199+ /// </summary>
200+ public class PackageInfo
201+ {
202+ private string name ;
203+ private string versionCode ;
204+ private string versionName ;
205+
206+ internal PackageInfo ( ) : this ( null , null , null ) { }
207+ internal PackageInfo ( string name , string versionCode , string versionName )
208+ {
209+ this . name = name ;
210+ this . versionCode = versionCode ;
211+ this . versionName = versionName ;
212+ }
213+
214+ /// <summary>
215+ /// Gets a value indicating the Apk's package name
216+ /// </summary>
217+ public string Name
218+ {
219+ get { return this . name ; }
220+ }
221+
222+ /// <summary>
223+ /// Gets a value indicating the Version Code of the Apk's package
224+ /// </summary>
225+ public string VersionCode
226+ {
227+ get { return this . versionCode ; }
228+ }
229+
230+ /// <summary>
231+ /// Gets a value indicating the Version Name of the Apk's package
232+ /// </summary>
233+ public string VersionName
234+ {
235+ get { return this . versionName ; }
236+ }
237+ }
238+
239+ /// <summary>
240+ /// Contains general information about an Apk
241+ /// </summary>
242+ public class ApplicationInfo
243+ {
244+ private string label ;
245+ private string icon ;
246+
247+ internal ApplicationInfo ( ) : this ( null , null ) { }
248+ internal ApplicationInfo ( string label , string icon )
249+ {
250+ this . label = label ;
251+ this . icon = icon ;
252+ }
253+
254+ /// <summary>
255+ /// Gets a value indicating the Application's Label
256+ /// </summary>
257+ public string Label
258+ {
259+ get { return this . label ; }
260+ }
261+
262+ /// <summary>
263+ /// Gets a value indicating the path inside the apk to the Application's default icon
264+ /// </summary>
265+ public string Icon
266+ {
267+ get { return this . icon ; }
268+ }
269+ }
270+
271+ /// <summary>
272+ /// Contains information about an Apk's main Activity
273+ /// </summary>
274+ public class LaunchableActivity
275+ {
276+ private string name ;
277+ private string label ;
278+ private string icon ;
279+
280+ internal LaunchableActivity ( ) : this ( null , null , null ) { }
281+ internal LaunchableActivity ( string name , string label , string icon )
282+ {
283+ this . name = name ;
284+ this . label = label ;
285+ this . icon = icon ;
286+ }
287+
288+ /// <summary>
289+ /// Gets a value indicating the name of the Apk's main Activity
290+ /// </summary>
291+ public string Name
292+ {
293+ get { return this . name ; }
294+ }
295+
296+ /// <summary>
297+ /// Gets a value indicating the label of the Apk's main Activity
298+ /// </summary>
299+ public string Label
300+ {
301+ get { return this . label ; }
302+ }
303+
304+ /// <summary>
305+ /// Gets a value indicating the path to the default icon of the Apk's main Activity
306+ /// </summary>
307+ public string Icon
308+ {
309+ get { return this . icon ; }
310+ }
311+ }
312+ }
313+ }
314+ }
0 commit comments