@hot-updater/react-native 1.0.8 → 1.1.1
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/HotUpdater.podspec +14 -2
- package/Package.swift +24 -3
- package/android/build.gradle +2 -6
- package/android/hot-updater-fingerprint.gradle +135 -0
- package/android/src/main/cpp/HotUpdaterRecovery.cpp +291 -21
- package/android/src/main/java/com/hotupdater/ActivityStartGate.kt +176 -15
- package/android/src/main/java/com/hotupdater/ArtifactFileResolver.kt +20 -8
- package/android/src/main/java/com/hotupdater/BundleFileStorageService.kt +145 -31
- package/android/src/main/java/com/hotupdater/CohortService.kt +10 -2
- package/android/src/main/java/com/hotupdater/FileManagerService.kt +3 -1
- package/android/src/main/java/com/hotupdater/HotUpdaterConfig.kt +249 -21
- package/android/src/main/java/com/hotupdater/HotUpdaterException.kt +8 -4
- package/android/src/main/java/com/hotupdater/HotUpdaterHeldContent.kt +92 -0
- package/android/src/main/java/com/hotupdater/HotUpdaterImpl.kt +319 -113
- package/android/src/main/java/com/hotupdater/HotUpdaterInstance.kt +87 -0
- package/android/src/main/java/com/hotupdater/HotUpdaterInstanceEnvironment.kt +323 -0
- package/android/src/main/java/com/hotupdater/HotUpdaterMainThread.kt +46 -0
- package/android/src/main/java/com/hotupdater/HotUpdaterProcess.kt +30 -0
- package/android/src/main/java/com/hotupdater/HotUpdaterRecoveryAttribution.kt +493 -0
- package/android/src/main/java/com/hotupdater/HotUpdaterRecoveryManager.kt +1541 -159
- package/android/src/main/java/com/hotupdater/HotUpdaterRecoverySlots.kt +137 -0
- package/android/src/main/java/com/hotupdater/HotUpdaterRecoveryState.kt +4 -0
- package/android/src/main/java/com/hotupdater/HotUpdaterRuntimeInstance.kt +53 -0
- package/android/src/main/java/com/hotupdater/HotUpdaterUpdateCheck.kt +149 -0
- package/android/src/main/java/com/hotupdater/InstallIdentityService.kt +12 -2
- package/android/src/main/java/com/hotupdater/NativeConfigUtils.kt +5 -6
- package/android/src/main/java/com/hotupdater/NativeUpdateCheck.kt +172 -0
- package/android/src/main/java/com/hotupdater/NativeUpdateChecker.kt +1007 -0
- package/android/src/main/java/com/hotupdater/NativeUpdateEventQueue.kt +111 -0
- package/android/src/main/java/com/hotupdater/OkHttpUpdateCheckTransport.kt +88 -0
- package/android/src/main/java/com/hotupdater/ReleaseCatalog.kt +491 -0
- package/android/src/main/java/com/hotupdater/ReleaseCatalogClient.kt +405 -0
- package/android/src/main/java/com/hotupdater/ReleaseSelection.kt +474 -0
- package/android/src/main/java/com/hotupdater/SignatureVerifier.kt +32 -10
- package/android/src/main/java/com/hotupdater/StrictJson.kt +392 -0
- package/android/src/main/java/com/hotupdater/VersionedPreferencesService.kt +24 -9
- package/android/src/main/java/com/hotupdater/WeakIdentitySet.kt +76 -0
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/BitReader.java +314 -0
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/BrotliError.java +47 -0
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/BrotliInputStream.java +174 -0
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/BrotliRuntimeException.java +21 -0
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/Context.java +58 -0
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/Decode.java +1574 -0
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/Decoder.java +72 -0
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/Dictionary.java +103 -0
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/DictionaryData.java +82 -0
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/Huffman.java +143 -0
- package/{LICENSE → android/src/main/java/com/hotupdater/vendor/brotli/dec/LICENSE} +6 -20
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/README.md +39 -0
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/State.java +100 -0
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/Transform.java +240 -0
- package/android/src/main/java/com/hotupdater/vendor/brotli/dec/Utils.java +163 -0
- package/android/src/main/resources/META-INF/LICENSE-brotli +19 -0
- package/android/src/newarch/HotUpdater.kt +53 -15
- package/android/src/newarch/HotUpdaterModule.kt +42 -17
- package/android/src/newarch/JavaScriptExceptionHooks.kt +45 -8
- package/android/src/oldarch/HotUpdater.kt +51 -12
- package/android/src/oldarch/HotUpdaterModule.kt +43 -17
- package/android/src/oldarch/HotUpdaterSpec.kt +2 -0
- package/android/src/oldarch/JavaScriptExceptionHooks.kt +25 -16
- package/ios/HotUpdater/Interface/HotUpdaterInterface.h +13 -0
- package/ios/HotUpdater/Internal/ArtifactFileResolver.swift +38 -7
- package/ios/HotUpdater/Internal/BuiltInAssetResolver.swift +10 -4
- package/ios/HotUpdater/Internal/BundleFileStorageService.swift +186 -48
- package/ios/HotUpdater/Internal/CohortService.swift +8 -0
- package/ios/HotUpdater/Internal/HotUpdater.mm +821 -71
- package/ios/HotUpdater/Internal/HotUpdaterAsync.swift +7 -0
- package/ios/HotUpdater/Internal/HotUpdaterConfig.swift +208 -25
- package/ios/HotUpdater/Internal/HotUpdaterFingerprintHash.m +10 -0
- package/ios/HotUpdater/Internal/HotUpdaterImpl.swift +940 -261
- package/ios/HotUpdater/Internal/HotUpdaterInstanceEnvironment.swift +492 -0
- package/ios/HotUpdater/Internal/HotUpdaterInstanceRouter.swift +83 -0
- package/ios/HotUpdater/Internal/HotUpdaterInterface.swift +28 -1
- package/ios/HotUpdater/Internal/HotUpdaterLaunchRecovery.swift +1553 -0
- package/ios/HotUpdater/Internal/HotUpdaterNativeUpdates.swift +353 -0
- package/ios/HotUpdater/Internal/LaunchPreparationLock.swift +54 -0
- package/ios/HotUpdater/Internal/NativeUpdateCheck.swift +2051 -0
- package/ios/HotUpdater/Internal/ReleaseCatalog.swift +634 -0
- package/ios/HotUpdater/Internal/ReleaseCatalogCacheService.swift +1 -1
- package/ios/HotUpdater/Internal/ReleaseSelection.swift +482 -0
- package/ios/HotUpdater/Internal/SignatureVerifier.swift +27 -10
- package/ios/HotUpdater/Internal/StrictJson.swift +363 -0
- package/ios/HotUpdater/Internal/URLSessionDownloadService.swift +4 -2
- package/ios/HotUpdater/Internal/UpdateFailure.swift +2 -0
- package/ios/HotUpdater/Package.swift +11 -0
- package/ios/HotUpdater/Public/HotUpdater/HotUpdater.h +4 -0
- package/ios/HotUpdater/Public/HotUpdater.h +21 -2
- package/ios/HotUpdater/Recovery/HotUpdaterRecoveryHooks.mm +66 -0
- package/ios/Plugins/HotUpdaterFingerprintPlugin/HotUpdaterFingerprintPlugin.swift +45 -0
- package/ios/scripts/generate-fingerprint-hash.zsh +85 -0
- package/lib/commonjs/checkForUpdate.js +3 -1
- package/lib/commonjs/checkForUpdate.js.map +1 -1
- package/lib/commonjs/index.js +9 -12
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/native.js +24 -79
- package/lib/commonjs/native.js.map +1 -1
- package/lib/commonjs/nativeUpdateEvents.js +66 -0
- package/lib/commonjs/nativeUpdateEvents.js.map +1 -0
- package/lib/commonjs/sdkVersion.js +1 -1
- package/lib/commonjs/specs/NativeHotUpdater.js.map +1 -1
- package/lib/module/checkForUpdate.js +3 -1
- package/lib/module/checkForUpdate.js.map +1 -1
- package/lib/module/index.js +10 -13
- package/lib/module/index.js.map +1 -1
- package/lib/module/native.js +19 -73
- package/lib/module/native.js.map +1 -1
- package/lib/module/nativeUpdateEvents.js +61 -0
- package/lib/module/nativeUpdateEvents.js.map +1 -0
- package/lib/module/sdkVersion.js +1 -1
- package/lib/module/specs/NativeHotUpdater.js.map +1 -1
- package/lib/typescript/commonjs/checkForUpdate.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +4 -14
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/native.d.ts +9 -46
- package/lib/typescript/commonjs/native.d.ts.map +1 -1
- package/lib/typescript/commonjs/nativeUpdateEvents.d.ts +12 -0
- package/lib/typescript/commonjs/nativeUpdateEvents.d.ts.map +1 -0
- package/lib/typescript/commonjs/sdkVersion.d.ts +1 -1
- package/lib/typescript/commonjs/specs/NativeHotUpdater.d.ts +19 -3
- package/lib/typescript/commonjs/specs/NativeHotUpdater.d.ts.map +1 -1
- package/lib/typescript/module/checkForUpdate.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +4 -14
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/native.d.ts +9 -46
- package/lib/typescript/module/native.d.ts.map +1 -1
- package/lib/typescript/module/nativeUpdateEvents.d.ts +12 -0
- package/lib/typescript/module/nativeUpdateEvents.d.ts.map +1 -0
- package/lib/typescript/module/sdkVersion.d.ts +1 -1
- package/lib/typescript/module/specs/NativeHotUpdater.d.ts +19 -3
- package/lib/typescript/module/specs/NativeHotUpdater.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/checkForUpdate.ts +7 -1
- package/src/index.ts +9 -17
- package/src/native.ts +19 -91
- package/src/nativeUpdateEvents.ts +77 -0
- package/src/sdkVersion.ts +1 -1
- package/src/specs/NativeHotUpdater.ts +20 -3
- package/android/libs/README.md +0 -50
- package/android/libs/hot-updater-brotli-dec-1.2.0.jar +0 -0
- package/android/src/bridge/BridgeReactInstance.kt +0 -38
- package/android/src/bridgeless/BridgeReactInstance.kt +0 -24
- package/android/src/main/java/com/hotupdater/ContentAppearedLog.kt +0 -31
- package/android/src/main/java/com/hotupdater/ReactIntegrationManagerBase.kt +0 -34
- package/android/src/newarch/ReactIntegrationManager.kt +0 -212
- package/android/src/oldarch/ReactIntegrationManager.kt +0 -120
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/* Copyright 2015 Google Inc. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
Distributed under MIT license.
|
|
4
|
+
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.hotupdater.vendor.brotli.dec;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Utilities for building Huffman decoding tables.
|
|
11
|
+
*/
|
|
12
|
+
final class Huffman {
|
|
13
|
+
|
|
14
|
+
private static final int MAX_LENGTH = 15;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns reverse(reverse(key, len) + 1, len).
|
|
18
|
+
*
|
|
19
|
+
* <p> reverse(key, len) is the bit-wise reversal of the len least significant bits of key.
|
|
20
|
+
*/
|
|
21
|
+
private static int getNextKey(int key, int len) {
|
|
22
|
+
int step = 1 << (len - 1);
|
|
23
|
+
while ((key & step) != 0) {
|
|
24
|
+
step = step >> 1;
|
|
25
|
+
}
|
|
26
|
+
return (key & (step - 1)) + step;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Stores {@code item} in {@code table[0], table[step], table[2 * step] .., table[end]}.
|
|
31
|
+
*
|
|
32
|
+
* <p> Assumes that end is an integer multiple of step.
|
|
33
|
+
*/
|
|
34
|
+
private static void replicateValue(int[] table, int offset, int step, int end, int item) {
|
|
35
|
+
int pos = end;
|
|
36
|
+
while (pos > 0) {
|
|
37
|
+
pos -= step;
|
|
38
|
+
table[offset + pos] = item;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param count histogram of bit lengths for the remaining symbols,
|
|
44
|
+
* @param len code length of the next processed symbol.
|
|
45
|
+
* @return table width of the next 2nd level table.
|
|
46
|
+
*/
|
|
47
|
+
private static int nextTableBitSize(int[] count, int len, int rootBits) {
|
|
48
|
+
int bits = len;
|
|
49
|
+
int left = 1 << (bits - rootBits);
|
|
50
|
+
while (bits < MAX_LENGTH) {
|
|
51
|
+
left -= count[bits];
|
|
52
|
+
if (left <= 0) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
bits++;
|
|
56
|
+
left = left << 1;
|
|
57
|
+
}
|
|
58
|
+
return bits - rootBits;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Builds Huffman lookup table assuming code lengths are in symbol order.
|
|
63
|
+
*
|
|
64
|
+
* @return number of slots used by resulting Huffman table
|
|
65
|
+
*/
|
|
66
|
+
static int buildHuffmanTable(int[] tableGroup, int tableIdx, int rootBits, int[] codeLengths,
|
|
67
|
+
int codeLengthsSize) {
|
|
68
|
+
final int tableOffset = tableGroup[tableIdx];
|
|
69
|
+
final int[] sorted = new int[codeLengthsSize]; // Symbols sorted by code length.
|
|
70
|
+
// TODO(eustas): fill with zeroes?
|
|
71
|
+
final int[] count = new int[MAX_LENGTH + 1]; // Number of codes of each length.
|
|
72
|
+
final int[] offset = new int[MAX_LENGTH + 1]; // Offsets in sorted table for each length.
|
|
73
|
+
|
|
74
|
+
// Build histogram of code lengths.
|
|
75
|
+
for (int sym = 0; sym < codeLengthsSize; ++sym) {
|
|
76
|
+
count[codeLengths[sym]]++;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Generate offsets into sorted symbol table by code length.
|
|
80
|
+
offset[1] = 0;
|
|
81
|
+
for (int len = 1; len < MAX_LENGTH; ++len) {
|
|
82
|
+
offset[len + 1] = offset[len] + count[len];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Sort symbols by length, by symbol order within each length.
|
|
86
|
+
for (int sym = 0; sym < codeLengthsSize; ++sym) {
|
|
87
|
+
if (codeLengths[sym] != 0) {
|
|
88
|
+
sorted[offset[codeLengths[sym]]++] = sym;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
int tableBits = rootBits;
|
|
93
|
+
int tableSize = 1 << tableBits;
|
|
94
|
+
int totalSize = tableSize;
|
|
95
|
+
|
|
96
|
+
// Special case code with only one value.
|
|
97
|
+
if (offset[MAX_LENGTH] == 1) {
|
|
98
|
+
for (int k = 0; k < totalSize; ++k) {
|
|
99
|
+
tableGroup[tableOffset + k] = sorted[0];
|
|
100
|
+
}
|
|
101
|
+
return totalSize;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Fill in root table.
|
|
105
|
+
int key = 0; // Reversed prefix code.
|
|
106
|
+
int symbol = 0;
|
|
107
|
+
int step = 1;
|
|
108
|
+
for (int len = 1; len <= rootBits; ++len) {
|
|
109
|
+
step = step << 1;
|
|
110
|
+
while (count[len] > 0) {
|
|
111
|
+
replicateValue(tableGroup, tableOffset + key, step, tableSize,
|
|
112
|
+
len << 16 | sorted[symbol++]);
|
|
113
|
+
key = getNextKey(key, len);
|
|
114
|
+
count[len]--;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Fill in 2nd level tables and add pointers to root table.
|
|
119
|
+
final int mask = totalSize - 1;
|
|
120
|
+
int low = -1;
|
|
121
|
+
int currentOffset = tableOffset;
|
|
122
|
+
step = 1;
|
|
123
|
+
for (int len = rootBits + 1; len <= MAX_LENGTH; ++len) {
|
|
124
|
+
step = step << 1;
|
|
125
|
+
while (count[len] > 0) {
|
|
126
|
+
if ((key & mask) != low) {
|
|
127
|
+
currentOffset += tableSize;
|
|
128
|
+
tableBits = nextTableBitSize(count, len, rootBits);
|
|
129
|
+
tableSize = 1 << tableBits;
|
|
130
|
+
totalSize += tableSize;
|
|
131
|
+
low = key & mask;
|
|
132
|
+
tableGroup[tableOffset + low] =
|
|
133
|
+
(tableBits + rootBits) << 16 | (currentOffset - tableOffset - low);
|
|
134
|
+
}
|
|
135
|
+
replicateValue(tableGroup, currentOffset + (key >> rootBits), step, tableSize,
|
|
136
|
+
(len - rootBits) << 16 | sorted[symbol++]);
|
|
137
|
+
key = getNextKey(key, len);
|
|
138
|
+
count[len]--;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return totalSize;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Sungyu Kang
|
|
1
|
+
Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors.
|
|
4
2
|
|
|
5
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
4
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -9,25 +7,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
9
7
|
copies of the Software, and to permit persons to whom the Software is
|
|
10
8
|
furnished to do so, subject to the following conditions:
|
|
11
9
|
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
copies or substantial portions of the Software.
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
14
12
|
|
|
15
13
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
14
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
ADDITIONAL DISCLAIMER
|
|
26
|
-
|
|
27
|
-
The authors of this software shall not be held responsible for any legal issues,
|
|
28
|
-
regulatory violations, policy violations, or disputes arising from the use,
|
|
29
|
-
distribution, or integration of this software.
|
|
30
|
-
|
|
31
|
-
Users are solely responsible for ensuring compliance with all applicable laws,
|
|
32
|
-
regulations, and third-party policies (including but not limited to app store
|
|
33
|
-
policies).
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Vendored Brotli decoder
|
|
2
|
+
|
|
3
|
+
These files are the Java Brotli decoder from
|
|
4
|
+
[google/brotli v1.2.0](https://github.com/google/brotli/tree/v1.2.0/java/org/brotli/dec)
|
|
5
|
+
(commit [028fb5a](https://github.com/google/brotli/commit/028fb5a23661f123017c060daa546b55cf4bde29)),
|
|
6
|
+
under its MIT license in [LICENSE](LICENSE).
|
|
7
|
+
|
|
8
|
+
**Why vendored:** the official `org.brotli:dec` package on Maven Central is
|
|
9
|
+
stuck at v0.1.2 (May 2017), which has known vulnerabilities. v1.2.0 fixes them:
|
|
10
|
+
|
|
11
|
+
- CVE-2020-8927: buffer overflow in Brotli versions before 1.0.8
|
|
12
|
+
- CVE-2025-6176: denial of service in versions up to 1.1.0
|
|
13
|
+
|
|
14
|
+
**Why sources, not a jar:** the decoder compiles into Hot Updater's own classes.
|
|
15
|
+
Tools that merge a React Native app and its native modules into one AAR, such as
|
|
16
|
+
React Native Brownfield's Gradle plugin, keep each module's classes but drop the
|
|
17
|
+
jars a module depends on through `files(...)`.
|
|
18
|
+
|
|
19
|
+
**Changes from upstream:** only the package. `package org.brotli.dec;` and
|
|
20
|
+
`import static org.brotli.dec.` became `com.hotupdater.vendor.brotli.dec`, so
|
|
21
|
+
Hot Updater's decoder never clashes with an app's own `org.brotli:dec`. The
|
|
22
|
+
test files, `BUILD.bazel`, `pom.xml`, and the Kotlin port are not included.
|
|
23
|
+
|
|
24
|
+
`proguard-rules.pro` keeps `com.hotupdater.vendor.brotli.**`: `Dictionary` loads
|
|
25
|
+
`DictionaryData` by name.
|
|
26
|
+
|
|
27
|
+
**Update:** copy the non-test `java/org/brotli/dec/*.java` files of the new
|
|
28
|
+
release, rewrite the package lines as above, and update the version, commit,
|
|
29
|
+
and CVE notes here.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
git clone --depth 1 --branch <tag> https://github.com/google/brotli.git
|
|
33
|
+
for f in brotli/java/org/brotli/dec/*.java; do
|
|
34
|
+
case "$f" in *Test.java|*TestUtils.java) continue ;; esac
|
|
35
|
+
sed -e 's/^package org\.brotli\.dec;/package com.hotupdater.vendor.brotli.dec;/' \
|
|
36
|
+
-e 's/^import static org\.brotli\.dec\./import static com.hotupdater.vendor.brotli.dec./' \
|
|
37
|
+
"$f" > "$(basename "$f")"
|
|
38
|
+
done
|
|
39
|
+
```
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* Copyright 2015 Google Inc. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
Distributed under MIT license.
|
|
4
|
+
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.hotupdater.vendor.brotli.dec;
|
|
8
|
+
|
|
9
|
+
import java.io.InputStream;
|
|
10
|
+
|
|
11
|
+
final class State {
|
|
12
|
+
byte[] ringBuffer;
|
|
13
|
+
byte[] contextModes;
|
|
14
|
+
byte[] contextMap;
|
|
15
|
+
byte[] distContextMap;
|
|
16
|
+
byte[] distExtraBits;
|
|
17
|
+
byte[] output;
|
|
18
|
+
byte[] byteBuffer; // BitReader
|
|
19
|
+
|
|
20
|
+
short[] shortBuffer; // BitReader
|
|
21
|
+
|
|
22
|
+
int[] intBuffer; // BitReader
|
|
23
|
+
int[] rings;
|
|
24
|
+
int[] blockTrees;
|
|
25
|
+
int[] literalTreeGroup;
|
|
26
|
+
int[] commandTreeGroup;
|
|
27
|
+
int[] distanceTreeGroup;
|
|
28
|
+
int[] distOffset;
|
|
29
|
+
|
|
30
|
+
long accumulator64; // BitReader: pre-fetched bits.
|
|
31
|
+
|
|
32
|
+
int runningState; // Default value is 0 == Decode.UNINITIALIZED
|
|
33
|
+
int nextRunningState;
|
|
34
|
+
int accumulator32; // BitReader: pre-fetched bits.
|
|
35
|
+
int bitOffset; // BitReader: bit-reading position in accumulator.
|
|
36
|
+
int halfOffset; // BitReader: offset of next item in intBuffer/shortBuffer.
|
|
37
|
+
int tailBytes; // BitReader: number of bytes in unfinished half.
|
|
38
|
+
int endOfStreamReached; // BitReader: input stream is finished.
|
|
39
|
+
int metaBlockLength;
|
|
40
|
+
int inputEnd;
|
|
41
|
+
int isUncompressed;
|
|
42
|
+
int isMetadata;
|
|
43
|
+
int literalBlockLength;
|
|
44
|
+
int numLiteralBlockTypes;
|
|
45
|
+
int commandBlockLength;
|
|
46
|
+
int numCommandBlockTypes;
|
|
47
|
+
int distanceBlockLength;
|
|
48
|
+
int numDistanceBlockTypes;
|
|
49
|
+
int pos;
|
|
50
|
+
int maxDistance;
|
|
51
|
+
int distRbIdx;
|
|
52
|
+
int trivialLiteralContext;
|
|
53
|
+
int literalTreeIdx;
|
|
54
|
+
int commandTreeIdx;
|
|
55
|
+
int j;
|
|
56
|
+
int insertLength;
|
|
57
|
+
int contextMapSlice;
|
|
58
|
+
int distContextMapSlice;
|
|
59
|
+
int contextLookupOffset1;
|
|
60
|
+
int contextLookupOffset2;
|
|
61
|
+
int distanceCode;
|
|
62
|
+
int numDirectDistanceCodes;
|
|
63
|
+
int distancePostfixBits;
|
|
64
|
+
int distance;
|
|
65
|
+
int copyLength;
|
|
66
|
+
int maxBackwardDistance;
|
|
67
|
+
int maxRingBufferSize;
|
|
68
|
+
int ringBufferSize;
|
|
69
|
+
int expectedTotalSize;
|
|
70
|
+
int outputOffset;
|
|
71
|
+
int outputLength;
|
|
72
|
+
int outputUsed;
|
|
73
|
+
int ringBufferBytesWritten;
|
|
74
|
+
int ringBufferBytesReady;
|
|
75
|
+
int isEager;
|
|
76
|
+
int isLargeWindow;
|
|
77
|
+
|
|
78
|
+
// Compound dictionary
|
|
79
|
+
int cdNumChunks;
|
|
80
|
+
int cdTotalSize;
|
|
81
|
+
int cdBrIndex;
|
|
82
|
+
int cdBrOffset;
|
|
83
|
+
int cdBrLength;
|
|
84
|
+
int cdBrCopied;
|
|
85
|
+
byte[][] cdChunks;
|
|
86
|
+
int[] cdChunkOffsets;
|
|
87
|
+
int cdBlockBits;
|
|
88
|
+
byte[] cdBlockMap;
|
|
89
|
+
|
|
90
|
+
InputStream input = Utils.makeEmptyInput(); // BitReader
|
|
91
|
+
|
|
92
|
+
State() {
|
|
93
|
+
this.ringBuffer = new byte[0];
|
|
94
|
+
this.rings = new int[10];
|
|
95
|
+
this.rings[0] = 16;
|
|
96
|
+
this.rings[1] = 15;
|
|
97
|
+
this.rings[2] = 11;
|
|
98
|
+
this.rings[3] = 4;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/* Copyright 2015 Google Inc. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
Distributed under MIT license.
|
|
4
|
+
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.hotupdater.vendor.brotli.dec;
|
|
8
|
+
|
|
9
|
+
import java.nio.ByteBuffer;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Transformations on dictionary words.
|
|
13
|
+
*
|
|
14
|
+
* Transform descriptor is a triplet: {prefix, operator, suffix}.
|
|
15
|
+
* "prefix" and "suffix" are short strings inserted before and after transformed dictionary word.
|
|
16
|
+
* "operator" is applied to dictionary word itself.
|
|
17
|
+
*
|
|
18
|
+
* Some operators has "built-in" parameters, i.e. parameter is defined by operator ordinal. Other
|
|
19
|
+
* operators have "external" parameters, supplied via additional table encoded in shared dictionary.
|
|
20
|
+
*
|
|
21
|
+
* Operators:
|
|
22
|
+
* - IDENTITY (0): dictionary word is inserted "as is"
|
|
23
|
+
* - OMIT_LAST_N (1 - 9): last N octets of dictionary word are not inserted; N == ordinal
|
|
24
|
+
* - OMIT_FIRST_M (12-20): first M octets of dictionary word are not inserted; M == ordinal - 11
|
|
25
|
+
* - UPPERCASE_FIRST (10): first "scalar" is XOR'ed with number 32
|
|
26
|
+
* - UPPERCASE_ALL (11): all "scalars" are XOR'ed with number 32
|
|
27
|
+
* - SHIFT_FIRST (21): first "scalar" is shifted by number form parameter table
|
|
28
|
+
* - SHIFT_ALL (22): all "scalar" is shifted by number form parameter table
|
|
29
|
+
*
|
|
30
|
+
* Here "scalar" is a variable length character coding similar to UTF-8 encoding.
|
|
31
|
+
* UPPERCASE_XXX / SHIFT_XXX operators were designed to change the case of UTF-8 encoded characters.
|
|
32
|
+
* While UPPERCASE_XXX works well only on ASCII charset, SHIFT is much more generic and could be
|
|
33
|
+
* used for most (all?) alphabets.
|
|
34
|
+
*/
|
|
35
|
+
final class Transform {
|
|
36
|
+
|
|
37
|
+
static final class Transforms {
|
|
38
|
+
final int numTransforms;
|
|
39
|
+
final int[] triplets;
|
|
40
|
+
final byte[] prefixSuffixStorage;
|
|
41
|
+
final int[] prefixSuffixHeads;
|
|
42
|
+
final short[] params;
|
|
43
|
+
|
|
44
|
+
Transforms(int numTransforms, int prefixSuffixLen, int prefixSuffixCount) {
|
|
45
|
+
this.numTransforms = numTransforms;
|
|
46
|
+
this.triplets = new int[numTransforms * 3];
|
|
47
|
+
this.params = new short[numTransforms];
|
|
48
|
+
this.prefixSuffixStorage = new byte[prefixSuffixLen];
|
|
49
|
+
this.prefixSuffixHeads = new int[prefixSuffixCount + 1];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static final int NUM_RFC_TRANSFORMS = 121;
|
|
54
|
+
static final Transforms RFC_TRANSFORMS = new Transforms(NUM_RFC_TRANSFORMS, 167, 50);
|
|
55
|
+
|
|
56
|
+
private static final int OMIT_FIRST_LAST_LIMIT = 9;
|
|
57
|
+
|
|
58
|
+
private static final int IDENTITY = 0;
|
|
59
|
+
private static final int OMIT_LAST_BASE = IDENTITY + 1 - 1; // there is no OMIT_LAST_0.
|
|
60
|
+
private static final int UPPERCASE_FIRST = OMIT_LAST_BASE + OMIT_FIRST_LAST_LIMIT + 1;
|
|
61
|
+
private static final int UPPERCASE_ALL = UPPERCASE_FIRST + 1;
|
|
62
|
+
private static final int OMIT_FIRST_BASE = UPPERCASE_ALL + 1 - 1; // there is no OMIT_FIRST_0.
|
|
63
|
+
private static final int SHIFT_FIRST = OMIT_FIRST_BASE + OMIT_FIRST_LAST_LIMIT + 1;
|
|
64
|
+
private static final int SHIFT_ALL = SHIFT_FIRST + 1;
|
|
65
|
+
|
|
66
|
+
// Bundle of 0-terminated strings.
|
|
67
|
+
// typo:off
|
|
68
|
+
private static final String PREFIX_SUFFIX_SRC = "# #s #, #e #.# the #.com/#\u00C2\u00A0# of # and"
|
|
69
|
+
+ " # in # to #\"#\">#\n#]# for # a # that #. # with #'# from # by #. The # on # as # is #ing"
|
|
70
|
+
+ " #\n\t#:#ed #(# at #ly #=\"# of the #. This #,# not #er #al #='#ful #ive #less #est #ize #"
|
|
71
|
+
+ "ous #";
|
|
72
|
+
private static final String TRANSFORMS_SRC = " !! ! , *! &! \" ! ) * * - ! # ! #!*! "
|
|
73
|
+
+ "+ ,$ ! - % . / # 0 1 . \" 2 3!* 4% ! # / 5 6 7 8 0 1 & $ 9 + : "
|
|
74
|
+
+ " ; < ' != > ?! 4 @ 4 2 & A *# ( B C& ) % ) !*# *-% A +! *. D! %' & E *6 F "
|
|
75
|
+
+ " G% ! *A *% H! D I!+! J!+ K +- *4! A L!*4 M N +6 O!*% +.! K *G P +%( ! G *D +D "
|
|
76
|
+
+ " Q +# *K!*G!+D!+# +G +A +4!+% +K!+4!*D!+K!*K";
|
|
77
|
+
// typo:on
|
|
78
|
+
|
|
79
|
+
private static void unpackTransforms(byte[] prefixSuffix,
|
|
80
|
+
int[] prefixSuffixHeads, int[] transforms, String prefixSuffixSrc, String transformsSrc) {
|
|
81
|
+
final int[] prefixSuffixBytes = Utils.toUtf8Runes(prefixSuffixSrc);
|
|
82
|
+
final int n = prefixSuffixBytes.length;
|
|
83
|
+
int index = 1;
|
|
84
|
+
int j = 0;
|
|
85
|
+
for (int i = 0; i < n; ++i) {
|
|
86
|
+
final int c = prefixSuffixBytes[i];
|
|
87
|
+
if (c == 35) { // == #
|
|
88
|
+
prefixSuffixHeads[index++] = j;
|
|
89
|
+
} else {
|
|
90
|
+
prefixSuffix[j++] = (byte) c;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
for (int i = 0; i < NUM_RFC_TRANSFORMS * 3; ++i) {
|
|
95
|
+
transforms[i] = (int) transformsSrc.charAt(i) - 32;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static {
|
|
100
|
+
unpackTransforms(RFC_TRANSFORMS.prefixSuffixStorage, RFC_TRANSFORMS.prefixSuffixHeads,
|
|
101
|
+
RFC_TRANSFORMS.triplets, PREFIX_SUFFIX_SRC, TRANSFORMS_SRC);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static int transformDictionaryWord(byte[] dst, int dstOffset, ByteBuffer src, int srcOffset,
|
|
105
|
+
int wordLen, Transforms transforms, int transformIndex) {
|
|
106
|
+
int offset = dstOffset;
|
|
107
|
+
final int[] triplets = transforms.triplets;
|
|
108
|
+
final byte[] prefixSuffixStorage = transforms.prefixSuffixStorage;
|
|
109
|
+
final int[] prefixSuffixHeads = transforms.prefixSuffixHeads;
|
|
110
|
+
final int transformOffset = 3 * transformIndex;
|
|
111
|
+
final int prefixIdx = triplets[transformOffset];
|
|
112
|
+
final int transformType = triplets[transformOffset + 1];
|
|
113
|
+
final int suffixIdx = triplets[transformOffset + 2];
|
|
114
|
+
int prefix = prefixSuffixHeads[prefixIdx];
|
|
115
|
+
final int prefixEnd = prefixSuffixHeads[prefixIdx + 1];
|
|
116
|
+
int suffix = prefixSuffixHeads[suffixIdx];
|
|
117
|
+
final int suffixEnd = prefixSuffixHeads[suffixIdx + 1];
|
|
118
|
+
|
|
119
|
+
int omitFirst = transformType - OMIT_FIRST_BASE;
|
|
120
|
+
int omitLast = transformType - OMIT_LAST_BASE;
|
|
121
|
+
if (omitFirst < 1 || omitFirst > OMIT_FIRST_LAST_LIMIT) {
|
|
122
|
+
omitFirst = 0;
|
|
123
|
+
}
|
|
124
|
+
if (omitLast < 1 || omitLast > OMIT_FIRST_LAST_LIMIT) {
|
|
125
|
+
omitLast = 0;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Copy prefix.
|
|
129
|
+
while (prefix != prefixEnd) {
|
|
130
|
+
dst[offset++] = prefixSuffixStorage[prefix++];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
int len = wordLen;
|
|
134
|
+
// Copy trimmed word.
|
|
135
|
+
if (omitFirst > len) {
|
|
136
|
+
omitFirst = len;
|
|
137
|
+
}
|
|
138
|
+
int dictOffset = srcOffset + omitFirst;
|
|
139
|
+
len -= omitFirst;
|
|
140
|
+
len -= omitLast;
|
|
141
|
+
int i = len;
|
|
142
|
+
while (i > 0) {
|
|
143
|
+
dst[offset++] = src.get(dictOffset++);
|
|
144
|
+
i--;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Ferment.
|
|
148
|
+
if (transformType == UPPERCASE_FIRST || transformType == UPPERCASE_ALL) {
|
|
149
|
+
int uppercaseOffset = offset - len;
|
|
150
|
+
if (transformType == UPPERCASE_FIRST) {
|
|
151
|
+
len = 1;
|
|
152
|
+
}
|
|
153
|
+
while (len > 0) {
|
|
154
|
+
final int c0 = (int) dst[uppercaseOffset] & 0xFF;
|
|
155
|
+
if (c0 < 0xC0) {
|
|
156
|
+
if (c0 >= 97 && c0 <= 122) { // in [a..z] range
|
|
157
|
+
dst[uppercaseOffset] = (byte) ((int) dst[uppercaseOffset] ^ 32);
|
|
158
|
+
}
|
|
159
|
+
uppercaseOffset += 1;
|
|
160
|
+
len -= 1;
|
|
161
|
+
} else if (c0 < 0xE0) {
|
|
162
|
+
dst[uppercaseOffset + 1] = (byte) ((int) dst[uppercaseOffset + 1] ^ 32);
|
|
163
|
+
uppercaseOffset += 2;
|
|
164
|
+
len -= 2;
|
|
165
|
+
} else {
|
|
166
|
+
dst[uppercaseOffset + 2] = (byte) ((int) dst[uppercaseOffset + 2] ^ 5);
|
|
167
|
+
uppercaseOffset += 3;
|
|
168
|
+
len -= 3;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
} else if (transformType == SHIFT_FIRST || transformType == SHIFT_ALL) {
|
|
172
|
+
int shiftOffset = offset - len;
|
|
173
|
+
final int param = (int) transforms.params[transformIndex];
|
|
174
|
+
/* Limited sign extension: scalar < (1 << 24). */
|
|
175
|
+
int scalar = (param & 0x7FFF) + (0x1000000 - (param & 0x8000));
|
|
176
|
+
while (len > 0) {
|
|
177
|
+
int step = 1;
|
|
178
|
+
final int c0 = (int) dst[shiftOffset] & 0xFF;
|
|
179
|
+
if (c0 < 0x80) {
|
|
180
|
+
/* 1-byte rune / 0sssssss / 7 bit scalar (ASCII). */
|
|
181
|
+
scalar += c0;
|
|
182
|
+
dst[shiftOffset] = (byte) (scalar & 0x7F);
|
|
183
|
+
} else if (c0 < 0xC0) {
|
|
184
|
+
/* Continuation / 10AAAAAA. */
|
|
185
|
+
} else if (c0 < 0xE0) {
|
|
186
|
+
/* 2-byte rune / 110sssss AAssssss / 11 bit scalar. */
|
|
187
|
+
if (len >= 2) {
|
|
188
|
+
final int c1 = (int) dst[shiftOffset + 1];
|
|
189
|
+
scalar += (c1 & 0x3F) | ((c0 & 0x1F) << 6);
|
|
190
|
+
dst[shiftOffset] = (byte) (0xC0 | ((scalar >> 6) & 0x1F));
|
|
191
|
+
dst[shiftOffset + 1] = (byte) ((c1 & 0xC0) | (scalar & 0x3F));
|
|
192
|
+
step = 2;
|
|
193
|
+
} else {
|
|
194
|
+
step = len;
|
|
195
|
+
}
|
|
196
|
+
} else if (c0 < 0xF0) {
|
|
197
|
+
/* 3-byte rune / 1110ssss AAssssss BBssssss / 16 bit scalar. */
|
|
198
|
+
if (len >= 3) {
|
|
199
|
+
final int c1 = (int) dst[shiftOffset + 1];
|
|
200
|
+
final int c2 = (int) dst[shiftOffset + 2];
|
|
201
|
+
scalar += (c2 & 0x3F) | ((c1 & 0x3F) << 6) | ((c0 & 0x0F) << 12);
|
|
202
|
+
dst[shiftOffset] = (byte) (0xE0 | ((scalar >> 12) & 0x0F));
|
|
203
|
+
dst[shiftOffset + 1] = (byte) ((c1 & 0xC0) | ((scalar >> 6) & 0x3F));
|
|
204
|
+
dst[shiftOffset + 2] = (byte) ((c2 & 0xC0) | (scalar & 0x3F));
|
|
205
|
+
step = 3;
|
|
206
|
+
} else {
|
|
207
|
+
step = len;
|
|
208
|
+
}
|
|
209
|
+
} else if (c0 < 0xF8) {
|
|
210
|
+
/* 4-byte rune / 11110sss AAssssss BBssssss CCssssss / 21 bit scalar. */
|
|
211
|
+
if (len >= 4) {
|
|
212
|
+
final int c1 = (int) dst[shiftOffset + 1];
|
|
213
|
+
final int c2 = (int) dst[shiftOffset + 2];
|
|
214
|
+
final int c3 = (int) dst[shiftOffset + 3];
|
|
215
|
+
scalar += (c3 & 0x3F) | ((c2 & 0x3F) << 6) | ((c1 & 0x3F) << 12) | ((c0 & 0x07) << 18);
|
|
216
|
+
dst[shiftOffset] = (byte) (0xF0 | ((scalar >> 18) & 0x07));
|
|
217
|
+
dst[shiftOffset + 1] = (byte) ((c1 & 0xC0) | ((scalar >> 12) & 0x3F));
|
|
218
|
+
dst[shiftOffset + 2] = (byte) ((c2 & 0xC0) | ((scalar >> 6) & 0x3F));
|
|
219
|
+
dst[shiftOffset + 3] = (byte) ((c3 & 0xC0) | (scalar & 0x3F));
|
|
220
|
+
step = 4;
|
|
221
|
+
} else {
|
|
222
|
+
step = len;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
shiftOffset += step;
|
|
226
|
+
len -= step;
|
|
227
|
+
if (transformType == SHIFT_FIRST) {
|
|
228
|
+
len = 0;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Copy suffix.
|
|
234
|
+
while (suffix != suffixEnd) {
|
|
235
|
+
dst[offset++] = prefixSuffixStorage[suffix++];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return offset - dstOffset;
|
|
239
|
+
}
|
|
240
|
+
}
|