@configura/web-core 2.1.0-alpha.2 → 2.1.0-alpha.3
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/.eslintrc.json +5 -5
- package/LICENSE +201 -201
- package/README.md +1 -1
- package/dist/cm/basic/Color.d.ts +16 -16
- package/dist/cm/basic/Color.js +18 -18
- package/dist/cm/basic/ColorF.d.ts +9 -9
- package/dist/cm/basic/ColorF.js +10 -10
- package/dist/cm/basic/boolean.d.ts +2 -2
- package/dist/cm/basic/boolean.js +11 -11
- package/dist/cm/basic/number.d.ts +3 -3
- package/dist/cm/basic/number.js +18 -18
- package/dist/cm/basic/string.d.ts +2 -2
- package/dist/cm/basic/string.js +11 -11
- package/dist/cm/core3D/ATriMeshF.d.ts +96 -96
- package/dist/cm/core3D/ATriMeshF.js +197 -197
- package/dist/cm/core3D/GMaterial3D.d.ts +62 -62
- package/dist/cm/core3D/GMaterial3D.js +112 -112
- package/dist/cm/core3D/GMaterialClassic.d.ts +55 -55
- package/dist/cm/core3D/GMaterialClassic.js +171 -171
- package/dist/cm/core3D/GMaterialPBR.d.ts +73 -73
- package/dist/cm/core3D/GMaterialPBR.js +314 -314
- package/dist/cm/core3D/MultiGMaterial3D.d.ts +8 -8
- package/dist/cm/core3D/MultiGMaterial3D.js +17 -17
- package/dist/cm/core3D/uvmapper/UVMapEnv.d.ts +19 -19
- package/dist/cm/core3D/uvmapper/UVMapEnv.js +47 -47
- package/dist/cm/core3D/uvmapper/UVMapper.d.ts +41 -41
- package/dist/cm/core3D/uvmapper/UVMapper.js +94 -94
- package/dist/cm/core3D/uvmapper/UVMapperBox.d.ts +4 -4
- package/dist/cm/core3D/uvmapper/UVMapperBox.js +181 -181
- package/dist/cm/core3D/uvmapper/UVMapperCylinder.d.ts +9 -9
- package/dist/cm/core3D/uvmapper/UVMapperCylinder.js +96 -96
- package/dist/cm/core3D/uvmapper/UVMapperPlane.d.ts +3 -3
- package/dist/cm/core3D/uvmapper/UVMapperPlane.js +84 -84
- package/dist/cm/core3D/uvmapper/UVTransformer.d.ts +5 -5
- package/dist/cm/core3D/uvmapper/UVTransformer.js +5 -5
- package/dist/cm/core3D/uvmapper/instantiateUVMapper.d.ts +3 -3
- package/dist/cm/core3D/uvmapper/instantiateUVMapper.js +4 -4
- package/dist/cm/format/cmsym/InvalidationEnv.d.ts +9 -9
- package/dist/cm/format/cmsym/InvalidationEnv.js +13 -13
- package/dist/cm/format/cmsym/SymImportEnv.d.ts +9 -9
- package/dist/cm/format/cmsym/SymImportEnv.js +9 -9
- package/dist/cm/format/cmsym/SymInv.d.ts +8 -8
- package/dist/cm/format/cmsym/SymInv.js +17 -17
- package/dist/cm/format/cmsym/SymNode.d.ts +94 -94
- package/dist/cm/format/cmsym/SymNode.js +652 -652
- package/dist/cm/format/cmsym/components/SymBox.d.ts +15 -15
- package/dist/cm/format/cmsym/components/SymBox.js +39 -39
- package/dist/cm/format/cmsym/components/SymComponent.d.ts +29 -29
- package/dist/cm/format/cmsym/components/SymComponent.js +56 -56
- package/dist/cm/format/cmsym/components/SymConnector.d.ts +5 -5
- package/dist/cm/format/cmsym/components/SymConnector.js +10 -10
- package/dist/cm/format/cmsym/components/SymDexObj.d.ts +11 -11
- package/dist/cm/format/cmsym/components/SymDexObj.js +10 -10
- package/dist/cm/format/cmsym/components/SymGFX.d.ts +11 -11
- package/dist/cm/format/cmsym/components/SymGFX.js +20 -20
- package/dist/cm/format/cmsym/components/SymGMaterial.d.ts +19 -19
- package/dist/cm/format/cmsym/components/SymGMaterial.js +88 -88
- package/dist/cm/format/cmsym/components/SymGMaterialSelector.d.ts +17 -17
- package/dist/cm/format/cmsym/components/SymGMaterialSelector.js +22 -22
- package/dist/cm/format/cmsym/components/SymGetMeshEnv.d.ts +9 -9
- package/dist/cm/format/cmsym/components/SymGetMeshEnv.js +9 -9
- package/dist/cm/format/cmsym/components/SymLODGroup.d.ts +9 -9
- package/dist/cm/format/cmsym/components/SymLODGroup.js +13 -13
- package/dist/cm/format/cmsym/components/SymLight.d.ts +8 -8
- package/dist/cm/format/cmsym/components/SymLight.js +10 -10
- package/dist/cm/format/cmsym/components/SymLines2D.d.ts +5 -5
- package/dist/cm/format/cmsym/components/SymLines2D.js +7 -7
- package/dist/cm/format/cmsym/components/SymMeasure.d.ts +33 -33
- package/dist/cm/format/cmsym/components/SymMeasure.js +149 -149
- package/dist/cm/format/cmsym/components/SymMesh.d.ts +29 -29
- package/dist/cm/format/cmsym/components/SymMesh.js +130 -130
- package/dist/cm/format/cmsym/components/SymMeshLight.d.ts +8 -8
- package/dist/cm/format/cmsym/components/SymMeshLight.js +10 -10
- package/dist/cm/format/cmsym/components/SymMultiSelector.d.ts +13 -13
- package/dist/cm/format/cmsym/components/SymMultiSelector.js +48 -48
- package/dist/cm/format/cmsym/components/SymParams.d.ts +16 -16
- package/dist/cm/format/cmsym/components/SymParams.js +58 -58
- package/dist/cm/format/cmsym/components/SymPlane.d.ts +15 -15
- package/dist/cm/format/cmsym/components/SymPlane.js +30 -30
- package/dist/cm/format/cmsym/components/SymPlaneDivider.d.ts +4 -4
- package/dist/cm/format/cmsym/components/SymPlaneDivider.js +7 -7
- package/dist/cm/format/cmsym/components/SymPrimitive2D.d.ts +3 -3
- package/dist/cm/format/cmsym/components/SymPrimitive2D.js +3 -3
- package/dist/cm/format/cmsym/components/SymProgs.d.ts +32 -32
- package/dist/cm/format/cmsym/components/SymProgs.js +120 -120
- package/dist/cm/format/cmsym/components/SymProps.d.ts +54 -54
- package/dist/cm/format/cmsym/components/SymProps.js +171 -171
- package/dist/cm/format/cmsym/components/SymRep.d.ts +13 -13
- package/dist/cm/format/cmsym/components/SymRep.js +28 -28
- package/dist/cm/format/cmsym/components/SymReps.d.ts +36 -36
- package/dist/cm/format/cmsym/components/SymReps.js +230 -230
- package/dist/cm/format/cmsym/components/SymShape.d.ts +10 -10
- package/dist/cm/format/cmsym/components/SymShape.js +17 -17
- package/dist/cm/format/cmsym/components/SymSphere.d.ts +18 -18
- package/dist/cm/format/cmsym/components/SymSphere.js +33 -33
- package/dist/cm/format/cmsym/components/SymSpotlight.d.ts +8 -8
- package/dist/cm/format/cmsym/components/SymSpotlight.js +10 -10
- package/dist/cm/format/cmsym/components/SymTags.d.ts +11 -11
- package/dist/cm/format/cmsym/components/SymTags.js +20 -20
- package/dist/cm/format/cmsym/components/SymText2D.d.ts +5 -5
- package/dist/cm/format/cmsym/components/SymText2D.js +8 -8
- package/dist/cm/format/cmsym/components/SymText3D.d.ts +5 -5
- package/dist/cm/format/cmsym/components/SymText3D.js +8 -8
- package/dist/cm/format/cmsym/components/SymTransform.d.ts +23 -23
- package/dist/cm/format/cmsym/components/SymTransform.js +101 -101
- package/dist/cm/format/cmsym/components/SymUVMapper.d.ts +13 -13
- package/dist/cm/format/cmsym/components/SymUVMapper.js +50 -50
- package/dist/cm/format/cmsym/components/instantiate.d.ts +2 -2
- package/dist/cm/format/cmsym/components/instantiate.js +121 -121
- package/dist/cm/format/cmsym/components/legacy.d.ts +7 -7
- package/dist/cm/format/cmsym/components/legacy.js +27 -27
- package/dist/cm/format/cmsym/components/mesh.d.ts +8 -8
- package/dist/cm/format/cmsym/components/mesh.js +28 -28
- package/dist/cm/format/cmsym/invalidation.d.ts +4 -4
- package/dist/cm/format/cmsym/invalidation.js +72 -72
- package/dist/cm/format/dex/DexIRef.d.ts +9 -9
- package/dist/cm/format/dex/DexIRef.js +18 -18
- package/dist/cm/format/dex/DexInt.d.ts +11 -11
- package/dist/cm/format/dex/DexInt.js +18 -18
- package/dist/cm/format/dex/DexInternalizedXRef.d.ts +19 -19
- package/dist/cm/format/dex/DexInternalizedXRef.js +65 -65
- package/dist/cm/format/dex/DexLoader.d.ts +8 -8
- package/dist/cm/format/dex/DexLoader.js +12 -12
- package/dist/cm/format/dex/DexManager.d.ts +20 -20
- package/dist/cm/format/dex/DexManager.js +78 -78
- package/dist/cm/format/dex/DexObj.d.ts +15 -15
- package/dist/cm/format/dex/DexObj.js +86 -86
- package/dist/cm/format/dex/DexReader.d.ts +90 -90
- package/dist/cm/format/dex/DexReader.js +532 -532
- package/dist/cm/format/dex/DexRef.d.ts +6 -6
- package/dist/cm/format/dex/DexRef.js +8 -8
- package/dist/cm/format/dex/DexReplacedXRefs.d.ts +9 -9
- package/dist/cm/format/dex/DexReplacedXRefs.js +22 -22
- package/dist/cm/format/dex/DexURL.d.ts +4 -4
- package/dist/cm/format/dex/DexURL.js +5 -5
- package/dist/cm/format/dex/DexVersion.d.ts +15 -15
- package/dist/cm/format/dex/DexVersion.js +53 -53
- package/dist/cm/format/dex/DexXRef.d.ts +18 -18
- package/dist/cm/format/dex/DexXRef.js +51 -51
- package/dist/cm/format/dex/DexXRefTargetFilter.d.ts +4 -4
- package/dist/cm/format/dex/DexXRefTargetFilter.js +5 -5
- package/dist/cm/geometry/Angle.d.ts +9 -9
- package/dist/cm/geometry/Angle.js +18 -18
- package/dist/cm/geometry/AngleF.d.ts +5 -5
- package/dist/cm/geometry/AngleF.js +8 -8
- package/dist/cm/geometry/Box.d.ts +7 -7
- package/dist/cm/geometry/Box.js +9 -9
- package/dist/cm/geometry/DetailMask.d.ts +37 -37
- package/dist/cm/geometry/DetailMask.js +114 -114
- package/dist/cm/geometry/LayerExpr.d.ts +2 -2
- package/dist/cm/geometry/LayerExpr.js +2 -2
- package/dist/cm/geometry/Matrix22.d.ts +7 -7
- package/dist/cm/geometry/Matrix22.js +9 -9
- package/dist/cm/geometry/Matrix33.d.ts +42 -42
- package/dist/cm/geometry/Matrix33.js +124 -124
- package/dist/cm/geometry/Orientation.d.ts +7 -7
- package/dist/cm/geometry/Orientation.js +7 -7
- package/dist/cm/geometry/Plane.d.ts +8 -8
- package/dist/cm/geometry/Plane.js +14 -14
- package/dist/cm/geometry/Point.d.ts +21 -21
- package/dist/cm/geometry/Point.js +65 -65
- package/dist/cm/geometry/Point2D.d.ts +9 -9
- package/dist/cm/geometry/Point2D.js +23 -23
- package/dist/cm/geometry/PointF.d.ts +11 -11
- package/dist/cm/geometry/PointF.js +27 -27
- package/dist/cm/geometry/Transform.d.ts +11 -11
- package/dist/cm/geometry/Transform.js +61 -61
- package/dist/cm/geometry/Transform2D.d.ts +7 -7
- package/dist/cm/geometry/Transform2D.js +6 -6
- package/dist/cm/io/Semver.d.ts +18 -18
- package/dist/cm/io/Semver.js +61 -61
- package/dist/index.js +1 -1
- package/package.json +4 -4
|
@@ -1,532 +1,532 @@
|
|
|
1
|
-
import { create_stream, DexMagic } from "@configura/internal";
|
|
2
|
-
import { memory } from "@configura/internal/web_core_internal_bg.wasm";
|
|
3
|
-
import { Color } from "../../basic/Color.js";
|
|
4
|
-
import { ColorF } from "../../basic/ColorF.js";
|
|
5
|
-
import { Angle } from "../../geometry/Angle.js";
|
|
6
|
-
import { AngleF } from "../../geometry/AngleF.js";
|
|
7
|
-
import { Box } from "../../geometry/Box.js";
|
|
8
|
-
import { Matrix33 } from "../../geometry/Matrix33.js";
|
|
9
|
-
import { Orientation } from "../../geometry/Orientation.js";
|
|
10
|
-
import { Plane } from "../../geometry/Plane.js";
|
|
11
|
-
import { Point } from "../../geometry/Point.js";
|
|
12
|
-
import { Point2D } from "../../geometry/Point2D.js";
|
|
13
|
-
import { Transform } from "../../geometry/Transform.js";
|
|
14
|
-
import { DexInt, DexInt64 } from "./DexInt.js";
|
|
15
|
-
import { DexInternalizedXRef } from "./DexInternalizedXRef.js";
|
|
16
|
-
import { DexIRef } from "./DexIRef.js";
|
|
17
|
-
import { DexObj } from "./DexObj.js";
|
|
18
|
-
import { DexRef } from "./DexRef.js";
|
|
19
|
-
import { DexReplacedXRefs } from "./DexReplacedXRefs.js";
|
|
20
|
-
import { DexURL } from "./DexURL.js";
|
|
21
|
-
import { DexVersion } from "./DexVersion.js";
|
|
22
|
-
import { DexXRef, DexXRefStyle } from "./DexXRef.js";
|
|
23
|
-
export function isStringToNumberMap(mp) {
|
|
24
|
-
for (const [k, v] of mp) {
|
|
25
|
-
return typeof k === "string" && typeof v === "number";
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
export function isStringToStringMap(mp) {
|
|
30
|
-
for (const [k, v] of mp) {
|
|
31
|
-
return typeof k === "string" && typeof v === "string";
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
export class DexReader {
|
|
36
|
-
constructor(_bytes, manager, url) {
|
|
37
|
-
this._bytes = _bytes;
|
|
38
|
-
this.manager = manager;
|
|
39
|
-
this.url = url;
|
|
40
|
-
this.isOpen = true;
|
|
41
|
-
this.version_1_2_0 = false;
|
|
42
|
-
this.version_1_1_0 = false;
|
|
43
|
-
this.version_0_0_1 = false;
|
|
44
|
-
this.accessed = true;
|
|
45
|
-
this.beginPos = -1;
|
|
46
|
-
this.openedTimeStamp = Date.now();
|
|
47
|
-
this.positions = new Map();
|
|
48
|
-
this.strs = new Map();
|
|
49
|
-
this.objs = new Map();
|
|
50
|
-
this.objsPos = new Map();
|
|
51
|
-
this.internalizedXRefs = new Map();
|
|
52
|
-
this.replacedXRefs = new DexReplacedXRefs();
|
|
53
|
-
this.stream = create_stream(_bytes);
|
|
54
|
-
manager.readers.set(url, this);
|
|
55
|
-
}
|
|
56
|
-
begin() {
|
|
57
|
-
this.beginPos = this.stream.get_position();
|
|
58
|
-
if (this.beginPos < 0) {
|
|
59
|
-
throw Error("this.beginPos is less than 0");
|
|
60
|
-
}
|
|
61
|
-
this.readHeader();
|
|
62
|
-
this.readShortcuts();
|
|
63
|
-
this.readTables();
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
end() {
|
|
67
|
-
// nada
|
|
68
|
-
}
|
|
69
|
-
read() {
|
|
70
|
-
if (this.beginPos < 0) {
|
|
71
|
-
const begin = this.begin();
|
|
72
|
-
if (!begin) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
this.root = this.readRoot();
|
|
76
|
-
this.end();
|
|
77
|
-
return this.root;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
readAngle() {
|
|
81
|
-
const radians = this.stream.read_f64();
|
|
82
|
-
return new Angle(radians);
|
|
83
|
-
}
|
|
84
|
-
readAngleF() {
|
|
85
|
-
const radians = this.stream.read_f32();
|
|
86
|
-
return new AngleF(radians);
|
|
87
|
-
}
|
|
88
|
-
readBox() {
|
|
89
|
-
const p0 = this.readPoint();
|
|
90
|
-
const p1 = this.readPoint();
|
|
91
|
-
return new Box(p0, p1);
|
|
92
|
-
}
|
|
93
|
-
readPlane() {
|
|
94
|
-
const vector = this.readPoint();
|
|
95
|
-
const distance = this.stream.read_f64();
|
|
96
|
-
return new Plane(vector, distance);
|
|
97
|
-
}
|
|
98
|
-
readByteArray() {
|
|
99
|
-
const length = this.stream.read_i32();
|
|
100
|
-
const start = this.stream.get_position();
|
|
101
|
-
const end = start + length;
|
|
102
|
-
this.stream.set_position(end);
|
|
103
|
-
this.stream.match_dex_magic(DexMagic.EndOdd);
|
|
104
|
-
return this.readBytes(start, length);
|
|
105
|
-
}
|
|
106
|
-
readBytes(start, length) {
|
|
107
|
-
const ptr = this.stream.get_ptr();
|
|
108
|
-
const mem = new Uint8Array(memory.buffer, ptr + start, length);
|
|
109
|
-
return mem.slice();
|
|
110
|
-
}
|
|
111
|
-
readColor() {
|
|
112
|
-
const type = this.stream.read_u8();
|
|
113
|
-
const r = this.stream.read_u8();
|
|
114
|
-
const g = this.stream.read_u8();
|
|
115
|
-
const b = this.stream.read_u8();
|
|
116
|
-
return new Color(type, r, g, b);
|
|
117
|
-
}
|
|
118
|
-
readColorF() {
|
|
119
|
-
const r = this.stream.read_f32();
|
|
120
|
-
const g = this.stream.read_f32();
|
|
121
|
-
const b = this.stream.read_f32();
|
|
122
|
-
const alpha = this.stream.read_f32();
|
|
123
|
-
return new ColorF(r, g, b, alpha);
|
|
124
|
-
}
|
|
125
|
-
readDexObj() {
|
|
126
|
-
const obj = DexObj.withReader(this);
|
|
127
|
-
const pos = this.stream.get_position();
|
|
128
|
-
if (this.objs.get(pos) !== undefined) {
|
|
129
|
-
throw Error(`pos: ${pos} already loaded!`);
|
|
130
|
-
}
|
|
131
|
-
this.readDexObjInto(obj);
|
|
132
|
-
return obj;
|
|
133
|
-
}
|
|
134
|
-
readDexObjArray() {
|
|
135
|
-
const count = this.stream.read_i32();
|
|
136
|
-
const refs = [];
|
|
137
|
-
for (let i = 0; i < count; i++) {
|
|
138
|
-
refs.push(this.readRef());
|
|
139
|
-
}
|
|
140
|
-
const pos = this.stream.get_position();
|
|
141
|
-
const objs = [];
|
|
142
|
-
for (const ref of refs) {
|
|
143
|
-
objs.push(this.loadDexObj(ref));
|
|
144
|
-
}
|
|
145
|
-
this.stream.set_position(pos);
|
|
146
|
-
this.stream.match_dex_magic(DexMagic.EndOdd);
|
|
147
|
-
return objs;
|
|
148
|
-
}
|
|
149
|
-
readDexObjInto(obj) {
|
|
150
|
-
this.stream.match_dex_magic(DexMagic.BeginObj);
|
|
151
|
-
if (obj.reader === undefined) {
|
|
152
|
-
throw Error("obj.reader is undefined");
|
|
153
|
-
}
|
|
154
|
-
obj.type = this.readStr();
|
|
155
|
-
obj.id = this.readStr();
|
|
156
|
-
const n = this.stream.unpack30();
|
|
157
|
-
for (let i = 0; i < n; i++) {
|
|
158
|
-
const key = this.readStr();
|
|
159
|
-
if (key === undefined) {
|
|
160
|
-
throw Error("key === undefined");
|
|
161
|
-
}
|
|
162
|
-
const value = this.readObject();
|
|
163
|
-
if (value instanceof Error) {
|
|
164
|
-
throw value;
|
|
165
|
-
}
|
|
166
|
-
obj.put(key, value);
|
|
167
|
-
}
|
|
168
|
-
this.stream.match_dex_magic(DexMagic.EndObj);
|
|
169
|
-
}
|
|
170
|
-
readOrientation() {
|
|
171
|
-
const yaw = this.readAngle();
|
|
172
|
-
const pitch = this.readAngle();
|
|
173
|
-
const roll = this.readAngle();
|
|
174
|
-
return new Orientation(yaw, pitch, roll);
|
|
175
|
-
}
|
|
176
|
-
readPoint() {
|
|
177
|
-
const x = this.stream.read_f64();
|
|
178
|
-
const y = this.stream.read_f64();
|
|
179
|
-
const z = this.stream.read_f64();
|
|
180
|
-
return new Point(x, y, z);
|
|
181
|
-
}
|
|
182
|
-
readPoint2D() {
|
|
183
|
-
const x = this.stream.read_f64();
|
|
184
|
-
const y = this.stream.read_f64();
|
|
185
|
-
return new Point2D(x, y);
|
|
186
|
-
}
|
|
187
|
-
readTransform() {
|
|
188
|
-
const bool = this.stream.read_bool();
|
|
189
|
-
if (bool) {
|
|
190
|
-
const c0 = this.readPoint();
|
|
191
|
-
const c1 = this.readPoint();
|
|
192
|
-
const c2 = this.readPoint();
|
|
193
|
-
const mapping = new Matrix33(c0, c1, c2);
|
|
194
|
-
const pos = this.readPoint();
|
|
195
|
-
return new Transform(pos, mapping);
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
const pos = this.readPoint();
|
|
199
|
-
return new Transform(pos);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
readDexVersion() {
|
|
203
|
-
const major = this.stream.read_u16();
|
|
204
|
-
const minor = this.stream.read_u8();
|
|
205
|
-
const patch = this.stream.read_u8();
|
|
206
|
-
return new DexVersion(major, minor, patch);
|
|
207
|
-
}
|
|
208
|
-
readDexXRef() {
|
|
209
|
-
const url = this.readStr();
|
|
210
|
-
const path = this.readStr();
|
|
211
|
-
if (url === undefined) {
|
|
212
|
-
throw Error("[readDexXRef] url is undefined");
|
|
213
|
-
}
|
|
214
|
-
const xref = this.internalizedXRefs.get(url);
|
|
215
|
-
let target = xref !== undefined ? this.manager.xrefTarget(xref) : url;
|
|
216
|
-
target = this.manager.expandRoot(target);
|
|
217
|
-
if (!rootedUrl(target)) {
|
|
218
|
-
throw Error("unresolved $-variables remain in '" + target + "'");
|
|
219
|
-
}
|
|
220
|
-
this.stream.match_dex_magic(DexMagic.EndXRef);
|
|
221
|
-
return new DexXRef(this, target, path, url, xref !== undefined ? xref.style : DexXRefStyle.External);
|
|
222
|
-
}
|
|
223
|
-
readHeader() {
|
|
224
|
-
this.beginPos = this.stream.get_position();
|
|
225
|
-
this.stream.match_dex_magic(DexMagic.BeginHeader);
|
|
226
|
-
this.writeVersion = this.readDexVersion();
|
|
227
|
-
this.version_0_0_1 = this.writeVersion.eq(new DexVersion(0, 0, 1));
|
|
228
|
-
this.version_1_1_0 = this.writeVersion.eq(new DexVersion(1, 1, 0));
|
|
229
|
-
this.version_1_2_0 = this.writeVersion.eq(new DexVersion(1, 2, 0));
|
|
230
|
-
this.positionsOffset = this.stream.read_i32();
|
|
231
|
-
this.thumbnailOffset = this.stream.read_i32();
|
|
232
|
-
// Skip rest of header
|
|
233
|
-
for (let i = 0; i < 7; i++) {
|
|
234
|
-
this.stream.read_i32();
|
|
235
|
-
}
|
|
236
|
-
this.stream.match_dex_magic(DexMagic.EndHeader);
|
|
237
|
-
}
|
|
238
|
-
readLayerExpression() {
|
|
239
|
-
const str = this.readStr();
|
|
240
|
-
// console.warn(`[DexReader.readLayerExpression] not yet impl, str:"${str}"`);
|
|
241
|
-
return str;
|
|
242
|
-
}
|
|
243
|
-
readRef() {
|
|
244
|
-
const pos = this.stream.read_i32();
|
|
245
|
-
if (pos <= 0) {
|
|
246
|
-
throw Error(`pos: ${pos} <= 0`);
|
|
247
|
-
}
|
|
248
|
-
const obj = this.objs.get(pos);
|
|
249
|
-
if (obj !== undefined) {
|
|
250
|
-
return obj;
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
return new DexIRef(this, pos);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
readRoot() {
|
|
257
|
-
this.takeShortcut("objs.offset");
|
|
258
|
-
this.stream.match_dex_magic(DexMagic.BeginObjs);
|
|
259
|
-
// this is not used in the original implementation
|
|
260
|
-
this.stream.read_i32();
|
|
261
|
-
const obj = this.readObject();
|
|
262
|
-
if (obj instanceof DexObj) {
|
|
263
|
-
return obj;
|
|
264
|
-
}
|
|
265
|
-
if (this.version_1_1_0) {
|
|
266
|
-
this.stream.match_dex_magic(DexMagic.EndObjs);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
readURL() {
|
|
270
|
-
const url = this.readStr();
|
|
271
|
-
if (url === undefined) {
|
|
272
|
-
throw Error("unknown url");
|
|
273
|
-
}
|
|
274
|
-
return new DexURL(url);
|
|
275
|
-
}
|
|
276
|
-
readURL_0_0_1() {
|
|
277
|
-
let url = "";
|
|
278
|
-
const valid = this.stream.read_bool();
|
|
279
|
-
if (!valid) {
|
|
280
|
-
throw Error("url invalid");
|
|
281
|
-
}
|
|
282
|
-
const filenameBase = this.stream.read_str();
|
|
283
|
-
const suffix = this.stream.read_str();
|
|
284
|
-
const fileSize = this.stream.read_i32();
|
|
285
|
-
this.stream.read_str();
|
|
286
|
-
url = filenameBase + "." + suffix;
|
|
287
|
-
const start = this.stream.get_position();
|
|
288
|
-
const end = start + fileSize;
|
|
289
|
-
const fileBuffer = this.readBytes(start, fileSize);
|
|
290
|
-
this.stream.set_position(end);
|
|
291
|
-
this.stream.match_dex_magic(DexMagic.EndOdd);
|
|
292
|
-
// tslint:disable-next-line: no-unused-expression
|
|
293
|
-
new DexReader(fileBuffer, this.manager, url);
|
|
294
|
-
return new DexURL(url);
|
|
295
|
-
}
|
|
296
|
-
loadDexObj(obj, key) {
|
|
297
|
-
obj = obj instanceof DexRef ? obj.load(key) : obj;
|
|
298
|
-
if (!(obj instanceof DexObj)) {
|
|
299
|
-
throw Error(`obj: ${obj} not instance of DexObj`);
|
|
300
|
-
}
|
|
301
|
-
return obj;
|
|
302
|
-
}
|
|
303
|
-
readShortcuts() {
|
|
304
|
-
if (this.positionsOffset === undefined) {
|
|
305
|
-
throw Error("this.positionsOffset is undefined");
|
|
306
|
-
}
|
|
307
|
-
const positionsPos = this.positionsOffset + this.beginPos;
|
|
308
|
-
this.stream.set_position(positionsPos);
|
|
309
|
-
this.stream.match_dex_magic(DexMagic.BeginPositions);
|
|
310
|
-
const count = this.stream.unpack30();
|
|
311
|
-
this.positions = new Map();
|
|
312
|
-
for (let i = 0; i < count; i++) {
|
|
313
|
-
const s = this.stream.read_nano_str();
|
|
314
|
-
const pos = this.stream.unpack30();
|
|
315
|
-
this.positions.set(s, pos);
|
|
316
|
-
}
|
|
317
|
-
this.stream.match_dex_magic(DexMagic.EndPositions);
|
|
318
|
-
}
|
|
319
|
-
takeShortcut(shortcut) {
|
|
320
|
-
const offset = this.positions.get(shortcut) || 0;
|
|
321
|
-
this.stream.set_position(offset + this.beginPos);
|
|
322
|
-
}
|
|
323
|
-
readTables() {
|
|
324
|
-
const currentPos = this.stream.get_position();
|
|
325
|
-
this.readStrs();
|
|
326
|
-
this.readInternalizedXRefs();
|
|
327
|
-
this.stream.set_position(currentPos);
|
|
328
|
-
}
|
|
329
|
-
readStrs() {
|
|
330
|
-
const strsOffset = this.positions.get("strs.offset");
|
|
331
|
-
if (strsOffset === undefined) {
|
|
332
|
-
throw Error("[readStrs] this.positions[strs.offset] is undefined");
|
|
333
|
-
}
|
|
334
|
-
if (strsOffset > 0) {
|
|
335
|
-
this.stream.set_position(strsOffset + this.beginPos);
|
|
336
|
-
this.stream.match_dex_magic(DexMagic.BeginStrs);
|
|
337
|
-
const n = this.stream.unpack30();
|
|
338
|
-
for (let i = 0; i < n; i++) {
|
|
339
|
-
const str = this.stream.read_nano_str();
|
|
340
|
-
const id = this.stream.unpack30();
|
|
341
|
-
this.strs.set(id, str);
|
|
342
|
-
}
|
|
343
|
-
this.stream.match_dex_magic(DexMagic.EndStrs);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
readSetStr() {
|
|
347
|
-
const count = this.stream.read_i32();
|
|
348
|
-
const strings = new Set();
|
|
349
|
-
for (let i = 0; i < count; i++) {
|
|
350
|
-
const s = this.readStr();
|
|
351
|
-
if (s !== undefined) {
|
|
352
|
-
strings.add(s);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return strings;
|
|
356
|
-
}
|
|
357
|
-
readStr() {
|
|
358
|
-
const id = this.stream.unpack30();
|
|
359
|
-
return id > 0 ? this.strs.get(id) : undefined;
|
|
360
|
-
}
|
|
361
|
-
readMapStrInt() {
|
|
362
|
-
const retMap = new Map();
|
|
363
|
-
const count = this.stream.read_i32();
|
|
364
|
-
for (let i = 0; i < count; i++) {
|
|
365
|
-
const key = this.readStr();
|
|
366
|
-
if (key === undefined) {
|
|
367
|
-
throw Error("[readStr] is undefined");
|
|
368
|
-
}
|
|
369
|
-
const value = this.stream.read_i32();
|
|
370
|
-
retMap.set(key, value);
|
|
371
|
-
}
|
|
372
|
-
return retMap;
|
|
373
|
-
}
|
|
374
|
-
readInternalizedXRefs() {
|
|
375
|
-
this.internalizedXRefs = new Map();
|
|
376
|
-
const xrefCount = this.positions.get("ixref.n");
|
|
377
|
-
if (xrefCount === undefined) {
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
for (let i = 0; i < xrefCount; i++) {
|
|
381
|
-
this.readInternalizedXRef(i, xrefCount);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
readInternalizedXRef(i, xrefCount) {
|
|
385
|
-
const key = "ixref" + i;
|
|
386
|
-
const offset = this.positions.get(key);
|
|
387
|
-
if (offset === undefined) {
|
|
388
|
-
throw Error("[readInternalizedXref] offset not defined");
|
|
389
|
-
}
|
|
390
|
-
this.stream.set_position(offset + this.beginPos);
|
|
391
|
-
this.stream.match_dex_magic(DexMagic.BeginInternalizedXRef);
|
|
392
|
-
const xrefLength = this.stream.unpack30();
|
|
393
|
-
const url = this.readStr();
|
|
394
|
-
if (url === undefined) {
|
|
395
|
-
throw Error("bad str id");
|
|
396
|
-
}
|
|
397
|
-
const xrefStyle = this.stream.read_cstr();
|
|
398
|
-
const hashId = this.stream.read_cstr();
|
|
399
|
-
const encoding = this.stream.read_cstr();
|
|
400
|
-
const hash = this.stream.read_cstr();
|
|
401
|
-
const internalized = new DexInternalizedXRef(i, xrefCount, this.stream.get_position(), xrefLength, url, xrefStyle, hashId, encoding, hash);
|
|
402
|
-
this.internalizedXRefs.set(url, internalized);
|
|
403
|
-
}
|
|
404
|
-
readInternalizedXRefFile(pos, length) {
|
|
405
|
-
this.stream.set_position(pos);
|
|
406
|
-
this.stream.match_dex_magic(DexMagic.OtherInternalizedXRefFile);
|
|
407
|
-
const start = this.stream.get_position();
|
|
408
|
-
const end = start + length;
|
|
409
|
-
this.stream.set_position(end);
|
|
410
|
-
this.stream.match_dex_magic(DexMagic.EndInternalizedXRef);
|
|
411
|
-
return this.readBytes(start, length);
|
|
412
|
-
}
|
|
413
|
-
internalizedXRef(url) {
|
|
414
|
-
return this.internalizedXRefs.get(url);
|
|
415
|
-
}
|
|
416
|
-
expandRelativeUrl(url) {
|
|
417
|
-
throw new Error("expandRelativeUrl not yet implemented");
|
|
418
|
-
}
|
|
419
|
-
putReplaceXRef(obj, k, xref) {
|
|
420
|
-
this.replacedXRefs.put(obj, k, xref);
|
|
421
|
-
}
|
|
422
|
-
readObject() {
|
|
423
|
-
const type = this.readStr();
|
|
424
|
-
switch (type) {
|
|
425
|
-
case "Angle":
|
|
426
|
-
return this.readAngle();
|
|
427
|
-
case "AngleF":
|
|
428
|
-
return this.readAngleF();
|
|
429
|
-
case "Bool":
|
|
430
|
-
return this.stream.read_bool();
|
|
431
|
-
case "Bound":
|
|
432
|
-
return this.readBox();
|
|
433
|
-
// case "BoundF":
|
|
434
|
-
// return new DexBoxF(getDexBoxF(this.b));
|
|
435
|
-
// case "Char":
|
|
436
|
-
// return new DexChar(getDexChar(this.b));
|
|
437
|
-
case "Color":
|
|
438
|
-
return this.readColor();
|
|
439
|
-
case "ColorF":
|
|
440
|
-
return this.readColorF();
|
|
441
|
-
case "DexObj[]":
|
|
442
|
-
return this.readDexObjArray();
|
|
443
|
-
// case "DexObj{}":
|
|
444
|
-
// return read_set_DexObj();
|
|
445
|
-
// case "DexObj->str":
|
|
446
|
-
// return read_map_DexObj_str();
|
|
447
|
-
case "Double":
|
|
448
|
-
return this.stream.read_f64();
|
|
449
|
-
case "Float":
|
|
450
|
-
return this.stream.read_f32();
|
|
451
|
-
case "Int":
|
|
452
|
-
return new DexInt(this.stream.read_i32());
|
|
453
|
-
case "Int64":
|
|
454
|
-
// TODO: is this read right?
|
|
455
|
-
return new DexInt64(this.stream.read_i32(), this.stream.read_i32());
|
|
456
|
-
case "LayerExpr":
|
|
457
|
-
return this.readLayerExpression();
|
|
458
|
-
// case "Line":
|
|
459
|
-
// return new DexLine(getDexLine(this.b));
|
|
460
|
-
// case "Line2D":
|
|
461
|
-
// return new DexLine2D(getDexLine2D(this.b));
|
|
462
|
-
// case "LineF":
|
|
463
|
-
// return new DexLineF(getDexLineF(this.b));
|
|
464
|
-
// case "LineF2D":
|
|
465
|
-
// return new DexLineF2D(getDexLineF2D(this.b));
|
|
466
|
-
// case "Nat":
|
|
467
|
-
// return new DexNat(this.b.getNat());
|
|
468
|
-
case "Orientation":
|
|
469
|
-
return this.readOrientation();
|
|
470
|
-
case "Point":
|
|
471
|
-
return this.readPoint();
|
|
472
|
-
case "Plane":
|
|
473
|
-
return this.readPlane();
|
|
474
|
-
case "Point2D":
|
|
475
|
-
return this.readPoint2D();
|
|
476
|
-
case "Str":
|
|
477
|
-
return this.readStr();
|
|
478
|
-
case "Transform":
|
|
479
|
-
return this.readTransform();
|
|
480
|
-
case "Url":
|
|
481
|
-
return this.version_0_0_1 ? this.readURL_0_0_1() : this.readURL();
|
|
482
|
-
case "Version":
|
|
483
|
-
return this.readDexVersion();
|
|
484
|
-
case "byte[]":
|
|
485
|
-
return this.readByteArray();
|
|
486
|
-
case "str{}":
|
|
487
|
-
return this.readSetStr();
|
|
488
|
-
case "dex":
|
|
489
|
-
return this.readDexObj();
|
|
490
|
-
case "null":
|
|
491
|
-
return undefined;
|
|
492
|
-
// case "point2D[]":
|
|
493
|
-
// return this.read_seq_point2D();
|
|
494
|
-
case "ref":
|
|
495
|
-
return this.readRef();
|
|
496
|
-
// case "str->str":
|
|
497
|
-
// return this.read_map_str_str();
|
|
498
|
-
case "str->int":
|
|
499
|
-
return this.readMapStrInt();
|
|
500
|
-
case "xref":
|
|
501
|
-
return this.readDexXRef();
|
|
502
|
-
default:
|
|
503
|
-
throw Error("[readObject] type not implemented: " + type);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
readObjectFromPos(pos) {
|
|
507
|
-
if (!(pos > this.beginPos)) {
|
|
508
|
-
throw Error("pos is less or equal to this.beginPos");
|
|
509
|
-
}
|
|
510
|
-
let obj = this.objs.get(pos);
|
|
511
|
-
if (obj !== undefined) {
|
|
512
|
-
return obj;
|
|
513
|
-
}
|
|
514
|
-
this.stream.set_position(pos);
|
|
515
|
-
obj = this.readObject();
|
|
516
|
-
if (obj === undefined) {
|
|
517
|
-
throw Error("[readObjectFromPos] z is not defined");
|
|
518
|
-
}
|
|
519
|
-
this.objs.set(pos, obj);
|
|
520
|
-
this.objsPos.set(obj, pos);
|
|
521
|
-
return obj;
|
|
522
|
-
}
|
|
523
|
-
toString() {
|
|
524
|
-
return `DexReader(url=${this.url})`;
|
|
525
|
-
}
|
|
526
|
-
bytes() {
|
|
527
|
-
return this._bytes;
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
function rootedUrl(url) {
|
|
531
|
-
return url.indexOf("$(") === -1;
|
|
532
|
-
}
|
|
1
|
+
import { create_stream, DexMagic } from "@configura/internal";
|
|
2
|
+
import { memory } from "@configura/internal/web_core_internal_bg.wasm";
|
|
3
|
+
import { Color } from "../../basic/Color.js";
|
|
4
|
+
import { ColorF } from "../../basic/ColorF.js";
|
|
5
|
+
import { Angle } from "../../geometry/Angle.js";
|
|
6
|
+
import { AngleF } from "../../geometry/AngleF.js";
|
|
7
|
+
import { Box } from "../../geometry/Box.js";
|
|
8
|
+
import { Matrix33 } from "../../geometry/Matrix33.js";
|
|
9
|
+
import { Orientation } from "../../geometry/Orientation.js";
|
|
10
|
+
import { Plane } from "../../geometry/Plane.js";
|
|
11
|
+
import { Point } from "../../geometry/Point.js";
|
|
12
|
+
import { Point2D } from "../../geometry/Point2D.js";
|
|
13
|
+
import { Transform } from "../../geometry/Transform.js";
|
|
14
|
+
import { DexInt, DexInt64 } from "./DexInt.js";
|
|
15
|
+
import { DexInternalizedXRef } from "./DexInternalizedXRef.js";
|
|
16
|
+
import { DexIRef } from "./DexIRef.js";
|
|
17
|
+
import { DexObj } from "./DexObj.js";
|
|
18
|
+
import { DexRef } from "./DexRef.js";
|
|
19
|
+
import { DexReplacedXRefs } from "./DexReplacedXRefs.js";
|
|
20
|
+
import { DexURL } from "./DexURL.js";
|
|
21
|
+
import { DexVersion } from "./DexVersion.js";
|
|
22
|
+
import { DexXRef, DexXRefStyle } from "./DexXRef.js";
|
|
23
|
+
export function isStringToNumberMap(mp) {
|
|
24
|
+
for (const [k, v] of mp) {
|
|
25
|
+
return typeof k === "string" && typeof v === "number";
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
export function isStringToStringMap(mp) {
|
|
30
|
+
for (const [k, v] of mp) {
|
|
31
|
+
return typeof k === "string" && typeof v === "string";
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
export class DexReader {
|
|
36
|
+
constructor(_bytes, manager, url) {
|
|
37
|
+
this._bytes = _bytes;
|
|
38
|
+
this.manager = manager;
|
|
39
|
+
this.url = url;
|
|
40
|
+
this.isOpen = true;
|
|
41
|
+
this.version_1_2_0 = false;
|
|
42
|
+
this.version_1_1_0 = false;
|
|
43
|
+
this.version_0_0_1 = false;
|
|
44
|
+
this.accessed = true;
|
|
45
|
+
this.beginPos = -1;
|
|
46
|
+
this.openedTimeStamp = Date.now();
|
|
47
|
+
this.positions = new Map();
|
|
48
|
+
this.strs = new Map();
|
|
49
|
+
this.objs = new Map();
|
|
50
|
+
this.objsPos = new Map();
|
|
51
|
+
this.internalizedXRefs = new Map();
|
|
52
|
+
this.replacedXRefs = new DexReplacedXRefs();
|
|
53
|
+
this.stream = create_stream(_bytes);
|
|
54
|
+
manager.readers.set(url, this);
|
|
55
|
+
}
|
|
56
|
+
begin() {
|
|
57
|
+
this.beginPos = this.stream.get_position();
|
|
58
|
+
if (this.beginPos < 0) {
|
|
59
|
+
throw Error("this.beginPos is less than 0");
|
|
60
|
+
}
|
|
61
|
+
this.readHeader();
|
|
62
|
+
this.readShortcuts();
|
|
63
|
+
this.readTables();
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
end() {
|
|
67
|
+
// nada
|
|
68
|
+
}
|
|
69
|
+
read() {
|
|
70
|
+
if (this.beginPos < 0) {
|
|
71
|
+
const begin = this.begin();
|
|
72
|
+
if (!begin) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.root = this.readRoot();
|
|
76
|
+
this.end();
|
|
77
|
+
return this.root;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
readAngle() {
|
|
81
|
+
const radians = this.stream.read_f64();
|
|
82
|
+
return new Angle(radians);
|
|
83
|
+
}
|
|
84
|
+
readAngleF() {
|
|
85
|
+
const radians = this.stream.read_f32();
|
|
86
|
+
return new AngleF(radians);
|
|
87
|
+
}
|
|
88
|
+
readBox() {
|
|
89
|
+
const p0 = this.readPoint();
|
|
90
|
+
const p1 = this.readPoint();
|
|
91
|
+
return new Box(p0, p1);
|
|
92
|
+
}
|
|
93
|
+
readPlane() {
|
|
94
|
+
const vector = this.readPoint();
|
|
95
|
+
const distance = this.stream.read_f64();
|
|
96
|
+
return new Plane(vector, distance);
|
|
97
|
+
}
|
|
98
|
+
readByteArray() {
|
|
99
|
+
const length = this.stream.read_i32();
|
|
100
|
+
const start = this.stream.get_position();
|
|
101
|
+
const end = start + length;
|
|
102
|
+
this.stream.set_position(end);
|
|
103
|
+
this.stream.match_dex_magic(DexMagic.EndOdd);
|
|
104
|
+
return this.readBytes(start, length);
|
|
105
|
+
}
|
|
106
|
+
readBytes(start, length) {
|
|
107
|
+
const ptr = this.stream.get_ptr();
|
|
108
|
+
const mem = new Uint8Array(memory.buffer, ptr + start, length);
|
|
109
|
+
return mem.slice();
|
|
110
|
+
}
|
|
111
|
+
readColor() {
|
|
112
|
+
const type = this.stream.read_u8();
|
|
113
|
+
const r = this.stream.read_u8();
|
|
114
|
+
const g = this.stream.read_u8();
|
|
115
|
+
const b = this.stream.read_u8();
|
|
116
|
+
return new Color(type, r, g, b);
|
|
117
|
+
}
|
|
118
|
+
readColorF() {
|
|
119
|
+
const r = this.stream.read_f32();
|
|
120
|
+
const g = this.stream.read_f32();
|
|
121
|
+
const b = this.stream.read_f32();
|
|
122
|
+
const alpha = this.stream.read_f32();
|
|
123
|
+
return new ColorF(r, g, b, alpha);
|
|
124
|
+
}
|
|
125
|
+
readDexObj() {
|
|
126
|
+
const obj = DexObj.withReader(this);
|
|
127
|
+
const pos = this.stream.get_position();
|
|
128
|
+
if (this.objs.get(pos) !== undefined) {
|
|
129
|
+
throw Error(`pos: ${pos} already loaded!`);
|
|
130
|
+
}
|
|
131
|
+
this.readDexObjInto(obj);
|
|
132
|
+
return obj;
|
|
133
|
+
}
|
|
134
|
+
readDexObjArray() {
|
|
135
|
+
const count = this.stream.read_i32();
|
|
136
|
+
const refs = [];
|
|
137
|
+
for (let i = 0; i < count; i++) {
|
|
138
|
+
refs.push(this.readRef());
|
|
139
|
+
}
|
|
140
|
+
const pos = this.stream.get_position();
|
|
141
|
+
const objs = [];
|
|
142
|
+
for (const ref of refs) {
|
|
143
|
+
objs.push(this.loadDexObj(ref));
|
|
144
|
+
}
|
|
145
|
+
this.stream.set_position(pos);
|
|
146
|
+
this.stream.match_dex_magic(DexMagic.EndOdd);
|
|
147
|
+
return objs;
|
|
148
|
+
}
|
|
149
|
+
readDexObjInto(obj) {
|
|
150
|
+
this.stream.match_dex_magic(DexMagic.BeginObj);
|
|
151
|
+
if (obj.reader === undefined) {
|
|
152
|
+
throw Error("obj.reader is undefined");
|
|
153
|
+
}
|
|
154
|
+
obj.type = this.readStr();
|
|
155
|
+
obj.id = this.readStr();
|
|
156
|
+
const n = this.stream.unpack30();
|
|
157
|
+
for (let i = 0; i < n; i++) {
|
|
158
|
+
const key = this.readStr();
|
|
159
|
+
if (key === undefined) {
|
|
160
|
+
throw Error("key === undefined");
|
|
161
|
+
}
|
|
162
|
+
const value = this.readObject();
|
|
163
|
+
if (value instanceof Error) {
|
|
164
|
+
throw value;
|
|
165
|
+
}
|
|
166
|
+
obj.put(key, value);
|
|
167
|
+
}
|
|
168
|
+
this.stream.match_dex_magic(DexMagic.EndObj);
|
|
169
|
+
}
|
|
170
|
+
readOrientation() {
|
|
171
|
+
const yaw = this.readAngle();
|
|
172
|
+
const pitch = this.readAngle();
|
|
173
|
+
const roll = this.readAngle();
|
|
174
|
+
return new Orientation(yaw, pitch, roll);
|
|
175
|
+
}
|
|
176
|
+
readPoint() {
|
|
177
|
+
const x = this.stream.read_f64();
|
|
178
|
+
const y = this.stream.read_f64();
|
|
179
|
+
const z = this.stream.read_f64();
|
|
180
|
+
return new Point(x, y, z);
|
|
181
|
+
}
|
|
182
|
+
readPoint2D() {
|
|
183
|
+
const x = this.stream.read_f64();
|
|
184
|
+
const y = this.stream.read_f64();
|
|
185
|
+
return new Point2D(x, y);
|
|
186
|
+
}
|
|
187
|
+
readTransform() {
|
|
188
|
+
const bool = this.stream.read_bool();
|
|
189
|
+
if (bool) {
|
|
190
|
+
const c0 = this.readPoint();
|
|
191
|
+
const c1 = this.readPoint();
|
|
192
|
+
const c2 = this.readPoint();
|
|
193
|
+
const mapping = new Matrix33(c0, c1, c2);
|
|
194
|
+
const pos = this.readPoint();
|
|
195
|
+
return new Transform(pos, mapping);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
const pos = this.readPoint();
|
|
199
|
+
return new Transform(pos);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
readDexVersion() {
|
|
203
|
+
const major = this.stream.read_u16();
|
|
204
|
+
const minor = this.stream.read_u8();
|
|
205
|
+
const patch = this.stream.read_u8();
|
|
206
|
+
return new DexVersion(major, minor, patch);
|
|
207
|
+
}
|
|
208
|
+
readDexXRef() {
|
|
209
|
+
const url = this.readStr();
|
|
210
|
+
const path = this.readStr();
|
|
211
|
+
if (url === undefined) {
|
|
212
|
+
throw Error("[readDexXRef] url is undefined");
|
|
213
|
+
}
|
|
214
|
+
const xref = this.internalizedXRefs.get(url);
|
|
215
|
+
let target = xref !== undefined ? this.manager.xrefTarget(xref) : url;
|
|
216
|
+
target = this.manager.expandRoot(target);
|
|
217
|
+
if (!rootedUrl(target)) {
|
|
218
|
+
throw Error("unresolved $-variables remain in '" + target + "'");
|
|
219
|
+
}
|
|
220
|
+
this.stream.match_dex_magic(DexMagic.EndXRef);
|
|
221
|
+
return new DexXRef(this, target, path, url, xref !== undefined ? xref.style : DexXRefStyle.External);
|
|
222
|
+
}
|
|
223
|
+
readHeader() {
|
|
224
|
+
this.beginPos = this.stream.get_position();
|
|
225
|
+
this.stream.match_dex_magic(DexMagic.BeginHeader);
|
|
226
|
+
this.writeVersion = this.readDexVersion();
|
|
227
|
+
this.version_0_0_1 = this.writeVersion.eq(new DexVersion(0, 0, 1));
|
|
228
|
+
this.version_1_1_0 = this.writeVersion.eq(new DexVersion(1, 1, 0));
|
|
229
|
+
this.version_1_2_0 = this.writeVersion.eq(new DexVersion(1, 2, 0));
|
|
230
|
+
this.positionsOffset = this.stream.read_i32();
|
|
231
|
+
this.thumbnailOffset = this.stream.read_i32();
|
|
232
|
+
// Skip rest of header
|
|
233
|
+
for (let i = 0; i < 7; i++) {
|
|
234
|
+
this.stream.read_i32();
|
|
235
|
+
}
|
|
236
|
+
this.stream.match_dex_magic(DexMagic.EndHeader);
|
|
237
|
+
}
|
|
238
|
+
readLayerExpression() {
|
|
239
|
+
const str = this.readStr();
|
|
240
|
+
// console.warn(`[DexReader.readLayerExpression] not yet impl, str:"${str}"`);
|
|
241
|
+
return str;
|
|
242
|
+
}
|
|
243
|
+
readRef() {
|
|
244
|
+
const pos = this.stream.read_i32();
|
|
245
|
+
if (pos <= 0) {
|
|
246
|
+
throw Error(`pos: ${pos} <= 0`);
|
|
247
|
+
}
|
|
248
|
+
const obj = this.objs.get(pos);
|
|
249
|
+
if (obj !== undefined) {
|
|
250
|
+
return obj;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
return new DexIRef(this, pos);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
readRoot() {
|
|
257
|
+
this.takeShortcut("objs.offset");
|
|
258
|
+
this.stream.match_dex_magic(DexMagic.BeginObjs);
|
|
259
|
+
// this is not used in the original implementation
|
|
260
|
+
this.stream.read_i32();
|
|
261
|
+
const obj = this.readObject();
|
|
262
|
+
if (obj instanceof DexObj) {
|
|
263
|
+
return obj;
|
|
264
|
+
}
|
|
265
|
+
if (this.version_1_1_0) {
|
|
266
|
+
this.stream.match_dex_magic(DexMagic.EndObjs);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
readURL() {
|
|
270
|
+
const url = this.readStr();
|
|
271
|
+
if (url === undefined) {
|
|
272
|
+
throw Error("unknown url");
|
|
273
|
+
}
|
|
274
|
+
return new DexURL(url);
|
|
275
|
+
}
|
|
276
|
+
readURL_0_0_1() {
|
|
277
|
+
let url = "";
|
|
278
|
+
const valid = this.stream.read_bool();
|
|
279
|
+
if (!valid) {
|
|
280
|
+
throw Error("url invalid");
|
|
281
|
+
}
|
|
282
|
+
const filenameBase = this.stream.read_str();
|
|
283
|
+
const suffix = this.stream.read_str();
|
|
284
|
+
const fileSize = this.stream.read_i32();
|
|
285
|
+
this.stream.read_str();
|
|
286
|
+
url = filenameBase + "." + suffix;
|
|
287
|
+
const start = this.stream.get_position();
|
|
288
|
+
const end = start + fileSize;
|
|
289
|
+
const fileBuffer = this.readBytes(start, fileSize);
|
|
290
|
+
this.stream.set_position(end);
|
|
291
|
+
this.stream.match_dex_magic(DexMagic.EndOdd);
|
|
292
|
+
// tslint:disable-next-line: no-unused-expression
|
|
293
|
+
new DexReader(fileBuffer, this.manager, url);
|
|
294
|
+
return new DexURL(url);
|
|
295
|
+
}
|
|
296
|
+
loadDexObj(obj, key) {
|
|
297
|
+
obj = obj instanceof DexRef ? obj.load(key) : obj;
|
|
298
|
+
if (!(obj instanceof DexObj)) {
|
|
299
|
+
throw Error(`obj: ${obj} not instance of DexObj`);
|
|
300
|
+
}
|
|
301
|
+
return obj;
|
|
302
|
+
}
|
|
303
|
+
readShortcuts() {
|
|
304
|
+
if (this.positionsOffset === undefined) {
|
|
305
|
+
throw Error("this.positionsOffset is undefined");
|
|
306
|
+
}
|
|
307
|
+
const positionsPos = this.positionsOffset + this.beginPos;
|
|
308
|
+
this.stream.set_position(positionsPos);
|
|
309
|
+
this.stream.match_dex_magic(DexMagic.BeginPositions);
|
|
310
|
+
const count = this.stream.unpack30();
|
|
311
|
+
this.positions = new Map();
|
|
312
|
+
for (let i = 0; i < count; i++) {
|
|
313
|
+
const s = this.stream.read_nano_str();
|
|
314
|
+
const pos = this.stream.unpack30();
|
|
315
|
+
this.positions.set(s, pos);
|
|
316
|
+
}
|
|
317
|
+
this.stream.match_dex_magic(DexMagic.EndPositions);
|
|
318
|
+
}
|
|
319
|
+
takeShortcut(shortcut) {
|
|
320
|
+
const offset = this.positions.get(shortcut) || 0;
|
|
321
|
+
this.stream.set_position(offset + this.beginPos);
|
|
322
|
+
}
|
|
323
|
+
readTables() {
|
|
324
|
+
const currentPos = this.stream.get_position();
|
|
325
|
+
this.readStrs();
|
|
326
|
+
this.readInternalizedXRefs();
|
|
327
|
+
this.stream.set_position(currentPos);
|
|
328
|
+
}
|
|
329
|
+
readStrs() {
|
|
330
|
+
const strsOffset = this.positions.get("strs.offset");
|
|
331
|
+
if (strsOffset === undefined) {
|
|
332
|
+
throw Error("[readStrs] this.positions[strs.offset] is undefined");
|
|
333
|
+
}
|
|
334
|
+
if (strsOffset > 0) {
|
|
335
|
+
this.stream.set_position(strsOffset + this.beginPos);
|
|
336
|
+
this.stream.match_dex_magic(DexMagic.BeginStrs);
|
|
337
|
+
const n = this.stream.unpack30();
|
|
338
|
+
for (let i = 0; i < n; i++) {
|
|
339
|
+
const str = this.stream.read_nano_str();
|
|
340
|
+
const id = this.stream.unpack30();
|
|
341
|
+
this.strs.set(id, str);
|
|
342
|
+
}
|
|
343
|
+
this.stream.match_dex_magic(DexMagic.EndStrs);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
readSetStr() {
|
|
347
|
+
const count = this.stream.read_i32();
|
|
348
|
+
const strings = new Set();
|
|
349
|
+
for (let i = 0; i < count; i++) {
|
|
350
|
+
const s = this.readStr();
|
|
351
|
+
if (s !== undefined) {
|
|
352
|
+
strings.add(s);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return strings;
|
|
356
|
+
}
|
|
357
|
+
readStr() {
|
|
358
|
+
const id = this.stream.unpack30();
|
|
359
|
+
return id > 0 ? this.strs.get(id) : undefined;
|
|
360
|
+
}
|
|
361
|
+
readMapStrInt() {
|
|
362
|
+
const retMap = new Map();
|
|
363
|
+
const count = this.stream.read_i32();
|
|
364
|
+
for (let i = 0; i < count; i++) {
|
|
365
|
+
const key = this.readStr();
|
|
366
|
+
if (key === undefined) {
|
|
367
|
+
throw Error("[readStr] is undefined");
|
|
368
|
+
}
|
|
369
|
+
const value = this.stream.read_i32();
|
|
370
|
+
retMap.set(key, value);
|
|
371
|
+
}
|
|
372
|
+
return retMap;
|
|
373
|
+
}
|
|
374
|
+
readInternalizedXRefs() {
|
|
375
|
+
this.internalizedXRefs = new Map();
|
|
376
|
+
const xrefCount = this.positions.get("ixref.n");
|
|
377
|
+
if (xrefCount === undefined) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
for (let i = 0; i < xrefCount; i++) {
|
|
381
|
+
this.readInternalizedXRef(i, xrefCount);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
readInternalizedXRef(i, xrefCount) {
|
|
385
|
+
const key = "ixref" + i;
|
|
386
|
+
const offset = this.positions.get(key);
|
|
387
|
+
if (offset === undefined) {
|
|
388
|
+
throw Error("[readInternalizedXref] offset not defined");
|
|
389
|
+
}
|
|
390
|
+
this.stream.set_position(offset + this.beginPos);
|
|
391
|
+
this.stream.match_dex_magic(DexMagic.BeginInternalizedXRef);
|
|
392
|
+
const xrefLength = this.stream.unpack30();
|
|
393
|
+
const url = this.readStr();
|
|
394
|
+
if (url === undefined) {
|
|
395
|
+
throw Error("bad str id");
|
|
396
|
+
}
|
|
397
|
+
const xrefStyle = this.stream.read_cstr();
|
|
398
|
+
const hashId = this.stream.read_cstr();
|
|
399
|
+
const encoding = this.stream.read_cstr();
|
|
400
|
+
const hash = this.stream.read_cstr();
|
|
401
|
+
const internalized = new DexInternalizedXRef(i, xrefCount, this.stream.get_position(), xrefLength, url, xrefStyle, hashId, encoding, hash);
|
|
402
|
+
this.internalizedXRefs.set(url, internalized);
|
|
403
|
+
}
|
|
404
|
+
readInternalizedXRefFile(pos, length) {
|
|
405
|
+
this.stream.set_position(pos);
|
|
406
|
+
this.stream.match_dex_magic(DexMagic.OtherInternalizedXRefFile);
|
|
407
|
+
const start = this.stream.get_position();
|
|
408
|
+
const end = start + length;
|
|
409
|
+
this.stream.set_position(end);
|
|
410
|
+
this.stream.match_dex_magic(DexMagic.EndInternalizedXRef);
|
|
411
|
+
return this.readBytes(start, length);
|
|
412
|
+
}
|
|
413
|
+
internalizedXRef(url) {
|
|
414
|
+
return this.internalizedXRefs.get(url);
|
|
415
|
+
}
|
|
416
|
+
expandRelativeUrl(url) {
|
|
417
|
+
throw new Error("expandRelativeUrl not yet implemented");
|
|
418
|
+
}
|
|
419
|
+
putReplaceXRef(obj, k, xref) {
|
|
420
|
+
this.replacedXRefs.put(obj, k, xref);
|
|
421
|
+
}
|
|
422
|
+
readObject() {
|
|
423
|
+
const type = this.readStr();
|
|
424
|
+
switch (type) {
|
|
425
|
+
case "Angle":
|
|
426
|
+
return this.readAngle();
|
|
427
|
+
case "AngleF":
|
|
428
|
+
return this.readAngleF();
|
|
429
|
+
case "Bool":
|
|
430
|
+
return this.stream.read_bool();
|
|
431
|
+
case "Bound":
|
|
432
|
+
return this.readBox();
|
|
433
|
+
// case "BoundF":
|
|
434
|
+
// return new DexBoxF(getDexBoxF(this.b));
|
|
435
|
+
// case "Char":
|
|
436
|
+
// return new DexChar(getDexChar(this.b));
|
|
437
|
+
case "Color":
|
|
438
|
+
return this.readColor();
|
|
439
|
+
case "ColorF":
|
|
440
|
+
return this.readColorF();
|
|
441
|
+
case "DexObj[]":
|
|
442
|
+
return this.readDexObjArray();
|
|
443
|
+
// case "DexObj{}":
|
|
444
|
+
// return read_set_DexObj();
|
|
445
|
+
// case "DexObj->str":
|
|
446
|
+
// return read_map_DexObj_str();
|
|
447
|
+
case "Double":
|
|
448
|
+
return this.stream.read_f64();
|
|
449
|
+
case "Float":
|
|
450
|
+
return this.stream.read_f32();
|
|
451
|
+
case "Int":
|
|
452
|
+
return new DexInt(this.stream.read_i32());
|
|
453
|
+
case "Int64":
|
|
454
|
+
// TODO: is this read right?
|
|
455
|
+
return new DexInt64(this.stream.read_i32(), this.stream.read_i32());
|
|
456
|
+
case "LayerExpr":
|
|
457
|
+
return this.readLayerExpression();
|
|
458
|
+
// case "Line":
|
|
459
|
+
// return new DexLine(getDexLine(this.b));
|
|
460
|
+
// case "Line2D":
|
|
461
|
+
// return new DexLine2D(getDexLine2D(this.b));
|
|
462
|
+
// case "LineF":
|
|
463
|
+
// return new DexLineF(getDexLineF(this.b));
|
|
464
|
+
// case "LineF2D":
|
|
465
|
+
// return new DexLineF2D(getDexLineF2D(this.b));
|
|
466
|
+
// case "Nat":
|
|
467
|
+
// return new DexNat(this.b.getNat());
|
|
468
|
+
case "Orientation":
|
|
469
|
+
return this.readOrientation();
|
|
470
|
+
case "Point":
|
|
471
|
+
return this.readPoint();
|
|
472
|
+
case "Plane":
|
|
473
|
+
return this.readPlane();
|
|
474
|
+
case "Point2D":
|
|
475
|
+
return this.readPoint2D();
|
|
476
|
+
case "Str":
|
|
477
|
+
return this.readStr();
|
|
478
|
+
case "Transform":
|
|
479
|
+
return this.readTransform();
|
|
480
|
+
case "Url":
|
|
481
|
+
return this.version_0_0_1 ? this.readURL_0_0_1() : this.readURL();
|
|
482
|
+
case "Version":
|
|
483
|
+
return this.readDexVersion();
|
|
484
|
+
case "byte[]":
|
|
485
|
+
return this.readByteArray();
|
|
486
|
+
case "str{}":
|
|
487
|
+
return this.readSetStr();
|
|
488
|
+
case "dex":
|
|
489
|
+
return this.readDexObj();
|
|
490
|
+
case "null":
|
|
491
|
+
return undefined;
|
|
492
|
+
// case "point2D[]":
|
|
493
|
+
// return this.read_seq_point2D();
|
|
494
|
+
case "ref":
|
|
495
|
+
return this.readRef();
|
|
496
|
+
// case "str->str":
|
|
497
|
+
// return this.read_map_str_str();
|
|
498
|
+
case "str->int":
|
|
499
|
+
return this.readMapStrInt();
|
|
500
|
+
case "xref":
|
|
501
|
+
return this.readDexXRef();
|
|
502
|
+
default:
|
|
503
|
+
throw Error("[readObject] type not implemented: " + type);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
readObjectFromPos(pos) {
|
|
507
|
+
if (!(pos > this.beginPos)) {
|
|
508
|
+
throw Error("pos is less or equal to this.beginPos");
|
|
509
|
+
}
|
|
510
|
+
let obj = this.objs.get(pos);
|
|
511
|
+
if (obj !== undefined) {
|
|
512
|
+
return obj;
|
|
513
|
+
}
|
|
514
|
+
this.stream.set_position(pos);
|
|
515
|
+
obj = this.readObject();
|
|
516
|
+
if (obj === undefined) {
|
|
517
|
+
throw Error("[readObjectFromPos] z is not defined");
|
|
518
|
+
}
|
|
519
|
+
this.objs.set(pos, obj);
|
|
520
|
+
this.objsPos.set(obj, pos);
|
|
521
|
+
return obj;
|
|
522
|
+
}
|
|
523
|
+
toString() {
|
|
524
|
+
return `DexReader(url=${this.url})`;
|
|
525
|
+
}
|
|
526
|
+
bytes() {
|
|
527
|
+
return this._bytes;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function rootedUrl(url) {
|
|
531
|
+
return url.indexOf("$(") === -1;
|
|
532
|
+
}
|