-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLazyBox.java
More file actions
616 lines (524 loc) · 20.9 KB
/
LazyBox.java
File metadata and controls
616 lines (524 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
package roj.plugins;
import roj.archive.sevenz.*;
import roj.archive.zip.ZipEditor;
import roj.archive.zip.ZipEntry;
import roj.archive.zip.ZipFile;
import roj.asm.ClassNode;
import roj.asmx.Context;
import roj.asmx.injector.CodeWeaver;
import roj.asmx.injector.WeaveException;
import roj.collect.CollectionX;
import roj.collect.HashMap;
import roj.collect.IntMap;
import roj.concurrent.TaskGroup;
import roj.concurrent.TaskPool;
import roj.crypt.CRC32;
import roj.ecc.ReedSolomonCodec;
import roj.http.curl.DownloadTask;
import roj.io.IOUtil;
import roj.io.LimitInputStream;
import roj.io.source.FileSource;
import roj.plugin.Plugin;
import roj.plugin.SimplePlugin;
import roj.text.CharList;
import roj.text.TextReader;
import roj.text.TextWriter;
import roj.ui.*;
import roj.util.*;
import java.io.*;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
import static roj.ui.CommandNode.argument;
import static roj.ui.CommandNode.literal;
/**
* @author Roj234
* @since 2024/5/15 14:10
*/
@SimplePlugin(id = "lazyBox", version = "1.4", desc = """
高仿瑞士军刀/doge
[文件工具]
复制文件(夹): cp[copy] <src> <dst>
移动文件(夹): mv[move] <src> <dst>
删除文件(夹): rd[rmdir] <path>
读取修改时间: mtime <file>
设置修改时间: mtime <file> <time>
修改时间与创建时间的差值: writecost <file>
批量正则替换: batchrpl <path> <regexp> <replacement>
[压缩包工具]
多线程7z验证: 7zverify <file>
7z差异计算: 7zdiff <file1> <file2>
zip增量更新: zipupdate <file>
删除文件夹: archive_del_folder <file>
[网页工具]
多线程下载文件: curl <url> <saveTo> [threads]
[Java工具]
Cpk压缩: cpk <input> [output]
Nixim注入: nixim <injector> <reference> [output]
""")
public class LazyBox extends Plugin {
@Override
protected void onEnable() throws Exception {
registerCommand(literal("7zverify").then(argument("path", Argument.file()).executes(this::qzVerify)));
registerCommand(literal("7zdiff").then(argument("file1", Argument.file()).then(argument("file2", Argument.file()).executes(this::qzDiff))));
registerCommand(literal("zipupdateexe")
.then(argument("自解压模板", Argument.file())
.then(argument("压缩包", Argument.file())
.executes(this::updateExe))));
registerCommand(literal("zipupdate").then(argument("path", Argument.file()).executes(this::zipUpdate)));
registerCommand(literal("ziprmfolder").then(argument("file", Argument.file()).executes(ctx -> {
try (var za = new ZipEditor(ctx.argument("file", File.class))) {
for (ZipEntry ze : za.entries()) {
String name = ze.getName();
if (name.endsWith("/")) {
if (ze.getSize() == 0) {
za.put(name, null);
} else {
getLogger().warn("'文件夹'{}的大小不为零: {}", name, ze.getSize());
za.put(name, null);
za.put(name.substring(0, name.length()-1), DynByteBuf.wrap(za.get(ze)));
}
}
}
za.save();
}
})));
registerCommand(literal("reccgen").then(argument("file", Argument.file()).then(argument("ratio", Argument.real(0.001, 0.5)).executes(ctx -> {
float exceptingRatio = (float)(double)ctx.argument("ratio", Double.class);
var file = ctx.argument("file", File.class);
int lastDataByte = -1;
int lastEccByte = -1;
float lastDelta = 1;
float lastRatio = -1;
for (int dataBytes = 253; dataBytes > 0; dataBytes--) {
for (int eccBytes = 2; dataBytes+eccBytes <= 255; eccBytes += 2) {
float ratio = (eccBytes/2f) / (dataBytes+eccBytes);
float delta = ratio - exceptingRatio;
if (delta > 0 && delta < lastDelta) {
lastDelta = delta;
lastRatio = ratio;
lastDataByte = dataBytes;
lastEccByte = eccBytes;
}
}
}
long fileSize = file.length();
var recc = new ReedSolomonCodec(lastDataByte, lastEccByte);
int stride = (int) Math.min((fileSize+recc.dataBytes()-1) / recc.dataBytes(), (Math.min(fileSize, 1048576) / recc.maxError()));
var metadata = new ByteList(16).put(0x00/*KIND_RS*/).put(lastDataByte).put(lastEccByte).putVUInt(stride).putVULong(fileSize);
metadata.putInt(CRC32.crc32(metadata.array(), 0, metadata.wIndex())).put(metadata.wIndex());
//System.out.println("这个文件尾部看起来已经追加过纠错码了");
System.out.println("RS("+lastDataByte+","+(lastDataByte+lastEccByte)+") 追加"+((float)lastEccByte)/(lastDataByte+lastEccByte)*100+"%的纠错码,允许在总体中出现"+lastRatio*100+"%的任意损坏");
System.out.println("分块卷积算法的矩阵大小为"+stride+", 使能纠错长度不大于"+(recc.maxError()*stride)+"的连续错误");
System.out.println("按任意键(Ctrl+C以取消)以开始在文件"+file.getName()+"后追加纠错码");
char c = TUI.key(null, new CharList());
if (c == 0) return;
try (var in = new LimitInputStream(new FileInputStream(file), fileSize);
var out = new FileOutputStream(file, true);
var bar = new EasyProgressBar("生成纠错码")) {
bar.setTotal(fileSize);
recc.generateInterleavedCode(in, out, stride, bar);
metadata.writeToStream(out);
bar.end("生成完毕");
} catch (IOException e) {
getLogger().warn("生成失败", e);
}
}))));
registerCommand(literal("reccfix").then(argument("file", Argument.file()).executes(ctx -> {
var file = ctx.argument("file", File.class);
try (var in = new FileSource(file);
var bar = new EasyProgressBar("校验&纠错")) {
var metadata = new ByteList();
in.seek(in.length()-1);
int dataLength = in.read();
in.seek(in.length()-1-dataLength);
in.readFully(metadata, dataLength);
var crc = CRC32.crc32(metadata.array(), 0, dataLength - 4);
if (crc != metadata.getInt(dataLength - 4)) throw new FastFailException("文件尾校验失败");
int eccType = metadata.readUnsignedByte();
if (eccType != 0) throw new FastFailException("不是RS纠错码:"+eccType);
var recc = new ReedSolomonCodec(metadata.readUnsignedByte(), metadata.readUnsignedByte());
var stride = metadata.readVUInt();
var originalSize = metadata.readVULong();
in.seek(0);
bar.setTotal(originalSize);
int i = recc.interleavedErrorCorrection(in, originalSize, stride, bar);
bar.end("发现并纠正了"+(i&Integer.MAX_VALUE)+"个错误");
if (i != 0) {
System.out.println("纠正了一些错误,不过,纠错码中的错误并不会被纠正,建议你删除并重新生成纠错码");
}
} catch (Exception e) {
getLogger().warn("校验失败", e);
}
})));
registerCommand(literal("reccdel").then(argument("file", Argument.file()).executes(ctx -> {
var file = ctx.argument("file", File.class);
try (var in = new FileSource(file)) {
var metadata = new ByteList();
in.seek(in.length()-1);
int dataLength = in.read();
in.seek(in.length()-1-dataLength);
in.readFully(metadata, dataLength);
var crc = CRC32.crc32(metadata.array(), 0, dataLength - 4);
if (crc != metadata.getInt(dataLength - 4)) throw new FastFailException("文件尾校验失败");
int eccType = metadata.readUnsignedByte();
if (eccType != 0) throw new FastFailException("不是RS纠错码:"+eccType);
var recc = new ReedSolomonCodec(metadata.readUnsignedByte(), metadata.readUnsignedByte());
int stride = metadata.readVUInt();
var originalSize = metadata.readVULong();
in.setLength(originalSize);
System.out.println("纠错码已删除");
} catch (Exception e) {
getLogger().warn("校验失败", e);
}
})));
//region 文件工具
{
CommandNode child = argument("源", Argument.path())
.then(argument("目标", Argument.path())
.executes(ctx -> {
File src = ctx.argument("源", File.class);
File dst = ctx.argument("目标", File.class);
if (!dst.exists() && !dst.mkdirs()) {
getLogger().error("目标不存在且无法创建");
return;
}
IOUtil.copyOrMove(src, dst, ctx.context.startsWith("fmove"));
}));
registerCommand(literal("fcopy").then(child));
registerCommand(literal("fmove").then(child));
registerCommand(literal("frmdir").then(argument("路径", Argument.path()).executes(ctx -> {
File path = ctx.argument("路径", File.class);
System.out.println("删除"+path.getAbsolutePath()+"及其所有文件?[y/n]");
char c = TUI.key("YyNn");
if (c != 'y' && c != 'Y') return;
System.out.println(IOUtil.deleteRecursively(path));
})));
registerCommand(literal("fmtime")
.then(argument("文件", Argument.path())
.then(argument("源", Argument.path()).executes(ctx -> {
File s = ctx.argument("文件", File.class);
File d = ctx.argument("源", File.class);
System.out.println(d.setLastModified(s.lastModified()));
})).then(argument("时间", Argument.Long(0, Long.MAX_VALUE))
.executes(ctx -> {
File s = ctx.argument("文件", File.class);
long d = ctx.argument("时间", Long.class);
System.out.println(s.setLastModified(d));
}))));
registerCommand(literal("ftimegap").then(argument("file", Argument.path()).executes(ctx -> {
File s = ctx.argument("file", File.class);
BasicFileAttributes attr = Files.readAttributes(s.toPath(), BasicFileAttributes.class);
long delta = attr.lastModifiedTime().to(TimeUnit.NANOSECONDS) - attr.creationTime().to(TimeUnit.NANOSECONDS);
System.out.println("delta= "+delta+"ns");
})));
registerCommand(literal("fregreplace").then(
argument("文件夹", Argument.folder()).then(
argument("正则", Argument.string()).then(
argument("替换", Argument.string()).executes(ctx -> {
Pattern regex = Pattern.compile(ctx.argument("正则", String.class));
String replace = ctx.argument("替换", String.class);
File path = ctx.argument("文件夹", File.class);
for (File file : IOUtil.listFiles(path)) {
try (TextReader in = TextReader.auto(file)) {
AtomicBoolean change = new AtomicBoolean(false);
CharList sb = IOUtil.getSharedCharBuf().readFully(in);
sb.preg_replace_callback(regex, m -> {
CharList tmp = new CharList(replace);
for (int i = 0; i < m.groupCount(); i++)
tmp.replace("$"+i, m.group(i));
String str = tmp.toStringAndFree();
if (!str.equals(m.group())) change.set(true);
return str;
});
if (!change.get()) continue;
try (TextWriter out = TextWriter.to(file, Charset.forName(in.charset()))) {
out.append(sb);
}
}
}
})).executes(ctx -> {
Pattern regex = Pattern.compile(ctx.argument("正则", String.class));
File path = ctx.argument("文件夹", File.class);
var pool = TaskPool.cpu().newGroup();
for (File file : IOUtil.listFiles(path)) {
pool.executeUnsafe(() -> {
try (TextReader in = TextReader.auto(file)) {
CharList sb = IOUtil.getSharedCharBuf().readFully(in);
sb.preg_match_callback(regex, m -> {
System.out.println(file.getName()+":"+m.start()+": "+m.group());
});
}
});
}
pool.await();
}))));
}
//endregion
registerCommand(literal("curl").then(argument("网址", Argument.string())
.then(argument("保存到", Argument.fileOptional(true))
.executes(this::download)
.then(argument("线程数", Argument.number(1, 256))
.executes(this::download)))));
Command nixim = ctx -> {
var nx = new CodeWeaver();
File src = ctx.argument("注入(Nixim)", File.class);
if (src.isDirectory()) {
IOUtil.listFiles(src, file -> {
if (IOUtil.getExtension(file.getName()).equals("class")) {
try {
nx.read(ClassNode.parseSkeleton(IOUtil.read(file)));
} catch (WeaveException | IOException e) {
Helpers.athrow(e);
}
}
return false;
});
} else {
if (IOUtil.getExtension(src.getName()).equals("class")) {
nx.read(ClassNode.parseSkeleton(IOUtil.read(src)));
} else {
try (var zf = new ZipFile(src)) {
for (var ze : zf.entries()) {
if (IOUtil.getExtension(ze.getName()).equals("class")) {
nx.read(ClassNode.parseSkeleton(zf.get(ze)));
}
}
}
}
}
src = ctx.argument("源", File.class);
File dst = ctx.argument("保存至", File.class);
if (dst == null) dst = IOUtil.addSuffix(src, "-注入");
IOUtil.copyFile(src, dst);
try (var archive = new ZipEditor(dst)) {
for (var entry : nx.registry().entrySet()) {
String file = entry.getKey().replace('.', '/')+".class";
InputStream in = archive.getInputStream(file);
if (in == null) {
System.err.println("nixim target "+file+" not found");
continue;
}
try {
var klass = new Context(entry.getKey(), in);
nx.transform(entry.getKey(), klass);
archive.put(file, klass::getCompressedShared, true);
} catch (Exception e) {
e.printStackTrace();
} finally {
in.close();
}
}
archive.save();
}
System.out.println("注入完成");
};
registerCommand(literal("nixim")
.then(argument("注入(Nixim)", Argument.file())
.then(argument("源", Argument.file())
.executes(nixim)
.then(argument("保存至", Argument.fileOptional(true)).executes(nixim)))));
}
private void zipUpdate(CommandContext ctx) throws IOException {
var za = new ZipEditor(ctx.argument("path", File.class));
Collection<String> entryName = CollectionX.mapToView(za.entries(), ZipEntry::getName, ZipEntry::new);
Map<String, String> fileView = CollectionX.toMap(entryName, x -> x.endsWith("/") ? null : x);
var update = new Shell("\u001b[96mZUpdate \u001b[97m> ");
update.register(literal("set").then(argument("name", Argument.suggest(fileView)).then(argument("path", Argument.file()).executes(c -> {
String out = c.argument("name", String.class);
File in = c.argument("path", File.class);
if (out == null || out.endsWith("/")) {
System.out.println("位置是目录");
return;
}
za.putStream(out, () -> {
try {
return new FileInputStream(in);
} catch (FileNotFoundException e) {
return Helpers.athrow2(e);
}
}, true);
}))));
update.register(literal("del").then(argument("name", Argument.oneOf(fileView)).executes(c -> za.put(ctx.argument("name", String.class), null))));
update.register(literal("reload").executes(c -> za.getPendingUpdates().clear()));
update.register(literal("save").executes(c -> za.save()));
update.register(literal("exit").executes(c -> {
za.close();
Tty.popHandler();
}));
update.onKeyboardInterrupt(() -> update.executeSync("exit"));
update.sortCommands();
Tty.pushHandler(update);
}
private void qzVerify(CommandContext ctx) {
File file = ctx.argument("path", File.class);
EasyProgressBar bar = new EasyProgressBar("验证压缩文件", "B");
AtomicReference<Throwable> failed = new AtomicReference<>();
try (SevenZFile archive = new SevenZFile(file)) {
for (SevenZEntry entry : archive.getEntriesByPresentOrder()) {
bar.addTotal(entry.getSize());
}
TaskGroup monitor = TaskPool.cpu().newGroup();
archive.parallelDecompress(monitor, (entry, in) -> {
byte[] arr = ArrayCache.getIOBuffer();
try {
while (true) {
int r = in.read(arr);
if (r < 0) break;
if (failed.get() != null) throw new FastFailException("-other thread failed-");
bar.increment(r);
}
} catch (FastFailException e) {
throw e;
} catch (Throwable e) {
monitor.cancel();
failed.set(e);
throw new FastFailException("-验证失败-");
} finally {
ArrayCache.putArray(arr);
}
}, null);
monitor.await();
} catch (Exception e) {
failed.compareAndSet(null, e);
}
Throwable exception = failed.getAndSet(null);
if (exception != null) {
bar.end("验证失败", Tty.RED);
exception.printStackTrace();
} else {
bar.end("验证成功");
}
bar.close();
}
private void qzDiff(CommandContext ctx) throws IOException {
SevenZFile in1 = new SevenZFile(ctx.argument("file1", File.class));
SevenZFile in2 = new SevenZFile(ctx.argument("file2", File.class));
HashMap<String, SevenZEntry> remain = in1.getEntries();
int add = 0, change = 0, del = 0, move = 0;
IntMap<SevenZEntry> in2_by_crc32 = new IntMap<>();
HashMap<SevenZEntry, String> in1_should_copy = new HashMap<>(), in2_should_copy = new HashMap<>();
for (SevenZEntry entry : in2.getEntriesByPresentOrder()) {
if (entry.isDirectory()) continue;
SevenZEntry oldEntry = remain.remove(entry.getName());
if (oldEntry == null) {
SevenZEntry prev = in2_by_crc32.put(entry.getCrc32(), entry);
if (prev != null) System.out.println("警告:在"+entry.getCrc32()+"["+entry.getName()+"]上出现了CRC冲突");
in2_should_copy.put(entry, "add/"+entry.getName());
add++;
} else if (oldEntry.getCrc32() != entry.getCrc32()) {
in1_should_copy.put(oldEntry, "mod_old/"+oldEntry.getName());
in2_should_copy.put(entry, "mod_new/"+entry.getName());
change++;
}
}
for (SevenZEntry oldEntry : remain.values()) {
if (oldEntry.isDirectory()) continue;
SevenZEntry entry = in2_by_crc32.get(oldEntry.getCrc32());
if (entry != null) {
in2_should_copy.remove(entry);
add--;
move++;
} else {
in1_should_copy.put(oldEntry, "del/"+oldEntry.getName());
del++;
}
}
if ((add|change|del|move) == 0) {
System.out.println("\u001b[92m两个压缩包完全相同");
return;
}
System.out.println("\u001b[93m新增\u001b[94m"+add+" \u001b[93m删除\u001b[94m"+del+" \u001b[93m修改\u001b[94m"+change+" \u001b[93m移动\u001b[94m"+move);
Shell c1 = new Shell("\u001b[96m7zDiff \u001b[97m> ");
Tty.pushHandler(c1);
c1.register(literal("save").then(argument("out", Argument.string()).executes(c -> {
SevenZPacker out = new SevenZPacker(c.argument("out", String.class));
out.setCodec(new LZMA2(3));
for (SevenZEntry oldEntry : remain.values()) {
if (oldEntry.isDirectory()) continue;
SevenZEntry entry = in2_by_crc32.remove(oldEntry.getCrc32());
if (entry != null) {
in2_should_copy.remove(entry);
out.beginEntry(SevenZEntry.ofNoAttribute("renamed/"+oldEntry.getName()));
out.write(entry.getName().getBytes(StandardCharsets.UTF_8));
} else {
in1_should_copy.put(oldEntry, "del/"+oldEntry.getName());
}
}
out.flush();
EasyProgressBar bar = new EasyProgressBar("复制块", "块");
bar.addTotal(in1_should_copy.size()+in2_should_copy.size());
var monitor = TaskPool.cpu().newGroup();
copy(monitor, in1, in1_should_copy, out, bar);
copy(monitor, in2, in2_should_copy, out, bar);
monitor.await();
in1.close();
in2.close();
out.close();
bar.end("Diff已保存");
Tty.popHandler();
})));
c1.register(literal("exit").executes(c -> {
in1.close();
in2.close();
Tty.popHandler();
}));
}
private static void copy(TaskGroup monitor, SevenZFile arc, HashMap<SevenZEntry, String> should_copy, SevenZPacker out, EasyProgressBar bar) {
arc.parallelDecompress(monitor, (entry, in) -> {
String prefix = should_copy.get(entry);
if (prefix == null) return;
try (SevenZWriter w = out.newParallelWriter()) {
w.beginEntry(SevenZEntry.ofNoAttribute(prefix));
IOUtil.copyStream(in, w);
bar.increment(1);
} catch (Exception e) {
Helpers.athrow(e);
}
});
}
private void download(CommandContext ctx) {
String url = ctx.argument("网址", String.class);
File saveTo = ctx.argument("保存到", File.class);
// Solved, you can use ?? next time
int threads = ctx.argument("线程数", Integer.class) != null ? ctx.argument("线程数", Integer.class) : Math.min(Runtime.getRuntime().availableProcessors() << 2, 64);
DownloadTask.useETag = false;
DownloadTask.defHeaders.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36");
DownloadTask.defMaxChunks = threads;
DownloadTask.defChunkStart = 0;
int retry = 2;
do {
try {
DownloadTask.download(url, saveTo).get();
break;
} catch (Throwable e) {
getLogger().warn("文件{}下载失败, 重试次数: {}/3", e, saveTo.getName(), (3-retry)+"/3");
}
} while (retry-- > 0);
}
private void updateExe(CommandContext ctx) throws IOException {
File exe = ctx.argument("自解压模板", File.class);
File zip = ctx.argument("压缩包", File.class);
long offset = Long.MAX_VALUE;
try (var zf = new ZipFile(exe, ZipFile.FLAG_Verify |ZipFile.FLAG_ReadCENOnly)) {
for (ZipEntry entry : zf.entries()) {
offset = Math.min(offset, entry.startPos());
}
}
var from = FileChannel.open(zip.toPath(), StandardOpenOption.READ);
var to = FileChannel.open(exe.toPath(), StandardOpenOption.WRITE, StandardOpenOption.READ).position(offset);
from.transferTo(0, from.size(), to);
from.close();
if (to.size() != to.position()) to.truncate(to.position());
to.close();
}
}