@configura/web-core 1.3.0-alpha.1 → 1.3.0-alpha.2

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