-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfakeheaderzip-.cs
More file actions
118 lines (116 loc) · 4.07 KB
/
Copy pathfakeheaderzip-.cs
File metadata and controls
118 lines (116 loc) · 4.07 KB
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
using System.Security.Cryptography;
using System.Text;
namespace EncFileCodec
{
internal class EncFileCodec
{
static void Main(string[] args)
{
//parseargs
List<string> argsnew = new List<string>();
for (int i = 0; i < args.Length; i++)
{
if (!args[i].Contains("\"")) argsnew.Add(args[i]);
else
{
string arg = args[i] + " ";
int j = 1;
while (true)
{
if (!args[i + j].Contains("\""))
{
arg += args[i + j] + " ";
}
else
{
arg += args[i + j];
break;
}
j++;
}
argsnew.Add(arg);
i += j;
}
}
args = argsnew.ToArray();
//
foreach (string arg in args)
{
FileStream fs = new(arg, FileMode.Open, FileAccess.Read);
long pos = -1;
string real = string.Empty;
pos = IndexOf(fs, zip, 0);
if(pos > 0)
{
real = ".zip";
goto Here;
}
pos = IndexOf(fs, rar, 0);
if (pos > 0)
{
real = ".rar";
goto Here;
}
pos = IndexOf(fs, sevenz, 0);
if (pos > 0)
{
real = ".7z";
goto Here;
}
//
if (real == string.Empty)
{
Console.WriteLine($"{arg} Failed. Compressed files may not be included.");
continue;
}
Here:
FileStream fsc = new(arg + real, FileMode.OpenOrCreate, FileAccess.Write);
fs.Position = pos;
fs.CopyTo(fsc);
fsc.Close();
FileStream fsh = new(arg + ".header", FileMode.OpenOrCreate, FileAccess.Write);
fs.Position = 0;
byte[] b = new byte[pos];
int i = fs.Read(b);
fsh.Write(b,0,i);
Console.WriteLine($"{arg} Done!");
}
}
public static byte[] zip = { 0x50,0x4b,0x03,0x04};
public static byte[] rar = { 0x52 ,0x61 ,0x72 ,0x21 ,0x1A ,0x07 ,0x00 };
public static byte[] sevenz = { 0x37 ,0x7A, 0xBC ,0xAF ,0x27 ,0x1C };
public static long IndexOf(FileStream srcBytes, byte[] searchBytes, long offset = 0)
{
if (offset == -1) { return -1; }
if (srcBytes == null) { return -1; }
if (searchBytes == null) { return -1; }
if (srcBytes.Length == 0) { return -1; }
if (searchBytes.Length == 0) { return -1; }
if (srcBytes.Length < searchBytes.Length) { return -1; }
for (long i = offset; i < srcBytes.Length - searchBytes.Length; i++)
{
if (GetByte(srcBytes,i) != searchBytes[0]) continue;
if (searchBytes.Length == 1) { return i; }
var flag = true;
for (long j = 1; j < searchBytes.Length; j++)
{
if (GetByte(srcBytes, i + j) != searchBytes[j])
{
flag = false;
break;
}
}
if (flag) { return i; }
}
return -1;
}
public static byte GetByte(FileStream fs,long pos)
{
fs.Position = pos;
byte b = (byte)fs.ReadByte();
fs.Position--;
return b;
}
}
}