-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
236 lines (191 loc) · 7.26 KB
/
main.cpp
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
MIT License
Copyright (c) 2024 Aleksandr Yuschenko
Support
https://t.me/Alex_Yuschenko
https://vsyst.ru
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <stdio.h>
#include <unistd.h>
#include <cstring>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <cstdint>
#include "vMP4.h"
#include "help.h"
#define BUFF_SIZE 5000000
#define OPN_VOL_HDR_SZ 0x10000
#define MAX_FILE_SIZE 4294000000
#define ERROR "\nERROR\n%s\n"
int main(int argc, char** argv)
{
const char* path_video;
const char* path_vera;
if ((argc == 2) and (!strcmp(argv[1],"-h")))
{
puts(HELP);
return 0;
}
else if (argc == 3)
{
path_video = argv[1];
path_vera = argv[2];
}
else
{
puts(PROMPT);
return 0;
}
mp4_tree* tree_mp4;
int32_t fd_video, fd_vera, fd_hidden;
uint64_t size_video, size_vera;
uint32_t size_new_mdat;
char* path_hidden;
struct stat finfo;
uint8_t buff[BUFF_SIZE];
uint32_t len;
printf("\nParsing video file...");
tree_mp4 = mp4_tree_new();
if ((mp4_parse(path_video, tree_mp4)) || (tree_mp4->mdat.offset + 8 != tree_mp4->moov.traks[0].mdia.minf.stbl.stco.chunks_offsets[2]))
{
printf(ERROR, "MP4 file parsing faild, please try to use another");
return -1;
}
size_video = (!stat(path_video, &finfo)) ? (uint64_t)finfo.st_size : 0;
if (size_video < 1)
{
printf(ERROR, "MP4 file size is too low");
return -1;
}
fd_video = open(path_video, O_RDONLY);
if (fd_video < 0)
{
printf(ERROR, "MP4 file open");
return -1;
}
printf("OK!\n");
printf("Parsing veracrypt file...");
size_vera = (!stat(path_vera, &finfo)) ? (uint64_t)finfo.st_size : 0;
if (size_vera < OPN_VOL_HDR_SZ * 2)
{
printf(ERROR, "Veracrypt file size is too low");
return -1;
}
if ((size_vera + size_video) > MAX_FILE_SIZE)
{
printf(ERROR, "Resulting file size cannot exceed 4294 MB");
return -1;
}
fd_vera = open(path_vera, O_RDONLY);
if (fd_vera < 0)
{
printf(ERROR, "Veracrypt file open");
return -1;
}
printf("OK!\n");
printf("Please wait.\nMaking resulting file...");
len = strlen(path_vera) + 5;
path_hidden = new char[len];
sprintf(path_hidden, "%s.mp4", path_vera);
fd_hidden = open(path_hidden, O_WRONLY | O_CREAT | O_TRUNC);
delete []path_hidden;
if (fd_hidden < 0)
{
printf(ERROR, "Resulting file create / open");
return -1;
}
uint32_t bytes_to_read;
uint32_t new_stco_offset;
uint32_t write_all = 0;
bytes_to_read = tree_mp4->ftyp.size;
lseek(fd_video, tree_mp4->ftyp.offset, SEEK_SET);
while (bytes_to_read > 0)
{
len = read(fd_video, buff, (bytes_to_read <= BUFF_SIZE) ? bytes_to_read : BUFF_SIZE);
bytes_to_read -= len;
write (fd_hidden, buff, len);
}
size_new_mdat = __builtin_bswap32((uint32_t)size_vera + tree_mp4->mdat.size - tree_mp4->ftyp.size - 8);
write (fd_hidden, &size_new_mdat, 4);
write (fd_hidden, MDAT, 4);
len = OPN_VOL_HDR_SZ - 8 - tree_mp4->ftyp.size;
for (uint32_t i = 0; i < len; i++) buff[i] = rand() % 255;
write (fd_hidden, buff, len);
bytes_to_read = size_vera - OPN_VOL_HDR_SZ;
lseek(fd_vera, OPN_VOL_HDR_SZ, SEEK_SET);
while (bytes_to_read > 0)
{
len = read(fd_vera, buff, (bytes_to_read <= BUFF_SIZE) ? bytes_to_read : BUFF_SIZE);
bytes_to_read -= len;
write (fd_hidden, buff, len);
}
bytes_to_read = tree_mp4->mdat.size - 8;
lseek(fd_video, tree_mp4->mdat.offset + 8, SEEK_SET);
while (bytes_to_read > 0)
{
len = read(fd_video, buff, (bytes_to_read <= BUFF_SIZE) ? bytes_to_read : BUFF_SIZE);
bytes_to_read -= len;
write (fd_hidden, buff, len);
}
bytes_to_read = tree_mp4->moov.traks[0].mdia.minf.stbl.stco.offset - tree_mp4->moov.offset + 8;
lseek(fd_video, tree_mp4->moov.offset, SEEK_SET);
while (bytes_to_read > 0)
{
len = read(fd_video, buff, (bytes_to_read <= BUFF_SIZE) ? bytes_to_read : BUFF_SIZE);
bytes_to_read -= len;
write_all += write (fd_hidden, buff, len);
}
for (uint32_t i = 0; i < tree_mp4->moov.traks[0].mdia.minf.stbl.stco.chunks_num; i++)
{
if (i > 1) new_stco_offset = __builtin_bswap32(tree_mp4->moov.traks[0].mdia.minf.stbl.stco.chunks_offsets[i] - tree_mp4->moov.traks[0].mdia.minf.stbl.stco.chunks_offsets[2] + (uint32_t)size_vera);
else new_stco_offset = __builtin_bswap32(tree_mp4->moov.traks[0].mdia.minf.stbl.stco.chunks_offsets[i]);
write_all += write (fd_hidden, &new_stco_offset, 4);
}
bytes_to_read = tree_mp4->moov.traks[1].mdia.minf.stbl.stco.offset - tree_mp4->moov.traks[0].mdia.minf.stbl.stco.offset - tree_mp4->moov.traks[0].mdia.minf.stbl.stco.size + 8;
lseek(fd_video, tree_mp4->moov.traks[0].mdia.minf.stbl.stco.offset + tree_mp4->moov.traks[0].mdia.minf.stbl.stco.size, SEEK_SET);
while (bytes_to_read > 0)
{
len = read(fd_video, buff, (bytes_to_read <= BUFF_SIZE) ? bytes_to_read : BUFF_SIZE);
bytes_to_read -= len;
write_all += write (fd_hidden, buff, len);
}
for (uint32_t i = 0; i < tree_mp4->moov.traks[1].mdia.minf.stbl.stco.chunks_num; i++)
{
if (i > 1) new_stco_offset = __builtin_bswap32(tree_mp4->moov.traks[1].mdia.minf.stbl.stco.chunks_offsets[i] - tree_mp4->moov.traks[0].mdia.minf.stbl.stco.chunks_offsets[2] + (uint32_t)size_vera);
else new_stco_offset = __builtin_bswap32(tree_mp4->moov.traks[1].mdia.minf.stbl.stco.chunks_offsets[i]);
write_all += write (fd_hidden, &new_stco_offset, 4);
}
bytes_to_read = tree_mp4->moov.size - write_all;
lseek(fd_video, tree_mp4->moov.traks[1].mdia.minf.stbl.stco.offset + tree_mp4->moov.traks[1].mdia.minf.stbl.stco.size, SEEK_SET);
while (bytes_to_read > 0)
{
len = read(fd_video, buff, (bytes_to_read <= BUFF_SIZE) ? bytes_to_read : BUFF_SIZE);
bytes_to_read -= len;
write_all += write (fd_hidden, buff, len);
}
close (fd_video);
close (fd_vera);
close (fd_hidden);
unlink(path_vera);
unlink(path_video);
mp4_tree_free(tree_mp4);
printf("OK!\n");
return 0;
}