正在查看: St.John's v1.0.9 应用的 FontDecoder.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: St.John's v1.0.9 应用的 FontDecoder.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.readium.r2.streamer.fetcher;
import android.util.Log;
import com.mcxiaoke.koi.HASH;
import com.mcxiaoke.koi.ext.StringKt;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Map;
import kotlin.Metadata;
import kotlin.Pair;
import kotlin.TuplesKt;
import kotlin.collections.MapsKt;
import kotlin.io.ByteStreamsKt;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.StringsKt;
import org.readium.r2.shared.Encryption;
import org.readium.r2.shared.Link;
import org.readium.r2.shared.Publication;
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000>\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0010$\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u0012\n\u0002\b\u0004\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\u001e\u0010\n\u001a\u00020\u000b2\u0006\u0010\f\u001a\u00020\u000b2\u0006\u0010\r\u001a\u00020\u000e2\u0006\u0010\u000f\u001a\u00020\u0007J \u0010\u0010\u001a\u00020\u00112\u0006\u0010\f\u001a\u00020\u000b2\u0006\u0010\u0012\u001a\u00020\u00072\u0006\u0010\u0013\u001a\u00020\u0004H\u0002J \u0010\u0014\u001a\u00020\u00152\u0006\u0010\f\u001a\u00020\u000b2\u0006\u0010\u0016\u001a\u00020\u00152\u0006\u0010\u0017\u001a\u00020\u0004H\u0002J\u0010\u0010\u0018\u001a\u00020\u00152\u0006\u0010\u0012\u001a\u00020\u0007H\u0002R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082D¢\u0006\u0002\n\u0000R\u001a\u0010\u0005\u001a\u000e\u0012\u0004\u0012\u00020\u0007\u0012\u0004\u0012\u00020\u00070\u0006X\u0082\u000e¢\u0006\u0002\n\u0000R\u001a\u0010\b\u001a\u000e\u0012\u0004\u0012\u00020\u0007\u0012\u0004\u0012\u00020\u00040\u0006X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\t\u001a\u00020\u0004X\u0082D¢\u0006\u0002\n\u0000¨\u0006\u0019"}, d2 = {"Lorg/readium/r2/streamer/fetcher/FontDecoder;", "", "()V", "adobe", "", "decodableAlgorithms", "", "", "decoders", "idpf", "decoding", "Ljava/io/InputStream;", "input", "publication", "Lorg/readium/r2/shared/Publication;", "path", "decodingFont", "Ljava/io/ByteArrayInputStream;", "pubId", "length", "deobfuscate", "", "publicationKey", "obfuscationLength", "getHashKeyAdobe", "r2-streamer-kotlin_devFolioReaderRelease"}, k = 1, mv = {1, 1, 13})
public final class FontDecoder {
private final int adobe = 1024;
private final int idpf = 1040;
private Map<String, String> decodableAlgorithms = MapsKt.mapOf(new Pair[]{TuplesKt.to("fontIdpf", "http://www.idpf.org/2008/embedding"), TuplesKt.to("fontAdobe", "http://ns.adobe.com/pdf/enc#RC")});
private Map<String, Integer> decoders = MapsKt.mapOf(new Pair[]{TuplesKt.to("http://www.idpf.org/2008/embedding", 1040), TuplesKt.to("http://ns.adobe.com/pdf/enc#RC", 1024)});
public final InputStream decoding(InputStream input, Publication publication, String path) {
Encryption encryption;
String algorithm;
Intrinsics.checkParameterIsNotNull(input, "input");
Intrinsics.checkParameterIsNotNull(publication, "publication");
Intrinsics.checkParameterIsNotNull(path, "path");
String identifier = publication.getMetadata().getIdentifier();
Link linkWithHref = publication.linkWithHref(path);
if (linkWithHref == null || (encryption = linkWithHref.getProperties().getEncryption()) == null || (algorithm = encryption.getAlgorithm()) == null) {
return input;
}
Map<String, Integer> map = this.decoders;
Encryption encryption2 = linkWithHref.getProperties().getEncryption();
Integer num = map.get(encryption2 != null ? encryption2.getAlgorithm() : null);
if (num == null) {
return input;
}
int intValue = num.intValue();
if (!this.decodableAlgorithms.values().contains(algorithm)) {
Log.e("Error", path + " is encrypted, but can't handle it");
return input;
}
return decodingFont(input, identifier, intValue);
}
private final ByteArrayInputStream decodingFont(InputStream input, String pubId, int length) {
return new ByteArrayInputStream(deobfuscate(input, length == this.adobe ? getHashKeyAdobe(pubId) : StringKt.toHexBytes(HASH.INSTANCE.sha1(pubId)), length));
}
private final byte[] deobfuscate(InputStream input, byte[] publicationKey, int obfuscationLength) {
byte[] readBytes = ByteStreamsKt.readBytes(input);
if (readBytes.length <= obfuscationLength) {
obfuscationLength = readBytes.length;
}
int i = obfuscationLength - 1;
if (i >= 0) {
int i2 = 0;
while (true) {
readBytes[i2] = (byte) (readBytes[i2] ^ publicationKey[i2 % publicationKey.length]);
if (i2 == i) {
break;
}
i2++;
}
}
return readBytes;
}
private final byte[] getHashKeyAdobe(String pubId) {
return StringKt.toHexBytes(StringsKt.replace$default(StringsKt.replace$default(pubId, "urn:uuid:", "", false, 4, (Object) null), "-", "", false, 4, (Object) null));
}
}