Skip to content

Commit

Permalink
Adjust bloat patch to only write zero bytes
Browse files Browse the repository at this point in the history
Previously, the bloat patch would still partially leak actual file contents. This commit fixes that so it only writes nonsense that is useless to an attacker.
  • Loading branch information
sleeyax committed Apr 18, 2024
1 parent fe595bd commit cddbf4c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bin/asarmor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ program
.option('-r, --restore', 'restore backup')
.option(
'-bl, --bloat [gigabytes]',
'add huge random files to disk on extraction attempt'
'fill the drive with useless data on extraction attempt'
)
.option('-e, --encrypt <src>', 'encrypt file contents')
.option('-k, --key <file path>', 'key file to use for encryption')
Expand Down
14 changes: 8 additions & 6 deletions src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { Archive, FileEntries } from './asar';

export type Patch = Partial<Archive>;

const CHUNK_SIZE = 1024 * 1024 * 1024;

/**
* Adds a bunch of random files with large sizes to the archive.
*
* This patch will result in huge files being written to disk upon extraction with `asar extract`, so use at your own risk AND responsibility!
* Upon extraction with `asar extract`, this patch will write empty zero-filled (0 bytes) files of the target size in chunks of `1 GB` to disk. Use at your own risk AND responsibility!
*
* Defaults to `100 GB` of bloat.
* Defaults to `100 GB`.
*/
export function createBloatPatch(gigabytes = 10): Patch {
export function createBloatPatch(gigabytes = 100): Patch {
const files: FileEntries = {};

for (let i = 0; i < gigabytes; i++) {
Expand All @@ -19,7 +19,9 @@ export function createBloatPatch(gigabytes = 10): Patch {
while (Object.keys(files).indexOf(filename) > -1)
filename = randomBytes(30).toString('hex');

files[filename] = { offset: '0', size: 1 * 1024 * 1024 * 1024 };
const offset = Number.MAX_SAFE_INTEGER - CHUNK_SIZE;

files[filename] = { offset: offset.toString(), size: CHUNK_SIZE };
}

return {
Expand Down

0 comments on commit cddbf4c

Please sign in to comment.