Androidmanifest. XML in the APK file of the android installation package records the detailed information of the application. When published, the file has been compiled into a binary code, so it cannot be viewed normally. For example, I want to view the package and version information of this package (this indicates that the package is on the server ).
Axmlprinter2.jar can help me do this well. If you have a Java environment, you can use the following command line to decode the content in XML.
Java-jar axmlprinter2.jar androidmanifest. xml> androidmanifest.txt
Of course, you canProgramBy calling external processes to run this
Processstartinfo pH = new processstartinfo ("axmlprinter2.jar", "androidmanifest. xml> androidmanifest.txt"); process. Start (ph );
However, the web program in Asp.net has a lot of inconvenience due to permission issues. Because my production environment does not have Java, I want to implement this function in C. Axmlprinter2.jar is availableSource code(Eclipse project), you can use C # to rewrite it.
With the help of the great ikvm. Net (Java implementation on DOTNET), I can convert axmlprinter2.jar into a DOTNET assembly
Ikvmc-out: axmlprinter2.dll axmlprinter2.jar
Reference the converted DLL and ikvm lib (ikvm. runtime. DLL, ikvm. openjdk. core. DLL), so that you can easily call the method in axmlprinter2.jar in C #. Below is a call in C #.
Public Static String Decodemanifestxml ( String Filepath)
{
If (! File. exists (filepath ))
Return Null ;
Try
{
Axmlresourceparser parser = New Axmlresourceparser ();
Parser. Open ( New Java. Io. fileinputstream (filepath ));
Const String Indent = " " ;
Stringbuilder xmlcontent = New Stringbuilder ();
While ( True )
{
Int Type = parser. Next ();
If (Type = 1 )
{
Break ;
}
Switch (Type)
{
Case 0 :
{
Xmlcontent. append ( " <? XML version = \ "1.0 \" encoding = \ "UTF-8 \"?> \ R \ n " );
Break ;
}
Case 2 :
{
Xmlcontent. appendformat ( " {0} <{1} {2} " , Indent, getnamespaceprefix (parser. getprefix (), parser. getname ());
Int Namespacecountbefore = parser. getnamespacecount (parser. getdepth ()- 1 );
Int Namespacecount = parser. getnamespacecount (parser. getdepth ());
For ( Int I = namespacecountbefore; I! = Namespacecount; ++ I)
{
Xmlcontent. appendformat ( " {0} xmlns: {1 }=\ "{2 }\" " ,
Indent,
Parser. getnamespaceprefix (I ),
Parser. getnamespaceuri (I ));
}
For ( Int I = 0 ; I! = Parser. getattributecount (); ++ I)
{
Xmlcontent. appendformat (" {0} {1} {2 }=\ "{3 }\" " , Indent,
Getnamespaceprefix (parser. getattributeprefix (I )),
Parser. getattributename (I ),
Getattributevalue (parser, I ));
}
Xmlcontent. appendformat ( " {0}> " , "" );
Break ;
}
Case 3 :
{
Xmlcontent. appendformat ( " {0} </{1} {2}> " , "" ,
Getnamespaceprefix (parser. getprefix ()),
Parser. getname ());
Break ;
}
Case 4 :
{
Xmlcontent. appendformat ( " {0} {1} " , Indent, parser. gettext ());
Break ;
}
}
}
Return Xmlcontent. tostring ();
}
Catch (Exception E)
{
Throw E;
}
}
Download completeCode
Key words: androidmanifest, decode, package, APK, C #, ikvm. net