在Android系统外部和内部读取Android应用的签名

	在Android系统外部和内部读取Android应用的签名

Android系统外读取签名(J2SE):;;;;*;;;;;;Main{ObjectmSync=Object();WeakReference[]mReadBuffer;main(String[]args){args=String[1];args[0]="";StringmArchiveSourcePath=args[0];WeakReference[]readBufferRef;[]readBuffer=(mSync){readBufferRef=mReadBuffer;(readBufferRef!=){mReadBuffer=readBuffer=();}(readBuffer==){readBuffer=[8192];readBufferRef=WeakReference[](readBuffer);}}{JarFilejarFile=JarFile(mArchiveSourcePath);[]certs=Enumerationentries=();(()){JarEntryje=(JarEntry)();(()){}(().startsWith("META-INF/")){}[]localCerts=loadCertificates(jarFile,je,readBuffer);(){("File"+mArchiveSourcePath+"entry"+()+":certs="+certs+"("+(certs!=:0)+")");}(localCerts==){("Packagehasnocertificatesatentry"+()+";ignoring!");();}(certs==){certs=localCerts;}{(i=0;;i++){found=(j=0;;j++){(certs[i]!=certs[i].equals(localCerts[j])){found=}}(!found||!=){("Packagehasmismatchedcertificatesatentry"+()+";ignoring!");();}}}}();(mSync){mReadBuffer=readBufferRef;}(certs!=){N=;(i=0;iN;i++){StringcharSig=String(toChars(certs[i].getEncoded()));("Cert#:"+i+"Type:"+certs[i].getType()+"Publickey:"+certs[i].getPublicKey()+"Hashcode:"+certs[i].hashCode()+"/0x"+(certs[i].hashCode())+"Tochar:"+charSig);}}{("Packagehasnocertificates;ignoring!");}}(CertificateEncodingExceptionex){(Main..getName()).log(,,ex);}(IOExceptione){("Exceptionreading"+mArchiveSourcePath+""+e);}(RuntimeExceptione){("Exceptionreading"+mArchiveSourcePath+""+e);}}[]toChars([]mSignature){[]sig=mSignature;N=;N2=N*2;[]text=[N2];(j=0;jj++){v=sig[j];d=(v4)0xf;text[j*2]=()(d=10(a+d-10):(0+d));d=v0xf;text[j*2+1]=()(d=10(a+d-10):(0+d));}text;}[]loadCertificates(JarFilejarFile,JarEntryje,[]readBuffer){{InputStreamis=(je);((readBuffer,0,)!=-1){}();([])(je!=():);}(IOExceptione){("Exceptionreading"+()+"in"+()+":"+e);}}}Android系统内读取签名:;;;;;;;;;;;;;;TestActivity{[]toChars([]mSignature){[]sig=mSignature;N=;N2=N*2;[]text=[N2];(j=0;jj++){v=sig[j];d=(v4)0xf;text[j*2]=()(d=10(a+d-10):(0+d));d=v0xf;text[j*2+1]=()(d=10(a+d-10):(0+d));}text;}OverrideonCreate(BundlesavedInstanceState){.onCreate(savedInstanceState);setContentView();{PackageInfopis=.getPackageManager().getPackageInfo("",_SIGNATURES);Signature[]sigs=;("versioncode="+);(sigs[0].hashCode()+"/0x"+(sigs[0].hashCode()));Stringsig=String(sigs[0].toChars());("toChar"+()+"length:"+sig);Stringapk="/sdcard/";PackageInfopi=.getPackageManager().getPackageArchiveInfo(apk,_SIGNATURES);Stringmain=String([0].toChars());("toChar"+()+"apk:"+main);((sig));}(NameNotFoundExceptione){();}}}---------------------------------------------------------专注移动开发Android,WindowsMobile,iPhone,J2ME,BlackBerry,Symbianpostedon2012-05-2717:28阅读(5108)所属分类:。