Is it possible to replace a string (zipped) code from apk dalvik
Question: I would like to replace a single string from the hex/dalvik apk code. I
realize this would entail finding how the string gets encoded when it is
converted from an Android class project into a signed apk file.

Is this possible? Well, I know in code, anythings possible.. but does anyone
here know how to do it? I have learned that it's possible to delete and add to
.apk files on a windows platform with a simple zip archive (such as replacing
icons for the SystemUI.apk), without breaking the apk.. but how would one do
it programmatically? Specifically in python?

Does anyone have any ideas on how to do this?

I have tried:

    
    
    import zipfile
    zf=zipfile.ZipFile('APK.apk') # my zip file
    for filename in ['classes.dex']: # zipped file content file
     data=zf.read(filename)
    data=data.replace('mystring','newstring') #replace string within the content file
    file=open('classes.dex','wb')
    file.write(data) # write NEW content file to local disk
    file.close()
    zin=zipfile.ZipFile('APK.apk','r')       # create zip in and zip out
    zout=zipfile.ZipFile('APK.apk','w')      # iterate through zipped contents and
    for item in zin.infolist():              # copy all EXCEPT 'classes.dex' content file
      buffer=zin.read(item.filename)
      if (item.filename!='classes.dex'):
        zout.writestr(item,buffer)
    zout.close()
    zin.close()
    zf=zipfile.ZipFile('APK.apk',mode='a')   # finally, add new content file from my local disk
    zf.write('classes.dex',arcname='classes.dex')
    zf.close()
    

This takes the original APK.apk file, and rewrites a string within one of the
zipped content files, then repacking it back to APK.apk. Problem is: ORIGINAL
APK.apk = 170 kb NEW APK.apk = 399 kb and NOT INSTALLABLE, the apk was
"broken", and the Android system won't install the apk.


Answer: You can't add a string with higher bytes than the original.. you have to
replace a string of particular size with the same size of string. Try lucky
patcher. It replaces string in your Android only.. no need to bring it to your
pc. :-)

