yashsingh1/xdaforums huggingface dataset:
[Android Software Development] mybeshoo:
Thank you for your replay, well what i did is the following

1- clone sampiles.

2- close Android Studio

3- Open Android Studio and select "patched-app" as a project, (Please make this step clear in your post)

4- Replace the apk with Instagram apk for fun and testing

5 - Connect my mobile to the PC

6- Click on Debug

I got these errors:

[IMG="Errors"]https://i.vgy.me/ZiRmir.png[/IMG]

Android resource compilation failed
C:\Users\DELL\AndroidStudioProjects\patched-app\app\build\intermediates\dexpatcher\decoded-app\res\values\public.xml:6082: error: resource 'drawable/$avd_hide_password__0' has invalid entry name '$avd_hide_password__0'. Invalid character '$avd_hide_password__0'.
C:\Users\DELL\AndroidStudioProjects\patched-app\app\build\intermediates\dexpatcher\decoded-app\res\values\public.xml:6083: error: resource 'drawable/$avd_hide_password__1' has invalid entry name '$avd_hide_password__1'. Invalid character '$avd_hide_password__1'.
C:\Users\DELL\AndroidStudioProjects\patched-app\app\build\intermediates\dexpatcher\decoded-app\res\values\public.xml:6084: error: resource 'drawable/$avd_hide_password__2' has invalid entry name '$avd_hide_password__2'. Invalid character '$avd_hide_password__2'.
C:\Users\DELL\AndroidStudioProjects\patched-app\app\build\intermediates\dexpatcher\decoded-app\res\values\public.xml:6085: error: resource 'drawable/$avd_show_password__0' has invalid entry name '$avd_show_password__0'. Invalid character '$avd_show_password__0'.
C:\Users\DELL\AndroidStudioProjects\patched-app\app\build\intermediates\dexpatcher\decoded-app\res\values\public.xml:6086: error: resource 'drawable/$avd_show_password__1' has invalid entry name '$avd_show_password__1'. Invalid character '$avd_show_password__1'.
C:\Users\DELL\AndroidStudioProjects\patched-app\app\build\intermediates\dexpatcher\decoded-app\res\values\public.xml:6087: error: resource 'drawable/$avd_show_password__2' has invalid entry name '$avd_show_password__2'. Invalid character '$avd_show_password__2'.
C:\Users\DELL\AndroidStudioProjects\patched-app\app\build\intermediates\dexpatcher\decoded-app\res\values\public.xml: error: file failed to compile.

What I am missing here?

Question:

1- Is DexPatcher will manage the build folder?

2- what if I want to include the AAR file and build the app without any patch commands, how to do that?

3- I do understand that batch command is in the

C:\Users\DELL\AndroidStudioProjects\patched-app\app\src\main\java\makeinfo\com\getid\MainActivity.java

How can i see the actual Java which extracted by dex2Jar. should I use an external tool like "jd-gui.exe"!
[Android Software Development] Lanchon:
i can't spoon feed info. you have to read the thread and other docs.

- Android resource compilation failed: covered in the dxp-gradle v2.0.0 release notes (and this thread). you haven't read them.

- what if I want to include the AAR file...: look in the several build.gradle files of the sample you are using, as described in the docs. you have to read and understand everything.

- ...and build the app without any patch commands: delete the .java files that form the patch (everything in patched-app\app\src\main\java\).

- How can i see the actual Java which extracted by dex2Jar: dex2jar produces bytecode, not java. you can use IDEA's (Android Studio's) built in decompiler to access the source code (IDEA decompiles bytecode just-in-time). look in the lower left corner of the screenshot in the first post of this thread; that's where you need to click to see the sources. if you don't like IDEA's decompiler (which is fernflower), then install a different java decompiler IDEA plugin. i use the CFR decompiler through a plugin.

- should I use an external tool like "jd-gui.exe": you can if you want. but i recommend Konloch's bytecode-viewer. jadx gui is supposed to be good too. i never tried TTDeDroid myself.
[Android Software Development] Lanchon:
> Well, I tried the "dexpatcher-gradle-samples\invalid-resources" , and I have very same results.

impossible. this WILL FIX those errors you first reported:

https://github.com/DexPatcher/dexpa...0.0/invalid-resources/app/build.gradle#L7-L18
[Android Software Development] Lanchon:
if you have resource errors, try an apktool roundtrip. if it fails, take the issue to the apktool project.

if it works with apktool, and you are using the same version of apktool with dexpatcher, then report it here.
[Android Software Development] Lanchon:
> multiDexJobs = 8

not recommended.

this is all wrong:

android {

compileSdkVersion 21

//buildToolsVersion '28.0.3'

defaultConfig {

// The 'package' attribute in the patched app manifest must be different from the

// source app ID to support class generation (R and BuildConfig), but here you can

// override the exported patched app ID to match the source.

applicationId 'makeinfo.com.getid'

// You must set these fields to match or be compatible with the corresponding data

// of the source app. (Data is displayed when the source apk library is built.)

minSdkVersion 9

targetSdkVersion 28

versionCode 1

versionName '1.0'

}

i assume this is not what you want either:

dependencies {

// We import an Android library, a file chooser, just for fun. This pulls in all its

// resources that will be transparently merged, like other resources from this project,

// with those of the source app. Each component will have its own independent 'R' class.

// The numeric IDs of the resources coming from the source app will be kept constant.

implementation('ru.bartwell:exfilepicker:1.8') {

// But the imported library has a transitive dependency on a module that is already

// present in the source app. So we exclude it from the import, keeping the source

// app's version. Alternatively we could delete the copy brought in by the source

// app using DexPatcher package annotations.

exclude module: 'support-v4'

}

}

i also have to assume your manifest is also wrong.

note that instagram probably uses anti-tampering. do an apktool rountrip, resign and test the app. it will probably not work.

i also have to guess that the instagram app is obfuscated. have you looked at it with bytecode-viewer or similar?
[Android Software Development] mybeshoo:
No, i can do APKTOOL on it and i can edit the smali code, APKtool b and sign the apk , it works very well on my phone!

Well, it is not...

and it is a very clear code.

[IMG="https://i.vgy.me/nPPgEC.png"]https://i.vgy.me/nPPgEC.png[/IMG]

I am following the default parameters in the project please advise, Please advice what is the best setting i have to use.

Kindly can you try that?

---------- Post added at 05:01 AM ---------- Previous post was at 04:43 AM ----------

Ps: Why don't you try to download Instagram and give it a try. you may find something to improve dexpatcher.

Regards.

---------- Post added at 05:08 AM ---------- Previous post was at 05:01 AM ----------

I updated the android section to

and still have the same problems
[Android Software Development] Lanchon:
> No, i can do APKTOOL on it and i can edit the smali code, APKtool b and sign the apk , it works very well on my phone!

cool !!!

then you can use dexpatcher on it too.

> Well, it is not...

unfortunately it is obfuscated.

some classes are referred from outside de dex files and can't be renamed to obfuscate them. for example, activities referred from the manifest.

some methods implement or override android framework methods and can't be renamed. for example, 'onCreate'.

the rest of the code is all obfuscated. take a look at the insides of the onCreate method you took a screenshot. for instance, do you think a class named 5Bw is part of instagram's source code? it's not even a legal java name.

> I am following the default parameters in the project please advise, Please advice what is the best setting i have to use.

Kindly can you try that?

you are supposed to know standard android development and what those parameters are. and your chosen values have to based on the app you are modifying. same for your manifest. you cannot instagram have code that requiere API level 25, for instance, and declare the patched app to require api level 21 and then use build tools 23! instagram has requirements, and you can only make them more strict, not more lax. there is an optional gradle task that prints some info. the rest is all typically available in the original manifest of the app in one way or the other.

you can't just copy over stuff from the sample. the sample is a sample, not a template. you have to understand why every line of the sample is there.
[Android Software Development] mybeshoo:
I am java developer, use to use abktool without knowing any thing regarding targeting sdk, now i know.

Ok, it is obfuscated, i think obfuscated mean, i will not understand any part of the code as dexprotector.com will hide any chance to understand. And other dex protection.

So under this situation, what is the advice to work on this?

Regard
[Android Software Development] mybeshoo:
Her is the SDK information of the app. which i already test it in the

Now regarding dependencies, i commented out the implementation, since it is not what we are looking for here.

-Regarding "obfuscated" as i understand dexpatcher can works now with obfuscated apk file.

Are you sure :)

I still have the same errors.
[Android Software Development] kinkina2009:
Look goods :o
[Android Software Development] Lanchon:
[MENTION=4177792]mybeshoo[/MENTION] android is not java. at some point if you are satisfied with what you have done you should go the apktool project and learn what are those item name="APKTOOL_DUMMY_n" values and figure out what you want to do about them. you can always redefine them in your patch.
[Android Software Development] mybeshoo:
Thank you so much for your kindly replay.

As I said before, I never post before searching. I value your time!

In the APK tool project, they said this is something not related to APKTOOL , and this is a missing value.

Well, that's would be understandable if apkTool b failed when I use it alone. but it works as expected.

https://github.com/iBotPeaches/Apktool/issues/1773#issuecomment-389602857

Yes and thank you, I learned something new form you. Thank you.:good::good:.

How to do that, there are more than 500 lines of APKTOOL_DUMMY_n! your advice will be more appreciated.

---------- Post added at 02:47 PM ---------- Previous post was at 02:25 PM ----------

Have a look, please

No problem with apktool at all and the app is working just fine on the device.

any way :

https://github.com/iBotPeaches/Apktool/issues/2260 here is a post on Apktool project.
[Android Software Development] Lanchon:
it is still a problem with apktool:

https://github.com/iBotPeaches/Apktool/issues/2095

https://github.com/iBotPeaches/Apktool/issues/2104

my guess is you are rebuilding with aapt1 in apktool and you use aapt2 in dexpatcher.

try an apktool roundtrip with aapt2 (apktool b --use-aapt2) and tell us what happens.

you can use aapt1 with dexpatcher (see dexpatcher-gradle v2 release notes) but it's not recommended: aapt1 is no longer supported by the android build system. plus, the option for using the hacked aapt binary (your other problem) only works for aapt2. and you need it.

if i were you, i would try fix the resources because apktool is somehow failing.

> How to do that, there are more than 500 lines of APKTOOL_DUMMY_n!

you replace them all with proper values.

you can replace them form your patch (see the samples, google how to replace resources from an AAR, its the same thing).

or you can create an apklib (which is a zip file) from the apk, then manually edit the contents, then feed the edited apklib to dexpatcher instead of the apk.

the apklib concept exists to let you manually tweak the apk before dexpatcher if there are problems. see the apklib sample to see how to generate an apklib. but basically you do it with another gradle project that produces the apklib file. then you use the file instead of the apk in your main project.
[Android Software Development] mybeshoo:
[MENTION=4141005]Lanchon[/MENTION]

Please review this :

https://github.com/iBotPeaches/Apktool/issues/2260#issuecomment-568957634

Is it somethings you need to update on your end?

Regard
[Android Software Development] Lanchon:
hey [MENTION=4177792]mybeshoo[/MENTION] ,

see this site:

https://www.apkmirror.com/?post_type=app_release&searchtype=apk&s=instagram

please post a link to the download page of the version and variant of instagram you are working on. the download has to be a BYTE PER BYTE EXACT match to your apk file. (please verify with MD5 or other hash).
[Android Software Development] ConnectionistSystems:
Gradle issue, can't import libraries

Hello [MENTION=4141005]Lanchon[/MENTION]

I want to thank you for your work first of all

After adding the samples repository to android studio and syncing with gradle files. I get the below error. I still have the imports showing up in red, can't add libraries below.

import lanchon.dexpatcher.gradle.tasks.Dex2jarTask;

import lanchon.dexpatcher.gradle.tasks.DexpatcherTask;

The error I get:

ERROR: Cannot cast object 'map(null)' with class 'org.gradle.api.internal.file.DefaultFilePropertyFactory$ResolvingDirectory' to class 'org.gradle.api.file.Directory'

Which points to line 112 in patched-dex/build.gradle

I just download the zip from github, so the issue shouldn't be because of an old version.

Thank you in advance!
[Android Software Development] Lanchon:
either you let Studio upgrade plugins or gradle, or you opened the root project with Studio instead of the 'parched-app' project. clone again and start from zero.
[Android Software Development] SilverDragon98:
help

could any one help my with my problem ?

i want to restore my source code on android studio for my project but sadly i have only the apk of the application :crying:

i have tried for 2 days to find a way but i couldn't so you are my last chance

i tried to understand how i can decompile the apk but sadly i don't understand i have read this thread and thread other xda site

but couldn't get the code to my android studio

so any help
[Android Software Development] Lanchon:
STOP SPAMMING THIS THREAD!

THIS THREAD IS NOT ABOUT DECOMPILERS!!!

please delete your message or i'll have to report you again.

good luck
[Android Software Development] sergentum:
how to

Hi. Is there any tutorial how to start? I cloned repo but the project can't be compiled. Have no idea how to make first steps, like where to put original apk etc.
[Android Software Development] surendrajat:
Oh My! 3 years of smali patching... From using bytecodeviewer and apktool to maintaining APK-Studio... to even creating my own APKLab, I couldn't even find something this awesome. I should be banging my head to the wall in front of me :P

Really amazing work here [MENTION=4141005]Lanchon[/MENTION]. Thank you for not abandoning it despite getting much less attraction than it deserves.

Just started your sample patch-app and it worked. This gives me hope for so much I can do with it. No more if-eq 39 0c ?? ?? :cond_2 omg! Thanks again!

Also, what humor and patience you had. Read almost entire thread today as a noob and decided to try and use only this now on :). It almost looks too good to be true tbh. Wish me luck.

Edit: I want to use Kotlin for developing patches. It should be fine, right?
[Android Software Development] Lanchon:
[MENTION=5602116]surendrajat[/MENTION] lol thanks!

it has issues... because apktool has issues and life is hard and android sucks donkey marbles and such.

all that surrounds the dexpatcher-tool is a mess, integrating with the android build system is a mess (the gradle plugins), obfuscation is a mess, but the tool itself works really well.

the upcoming version of the tool will really do MAGIC for obfuscated code analysis and patching (i hope!), a lot of work went into it. but still the gradle plugins have to grow to support all the new functionality before users can fully appreciate the new capabilities... and worse, i have to write tons of documentation regarding this.

the tool needs:

- update to the latest dexlib2/android 10

- the damn DexEdit tag

- and tool v2 will be able to patch the innards of method code (global and local), which btw i've already designed to the last letter

the gradle plugins need:

- update to the latest android build system and its gradle version

- then update to support obfuscation in the upcoming tool

- then plugins to support other workflows:

- - apktool-only roundtrips (to end the android build system nightmare)

- - dxp-live

and dexpatcher-live should finally get out of the drawing board and go live, so to speak. tired of signature issues, apk rebuild issues, etc, i want a "live" patcher working on the android system itself, and providing a user experience not unlike Xposed. this would end the gradle nightmares. i KNOW how to do this to the last dot (on android 9, not 10), i just need time. an infnite amount of it...

speaking of time, in a little bit news are coming...
[Android Software Development] surendrajat:
Awesome! Before you share that news, I'll quickly say a few more words.

Man! That's a lot of work, even though I don't understand all yet but it shouldn't be that easy either. I want to help and if you think I can help in any way DM anytime. I'm planning to write an introductory article once I'm successful with a few small apps I always patch with smali.

That will be just too good :P

Thanks!
[Android Software Development] Lanchon:
UPDATE: DexPatcher-tool v1.8.0-beta1 is out!

Now supports patching OBFUSCATED CODE, YAY !!!

This is a HUGE release, more than doubling the code size of the tool.

Bugs? Sure! Docs? Sorry! But now it is up there and you can start digging in, enjoy!

https://github.com/DexPatcher/dexpatcher-tool/releases
[Android Software Development] Lanchon:
https://xdaforums.com/showpost.php?p=81467385&postcount=352
[Android Software Development] surendrajat:
Feedback: Impressive!

Cool. I will look into it to see how can I use it with my apps.

So I tried patching one of my apps and I'm (almost) successful. Gotta say... it's so impressive. I was able to debug the patch in the android studio. lol :laugh:

However, I hit a road-block where it was a large method and I only wanted to revert an if condition in the middle of it, and this, if I'm not mistaken, requires implementing(copying) the entire method and DexReplace it as DexPrepend and DexAppend won't work in such situation. I hope there was some solution to that too.

Apart from that, I'm loving it. Wrote 5 patches in 1 hour and successfully tested. Feels like I got source :P

One thing I noticed: Android Studio 3.5+ does not have instant run so you can remove that warning from the main post.

Also, I've sorta compiled a changelog for Dexpatcher-tool if someone is interested in it: https://gist.github.com/Surendrajat/eae55bcd0961a6056463d66e9eff0287
[Android Software Development] Lanchon:
dxp-tool v2 is designed but not implemented.

v1 targets definitions of stuff

v2 adds the possibility of targeting usage of stuff

for instance you can hook a method CALL; means altering the call site, not the method definition. so you can hook methods that are not defined in the code (ie: the framework :) )

the granularity is expressive: you can hook a method call inside of a specific method, or a named group of methods, or globally.

so a requirement like yours could many times be fulfilled by hooking stuff used by the if expression only in that method. that is as close as dxp will ever get you without copy pasting code, i guess.

method calls (static or virtual) can always be hooked.

field access could also be hooked. fields could be hooked to getters/setters, unless the unpatched method body is on the brink of being too large for the classfile format. but fields could always be hooked to other fields instead. field hooking will probably not happen in the first incarnation of v2, and whether i'll go for hooking to access methods or to an alternative field or no field hooking at all is undecided. so far, the design includes field hooking via access methods.

the issue of whether constructor calls can be hooked is undecided. many times, yes, but it might fail (on patch time) in obfuscated cases. this seems to be unsolvable in the general case. an after-constructor hook is doable, with the same caveat regarding extremely large method bodies.
[Android Software Development] surendrajat:
Glad to know it's possible(and coming) :)

Hopefully, you will get enough time to make it happen.
[Android Software Development] surendrajat:
[MENTION=4141005]Lanchon[/MENTION] seems like it's necessary to add extends and implementes to the patch classes otherwise it'll throw a runtime exception even if it's successfully compiled.

Also, if I use multiDexEnabled true as the original apk has 2 dex files, rebuilding it produces 4 dex files (upto classes4.dex). Is that normal?
[Android Software Development] Lanchon:
> seems like it's necessary to add extends and implementes to the patch classes otherwise it'll throw a runtime exception even if it's successfully compiled.

when you edit an item in dxp, you are re-declaring it. the declaration should 'match' only to the extent of targeting the item. eg: you can redeclare a method that was protected and make it public. or not, but if you don't, it's your responsibility to redeclare with the original attributes.

you can't for instance redeclare argument types of a method, because that is part of the JVM signature for the method, and thus its also part of targeting: if you change an argument type, you'll just target another method. but you can redeclare all other attributes: most modifiers, annotations, etc.

classes are the same, only that only the fully qualified name is the only targeting data. all else, including extends and implements, you can modify and there's good reason for that.

but if you don't want to, you can avoid the redeclaration using the contentOnly=true attribute.

have you read the docs? it's documented.

docs are here:

https://dexpatcher.github.io/

carefully read the files this section:

PATCHING JAVA CODE IN JAVA

in this case you want:

The patch itself with explanatory comments.

> I use multiDexEnabled true as the original apk has 2 dex files, rebuilding it produces 4 dex files (upto classes4.dex). Is that normal?

chances are you are building debug builds using threaded multidex on a machine with 4 (virtual) cores or more.

dxp-tool release notes, for maybe the 1.2.0 betas i think, go into the subject of performance and talk about threading in more detail, if you are curious. but all you need to know is the difference between mdex and threaded mdex in dxp-tool.

then go see build.gradle file of the multi-dex sample. you'll see how dxp-gradle automatically chooses mdex modes according to the min android version being targeted and also how, for performance reasons, dxp-gradle will automatically enable threaded mdex under some conditions, but only for debug builds.

while there, you can see the difference in patching performance using threaded vs non-threaded mdex by comparing debug and release build logs. using the --stats option, dxp-tool will do some coarse profiling. if not enabled by default in that build, you can set dexpatcher.stats (or close to that) in the build script.
[Android Software Development] surendrajat:
Thanks for the usual great explanation. Actually I read the docs and figured out the most but sometimes it's stupidly tempting to ask instead. :o

About multidex, I tried those options to disable performance optimizations too but now I know that I need to build a releaseBuild. I was avoiding setting up signing certificate and all :)

Thanks again!