-
Notifications
You must be signed in to change notification settings - Fork 59
326 lines (285 loc) · 13.7 KB
/
patcher.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
name: Modify Framework and Services
on:
workflow_dispatch:
inputs:
jar_urls:
description: 'JSON object containing URLs to download the JAR files'
required: true
default: '{"framework_jar_url": "", "services_jar_url": "", "miui_services_jar_url": "", "miui_framework_jar_url": ""}'
android_api_level:
description: 'Android API level'
required: true
default: '34'
features:
description: 'JSON object containing feature flags'
required: true
default: '{"isCN": "true", "defaultcore": "true", "core": "false", "fixNotification": "true", "addGboard": "false", "disableFlagSecure": "true", "multiFloatingWindow": "true"}'
custom_device_name:
description: 'Device Name'
required: true
custom_version:
description: 'Version'
required: true
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
actions: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- name: Install dependencies
run: |
sudo apt install -y default-jdk zipalign p7zip-full python3 aria2 jq
pip install gdown
- name: Write inputs to files
run: |
echo '${{ github.event.inputs.jar_urls }}' > jar_urls.json
echo '${{ github.event.inputs.features }}' > features.json
- name: Parse JSON inputs
run: |
framework_jar_url=$(jq -r .framework_jar_url jar_urls.json)
services_jar_url=$(jq -r .services_jar_url jar_urls.json)
miui_services_jar_url=$(jq -r .miui_services_jar_url jar_urls.json)
miui_framework_jar_url=$(jq -r .miui_framework_jar_url jar_urls.json)
isCN=$(jq -r .isCN features.json)
defaultcore=$(jq -r .defaultcore features.json)
core=$(jq -r .core features.json)
fixNotification=$(jq -r .fixNotification features.json)
addGboard=$(jq -r .addGboard features.json)
disableFlagSecure=$(jq -r .disableFlagSecure features.json)
multiFloatingWindow=$(jq -r .multiFloatingWindow features.json)
# Export variables for use in subsequent steps
echo "framework_jar_url=$framework_jar_url" >> $GITHUB_ENV
echo "services_jar_url=$services_jar_url" >> $GITHUB_ENV
echo "miui_services_jar_url=$miui_services_jar_url" >> $GITHUB_ENV
echo "miui_framework_jar_url=$miui_framework_jar_url" >> $GITHUB_ENV
echo "isCN=$isCN" >> $GITHUB_ENV
echo "defaultcore=$defaultcore" >> $GITHUB_ENV
echo "core=$core" >> $GITHUB_ENV
echo "fixNotification=$fixNotification" >> $GITHUB_ENV
echo "addGboard=$addGboard" >> $GITHUB_ENV
echo "disableFlagSecure=$disableFlagSecure" >> $GITHUB_ENV
echo "multiFloatingWindow=$multiFloatingWindow" >> $GITHUB_ENV
- name: Download and validate JARs
run: |
download_file() {
url=$1
output=$2
if echo "$url" | grep -q "drive.google.com"; then
gdown --fuzzy -O "$output" "$url"
else
curl -L -C - -o "$output" "$url"
fi
}
download_file "${{ env.framework_jar_url }}" framework.jar
download_file "${{ env.services_jar_url }}" services.jar
download_file "${{ env.miui_services_jar_url }}" miui-services.jar
download_file "${{ env.miui_framework_jar_url }}" miui-framework.jar
for jar in framework.jar services.jar miui-services.jar miui-framework.jar; do
file_size=$(stat -c%s "$jar")
if [ $file_size -lt 1500000 ]; then
echo "Error: $jar is too small. Download might have failed." >&2
exit 1
fi
done
- name: Extract framework.jar
run: 7z x framework.jar -oframework
- name: Extract services.jar
run: 7z x services.jar -oservices
- name: Extract miui-services.jar
run: 7z x miui-services.jar -omiui_services
- name: Extract miui-framework.jar
run: 7z x miui-framework.jar -omiui_framework
- name: Decompile framework dex files if available
run: |
if [ -f framework/classes.dex ]; then
java -jar baksmali.jar d -a ${{ github.event.inputs.android_api_level }} framework/classes.dex -o classes
else
echo "framework/classes.dex not found, skipping decompilation."
fi
for i in {2..5}; do
if [ -f "framework/classes${i}.dex" ]; then
java -jar baksmali.jar d -a ${{ github.event.inputs.android_api_level }} "framework/classes${i}.dex" -o "classes${i}"
else
echo "framework/classes${i}.dex not found, skipping decompile."
fi
done
- name: Decompile services dex files if available
run: |
if [ -f services/classes.dex ]; then
java -jar baksmali.jar d -a ${{ github.event.inputs.android_api_level }} services/classes.dex -o services_classes
else
echo "services/classes.dex not found, skipping decompilation."
fi
for i in {2..5}; do
if [ -f "services/classes${i}.dex" ]; then
java -jar baksmali.jar d -a ${{ github.event.inputs.android_api_level }} "services/classes${i}.dex" -o "services_classes${i}"
else
echo "services/classes${i}.dex not found, skipping decompile."
fi
done
- name: Decompile miui-services dex file
run: |
java -jar baksmali.jar d -a ${{ github.event.inputs.android_api_level }} miui_services/classes.dex -o miui_services_classes
- name: Decompile miui-framework dex file
run: |
java -jar baksmali.jar d -a ${{ github.event.inputs.android_api_level }} miui_framework/classes.dex -o miui_framework_classes
- name: Backup smali files
run: |
cp -r classes classes_backup || echo "classes directory not found, skipping backup."
cp -r classes2 classes2_backup || echo "classes2 directory not found, skipping backup."
cp -r classes3 classes3_backup || echo "classes3 directory not found, skipping backup."
cp -r classes4 classes4_backup || echo "classes4 directory not found, skipping backup."
cp -r classes5 classes5_backup || echo "classes5 directory not found, skipping backup."
cp -r services_classes services_classes_backup || echo "services_classes directory not found, skipping backup."
cp -r services_classes2 services_classes2_backup || echo "services_classes2 directory not found, skipping backup."
cp -r services_classes3 services_classes3_backup || echo "services_classes3 directory not found, skipping backup."
cp -r services_classes4 services_classes4_backup || echo "services_classes4 directory not found, skipping backup."
cp -r services_classes5 services_classes5_backup || echo "services_classes5 directory not found, skipping backup."
cp -r miui_services_classes miui_services_classes_backup
cp -r miui_framework_classes miui_framework_classes_backup
- name: Modify framework smali
run: |
python3 framework_patch.py "${{ env.defaultcore }}" "${{ env.core }}"
- name: Modify services smali
run: |
python3 services_patch.py "${{ env.defaultcore }}" "${{ env.disableFlagSecure }}"
- name: Modify miui-services smali files
run: |
python3 miui-service_Patch.py "${{ env.isCN }}" "${{ env.fixNotification }}" "${{ env.multiFloatingWindow }}" "${{ env.addGboard }}" "${{ env.disableFlagSecure }}"
- name: Modify miui-framework smali files
run: |
python3 miui-framework_patch.py "${{ env.addGboard }}"
- name: Recompile framework dex files
run: |
if [ -d classes ]; then
java -jar smali.jar a -a ${{ github.event.inputs.android_api_level }} classes -o framework/classes.dex
else
echo "classes directory not found, skipping recompilation."
fi
for i in {2..5}; do
if [ -d "classes$i" ]; then
java -jar smali.jar a -a ${{ github.event.inputs.android_api_level }} "classes$i" -o "framework/classes$i.dex"
else
echo "classes$i directory not found, skipping recompilation."
fi
done
- name: Recompile services dex files
run: |
if [ -d services_classes ]; then
java -jar smali.jar a -a ${{ github.event.inputs.android_api_level }} services_classes -o services/classes.dex
else
echo "services_classes directory not found, skipping recompilation."
fi
for i in {2..5}; do
if [ -d "services_classes$i" ]; then
java -jar smali.jar a -a ${{ github.event.inputs.android_api_level }} "services_classes$i" -o "services/classes$i.dex"
else
echo "services_classes$i directory not found, skipping recompilation."
fi
done
- name: Recompile miui-services dex file
run: |
java -jar smali.jar a -a ${{ github.event.inputs.android_api_level }} miui_services_classes -o miui_services/classes.dex
- name: Recompile miui-framework dex file
run: |
java -jar smali.jar a -a ${{ github.event.inputs.android_api_level }} miui_framework_classes -o miui_framework/classes.dex
- name: Recompile framework.jar
run: |
cd framework
7z a -tzip ../framework_new.zip *
cd ..
- name: Recompile services.jar
run: |
cd services
7z a -tzip ../services_new.zip *
cd ..
- name: Recompile miui-services.jar
run: |
cd miui_services
7z a -tzip ../miui_services_new.zip *
cd ..
- name: Recompile miui-framework.jar
run: |
cd miui_framework
7z a -tzip ../miui_framework_new.zip *
cd ..
- name: Align the zips
run: |
zipalign -f -p -v -z 4 framework_new.zip aligned_framework.jar
zipalign -f -p -v -z 4 services_new.zip aligned_services.jar
zipalign -f -p -v -z 4 miui_services_new.zip aligned_miui_services.jar
zipalign -f -p -v -z 4 miui_framework_new.zip aligned_miui_framework.jar
- name: Copy aligned jars to Magisk module
run: |
mkdir -p magisk_module/system/framework
mkdir -p magisk_module/system/system_ext/framework
cp aligned_framework.jar magisk_module/system/framework/framework.jar
cp aligned_services.jar magisk_module/system/framework/services.jar
cp aligned_miui_services.jar magisk_module/system/system_ext/framework/miui-services.jar
cp aligned_miui_framework.jar magisk_module/system/system_ext/framework/miui-framework.jar
- name: Create Version From Link
run: |
if [ -z "${{ github.event.inputs.custom_version }}" ]; then
framework_url="${{ env.framework_jar_url }}"
version=$(echo $framework_url | grep -oP '(?<=V)[^/]*(?=/system)')
echo "version=${version}" >> $GITHUB_ENV
else
echo "version=${{ github.event.inputs.custom_version }}" >> $GITHUB_ENV
fi
if [ -z "${{ github.event.inputs.custom_device_name }}" ]; then
framework_url="${{ env.framework_jar_url }}"
device_name=$(echo $framework_url | grep -oP '(?<=redmi/)[^/]*(?=/-)')
echo "device_name=${device_name}" >> $GITHUB_ENV
else
echo "device_name=${{ github.event.inputs.custom_device_name }}" >> $GITHUB_ENV
fi
echo "version=${version}"
echo "device_name=${device_name}"
- name: Zip Magisk module
run: |
cd magisk_module
UNIQUE_NAME="moded_framework_services_${{ env.device_name }}_${{ env.version }}_$(date +%Y%m%d%H%M%S).zip"
zip -r ../$UNIQUE_NAME *
cd ..
mkdir -p out
chmod +w $UNIQUE_NAME
mv $UNIQUE_NAME out/
echo "UNIQUE_NAME=$UNIQUE_NAME" >> $GITHUB_ENV
- name: Create Release Notes
run: |
echo "## Release Notes" > release_notes.txt
echo "- Built modified jars from commit ${{ github.sha }}" >> release_notes.txt
echo "- Version: ${{ env.version }}" >> release_notes.txt
echo "- Device: ${{ env.device_name }}" >> release_notes.txt
echo "- Core patch: ${{ env.core }}" >> release_notes.txt
echo "- Default Core: ${{ env.defaultcore }}" >> release_notes.txt
echo "- Fix Notification: ${{ env.fixNotification }}" >> release_notes.txt
echo "- Add Gboard: ${{ env.addGboard }}" >> release_notes.txt
echo "- Disable Flag Secure: ${{ env.disableFlagSecure }}" >> release_notes.txt
echo "- Multi Floating Window: ${{ env.multiFloatingWindow }}" >> release_notes.txt
- name: Create Release
uses: ncipollo/release-action@v1
with:
artifacts: out/*
tag: ${{ env.version }}
name: moded_${{ env.device_name }}_${{ env.version }}
allowUpdates: true
makeLatest: true
bodyFile: release_notes.txt
token: ${{ secrets.GITHUB_TOKEN }}
- name: Notify via Telegram
run: |
curl -s -X POST https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage \
-d chat_id=@codes9488 \
-d message_thread_id=3 \
-d parse_mode="MarkdownV2" \
-d text="*Release *%0A%0A🔧 *Device:* \`${{ env.device_name }}\`%0A🔢 *Version:* \`${{ env.version }}\`%0A🌐 *Build ID:* \`${{ github.sha }}\`%0A📝 *Core Patch:* \`${{ env.core }}\`%0A🔧 *Default Core:* \`${{ env.defaultcore }}\`%0A🔧 *Fix Notification:* \`${{ env.fixNotification }}\`%0A🔧 *Add Gboard:* \`${{ env.addGboard }}\`%0A🔧 *Disable Flag Secure:* \`${{ env.disableFlagSecure }}\`%0A🔧 *Multi Floating Window:* \`${{ env.multiFloatingWindow }}\`%0A%0A🔗 [Download](https://github.com/${{ github.repository }}/releases/tag/${{ env.version }})%0A%0A \\#Release \\#${{ env.device_name }}"