From e12d9ddc8886a50c408a0f942b4ab946ef0e0fd1 Mon Sep 17 00:00:00 2001 From: fanruinet Date: Wed, 1 Jun 2022 21:47:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=A7=E8=83=BD=E6=94=B9=E8=BF=9B=EF=BC=9A?= =?UTF-8?q?=20=E5=B0=86getFileInfo=E4=B8=AD=E8=AE=A1=E7=AE=97MD5=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=B1JS=E5=AE=9E=E7=8E=B0=E6=94=B9?= =?UTF-8?q?=E4=B8=BAJava=E5=AE=9E=E7=8E=B0=EF=BC=8C=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E9=9C=80=E8=A6=81JS=E5=BC=95=E6=93=8E=E3=80=82=20=E5=87=8F?= =?UTF-8?q?=E5=B0=91=E4=BA=86=E8=AE=A1=E7=AE=97proof=5Fcode=E6=89=80?= =?UTF-8?q?=E9=9C=80=E4=BB=8E=E7=A3=81=E7=9B=98=E4=B8=8A=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E9=87=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + src/main/java/com/yxhpy/BaseAliPan.java | 48 ++++---- src/main/resources/en.js | 143 ------------------------ 3 files changed, 24 insertions(+), 169 deletions(-) create mode 100644 .gitignore delete mode 100644 src/main/resources/en.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c498fe7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +/loginInfo diff --git a/src/main/java/com/yxhpy/BaseAliPan.java b/src/main/java/com/yxhpy/BaseAliPan.java index d8d4797..8770eb5 100644 --- a/src/main/java/com/yxhpy/BaseAliPan.java +++ b/src/main/java/com/yxhpy/BaseAliPan.java @@ -5,10 +5,8 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.http.*; import cn.hutool.log.GlobalLogFactory; import cn.hutool.log.Log; -import cn.hutool.script.JavaScriptEngine; import com.yxhpy.conifg.RequestConfig; import com.yxhpy.fileWatch.FileListener; -import com.yxhpy.fileWatch.WatchRun; import com.yxhpy.entity.DownloadEntity; import com.yxhpy.entity.EncFileInfoEntity; import com.yxhpy.entity.response.*; @@ -16,10 +14,8 @@ import com.yxhpy.enumCode.QrStatus; import com.yxhpy.utils.*; import okhttp3.*; -import javax.script.*; import java.io.*; import java.math.BigInteger; -import java.net.URL; import java.util.*; import java.util.List; import java.util.concurrent.ConcurrentSkipListSet; @@ -51,7 +47,6 @@ public class BaseAliPan { public BaseAliPan() { request = new Request(); - } public DataEntity getLoginQr() { @@ -163,23 +158,25 @@ public class BaseAliPan { String name = FileUtil.getName(file); long size = FileUtil.size(file); String accessToken = loginInfo.getAccessToken(); - JavaScriptEngine instance = JavaScriptEngine.instance(); - InputStream resourceAsStream = BaseAliPan.class.getClassLoader().getResourceAsStream("en.js"); - try (InputStreamReader fileReader = new InputStreamReader(resourceAsStream); - InputStream stream = new FileInputStream(file)) { - instance.eval(fileReader); - String limit = (String) instance.invokeFunction("h", instance.invokeFunction("m", accessToken)); - BigInteger bigInteger = new BigInteger(limit.substring(0, 16), 16); - long left = size == 0 ? size : bigInteger.mod(BigInteger.valueOf(size)).longValueExact(); - long right = Math.min(left + 8, size); - int preSize = (int) Math.min(1024, size); - byte[] preLimit = FileUtils.readLimitBytes(file, 0, preSize); - byte[] proofCodeLimit = FileUtils.readLimitBytes(file, (int)left, (int)right); - String preHash = MD5Util.hashCode(preLimit, MD5Util.SHA1); + String limit = MD5Util.hashCode(accessToken.getBytes(), MD5Util.MD5); + BigInteger bigInteger = new BigInteger(limit.substring(0, 16), 16); + long left = size == 0 ? size : bigInteger.mod(BigInteger.valueOf(size)).longValueExact(); + long right = Math.min(left + 8, size); + int preSize = (int) Math.min(1024, size); + try (FileInputStream stream = new FileInputStream(file)) { String contentHash = MD5Util.hashCode(stream, MD5Util.SHA1); + + byte[] preLimit = new byte[preSize]; + stream.getChannel().position(0); + stream.read(preLimit); + String preHash = MD5Util.hashCode(preLimit, MD5Util.SHA1); + + stream.getChannel().position(left); + byte[] proofCodeLimit = new byte[(int)(right - left)]; + stream.read(proofCodeLimit); String proofCode = Base64Encoder.encode(proofCodeLimit); return new EncFileInfoEntity(name, size, preHash, contentHash, proofCode); - } catch (IOException | ScriptException | NoSuchMethodException e) { + } catch (IOException e) { e.printStackTrace(); } return null; @@ -192,7 +189,7 @@ public class BaseAliPan { map.put("parent_file_id", parentFileId); map.put("name", fileInfo.getFileName()); map.put("type", "file"); -// refuse auto_rename + // refuse auto_rename map.put("check_name_mode", "refuse"); map.put("size", fileInfo.getFileSize()); map.put("pre_hash", fileInfo.getPreHash()); @@ -281,7 +278,7 @@ public class BaseAliPan { } } String fileName = path + File.separator + name; - if (Objects.equals(getFileIdByPath(fileName), fileId)){ + if (Objects.equals(getFileIdByPath(fileName), fileId)) { return; } addFileId(fileName, fileId); @@ -426,7 +423,6 @@ public class BaseAliPan { if (item == null) { FolderCreateEntity withFolders = createWithFolders(fileId, name); fileId = withFolders.getFileId(); - } else { fileId = item.getFileId(); } @@ -512,7 +508,7 @@ public class BaseAliPan { public void run() { File basePath = new File(BASE_PATH); - if (!basePath.exists()){ + if (!basePath.exists()) { basePath.mkdirs(); } int delayRestart = 5000; @@ -526,7 +522,7 @@ public class BaseAliPan { } else { startLogin(); } - while (true){ + while (true) { try { if (RequestConfig.PROVIDER) { initDefault(); @@ -534,9 +530,9 @@ public class BaseAliPan { initDownloader(); } Thread.currentThread().join(); - } catch (Exception e){ + } catch (Exception e) { log.error("错误:" + e.getMessage()); - if (RequestConfig.ENABLE_RESTART){ + if (RequestConfig.ENABLE_RESTART) { log.info(delayRestart + "毫秒后开始重新启动项目"); try { Thread.sleep(delayRestart); diff --git a/src/main/resources/en.js b/src/main/resources/en.js deleted file mode 100644 index 64fdfee..0000000 --- a/src/main/resources/en.js +++ /dev/null @@ -1,143 +0,0 @@ -function o(e, t) { - var n = (65535 & e) + (65535 & t); - return (e >> 16) + (t >> 16) + (n >> 16) << 16 | 65535 & n -} -function a(e, t, n, r, i, a) { - return o((s = o(o(t, e), o(r, a))) << (c = i) | s >>> 32 - c, n); - var s, c - } -function s(e, t, n, r, i, o, s) { - return a(t & n | ~t & r, e, t, i, o, s) -} -function c(e, t, n, r, i, o, s) { - return a(t & r | n & ~r, e, t, i, o, s) -} -function l(e, t, n, r, i, o, s) { - return a(t ^ n ^ r, e, t, i, o, s) -} -function u(e, t, n, r, i, o, s) { - return a(n ^ (t | ~r), e, t, i, o, s) -} -function d(e, t) { - var n, r, i, a, d; - e[t >> 5] |= 128 << t % 32, - e[14 + (t + 64 >>> 9 << 4)] = t; - var f = 1732584193 - , p = -271733879 - , h = -1732584194 - , A = 271733878; - for (n = 0; n < e.length; n += 16) - r = f, - i = p, - a = h, - d = A, - f = s(f, p, h, A, e[n], 7, -680876936), - A = s(A, f, p, h, e[n + 1], 12, -389564586), - h = s(h, A, f, p, e[n + 2], 17, 606105819), - p = s(p, h, A, f, e[n + 3], 22, -1044525330), - f = s(f, p, h, A, e[n + 4], 7, -176418897), - A = s(A, f, p, h, e[n + 5], 12, 1200080426), - h = s(h, A, f, p, e[n + 6], 17, -1473231341), - p = s(p, h, A, f, e[n + 7], 22, -45705983), - f = s(f, p, h, A, e[n + 8], 7, 1770035416), - A = s(A, f, p, h, e[n + 9], 12, -1958414417), - h = s(h, A, f, p, e[n + 10], 17, -42063), - p = s(p, h, A, f, e[n + 11], 22, -1990404162), - f = s(f, p, h, A, e[n + 12], 7, 1804603682), - A = s(A, f, p, h, e[n + 13], 12, -40341101), - h = s(h, A, f, p, e[n + 14], 17, -1502002290), - f = c(f, p = s(p, h, A, f, e[n + 15], 22, 1236535329), h, A, e[n + 1], 5, -165796510), - A = c(A, f, p, h, e[n + 6], 9, -1069501632), - h = c(h, A, f, p, e[n + 11], 14, 643717713), - p = c(p, h, A, f, e[n], 20, -373897302), - f = c(f, p, h, A, e[n + 5], 5, -701558691), - A = c(A, f, p, h, e[n + 10], 9, 38016083), - h = c(h, A, f, p, e[n + 15], 14, -660478335), - p = c(p, h, A, f, e[n + 4], 20, -405537848), - f = c(f, p, h, A, e[n + 9], 5, 568446438), - A = c(A, f, p, h, e[n + 14], 9, -1019803690), - h = c(h, A, f, p, e[n + 3], 14, -187363961), - p = c(p, h, A, f, e[n + 8], 20, 1163531501), - f = c(f, p, h, A, e[n + 13], 5, -1444681467), - A = c(A, f, p, h, e[n + 2], 9, -51403784), - h = c(h, A, f, p, e[n + 7], 14, 1735328473), - f = l(f, p = c(p, h, A, f, e[n + 12], 20, -1926607734), h, A, e[n + 5], 4, -378558), - A = l(A, f, p, h, e[n + 8], 11, -2022574463), - h = l(h, A, f, p, e[n + 11], 16, 1839030562), - p = l(p, h, A, f, e[n + 14], 23, -35309556), - f = l(f, p, h, A, e[n + 1], 4, -1530992060), - A = l(A, f, p, h, e[n + 4], 11, 1272893353), - h = l(h, A, f, p, e[n + 7], 16, -155497632), - p = l(p, h, A, f, e[n + 10], 23, -1094730640), - f = l(f, p, h, A, e[n + 13], 4, 681279174), - A = l(A, f, p, h, e[n], 11, -358537222), - h = l(h, A, f, p, e[n + 3], 16, -722521979), - p = l(p, h, A, f, e[n + 6], 23, 76029189), - f = l(f, p, h, A, e[n + 9], 4, -640364487), - A = l(A, f, p, h, e[n + 12], 11, -421815835), - h = l(h, A, f, p, e[n + 15], 16, 530742520), - f = u(f, p = l(p, h, A, f, e[n + 2], 23, -995338651), h, A, e[n], 6, -198630844), - A = u(A, f, p, h, e[n + 7], 10, 1126891415), - h = u(h, A, f, p, e[n + 14], 15, -1416354905), - p = u(p, h, A, f, e[n + 5], 21, -57434055), - f = u(f, p, h, A, e[n + 12], 6, 1700485571), - A = u(A, f, p, h, e[n + 3], 10, -1894986606), - h = u(h, A, f, p, e[n + 10], 15, -1051523), - p = u(p, h, A, f, e[n + 1], 21, -2054922799), - f = u(f, p, h, A, e[n + 8], 6, 1873313359), - A = u(A, f, p, h, e[n + 15], 10, -30611744), - h = u(h, A, f, p, e[n + 6], 15, -1560198380), - p = u(p, h, A, f, e[n + 13], 21, 1309151649), - f = u(f, p, h, A, e[n + 4], 6, -145523070), - A = u(A, f, p, h, e[n + 11], 10, -1120210379), - h = u(h, A, f, p, e[n + 2], 15, 718787259), - p = u(p, h, A, f, e[n + 9], 21, -343485551), - f = o(f, r), - p = o(p, i), - h = o(h, a), - A = o(A, d); - return [f, p, h, A] -} -function f(e) { - var t, n = "", r = 32 * e.length; - for (t = 0; t < r; t += 8) - n += String.fromCharCode(e[t >> 5] >>> t % 32 & 255); - return n -} -function p(e) { - var t, n = []; - for (n[(e.length >> 2) - 1] = void 0, - t = 0; t < n.length; t += 1) - n[t] = 0; - var r = 8 * e.length; - for (t = 0; t < r; t += 8) - n[t >> 5] |= (255 & e.charCodeAt(t / 8)) << t % 32; - return n -} -function h(e) { - var t, n, r = "0123456789abcdef", i = ""; - for (n = 0; n < e.length; n += 1) - t = e.charCodeAt(n), - i += r.charAt(t >>> 4 & 15) + r.charAt(15 & t); - return i -} -function A(e) { - return unescape(encodeURIComponent(e)) -} -function m(e) { - return function(e) { - return f(d(p(e), 8 * e.length)) - }(A(e)) -} -function g(e, t) { - return function(e, t) { - var n, r, i = p(e), o = [], a = []; - for (o[15] = a[15] = void 0, - i.length > 16 && (i = d(i, 8 * e.length)), - n = 0; n < 16; n += 1) - o[n] = 909522486 ^ i[n], - a[n] = 1549556828 ^ i[n]; - return r = d(o.concat(p(t)), 512 + 8 * t.length), - f(d(a.concat(r), 640)) - }(A(e), A(t)) -} -- Gitee