Windows命令分割二进制文件

发布于 2024-11-01 17:36:24 字数 123 浏览 1 评论 0原文

我想将二进制文件分割成更小的块。有人知道 Windows 命令吗?

由于 Android 的 UNCOMPRESS_DATA_MAX 约束,我无法使用 1MB 或更大的文件覆盖数据库。因此,如果有更好的方法,我也同意。

I would like to split a binary file into smaller chunks. Anyone knows a Windows command for that?

Because of Android's UNCOMPRESS_DATA_MAX constraint, I cannot overwrite the Database with a file 1MB or larger. So if there is a better way to do it I am OK with that too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

圈圈圆圆圈圈 2024-11-08 17:36:24

方法1:

makecab可以将二进制文件以其自己的格式分割成更小的编码块,但它们不能被视为只是原始字节,类似于平面二进制文件例如。通过copy加入,即。如果您正在考虑通过 CMD 编辑二进制文件,例如文件修补。不过,如果您只是想分割一个文件,然后在不进行编辑的情况下合并成一个文件,那么这些块可以通过 extrac32 连接起来。

例如。要使用 makecab 分割二进制文件,然后使用 extrac32 连接,首先创建一个 ddf(文本)文件:

.Set CabinetNameTemplate=test_*.cab; <-- Enter chunk name format
.Set MaxDiskSize=900000; <-- Enter file split/chunk size
.Set ClusterSize=1000
.Set Cabinet=on;
.Set Compress=off;
.set CompressionType=LZX;
.set CompressionMemory=21
.Set DiskDirectoryTemplate=;
file.in

然后:

rem Optional: set compression on to save disk space
makecab /f ddf.txt

要取回原始文件,请确保所有块都在同一个文件中目录:

REM join by calling 1st file in the sequence
extrac32 test_1.cab file.out

MakeCAB 引入了文件夹的概念来引用连续的压缩字节集。

“MakeCAB 获取正在压缩的产品或应用程序中的所有文件,将字节作为一个连续的字节流,压缩整个流,将其切成适当的文件夹,然后用文件夹填充一个或多个文件柜。 ”

方法2:
对于原始字节块,powershell 可以拆分文件:

set size=1000000
set file=test.mp3

for %j in (%file%) do (
set /a chunks=%~zj/%size% >nul

for /l %i in (0,1,!chunks!) do (
set /a tail=%~zj-%i*%size% >nul
powershell gc %file% -Encoding byte -Tail !tail! ^| sc %file%_%i -Encoding byte
if %i lss !chunks! FSUTIL file seteof %file%_%i %size% >nul
)
)

方法 3: 通过 certutil & CMD:

set file="x.7z"             &REM compressed to generate CRLF pairs
set max=70000000            &REM certutil has max file limit around 74MB

REM Findstr line limit 8k
REM Workaround: wrap in some archive to generate CRLF pairs

for %i in (%file%) do (
set /a num=%~zi/%max% >nul      &REM No. of chunks
set /a last=%~zi%%max% >nul     &REM size of last chunk
if %last%==0 set /a num=num-1       &REM ove zero byte chunk
set size=%~zi
)

ren %file% %file%.0

for /l %i in (1 1 %num%) do (
set /a s1=%i*%max% >nul
set /a s2="(%i+1)*%max%" >nul
set /a prev=%i-1 >nul

echo Writing %file%.%i
type %file%.!prev! | (
  (for /l %j in (1 1 %max%) do pause)>nul& findstr "^"> %file%.%i)

FSUTIL file seteof %file%.!prev! %max% >nul
)
if not %last%==0 FSUTIL file seteof %file%.%num% %last% >nul
echo Done.

注释:

  1. 块可以通过 copy /b 连接
  2. 文件扩展名可以通过填充块编号变得更整洁
  3. 可以循环以分割整个目录

请参阅下面的示例输出:

Directory of C:\Users\Stax\Desktop\Parking

03/05/2022  01:04    <DIR>          .
03/05/2022  01:04    <DIR>          ..
03/05/2022  01:04               407 Court Notice.pdf.000
03/05/2022  01:04             4,000 Court Notice.pdf.001
03/05/2022  01:04             4,000 Court Notice.pdf.002
03/05/2022  01:04               557 Parking fine.pdf.000
03/05/2022  01:04             4,000 Parking fine.pdf.001
03/05/2022  01:04             4,000 Parking fine.pdf.002
03/05/2022  01:04             4,000 Parking fine.pdf.003
03/05/2022  01:04             4,000 Parking fine.pdf.004
               8 File(s)         24,964 bytes

方法 2 & 3 然后可以通过 copy 加入

在 Win 10 上测试

Method 1:

makecab can split a binary file into smaller encoded chunks in it's own format, but they can't be treated as just raw bytes, similar to a flat binary file eg. to join via copy ie. in case you were looking at editing a binary file via CMD, eg. file patching. The chunks, however can then be joined by extrac32, in case you were just looking at splitting a file and then joining into one piece later, without editing.

eg. To split binary file with makecab then join with extrac32, first make a ddf (text) file:

.Set CabinetNameTemplate=test_*.cab; <-- Enter chunk name format
.Set MaxDiskSize=900000; <-- Enter file split/chunk size
.Set ClusterSize=1000
.Set Cabinet=on;
.Set Compress=off;
.set CompressionType=LZX;
.set CompressionMemory=21
.Set DiskDirectoryTemplate=;
file.in

Then:

rem Optional: set compression on to save disk space
makecab /f ddf.txt

To get the original file back, ensure all chunks are in the same directory:

REM join by calling 1st file in the sequence
extrac32 test_1.cab file.out

MakeCAB introduces the concept of a folder to refer to a contiguous set of compressed bytes.

"MakeCAB takes all of the files in the product or application being compressed, lays the bytes down as one continuous byte stream, compresses the entire stream, chopping it up into folders as appropriate, and then fills up one or more cabinets with the folders."

Method 2:
For raw byte chunks, powershell can split files:

set size=1000000
set file=test.mp3

for %j in (%file%) do (
set /a chunks=%~zj/%size% >nul

for /l %i in (0,1,!chunks!) do (
set /a tail=%~zj-%i*%size% >nul
powershell gc %file% -Encoding byte -Tail !tail! ^| sc %file%_%i -Encoding byte
if %i lss !chunks! FSUTIL file seteof %file%_%i %size% >nul
)
)

Method 3: via certutil & CMD:

set file="x.7z"             &REM compressed to generate CRLF pairs
set max=70000000            &REM certutil has max file limit around 74MB

REM Findstr line limit 8k
REM Workaround: wrap in some archive to generate CRLF pairs

for %i in (%file%) do (
set /a num=%~zi/%max% >nul      &REM No. of chunks
set /a last=%~zi%%max% >nul     &REM size of last chunk
if %last%==0 set /a num=num-1       &REM ove zero byte chunk
set size=%~zi
)

ren %file% %file%.0

for /l %i in (1 1 %num%) do (
set /a s1=%i*%max% >nul
set /a s2="(%i+1)*%max%" >nul
set /a prev=%i-1 >nul

echo Writing %file%.%i
type %file%.!prev! | (
  (for /l %j in (1 1 %max%) do pause)>nul& findstr "^"> %file%.%i)

FSUTIL file seteof %file%.!prev! %max% >nul
)
if not %last%==0 FSUTIL file seteof %file%.%num% %last% >nul
echo Done.

Notes:

  1. Chunks can be joined by copy /b
  2. Filename extensions can be made neater by padding chunk numbers
  3. Can be looped to split entire directories

See example output below:

Directory of C:\Users\Stax\Desktop\Parking

03/05/2022  01:04    <DIR>          .
03/05/2022  01:04    <DIR>          ..
03/05/2022  01:04               407 Court Notice.pdf.000
03/05/2022  01:04             4,000 Court Notice.pdf.001
03/05/2022  01:04             4,000 Court Notice.pdf.002
03/05/2022  01:04               557 Parking fine.pdf.000
03/05/2022  01:04             4,000 Parking fine.pdf.001
03/05/2022  01:04             4,000 Parking fine.pdf.002
03/05/2022  01:04             4,000 Parking fine.pdf.003
03/05/2022  01:04             4,000 Parking fine.pdf.004
               8 File(s)         24,964 bytes

Methods 2 & 3 can then be joined by copy

Tested on Win 10

束缚m 2024-11-08 17:36:24

没有内置的 DOS 命令可以实现此目的。使用 unix split 命令的 dos 端口

split BIGFILE -b 1000000

有第 3 方替代方案,但这是最简单的。

There's no built-in DOS command for that. Use the dos port of the unix split command:

split BIGFILE -b 1000000

There are 3rd party alternatives, but this is the simplest.

一桥轻雨一伞开 2024-11-08 17:36:24

您还可以从 http://gnuwin32.sourceforge.net 安装 GnuWin

对于我的工作,我需要提取一些来自大型 Oracle 导出文件 DataBase.bak 的行。

该文件是一个二进制文件,由文本行和二进制行混合而成。

要提取 2 个特定行之间的所有行,我只需输入以下命令

split -l 4114807 database.bak from.
split -l 10357 from.A to.
copy to.A database.RANGE.bak

第一个命令将从 0 到 4114807 的所有行提取到 from.A 文件中,并将从 4114808 到 2*4114807 的所有行提取到 来自.B 文件。

我在Notepad++中加载Database.Bak文件时发现FROM行号(= 4114807)。
注意:Notepad++中显示的行号不等于split 命令中使用 l 参数,因为 Notepad++ 行号是由 LFCR 字符生成的!

我使用第二个命令将 from.B 文件中包含的所有前 10357 行提取到 to.A 文件中。

要终止,我将 to.A 文件复制到包含所需提取的新 Database.RANGE.bak 文件中。

工作完成后,我从当前目录中删除所有 from.* 和 to.* 文件。

You can also install GnuWin from http://gnuwin32.sourceforge.net

For my work, I need to extract some lines from a big Oracle export's file DataBase.bak.

This file is a binary file that is a mix of text's lines and binary lines.

To extract all lines between 2 specifics lines, I only enter following to command

split -l 4114807 database.bak from.
split -l 10357 from.A to.
copy to.A database.RANGE.bak

The first command extract all lines from 0 to 4114807 into from.A file and all lines from 4114808 to 2*4114807 into from.B file.

I found FROM line's number (= 4114807) in loading Database.Bak file in Notepad++.
Caution: the line's number displayed in Notepad++ is not equal to l parameter used in split command because Notepad++ line's number are generated by LF and also CR characters !

I use the second command to extract all first 10357 lines contains in from.B file into to.A file.

To terminate, I copy to.A file into a new Database.RANGE.bak file that contains needed extraction.

When job is done, I delete all from.* and to.* files from current directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文