add exterminated writeup and fix diplodocus typos
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
1 parent
3e9261a7c8
commit
55075855bb
13 files changed
+476
-14
No files matched your search
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
with open('./disk.img', 'rb') as f:
|
||||
data = f.read()
|
||||
blocks = [data[i * 0x1000:(i * 0x1000) + 0x1000] for i in range(len(data) // 0x1000)]
|
||||
|
||||
clear = bytearray()
|
||||
|
||||
for block in blocks:
|
||||
x = 0
|
||||
for b in block:
|
||||
c = x ^ b
|
||||
clear.append(c)
|
||||
x = c
|
||||
|
||||
os.write(1, clear)
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
int64_t encrypt_block(char* block, int64_t len)
|
||||
{
|
||||
int64_t i;
|
||||
for (i = 0; i < len; i = (i + 1))
|
||||
{
|
||||
block[((len - i) - 1)] = (block[((len - i) - 1)] ^ block[((len - i) - 2)]);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
int64_t encrypt_file(char* name)
|
||||
{
|
||||
return encrypt_file2(name);
|
||||
}
|
||||
|
||||
int64_t encrypt_file2(char* name)
|
||||
{
|
||||
int32_t inode = 0;
|
||||
int32_t len_read = 0;
|
||||
uint64_t blocksize = ((uint64_t)fs->blocksize);
|
||||
void* block = xcalloc(1, blocksize); // Allocate data for encrypted block
|
||||
int64_t fd = get_size(name); // Get the file size
|
||||
if (fd != 0)
|
||||
{
|
||||
fd = open(name, 2); // Open the file
|
||||
int32_t fd = fd;
|
||||
if (fd != 0xffffffff)
|
||||
{
|
||||
if (inode == 0)
|
||||
// Create an inode for the encrypted file
|
||||
ext2fs_new_inode(fs, 0, 0x41ed, 0, &inode);
|
||||
|
||||
ext2fs_inode_alloc_stats2(fs, ((uint64_t)inode), 1, 1);
|
||||
char stop = 0;
|
||||
int64_t nb_blocks = 1;
|
||||
uint64_t* blocks = xcalloc(1, 0x10);
|
||||
do
|
||||
{
|
||||
// Fill the block with file data
|
||||
if (fill_block(fd, block, blocksize, &len_read) == 0)
|
||||
break;
|
||||
|
||||
// Determine if another block is needed to encrypt the file
|
||||
int32_t n_blocks = len_read / 0x1000;
|
||||
int32_t len_read;
|
||||
if (len_read % 0x1000 != 0)
|
||||
stop = 1;
|
||||
|
||||
// Encrypt the block
|
||||
encrypt_block(block, ((int64_t)len_read));
|
||||
|
||||
// Write encrypted block to the filesystem
|
||||
int64_t new_block = write_block(block, ((uint64_t)fs->blocksize), inode);
|
||||
|
||||
// Some stuff I did not bother to understand
|
||||
// probably setting up recursive blocks for big files
|
||||
// or preparing new empty blocks for the file that must be
|
||||
// emptied
|
||||
// but I do not know nor does it really matter for now
|
||||
if (blocks[((nb_blocks - 1) * 2)] == 0)
|
||||
{
|
||||
blocks[((nb_blocks - 1) * 2)] = new_block;
|
||||
blocks[(((nb_blocks - 1) * 2) + 1)] = new_block;
|
||||
}
|
||||
else if ((blocks[(((nb_blocks - 1) * 2) + 1)] + 1) != new_block)
|
||||
{
|
||||
nb_blocks = (nb_blocks + 1);
|
||||
realloc(blocks, (nb_blocks << 4));
|
||||
blocks[((nb_blocks - 1) * 2)] = new_block;
|
||||
blocks[(((nb_blocks - 1) * 2) + 1)] = new_block;
|
||||
}
|
||||
else
|
||||
blocks[(((nb_blocks - 1) * 2) + 1)] = new_block;
|
||||
|
||||
memset(block, 0, ((uint64_t)fs->blocksize));
|
||||
} while ((stop & 1) == 0);
|
||||
// Remove data from the original file
|
||||
fd = delete_data(name, nb_blocks, blocks);
|
||||
}
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
DIR* encrypt_folder(char* path, void* callback)
|
||||
{
|
||||
DIR* dir = opendir(path);
|
||||
if (dir != 0)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
struct dirent64* dirent = readdir(dir);
|
||||
if (dirent == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (((uint32_t)dirent->d_type) != 4)
|
||||
{
|
||||
callback(&dirent->d_name);
|
||||
}
|
||||
else if ((strcmp(&dirent->d_name, ".") != 0 && strcmp(&dirent->d_name, "..") != 0))
|
||||
{
|
||||
chdir(&dirent->d_name);
|
||||
encrypt_folder(".", callback);
|
||||
}
|
||||
}
|
||||
chdir("..");
|
||||
dir = closedir(dir);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 90 MiB |
@@ -0,0 +1,43 @@
|
||||
int32_t main(int32_t argc, char** argv, char** envp)
|
||||
{
|
||||
int32_t res;
|
||||
if (argc != 2)
|
||||
{
|
||||
char** rax;
|
||||
rax = 0;
|
||||
printf("Usage %s <device> \n", *(int64_t*)argv);
|
||||
res = 1;
|
||||
}
|
||||
else if (check_fs_opened() != 0)
|
||||
{
|
||||
res = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
open_and_read(argv[1]);
|
||||
if (fs == 0)
|
||||
{
|
||||
perror("Could not get handle on FS");
|
||||
exit(1);
|
||||
/* no return */
|
||||
}
|
||||
if (check_flag_clear() != 0)
|
||||
{
|
||||
res = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fs->blocksize != 0x1000)
|
||||
{
|
||||
perror("FS blocksize is invalid");
|
||||
exit(1);
|
||||
/* no return */
|
||||
}
|
||||
encrypt_folder(".", encrypt_file);
|
||||
ext2fs_flush(fs);
|
||||
write_inode_bitmap();
|
||||
res = 0;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 191 KiB |