Skip to content

Commit

Permalink
(chore) remove superfluous namesapce declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
leonjza committed Feb 13, 2022
1 parent c3eedb5 commit 5081750
Show file tree
Hide file tree
Showing 38 changed files with 3,949 additions and 4,017 deletions.
73 changes: 35 additions & 38 deletions agent/src/android/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,51 @@ import {
} from "./lib/libjava";
import { ClipboardManager } from "./lib/types";

export namespace clipboard {
export const monitor = (): Promise<void> => {
// -- Sample Java
//
// ClipboardManager f = (ClipboardManager)getApplicationContext().getSystemService(CLIPBOARD_SERVICE);
// ClipData.Item i = f.getPrimaryClip().getItemAt(0);
// Log.e("t", "?:" + i.getText());

export const monitor = (): Promise<void> => {
// -- Sample Java
//
// ClipboardManager f = (ClipboardManager)getApplicationContext().getSystemService(CLIPBOARD_SERVICE);
// ClipData.Item i = f.getPrimaryClip().getItemAt(0);
// Log.e("t", "?:" + i.getText());
send(`${c.yellowBright("Warning!")} This module is still broken. A pull request fixing it would be awesome!`);

send(`${c.yellowBright("Warning!")} This module is still broken. A pull request fixing it would be awesome!`);
// https://developer.android.com/reference/android/content/Context.html#CLIPBOARD_SERVICE
const CLIPBOARD_SERVICE: string = "clipboard";

// https://developer.android.com/reference/android/content/Context.html#CLIPBOARD_SERVICE
const CLIPBOARD_SERVICE: string = "clipboard";
// a variable for clipboard text
let data: string;

// a variable for clipboard text
let data: string;
return wrapJavaPerform(() => {

return wrapJavaPerform(() => {
const clipboardManager: ClipboardManager = Java.use("android.content.ClipboardManager");
const context = getApplicationContext();
const clipboardHandle = context.getApplicationContext().getSystemService(CLIPBOARD_SERVICE);
const cp = Java.cast(clipboardHandle, clipboardManager);

const clipboardManager: ClipboardManager = Java.use("android.content.ClipboardManager");
const context = getApplicationContext();
const clipboardHandle = context.getApplicationContext().getSystemService(CLIPBOARD_SERVICE);
const cp = Java.cast(clipboardHandle, clipboardManager);
setInterval(() => {

setInterval(() => {
const primaryClip = cp.getPrimaryClip();

const primaryClip = cp.getPrimaryClip();
// Check if there is at least some data
if (primaryClip == null || primaryClip.getItemCount() <= 0) {
return;
}

// Check if there is at least some data
if (primaryClip == null || primaryClip.getItemCount() <= 0) {
return;
}
// If we have managed to get the primary clipboard and there are
// items stored in it, process an update.
const currentString = primaryClip.getItemAt(0).coerceToText(context).toString();

// If we have managed to get the primary clipboard and there are
// items stored in it, process an update.
const currentString = primaryClip.getItemAt(0).coerceToText(context).toString();
// If the data is the same, just stop.
if (data === currentString) {
return;
}

// If the data is the same, just stop.
if (data === currentString) {
return;
}
// Update the data with the new string and report back.
data = currentString;

// Update the data with the new string and report back.
data = currentString;
send(`${c.blackBright(`[pasteboard-monitor]`)} Data: ${c.greenBright(data.toString())}`);

send(`${c.blackBright(`[pasteboard-monitor]`)} Data: ${c.greenBright(data.toString())}`);

}, 1000 * 5);
});
};
}
}, 1000 * 5);
});
};
291 changes: 144 additions & 147 deletions agent/src/android/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,152 +10,149 @@ import {
JavaClass
} from "./lib/types";

export namespace androidfilesystem {

export const exists = (path: string): Promise<boolean> => {
// -- Sample Java
//
// File path = new File(".");
// Boolean e = path.exists();

return wrapJavaPerform(() => {
const file: File = Java.use("java.io.File");
const currentFile: JavaClass = file.$new(path);

return currentFile.exists();
});
};

export const readable = (path: string): Promise<boolean> => {
// -- Sample Java Code
//
// File d = new File(".");
// d.canRead();

return wrapJavaPerform(() => {
const file: File = Java.use("java.io.File");
const currentFile: JavaClass = file.$new(path);

return currentFile.canRead();
});
};

export const writable = (path: string): Promise<boolean> => {
// -- Sample Java Code
//
// File d = new File(".");
// d.canWrite();

return wrapJavaPerform(() => {
const file: File = Java.use("java.io.File");
const currentFile: JavaClass = file.$new(path);

return currentFile.canWrite();
});
};

export const pathIsFile = (path: string): Promise<boolean> => {
// -- Sample Java Code
//
// File d = new File(".");
// d.isFile();

return wrapJavaPerform(() => {
const file: File = Java.use("java.io.File");
const currentFile: JavaClass = file.$new(path);

return currentFile.isFile();
});
};

export const pwd = (): Promise<string> => {
// -- Sample Java
//
// getApplicationContext().getFilesDir().getAbsolutePath()

return wrapJavaPerform(() => {
const context = getApplicationContext();
return context.getFilesDir().getAbsolutePath().toString();
});
};

// heavy lifting is done in frida-fs here.
export const readFile = (path: string): Buffer => {
return fs.readFileSync(path);
};

// heavy lifting is done in frida-fs here.
export const writeFile = (path: string, data: string): void => {
const writeStream: any = fs.createWriteStream(path);

writeStream.on("error", (error: Error) => {
throw error;
});

writeStream.write(hexStringToBytes(data));
writeStream.end();
};

export const deleteFile = (path: string): Promise<boolean> => {
// -- Sample Java Code
//
// File d = new File(".");
// d.delete();

return wrapJavaPerform(() => {
const file: File = Java.use("java.io.File");
const currentFile: JavaClass = file.$new(path);

return currentFile.delete();
});
};

export const ls = (p: string): Promise<IAndroidFilesystem> => {
// -- Sample Java Code
//
// File d = new File(".");
// File[] files = d.listFiles();
// Log.e(getClass().getName(), "Files: " + files.length);
// for (int i = 0; i < files.length; i++) {
// Log.e(getClass().getName(),
// files[i].getName() + ": " + files[i].canRead()
// + " " + files[i].lastModified()
// + " " + files[i].length()
// );
// }

return wrapJavaPerform(() => {
const file: File = Java.use("java.io.File");
const directory: JavaClass = file.$new(p);

const response: IAndroidFilesystem = {
files: {},
path: p,
readable: directory.canRead(),
writable: directory.canWrite(),
export const exists = (path: string): Promise<boolean> => {
// -- Sample Java
//
// File path = new File(".");
// Boolean e = path.exists();

return wrapJavaPerform(() => {
const file: File = Java.use("java.io.File");
const currentFile: JavaClass = file.$new(path);

return currentFile.exists();
});
};

export const readable = (path: string): Promise<boolean> => {
// -- Sample Java Code
//
// File d = new File(".");
// d.canRead();

return wrapJavaPerform(() => {
const file: File = Java.use("java.io.File");
const currentFile: JavaClass = file.$new(path);

return currentFile.canRead();
});
};

export const writable = (path: string): Promise<boolean> => {
// -- Sample Java Code
//
// File d = new File(".");
// d.canWrite();

return wrapJavaPerform(() => {
const file: File = Java.use("java.io.File");
const currentFile: JavaClass = file.$new(path);

return currentFile.canWrite();
});
};

export const pathIsFile = (path: string): Promise<boolean> => {
// -- Sample Java Code
//
// File d = new File(".");
// d.isFile();

return wrapJavaPerform(() => {
const file: File = Java.use("java.io.File");
const currentFile: JavaClass = file.$new(path);

return currentFile.isFile();
});
};

export const pwd = (): Promise<string> => {
// -- Sample Java
//
// getApplicationContext().getFilesDir().getAbsolutePath()

return wrapJavaPerform(() => {
const context = getApplicationContext();
return context.getFilesDir().getAbsolutePath().toString();
});
};

// heavy lifting is done in frida-fs here.
export const readFile = (path: string): Buffer => {
return fs.readFileSync(path);
};

// heavy lifting is done in frida-fs here.
export const writeFile = (path: string, data: string): void => {
const writeStream: any = fs.createWriteStream(path);

writeStream.on("error", (error: Error) => {
throw error;
});

writeStream.write(hexStringToBytes(data));
writeStream.end();
};

export const deleteFile = (path: string): Promise<boolean> => {
// -- Sample Java Code
//
// File d = new File(".");
// d.delete();

return wrapJavaPerform(() => {
const file: File = Java.use("java.io.File");
const currentFile: JavaClass = file.$new(path);

return currentFile.delete();
});
};

export const ls = (p: string): Promise<IAndroidFilesystem> => {
// -- Sample Java Code
//
// File d = new File(".");
// File[] files = d.listFiles();
// Log.e(getClass().getName(), "Files: " + files.length);
// for (int i = 0; i < files.length; i++) {
// Log.e(getClass().getName(),
// files[i].getName() + ": " + files[i].canRead()
// + " " + files[i].lastModified()
// + " " + files[i].length()
// );
// }

return wrapJavaPerform(() => {
const file: File = Java.use("java.io.File");
const directory: JavaClass = file.$new(p);

const response: IAndroidFilesystem = {
files: {},
path: p,
readable: directory.canRead(),
writable: directory.canWrite(),
};

if (!response.readable) { return response; }

// get a listing of the files in the directory
const files: any[] = directory.listFiles();

for (const f of files) {
response.files[f.getName()] = {
attributes: {
isDirectory: f.isDirectory(),
isFile: f.isFile(),
isHidden: f.isHidden(),
lastModified: f.lastModified(),
size: f.length(),
},
fileName: f.getName(),
readable: f.canRead(),
writable: f.canWrite(),
};
}

if (!response.readable) { return response; }

// get a listing of the files in the directory
const files: any[] = directory.listFiles();

for (const f of files) {
response.files[f.getName()] = {
attributes: {
isDirectory: f.isDirectory(),
isFile: f.isFile(),
isHidden: f.isHidden(),
lastModified: f.lastModified(),
size: f.length(),
},
fileName: f.getName(),
readable: f.canRead(),
writable: f.canWrite(),
};
}

return response;
});
};
}
return response;
});
};
Loading

0 comments on commit 5081750

Please sign in to comment.