First commit

This commit is contained in:
eevee
2024-11-03 18:29:07 +03:00
commit db63ef6ff2
41 changed files with 1742 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
namespace ivinject.Common.Models;
internal class BinaryHeaders
{
private const uint FatMagic = 0xcafebabe;
private const uint FatMagic64 = 0xcafebabf;
private const uint FatCigam = 0xbebafeca;
private const uint FatCigam64 = 0xbfbafeca;
private const uint MhMagic = 0xfeedface;
private const uint MhMagic64 = 0xfeedfacf;
private const uint MhCigam = 0xcefaedfe;
private const uint MhCigam64 = 0xcffaedfe;
internal static readonly uint[] FatHeaders =
[
FatMagic,
FatMagic64,
FatCigam,
FatCigam64
];
internal static readonly uint[] MhHeaders =
[
MhMagic,
MhMagic64,
MhCigam,
MhCigam64
];
}
+68
View File
@@ -0,0 +1,68 @@
using System.Diagnostics;
using static ivinject.Common.Models.BinaryHeaders;
namespace ivinject.Common.Models;
internal class IviMachOBinary(string fileName)
{
private FileInfo FileInfo { get; } = new(fileName);
internal string Name => FileInfo.Name;
internal string FullName => FileInfo.FullName;
internal bool IsFatFile
{
get
{
var header = File.OpenRead(FullName).FileHeader();
return FatHeaders.Contains(header);
}
}
internal string FileSize
{
get
{
FileInfo.Refresh();
var size = FileInfo.Length;
return size switch
{
< 1024 => $"{size:F0} bytes",
_ when size >> 10 < 1024 => $"{size / (float)1024:F1} KB",
_ when size >> 20 < 1024 => $"{(size >> 10) / (float)1024:F1} MB",
_ => $"{(size >> 30) / (float)1024:F1} GB"
};
}
}
internal async Task<bool> IsEncrypted()
{
using var process = Process.Start(
new ProcessStartInfo
{
FileName = "otool",
Arguments = $"-l {FullName}",
RedirectStandardOutput = true
}
);
var output = await process!.StandardOutput.ReadToEndAsync();
return RegularExpressions.OToolEncryptedBinary().IsMatch(output);
}
internal async Task<bool> Thin()
{
using var process = Process.Start(
new ProcessStartInfo
{
FileName = "lipo",
Arguments = $"-thin arm64 {FullName} -output {FullName}"
}
);
await process!.WaitForExitAsync();
return process.ExitCode == 0;
}
}
+12
View File
@@ -0,0 +1,12 @@
using System.Text.RegularExpressions;
namespace ivinject.Common.Models;
internal static partial class RegularExpressions
{
[GeneratedRegex("cryptid 1", RegexOptions.Compiled)]
internal static partial Regex OToolEncryptedBinary();
[GeneratedRegex(@"\.(?:app|\w*ipa)$", RegexOptions.Compiled)]
internal static partial Regex ApplicationPackage();
}