Created
July 16, 2021 08:48
-
-
Save Shkarlatov/901eea13475d38ff55e2d17faf7745c1 to your computer and use it in GitHub Desktop.
Extract qsqlchiper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using SQLite; | |
| using System; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| using System.IO.Compression; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| namespace ConsoleApp1 | |
| { | |
| class Dev | |
| { | |
| public int dev_id { get; set; } | |
| public string dev_name { get; set; } | |
| public string ven_name { get; set; } | |
| public string type_name { get; set; } | |
| public string desc { get; set; } | |
| public string date { get; set; } | |
| public List<object> Files { get; set; } | |
| } | |
| class Data | |
| { | |
| public int data_id { get; set; } | |
| public int dev_id { get; set; } | |
| public sbyte type { get; set; } | |
| public string name { get; set; } | |
| public byte[] bin { get; set; } | |
| } | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| string db_path = ""; | |
| if (args.Length == 1) db_path = args[0]; | |
| else return; | |
| Console.WriteLine($"Input {db_path}"); | |
| Console.WriteLine($"Output {Directory.GetCurrentDirectory()}"); | |
| using (var db = new SQLiteConnection(db_path,SQLiteOpenFlags.ReadOnly)) | |
| { | |
| var key = db.CreateCommand("PRAGMA key='1bc29b36f623ba82aaf6724fd3b16718';"); | |
| key.ExecuteNonQuery(); | |
| Directory.CreateDirectory("data"); | |
| var allDevice = db.CreateCommand("select dev_id,dev_name,ven_name,type_name,desc,date from dev,type,ven where dev.type_id=type.type_id and dev.ven_id=ven.ven_id"); | |
| var q = allDevice.ExecuteQuery<Dev>(); | |
| var total = q.Count; | |
| int count = 0; | |
| foreach (var t in q) | |
| { | |
| string path = Path.Combine("data", t.dev_id.ToString()); | |
| Directory.CreateDirectory(path); | |
| var file = File.CreateText(Path.Combine(path, "info.txt")); | |
| string txt = $"{t.dev_name};{t.ven_name};{t.type_name};{t.date};{t.desc}"; | |
| file.Write(txt); | |
| file.Flush(); | |
| var f = db.CreateCommand("select * from data where dev_id=?", t.dev_id); | |
| var files = f.ExecuteQuery<Data>(); | |
| foreach (var ff in files) | |
| { | |
| string file_path; | |
| switch (ff.type) | |
| { | |
| case 0: | |
| file_path = "Photo"; | |
| break; | |
| case 1: | |
| file_path = "Xray"; | |
| break; | |
| case 2: | |
| file_path = "Pdf"; | |
| break; | |
| default: | |
| throw new ArgumentException("Unknow file type"); | |
| } | |
| string new_path = Path.Combine(path, file_path); | |
| Directory.CreateDirectory(new_path); | |
| if (ff.type == 2) | |
| { | |
| using (var mem = new MemoryStream(ff.bin.Skip(6).ToArray())) | |
| using (var def = new DeflateStream(mem, CompressionMode.Decompress)) | |
| using (var myfile = File.Create(Path.Combine(new_path, ff.name.Replace("bmp", "jpg")))) | |
| { | |
| def.CopyTo(myfile); | |
| myfile.Flush(); | |
| } | |
| } | |
| else | |
| { | |
| using (var myfile = File.Create(Path.Combine(new_path, ff.name.Replace("bmp", "jpg")))) | |
| { | |
| myfile.Write(ff.bin, 0, ff.bin.Length); | |
| myfile.Flush(); | |
| } | |
| } | |
| } | |
| count++; | |
| Console.Write($"{count}\\{total}\r"); | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment