Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
finish
  • Loading branch information
fiseleo authored May 26, 2024
1 parent 5c05b56 commit 41e0d68
Show file tree
Hide file tree
Showing 50 changed files with 7,881 additions and 0 deletions.
53 changes: 53 additions & 0 deletions BAdownload/APK.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Diagnostics;
using System.IO;

class APK
{
public static void Main(string[] args)
{

string pythonInterpreterRelativePath = @"python\python.exe";
string pythonScriptRelativePath = @"python\download_apk.py";
string currentDirectory = Environment.CurrentDirectory;
string fullPathToPythonInterpreter = Path.GetFullPath(Path.Combine(currentDirectory, pythonInterpreterRelativePath));
string fullPathToPythonScript = Path.GetFullPath(Path.Combine(currentDirectory, pythonScriptRelativePath));
Console.WriteLine($"Python Interpreter Path: {fullPathToPythonInterpreter}");
Console.WriteLine($"Python Script Path: {fullPathToPythonScript}");
if (!File.Exists(fullPathToPythonInterpreter))
{
Console.WriteLine($"Error: Python interpreter not found at {fullPathToPythonInterpreter}");
return;
}

if (!File.Exists(fullPathToPythonScript))
{
Console.WriteLine($"Error: Python script not found at {fullPathToPythonScript}");
return;
}

ProcessStartInfo start = new ProcessStartInfo();
start.FileName = fullPathToPythonInterpreter;
start.Arguments = fullPathToPythonScript;
start.WorkingDirectory = Path.GetDirectoryName(fullPathToPythonInterpreter);
start.UseShellExecute = false;
start.RedirectStandardOutput = true;

try
{
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.WriteLine(result);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
APKzip.zipMain(args);
}
}
81 changes: 81 additions & 0 deletions BAdownload/APKver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;

class APKver
{
public static async Task verMain(string[] args)
{
string pythonInterpreterRelativePath = @"python\python.exe";
string pythonScriptRelativePath = @"python\local_info.py";

string currentDirectory = Environment.CurrentDirectory;

string fullPathToPythonInterpreter = Path.GetFullPath(Path.Combine(currentDirectory, pythonInterpreterRelativePath));
string fullPathToPythonScript = Path.GetFullPath(Path.Combine(currentDirectory, pythonScriptRelativePath));

Console.WriteLine($"Python Interpreter Path: {fullPathToPythonInterpreter}");
Console.WriteLine($"Python Script Path: {fullPathToPythonScript}");

if (!File.Exists(fullPathToPythonInterpreter))
{
Console.WriteLine($"Error: Python interpreter not found at {fullPathToPythonInterpreter}");
return;
}

if (!File.Exists(fullPathToPythonScript))
{
Console.WriteLine($"Error: Python script not found at {fullPathToPythonScript}");
return;
}

ProcessStartInfo start = new ProcessStartInfo
{
FileName = fullPathToPythonInterpreter,
Arguments = fullPathToPythonScript,
WorkingDirectory = Path.GetDirectoryName(fullPathToPythonInterpreter),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};

try
{
using (Process process = Process.Start(start))
{
if (process == null)
{
Console.WriteLine("Error: Unable to start the process.");
return;
}

using (StreamReader reader = process.StandardOutput)
{

string result = reader.ReadToEnd();
Console.WriteLine(result);
}

using (StreamReader errorReader = process.StandardError)
{

string errors = errorReader.ReadToEnd();
if (!string.IsNullOrEmpty(errors))
{
Console.WriteLine($"Errors: {errors}");
}
}

await process.WaitForExitAsync();
}


await url.urlMain(args);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
52 changes: 52 additions & 0 deletions BAdownload/APKzip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.IO;
using System.IO.Compression;

class APKzip
{
public static async void zipMain(string[] args)
{
string downloadedApkRelativePath = @"python\APK\com.YostarJP.BlueArchive.apk";
string extractionRelativePath = @"python\APK\unzip";

try
{
string currentDirectory = Environment.CurrentDirectory;
string downloadedApkFilePath = Path.Combine(currentDirectory, downloadedApkRelativePath);
string extractionPath = Path.Combine(currentDirectory, extractionRelativePath);

Directory.CreateDirectory(extractionPath);

using (ZipArchive archive = ZipFile.OpenRead(downloadedApkFilePath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
string entryFullName = Path.Combine(extractionPath, entry.FullName);
string entryDirectory = Path.GetDirectoryName(entryFullName);

if (string.IsNullOrEmpty(entryDirectory))
continue; // Skip if the entry is for directory

if (!Directory.Exists(entryDirectory))
Directory.CreateDirectory(entryDirectory);

if (File.Exists(entryFullName))
{
Console.WriteLine($"Skipped: {entryFullName} already exists.");
continue; // Skip if the file already exists
}

entry.ExtractToFile(entryFullName);
}
}

Console.WriteLine("APK extracted successfully!");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
await APKver.verMain(args);
}
}

24 changes: 24 additions & 0 deletions BAdownload/BAdownload.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="K4os.Hash.xxHash" Version="1.0.8" />
<PackageReference Include="MemoryPack" Version="1.21.1" />
<PackageReference Include="MemoryPack.Generator" Version="1.21.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Standart.Hash.xxHash" Version="4.0.5" />
<PackageReference Include="System.Data.HashFunction.xxHash" Version="2.0.0" />
<PackageReference Include="XXHash3.NET" Version="2.1.0" />
<PackageReference Include="xxHashSharp" Version="1.0.0" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions BAdownload/BAdownload.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BAdownload", "BAdownload.csproj", "{BDDC6BDD-028D-45C7-B11B-63F6F98E7A27}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BDDC6BDD-028D-45C7-B11B-63F6F98E7A27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BDDC6BDD-028D-45C7-B11B-63F6F98E7A27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BDDC6BDD-028D-45C7-B11B-63F6F98E7A27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BDDC6BDD-028D-45C7-B11B-63F6F98E7A27}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F47CE968-4A68-4507-92DE-E2288AEDE088}
EndGlobalSection
EndGlobal
92 changes: 92 additions & 0 deletions BAdownload/Crc32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System.Security.Cryptography;
public class Crc32 : HashAlgorithm
{
public const uint DefaultPolynomial = 0xedb88320u;
public const uint DefaultSeed = 0xffffffffu;

private uint hash;
private readonly uint seed;
private readonly uint[] table;
private static uint[] defaultTable;

public Crc32()
: this(DefaultPolynomial, DefaultSeed)
{
}

public Crc32(uint polynomial, uint seed)
{
if (!BitConverter.IsLittleEndian)
throw new PlatformNotSupportedException("Not implemented for big-endian platforms");
table = InitializeTable(polynomial);
this.seed = hash = seed;
}

public override void Initialize()
{
hash = seed;
}

protected override void HashCore(byte[] array, int ibStart, int cbSize)
{
hash = CalculateHash(table, hash, array, ibStart, cbSize);
}

protected override byte[] HashFinal()
{
var hashBuffer = UInt32ToBigEndianBytes(~hash);
HashValue = hashBuffer;
return hashBuffer;
}

public override int HashSize => 32;

public uint Value => ~hash;

public void Update(byte[] buffer, int start, int size)
{
hash = CalculateHash(table, hash, buffer, start, size);
}

private static uint[] InitializeTable(uint polynomial)
{
if (polynomial == DefaultPolynomial && defaultTable != null)
return defaultTable;

var createTable = new uint[256];
for (var i = 0; i < 256; i++)
{
var entry = (uint)i;
for (var j = 0; j < 8; j++)
if ((entry & 1) == 1)
entry = (entry >> 1) ^ polynomial;
else
entry >>= 1;
createTable[i] = entry;
}

if (polynomial == DefaultPolynomial)
defaultTable = createTable;

return createTable;
}

private static uint CalculateHash(uint[] table, uint seed, IList<byte> buffer, int start, int size)
{
var crc = seed;
for (var i = start; i < size - start; i++)
crc = (crc >> 8) ^ table[buffer[i] ^ crc & 0xff];
return crc;
}

private byte[] UInt32ToBigEndianBytes(uint x)
{
return new[]
{
(byte)((x >> 24) & 0xff),
(byte)((x >> 16) & 0xff),
(byte)((x >> 8) & 0xff),
(byte)(x & 0xff)
};
}
}
Loading

0 comments on commit 41e0d68

Please sign in to comment.