Refactor environment hooks to use a namespace instead of a class.

This commit is contained in:
Leon Jacobs
2018-08-31 21:27:09 +02:00
parent f92bc39d10
commit 6f3e3d85ac
3 changed files with 45 additions and 41 deletions
+41 -38
View File
@@ -5,17 +5,29 @@ import { NSBundle } from "../ios/lib/types";
import { DeviceType } from "../lib/constants";
import { IAndroidPackage, IFridaInfo, IIosBundlePaths, IIosPackage } from "../lib/interfaces";
export class Environment {
export namespace environment {
public runtime(): string {
// small helper function to lookup ios bundle paths
const getPathForNSLocation = (NSPath: NSSearchPaths): string => {
const p = getNSFileManager().URLsForDirectory_inDomains_(NSPath, NSUserDomainMask).lastObject();
if (p) {
return p.path().toString();
}
return "";
};
export const runtime = (): string => {
if (ObjC.available) { return DeviceType.IOS; }
if (Java.available) { return DeviceType.ANDROID; }
return DeviceType.UNKNOWN;
}
};
public frida(): IFridaInfo {
export const frida = (): IFridaInfo => {
return {
arch: Process.arch,
@@ -24,9 +36,18 @@ export class Environment {
platform: Process.platform,
version: Frida.version,
};
}
};
public iosPackage(): IIosPackage {
export const iosPackage = (): IIosPackage => {
// -- Sample Objective-C
//
// NSFileManager *fm = [NSFileManager defaultManager];
// NSString *pictures = [[fm URLsForDirectory:NSPicturesDirectory inDomains:NSUserDomainMask] lastObject].path;
// NSBundle *bundle = [NSBundle mainBundle];
// NSString *bundlePath = [bundle bundlePath];
// NSString *receipt = [bundle appStoreReceiptURL].path;
// NSString *resourcePath = [bundle resourcePath];
const { UIDevice } = ObjC.classes;
const mb: NSBundle = getNSMainBundle();
@@ -39,30 +60,21 @@ export class Environment {
systemName: UIDevice.currentDevice().systemName().toString(),
systemVersion: UIDevice.currentDevice().systemVersion().toString(),
};
};
// -- Sample Objective-C
//
// NSFileManager *fm = [NSFileManager defaultManager];
// NSString *pictures = [[fm URLsForDirectory:NSPicturesDirectory inDomains:NSUserDomainMask] lastObject].path;
// NSBundle *bundle = [NSBundle mainBundle];
// NSString *bundlePath = [bundle bundlePath];
// NSString *receipt = [bundle appStoreReceiptURL].path;
// NSString *resourcePath = [bundle resourcePath];
}
public iosPaths(): IIosBundlePaths {
export const iosPaths = (): IIosBundlePaths => {
const mb: NSBundle = getNSMainBundle();
return {
BundlePath: mb.bundlePath().toString(),
CachesDirectory: this.getPathForNSLocation(NSSearchPaths.NSCachesDirectory),
DocumentDirectory: this.getPathForNSLocation(NSSearchPaths.NSDocumentDirectory),
LibraryDirectory: this.getPathForNSLocation(NSSearchPaths.NSLibraryDirectory),
CachesDirectory: getPathForNSLocation(NSSearchPaths.NSCachesDirectory),
DocumentDirectory: getPathForNSLocation(NSSearchPaths.NSDocumentDirectory),
LibraryDirectory: getPathForNSLocation(NSSearchPaths.NSLibraryDirectory),
};
}
};
public androidPackage(): Promise<IAndroidPackage> {
export const androidPackage = (): Promise<IAndroidPackage> => {
return wrapJavaPerform(() => {
@@ -82,9 +94,13 @@ export class Environment {
version: Java.androidVersion,
};
});
}
};
public androidPaths(): any {
export const androidPaths = (): Promise<any> => {
// -- Sample Java
//
// getApplicationContext().getFilesDir().getAbsolutePath()
return wrapJavaPerform(() => {
@@ -100,18 +116,5 @@ export class Environment {
packageCodePath: context.getPackageCodePath().toString(),
};
});
// -- Sample Java
//
// getApplicationContext().getFilesDir().getAbsolutePath()
}
private getPathForNSLocation(NSPath: NSSearchPaths): string {
const p = getNSFileManager().URLsForDirectory_inDomains_(NSPath, NSUserDomainMask).lastObject();
if (p) { return p.path().toString(); }
return "";
}
};
}
+1 -2
View File
@@ -1,5 +1,5 @@
import { AndroidFilesystem } from "./android/filesystem";
import { Environment } from "./generic/environment";
import { environment } from "./generic/environment";
import { IosFilesystem } from "./ios/filesystem";
import { IosJailBreak } from "./ios/jailbreak";
import { IosKeychain } from "./ios/keychain";
@@ -9,7 +9,6 @@ import { Jobs } from "./lib/jobs";
import { version } from "./version";
const jobs: Jobs = new Jobs();
const environment: Environment = new Environment();
const keychain: IosKeychain = new IosKeychain();
const androidfilesystem: AndroidFilesystem = new AndroidFilesystem();
+3 -1
View File
@@ -4,7 +4,9 @@
"tslint:recommended"
],
"jsRules": {},
"rules": {},
"rules": {
"no-namespace": false
},
"rulesDirectory": [],
"alwaysShowStatus": true
}