Apk file parsing and learning notes

Source: Internet
Author: User

AndroidApplication Package File(APKIs an application installation file format on the Android operating system."Application package file".

If you know how to use the decompilation tool, you can download the apk parsing tool to obtain the decompilation code.

Download: SharpZipLib.zip http://www.icsharpcode.net/opensource/sharpziplib/download.aspx

The main method is as follows:

Using ICSharpCode. SharpZipLib. Zip;

Public static Dictionary <object, object> getPackageInfo (string path ){

Dictionary <object, object> returnMap = new Dictionary <object, object> ();
ReturnMap. Add ("VersionCode )","");
ReturnMap. Add ("version name (VersionName )","");
ReturnMap. Add ("Package name )","");
ReturnMap. Add ("signature (Sig )","");
ReturnMap. Add ("START activity ","");
ReturnMap ["certificate validity period"] = "";
ReturnMap ["Certificate expiration time"] = "";
ReturnMap ["Certificate Hash"] = "";
ReturnMap ["Certificate MD5"] = "";
ReturnMap ["PublicKey"] = "";
List <string> list = new List <string> {". DSA", ". RSA "};
If (string. IsNullOrWhiteSpace (path ))
{
Throw new Exception ("incorrect file path:" + path );
}
String str = "";
If (path. LastIndexOf (".")> = 0)
{
Str = path. Substring (path. LastIndexOf ("."));
}
If (". apk". Equals (str, StringComparison. OrdinalIgnoreCase ))
{
Try
{
ZipInputStream zip = new ZipInputStream (File. OpenRead (path ));
ZipEntry zipEntry = null;
While (zipEntry = zip. GetNextEntry ())! = Null)
{
String fileName = Path. GetFileName (zipEntry. Name );
If (fileName! = Null) & (fileName. LastIndexOf (".")> = 0 ))
{
String item = fileName. Substring (fileName. LastIndexOf ("."));
If ("AndroidManifest. xml". Equals (fileName, StringComparison. OrdinalIgnoreCase ))
{
GetPackageDetails (zip, zipEntry, returnMap );
}
Else if (list. Contains (item ))
{
GetSig (zip, zipEntry, returnMap );
}
}
}
Zip. Close ();
}
Catch (Exception exception)
{
Throw new Exception ("parsing apk package error:" + exception. Message );
}
}
Return returnMap;
}

Private static void getSig (ZipInputStream zip, ZipEntry zipEntry, Dictionary <object, object> returnMap)
{
MemoryStream stream = new MemoryStream ();
Byte [] rawCertData = new byte [0x400];
Int count = 0;
While (count = zip. Read (rawCertData, 0, 0x400)> 0)
{
Stream. Write (rawCertData, 0, count );
}
Stream. Seek (0L, SeekOrigin. Begin );
String str = "";
X509Certificate certificate = new X509Certificate (stream. GetBuffer ());
ReturnMap ["certificate validity period"] = certificate. GetEffectiveDateString ();
ReturnMap ["certificate expiration time"] = certificate. GetExpirationDateString ();
ReturnMap ["certificate Hash"] = certificate. GetCertHashString ();
ReturnMap ["certificate MD5"] = BitConverter. ToString (MD5.Create (). ComputeHash (certificate. GetRawCertData (). Replace ('-',':');
ReturnMap ["PublicKey"] = certificate. GetPublicKeyString ();
RawCertData = certificate. GetRawCertData ();
Byte [] buffer2 = SHA1.Create (). ComputeHash (certificate. GetRawCertData ());
For (int I = 0; I <buffer2.Length; I ++)
{
Str = str + (sbyte) buffer2 [I]);
}
Stream. Close ();
ReturnMap ["signature (Sig)"] = str;
}

The size of the apk file to be uploaded is limited. The web. config file is added as follows:

<System. web>
<HttpRuntime maxRequestLength = "" executionTimeout = "3600"/>
</System. web>

<System. webServer>
<Security>
<RequestFiltering>

<RequestLimits maxAllowedContentLength = "">
</RequestLimits>
</RequestFiltering>
</Security>
</System. webServer>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.