Skip to content

Instantly share code, notes, and snippets.

View vladionescu's full-sized avatar

Vlad Ionescu vladionescu

  • West Coast, USA
View GitHub Profile
// Clean up temp dir
error = nil;
success = [fileManager removeItemAtPath:temporaryDirectoryURL error:&error];
if (!success) {
NSLog(@"Error removing dir %@ at path: %@", temporaryDirectoryURL, error.localizedDescription);
}
@vladionescu
vladionescu / move_to_final_dest.m
Created March 20, 2020 16:52
Move a file from a temporary directory into the current bundle's containing directory
// Name of the final file that the user will see
NSString *finalFileName = @"FileSwap.mp4";
// Move real file from temp to the containing dir
NSURL *finalFileURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@",appParentDirectory,finalFileName]];
error = nil;
[fileManager moveItemAtURL:temporaryFileURL
toURL:finalFileURL
error:&error];
@vladionescu
vladionescu / delete_bundle.m
Created March 20, 2020 16:51
Delete self (app bundle) from disk
// Delete this app directory
error = nil;
BOOL success = [fileManager removeItemAtPath:appBundlePath error:&error];
if (!success) {
NSLog(@"Error removing dir %@ at path: %@", appBundlePath, error.localizedDescription);
}
@vladionescu
vladionescu / get_bundle_path.m
Created March 20, 2020 16:49
Get a bundle's path on disk, as well as its containing directory
// Get paths
NSString *appBundlePath = [thisBundle bundlePath];
NSString *appParentDirectory = [appBundlePath stringByDeletingLastPathComponent];
NSLog(@"Bundle: %@", appBundlePath);
NSLog(@"Parent dir: %@", appParentDirectory);
@vladionescu
vladionescu / move_to_temp.m
Created March 20, 2020 16:45
Move a file from app bundle to an existing temporary directory
// Name of the real file in this bundle's/app's Resources
NSString *originalResourceFileName = @"ErrorVideo";
NSString *originalResourceFileExtension = @"mp4";
// Name the real file will have when copied to a tmp dir for a brief moment
NSString *temporaryFileName = @".nothing_suspicious";
// Move real file out of our bundle into temp, in preparation for removing the bundle
NSBundle* thisBundle = [NSBundle mainBundle];
NSURL *temporaryFileURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",temporaryDirectoryURL,temporaryFileName]];
@vladionescu
vladionescu / make_temp_dir.m
Created March 20, 2020 16:41
Create a temporary directory on the same filesystem as /Users/
// Create the temp dir
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *userDownloadsURL = [NSURL fileURLWithPath:@"/Users/" isDirectory:YES];
NSError *error = nil;
NSURL *temporaryDirectoryURL = [fileManager URLForDirectory:NSItemReplacementDirectory
inDomain:NSUserDomainMask
appropriateForURL:userDownloadsURL
create:YES
error:&error];
@vladionescu
vladionescu / delete_bundle.m
Last active March 20, 2020 01:28
Create a temporary directory on the same filesystem as /Users/
// Delete this app directory
error = nil;
BOOL success = [fileManager removeItemAtPath:appBundlePath error:&error];
if (!success) {
NSLog(@"Error removing dir %@ at path: %@", appBundlePath, error.localizedDescription);
}
@vladionescu
vladionescu / Dockerfile
Created February 20, 2020 21:38
Dockerfile to build and start a golang Keybase bot
# Build the bot golang binary first
FROM golang:1.13-alpine as builder
ENV GOOS=linux \
GOARCH=amd64 \
CGO_ENABLED=0
# Need git for 'go get'
RUN apk update && apk add --no-cache git
@vladionescu
vladionescu / local-dhcp.py
Created September 9, 2019 17:18
Wrapper around dnsmasq to run a local DHCP server, easier to use than reading through all of dnsmasq's arguments.
#!/usr/bin/env python3
import argparse, subprocess
parser = argparse.ArgumentParser(description='Run a local DHCP server.')
parser.add_argument('--interface', '-i', default='en8', help='Listen on interface [default en8]')
parser.add_argument('--bind-ip', '-b', default='192.168.0.2', help='Listen on this IP address (local address for interface) [default 912.168.0.2]')
parser.add_argument('--range', '-r', default='192.168.0.10,192.168.0.50', help='DHCP range for issued client addresses, comma separated [default 192.168.0.10,192.168.0.50]')
args = parser.parse_args()
@vladionescu
vladionescu / try1.py
Created September 3, 2019 21:34
Try to solve FLARE ON 2019 #3
#!/usr/bin/env python3
class Win(object):
ratio_min = 2.0
ratio_max = 2.5
mass = 72
happy = 30
clean = 0
class Try(object):