Skip to content

Commit 6a6f72d

Browse files
committed
Initial commit
0 parents  commit 6a6f72d

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed

android/reverse-engineering.md

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Android reverse engineering
2+
3+
This step will contain the following ...
4+
5+
- Getting the .apk file (if not already)
6+
- Decompiling it to (.jar, .smali, .java files)
7+
- Inserting logging statements
8+
- Recompiling, aligning and signing
9+
10+
# Getting the .apk
11+
12+
## Gplaycli (preferred)
13+
- Project link - https://github.com/matlink/gplaycli
14+
15+
Using gplaycli is the easiest way, just install it using `pip install gplaycli`, followed by `gplaycli -d com.eboks.activities`
16+
17+
This outputs the .apk file in the current directory.
18+
19+
## Online tools
20+
This only tool can be used, to get the apk file - https://apps.evozi.com/apk-downloader/
21+
22+
Keep in mind, this might NOT be the newest version, but might be cached.
23+
24+
# Decompiling
25+
26+
## Decompiling to smali
27+
- Project link - https://bitbucket.org/iBotPeaches/apktool/downloads/
28+
29+
Download the latest release of `apktool.jar`, and save it to the same directory as your `.apk`, I have the following structure.
30+
31+
```
32+
- eboks/
33+
- apktool.jar
34+
- com.eboks.activities.apk
35+
```
36+
37+
Use the following command, to get the smali code `java -jar apktool.jar d com.eboks.activities.jar`, and all the files are now in `com.eboks.activities`.
38+
39+
## Decompiling to jar
40+
- Project link - https://github.com/pxb1988/dex2jar
41+
42+
Go to the releases, and download the latest release (not nightly builds and not just the source).
43+
Extract it to a directory of your choice, I prefer the same as my .apk file, so I have the following structure
44+
45+
```
46+
- eboks/
47+
- dex2jar/
48+
- com.eboks.activities.apk
49+
```
50+
51+
Then just use the following command `./dex2jar/d2j-dex2jar.sh com.eboks.activities.apk`, which will result in a `.jar` with `-dex2jar.jar` appended to it.
52+
53+
## Decompiling to java
54+
- Project link - https://bitbucket.org/mstrobel/procyon/downloads/
55+
56+
Download the latest release so you have the following structure (this requires the previous `.jar` file).
57+
58+
```
59+
- eboks/
60+
- dex2jar/
61+
- procyon.jar
62+
- com.eboks.activities.apk
63+
- com.eboks.activities-dex2jar.jar
64+
```
65+
66+
To get the `.java` files, do the following `java -jar procyon.jar -jar com.eboks.activities-dex2jar.jar -o java-classes`.
67+
68+
69+
# Inserting logging statements
70+
- Project link - https://github.com/eyJhb/IGLogger
71+
72+
This requires a bit more, since we need to use something called `iglogger`, download the `.smali` file, and place it in your apps smali root.
73+
74+
This would be `com.eboks.activities/smali/iglogger.smali`, to use it, you need to place various debug statements in the code.
75+
76+
Normally there will be a `.locals` in a function, so if you want to write a new string (to know what the next value will be), increase this, and use `.locals n-1`, to for your `vN`.
77+
78+
Example
79+
80+
```
81+
.method private static iv()[B
82+
.locals 2
83+
84+
.line 68
85+
new-instance v0, Ljava/security/SecureRandom;
86+
87+
invoke-direct {v0}, Ljava/security/SecureRandom;-><init>()V
88+
89+
const/16 v1, 0x10
90+
91+
.line 69
92+
new-array v1, v1, [B
93+
94+
.line 70
95+
invoke-virtual {v0, v1}, Ljava/security/SecureRandom;->nextBytes([B)V
96+
97+
return-object v1
98+
.end method
99+
```
100+
101+
```
102+
.method private static iv()[B
103+
.locals 3
104+
const-string v2, "!!!loginEncryptHelper.iv!!!"
105+
invoke-static {v2}, Liglogger;->d(Ljava/lang/String;)I
106+
107+
.line 68
108+
new-instance v0, Ljava/security/SecureRandom;
109+
110+
invoke-direct {v0}, Ljava/security/SecureRandom;-><init>()V
111+
112+
const/16 v1, 0x10
113+
114+
.line 69
115+
new-array v1, v1, [B
116+
117+
.line 70
118+
invoke-virtual {v0, v1}, Ljava/security/SecureRandom;->nextBytes([B)V
119+
invoke-static {v1}, Liglogger;->d([B)I
120+
121+
return-object v1
122+
.end method
123+
```
124+
125+
This will print out the information needed.
126+
127+
# Recompiling, aligning and signing
128+
129+
## Recompiling
130+
We here use `apktool` yet again - `java -jar apktool.jar b com.eboks.activities` (the folder name).
131+
This gives us a files in `com.eboks.activities/dists/com.eboks.activities.apk`, this file needs to be zipaligned.
132+
133+
Install zipalign tool `apt install zipalign`, and use `zipalign -v -p 4 com.eboks.activities/dist/com.eboks.activities.apk app-alligned.apk`.
134+
135+
Now for the signing, this is a little more tricky... We need `apksigner` which is a part of the `Android SDK Tools`, which will not be covered here.
136+
We also need to generate our signing keys using `keytools` (part of the Java JRE), where we can use this command `keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias my-alias`, I just use `123456` for all passwords prompts etc..
137+
138+
Now when all this is done, you should be able to sign your alligned apk using ...
139+
140+
```
141+
echo -n 123456 | apksigner sign --ks my-release-key.jks --out app-release.apk app-alligned.apk
142+
```
143+
144+
Now just install it!
145+
146+
# Automated build script
147+
148+
```
149+
rm builds/app-alligned.apk ; \
150+
java -jar apktool.jar b -o builds/app.apk app && \
151+
zipalign -v -p 4 builds/app.apk builds/app-alligned.apk && \
152+
echo -n 123456 | apksigner sign --ks my-release-key.jks --out builds/app-release.apk builds/app-alligned.apk
153+
```

readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Guides
2+
This repository has various guides, for various tools, that I need to remember.
3+
4+
Feel free to contribute with whatever...

0 commit comments

Comments
 (0)