frida-screenshot 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2 -2
- package/dist/lib/ios.d.ts +2 -1
- package/dist/lib/ios.js +29 -13
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import ObjC from "frida-objc-bridge";
|
|
2
|
-
export default function screenshot(view: ObjC.Object): Promise<ArrayBuffer>;
|
|
2
|
+
export default function screenshot(view: ObjC.Object, options?: ScreenshotOptions): Promise<ArrayBuffer>;
|
|
3
|
+
export interface ScreenshotOptions {
|
|
4
|
+
constrainSize?: number;
|
|
5
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@ import ObjC from "frida-objc-bridge";
|
|
|
2
2
|
import { ios } from './lib/ios.js';
|
|
3
3
|
const IOS = Symbol('ios');
|
|
4
4
|
const UNKNOWN = Symbol('unknown');
|
|
5
|
-
export default function screenshot(view) {
|
|
5
|
+
export default function screenshot(view, options) {
|
|
6
6
|
if (getOS() === IOS) {
|
|
7
|
-
return ios(view);
|
|
7
|
+
return ios(view, options);
|
|
8
8
|
}
|
|
9
9
|
else {
|
|
10
10
|
return new Promise(function (_, reject) {
|
package/dist/lib/ios.d.ts
CHANGED
package/dist/lib/ios.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import ObjC from "frida-objc-bridge";
|
|
2
|
-
const CGFloat = (Process.pointerSize === 4) ? 'float' : 'double';
|
|
3
|
-
const CGSize = [CGFloat, CGFloat];
|
|
4
2
|
const blocks = new Set();
|
|
5
|
-
export function ios(view) {
|
|
3
|
+
export function ios(view, options) {
|
|
6
4
|
return performOnMainThread(() => {
|
|
7
5
|
const api = getApi();
|
|
8
6
|
if (api === null) {
|
|
@@ -13,10 +11,29 @@ export function ios(view) {
|
|
|
13
11
|
}
|
|
14
12
|
const bounds = view.bounds();
|
|
15
13
|
const size = bounds[1];
|
|
16
|
-
api.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const format = api.UIGraphicsImageRendererFormat.preferredFormat();
|
|
15
|
+
const constrainSize = options?.constrainSize;
|
|
16
|
+
if (constrainSize !== undefined) {
|
|
17
|
+
if (typeof constrainSize !== "number" || constrainSize <= 0) {
|
|
18
|
+
throw new Error("Invalid constrainSize value");
|
|
19
|
+
}
|
|
20
|
+
const maxDimension = Math.max(size[0], size[1]);
|
|
21
|
+
const scale = format.scale().valueOf();
|
|
22
|
+
if (maxDimension * scale > constrainSize) {
|
|
23
|
+
format.setScale_(constrainSize / maxDimension);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const renderer = api.UIGraphicsImageRenderer.alloc().initWithSize_format_(size, format).autorelease();
|
|
27
|
+
const actionBlock = new ObjC.Block({
|
|
28
|
+
argTypes: ["object"],
|
|
29
|
+
retType: "void",
|
|
30
|
+
implementation: () => {
|
|
31
|
+
view.drawViewHierarchyInRect_afterScreenUpdates_(bounds, true);
|
|
32
|
+
setTimeout(() => blocks.delete(actionBlock), 0);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
blocks.add(actionBlock);
|
|
36
|
+
const image = renderer.imageWithActions_(actionBlock);
|
|
20
37
|
const png = new ObjC.Object(api.UIImagePNGRepresentation(image));
|
|
21
38
|
const data = png.bytes();
|
|
22
39
|
return data.readByteArray(png.length());
|
|
@@ -39,7 +56,7 @@ function performOnMainThread(action) {
|
|
|
39
56
|
return;
|
|
40
57
|
}
|
|
41
58
|
const block = new ObjC.Block({
|
|
42
|
-
retType:
|
|
59
|
+
retType: "void",
|
|
43
60
|
argTypes: [],
|
|
44
61
|
implementation() {
|
|
45
62
|
try {
|
|
@@ -61,15 +78,14 @@ function performOnMainThread(action) {
|
|
|
61
78
|
let cachedApi = null;
|
|
62
79
|
function getApi() {
|
|
63
80
|
if (cachedApi === null) {
|
|
64
|
-
const uikit = Process.getModuleByName(
|
|
81
|
+
const uikit = Process.getModuleByName("UIKit");
|
|
65
82
|
cachedApi = {
|
|
66
83
|
UIApplication: ObjC.classes.UIApplication,
|
|
67
84
|
UIWindow: ObjC.classes.UIWindow,
|
|
85
|
+
UIGraphicsImageRendererFormat: ObjC.classes.UIGraphicsImageRendererFormat,
|
|
86
|
+
UIGraphicsImageRenderer: ObjC.classes.UIGraphicsImageRenderer,
|
|
68
87
|
NSThread: ObjC.classes.NSThread,
|
|
69
|
-
|
|
70
|
-
UIGraphicsEndImageContext: new NativeFunction(uikit.getExportByName('UIGraphicsEndImageContext'), 'void', []),
|
|
71
|
-
UIGraphicsGetImageFromCurrentImageContext: new NativeFunction(uikit.getExportByName('UIGraphicsGetImageFromCurrentImageContext'), 'pointer', []),
|
|
72
|
-
UIImagePNGRepresentation: new NativeFunction(uikit.getExportByName('UIImagePNGRepresentation'), 'pointer', ['pointer'])
|
|
88
|
+
UIImagePNGRepresentation: new NativeFunction(uikit.getExportByName("UIImagePNGRepresentation"), "pointer", ["pointer"])
|
|
73
89
|
};
|
|
74
90
|
}
|
|
75
91
|
return cachedApi;
|