【发布时间】:2020-05-26 17:38:39
【问题描述】:
基本上,我在 Linux 上使用“cat”命令组合两个二进制文件。 我希望能够使用 C 再次将它们分开 这是我目前得到的代码
int main(int argc, char *argv[]) {
// Getting this file
FILE *localFile = fopen(argv[0], "rb");
// Naming a new file to save our carved binary
FILE *newFile = fopen(argv[1], "wb+");
// Moving the cursor to the offset: 19672 which is the size of this file
fseek(localFile, 19672, SEEK_SET);
// Copying to the new file
char ch;
while ( ( ch = fgetc(localFile) ) != EOF ) {
fputc(ch, newFile);
}
}
【问题讨论】:
-
你的问题是什么?
-
fgetc返回int,而不是char。 -
您希望它适用于本示例还是一般情况下?因为如果你不知道大小并且没有任何分隔符分隔两个文件是不可能的。
-
cat命令在哪里使用?这似乎是 C 源代码,没有来自它的系统调用。 -
我确实知道原始文件(file1)的大小,所以我想将光标移动到该偏移量,因为另一个文件应该位于那里
标签: c binary concatenation fopen fseek