Skip to content

Commit 3b15097

Browse files
ComputerEliteComputerElite
authored andcommitted
add custom permissions, Update patching and signing code to be async Tasks
1 parent d333c3f commit 3b15097

15 files changed

Lines changed: 303 additions & 229 deletions

QuestAppVersionSwitcher/APKSigner.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public static async Task<bool> SignApk(string path, string pemData, Dictionary<s
375375
QAVSWebserver.patchStatus.currentOperation = "Aligning apk";
376376
QAVSWebserver.BroadcastPatchingStatus();
377377
Logger.Log("Aligning Apk");
378-
if (!ApkAligner.AlignApk(path))
378+
if (!await ApkAligner.AlignApk(path))
379379
{
380380
Logger.Log("Aligning failed... Aborting", LoggingType.Warning);
381381
return false;
@@ -388,12 +388,12 @@ public static async Task<bool> SignApk(string path, string pemData, Dictionary<s
388388

389389
Logger.Log("Make APK Signature Scheme v2");
390390
FileStream fs = new FileStream(path, FileMode.Open);
391-
using FileMemory memory = new FileMemory(fs);
391+
await using FileMemory memory = new FileMemory(fs);
392392
TempFile t = new TempFile();
393-
using FileStream tmp = new FileStream(t.Path, FileMode.Create);
394-
using FileMemory outMemory = new FileMemory(tmp);
393+
await using FileStream tmp = new FileStream(t.Path, FileMode.Create);
394+
await using FileMemory outMemory = new FileMemory(tmp);
395395
memory.Position = memory.Length() - 22;
396-
while(memory.ReadInt() != EndOfCentralDirectory.SIGNATURE)
396+
while(await memory.ReadInt() != EndOfCentralDirectory.SIGNATURE)
397397
{
398398
memory.Position -= 4 + 1;
399399
}
@@ -402,7 +402,8 @@ public static async Task<bool> SignApk(string path, string pemData, Dictionary<s
402402
EndOfCentralDirectory eocd;
403403
try
404404
{
405-
eocd = new EndOfCentralDirectory(memory);
405+
eocd = new EndOfCentralDirectory();
406+
await eocd.Populate(memory);
406407
}
407408
catch (Exception e)
408409
{
@@ -414,8 +415,8 @@ public static async Task<bool> SignApk(string path, string pemData, Dictionary<s
414415
var cd = eocd.OffsetOfCD;
415416
memory.Position = cd-16-8;
416417

417-
var d = memory.ReadULong();
418-
var d2 = memory.ReadString(16);
418+
var d = await memory.ReadULong();
419+
var d2 = await memory.ReadString(16);
419420
var section1 = await GetSectionDigests(fs, 0, cd);
420421
var section3 = await GetSectionDigests(fs, cd, eocdPosition);
421422
var section4 = await GetSectionDigests(fs, eocdPosition, fs.Length);
@@ -444,7 +445,7 @@ public static async Task<bool> SignApk(string path, string pemData, Dictionary<s
444445

445446
signedData.Certificates.Add(cert.GetEncoded());
446447

447-
signedData.Write(memorySignedData);
448+
await signedData.Write(memorySignedData);
448449
signer.SignedData = signedDataMs.ToArray();
449450
ISigner signerType = SignerUtilities.GetSigner("SHA256WithRSA");
450451
signerType.Init(true, privateKey);
@@ -455,18 +456,19 @@ public static async Task<bool> SignApk(string path, string pemData, Dictionary<s
455456
block.Signers.Add(signer);
456457

457458
APKSigningBlock signingBlock = new APKSigningBlock();
458-
signingBlock.Values.Add(block.ToIDValuePair());
459+
signingBlock.Values.Add(await block.ToIDValuePair());
459460

460461
fs.Position = 0;
461-
outMemory.WriteBytes(memory.ReadBytes(cd));
462-
signingBlock.Write(outMemory);
462+
await outMemory.WriteBytes(await memory.ReadBytes(cd));
463+
await signingBlock.Write(outMemory);
463464
eocd.OffsetOfCD = (int)tmp.Position;
464-
outMemory.WriteBytes(memory.ReadBytes((int) (eocdPosition - cd)));
465-
eocd.Write(outMemory);
465+
await outMemory.WriteBytes(await memory.ReadBytes((int) (eocdPosition - cd)));
466+
await eocd.Write(outMemory);
466467

467468
fs.Close();
468469
tmp.Close();
469470
if(File.Exists(path)) File.Delete(path);
471+
470472
File.Move(t.Path, path);
471473
return true;
472474
}

QuestAppVersionSwitcher/Assets/html/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ <h2>Patching options</h2>
7474
<br>
7575
<div id="other">
7676
</div>
77+
<br>
78+
<h4>Features</h4>
79+
<input type="text" id="featureName" placeholder="feature name">
80+
<br>
81+
<br>
82+
<label class="option">
83+
<label class="switch normal">
84+
<input id="requireFeature" type="checkbox" checked>
85+
<span class="slider round"></span>
86+
</label>
87+
Require feature
88+
</label>
89+
<br>
90+
<br>
91+
<div class="button" onclick="AddFeature()">Add Feature</div>
92+
<br>
93+
<div id="otherFeatures">
94+
</div>
95+
<br>
96+
<div class="button" onclick="AddSpecificFeature('com.oculus.feature.PASSTHROUGH', true)">Add Passthrough Feature</div>
7797
</div>
7898

7999
</div>

QuestAppVersionSwitcher/Assets/html/script.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ const handTrackingVersion = document.getElementById("handtrackingversion")
333333
const debugCheckbox = document.getElementById("debug")
334334
const otherContainer = document.getElementById("other")
335335
var otherPermissions = []
336+
var otherFeatures = []
336337

337338
function UploadMod() {
338339
var input = document.createElement('input');
@@ -429,6 +430,34 @@ function AddPermission() {
429430
document.getElementById("otherName").value = ""
430431
UpdatePermissions()
431432
}
433+
function AddSpecificFeature(name, required) {
434+
otherFeatures.push({name: name, required: required})
435+
UpdateFeatures()
436+
}
437+
438+
function AddFeature() {
439+
otherFeatures.push({name: document.getElementById("featureName").value, required: document.getElementById("requireFeature").checked})
440+
document.getElementById("featureName").value = ""
441+
UpdateFeatures()
442+
}
443+
444+
function UpdateFeatures() {
445+
var perms = ""
446+
for(const p of otherFeatures){
447+
perms += `
448+
<div style="padding: 10px; margin-right: 20px; border-radius: 5px; border: 1px #242424 solid;">
449+
${p.name} ${p.required ? "(Required)" : "(Not required)"}
450+
<div class="button" style="display: inline" onclick="RemoveFeature('${p.name}')">X</div>
451+
</div>`
452+
}
453+
if(perms == "") perms = "No custom features added yet"
454+
document.getElementById("otherFeatures").innerHTML = perms
455+
}
456+
457+
function RemoveFeature(name) {
458+
otherFeatures = otherFeatures.filter(a => a.name != name)
459+
UpdateFeatures()
460+
}
432461

433462
function UpdatePermissions() {
434463
var perms = ""
@@ -439,6 +468,7 @@ function UpdatePermissions() {
439468
<div class="button" style="display: inline" onclick="RemovePermission('${p}')">X</div>
440469
</div>`
441470
}
471+
if(perms == "") perms = "No custom permissions added yet"
442472
otherContainer.innerHTML = perms
443473
}
444474

@@ -453,6 +483,7 @@ function PatchGame() {
453483
patchInProgress = true
454484
var patchOptions = {
455485
otherPermissions: otherPermissions,
486+
otherFeatures: otherFeatures,
456487
debug: debugCheckbox.checked,
457488
handTracking: handTrackingCheckbox.checked,
458489
handTrackingVersion: parseInt(handTrackingVersion.value),

QuestAppVersionSwitcher/CoreVars.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,16 @@ public class PatchingPermissions
6565
public bool handTracking { get; set; } = true;
6666
public bool debug { get; set; } = true;
6767
public List<string> otherPermissions { get; set; } = new List<string>();
68+
public List<UsesFeature> otherFeatures { get; set; } = new List<UsesFeature>();
6869
public HandTrackingVersion handTrackingVersion { get; set; }
6970
}
7071

72+
public class UsesFeature
73+
{
74+
public string name { get; set; } = "";
75+
public bool required { get; set; } = true;
76+
}
77+
7178
public enum HandTrackingVersion
7279
{
7380
None,

QuestAppVersionSwitcher/PatchingManager.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System.Net;
2222
using System.Text;
2323
using System.Text.Json;
24+
using Org.BouncyCastle.Bcpg.Sig;
2425

2526
namespace QuestAppVersionSwitcher
2627
{
@@ -340,7 +341,7 @@ public static bool PatchManifest(ZipArchive apkArchive)
340341

341342
// First we add permissions and features to the APK for modding
342343
List<string> addingPermissions = new List<string>();
343-
List<string> addingFeatures = new List<string>();
344+
List<UsesFeature> addingFeatures = new List<UsesFeature>();
344345
PatchingPermissions permissions = CoreService.coreVars.patchingPermissions;
345346
if (permissions.externalStorage)
346347
{
@@ -362,7 +363,7 @@ public static bool PatchManifest(ZipArchive apkArchive)
362363
"com.oculus.permission.HAND_TRACKING"
363364
});
364365
// Tell Android (and thus Oculus home) that this app supports hand tracking and we can launch the app with it
365-
addingFeatures.Add("oculus.software.handtracking");
366+
addingFeatures.Add(new UsesFeature {name = "oculus.software.handtracking", required = false});
366367
}
367368
addingPermissions.AddRange(permissions.otherPermissions);
368369

@@ -379,16 +380,15 @@ public static bool PatchManifest(ZipArchive apkArchive)
379380
manifest.Children.Add(permElement);
380381
}
381382

382-
foreach (string feature in addingFeatures)
383+
foreach (UsesFeature feature in addingFeatures)
383384
{
384-
if (existingFeatures.Contains(feature)) { continue; } // Do not add existing features
385+
if (existingFeatures.Contains(feature.name)) { continue; } // Do not add existing features
385386

386-
Logger.Log("adding feature " + feature);
387+
Logger.Log("adding feature " + feature.name);
387388
AxmlElement featureElement = new AxmlElement("uses-feature");
388-
AddNameAttribute(featureElement, feature);
389+
AddNameAttribute(featureElement, feature.name);
389390

390-
// TODO: User may want the feature to be required instead of suggested
391-
featureElement.Attributes.Add(new AxmlAttribute("required", AndroidNamespaceUri, RequiredAttributeResourceId, false));
391+
featureElement.Attributes.Add(new AxmlAttribute("required", AndroidNamespaceUri, RequiredAttributeResourceId, feature.required));
392392
manifest.Children.Add(featureElement);
393393
}
394394

QuestAppVersionSwitcher/Properties/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.13.10" package="com.ComputerElite.questappversionswitcher" android:installLocation="preferExternal" android:versionCode="93">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.13.11" package="com.ComputerElite.questappversionswitcher" android:installLocation="preferExternal" android:versionCode="94">
33
<uses-sdk android:minSdkVersion="28" android:targetSdkVersion="32" />
44
<uses-permission android:name="oculus.permission.handtracking" />
55
<uses-permission android:name="com.oculus.permission.HAND_TRACKING" />

QuestAppVersionSwitcher/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
// Minor Version
2323
// Build Number
2424
// Revision
25-
[assembly: AssemblyVersion("1.13.10.0")]
26-
[assembly: AssemblyFileVersion("1.13.10.0")]
25+
[assembly: AssemblyVersion("1.13.11.0")]
26+
[assembly: AssemblyFileVersion("1.13.11.0")]

0 commit comments

Comments
 (0)