用c打开rar文件

发布于 2024-09-14 14:00:14 字数 642 浏览 4 评论 0原文

我必须用 C 编写代码才能在 Windows 中提取受密码保护的 rar 文件。我不知道如何做到这一点。有人能给我建议或提供一段示例代码吗?我将非常感激。

编辑:

这是我用来打开 rar 文件的代码。在系统命令 ranjit 中是密码。它给出了模块+文件名中未定义的符号系统错误。有人可以帮助我吗?两天以来我一直在努力解决这个问题。 编辑:此代码打开存档但不提取它。如果我在命令行中使用 unrar 命令,它会提取文件。我该怎么办?

#include<stdio.h>
#include<stdlib.h>
int main(int argc, char **argv)
     {
     char file[20];
     char file2[50] = "F:\\Program Files\\WinRAR\\unrar.exe";
     printf("enter the name of the rar file : ");
     gets(file);
     puts(file);
     system(("%s e -p ranjit %s >C:\stdout.log 2>C:\stderr.log",file2, file));
     getchar();
     return 0;
     }

I have to write code in C to extract a password protected rar file in windows. I don't have any clue about how to do this. can anybody suggest me something or provide a sample piece of code? I will be very thankful.

EDIT:

This is the code I am using to open the rar file.In the system command ranjit is the password. It's giving the error undefined symbol_system in module+thefile name. Can anybody help me?? I am struggling on this since two days.
EDIT: This code opens the archive but do not extract it. If I uses the unrar command in command line, it extracts the file. What I should I do?

#include<stdio.h>
#include<stdlib.h>
int main(int argc, char **argv)
     {
     char file[20];
     char file2[50] = "F:\\Program Files\\WinRAR\\unrar.exe";
     printf("enter the name of the rar file : ");
     gets(file);
     puts(file);
     system(("%s e -p ranjit %s >C:\stdout.log 2>C:\stderr.log",file2, file));
     getchar();
     return 0;
     }

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

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

发布评论

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

评论(2

空袭的梦i 2024-09-21 14:00:14

除了 karlphilip 的建议之外,http://www.rarlabs 上还有一些可能很有趣的资源。 com/rar_add.htm

我特别认为 UnRAR.dllUnRAR 源 可能相关。不过我现在还不能真正检查一下。

In addition to what karlphilip's suggestions there's also a couple of potentialliy interesting looking resources at http://www.rarlabs.com/rar_add.htm.

In particular I am thinking UnRAR.dll and UnRAR source may be relevant. I can't really check it out at the momment though.

与君绝 2024-09-21 14:00:14

使用 unrar 库 - 将文件提取到文件流缓冲区

但如果您正在寻找纯 C 解决方案,请查看: http://www.unrarlib.org/

引用他们的常见问题解答:URARFileLib(UniquE RAR 文件库的简称,也称为 unrarlib)是 C 程序员访问 RAR 存档的免费库。

另一种方法system() 调用命令行工具(例如unrar )已经安装在您的系统上来完成这项工作:

system("unrar x -ppassword protected_file.rar /destination_directory");

例如,假设受保护的文件名为file.rar,密码为1234并且目标目录是/home/user,您可以使用以下参数调用system():

system("unrar x -p1234 file.rar /home/user/");

Using unrar library - extracting files into a filestream buffer

But if you're looking for a pure C solution, take a look at: http://www.unrarlib.org/

Quote from their FAQ: The URARFileLib (short name for UniquE RAR File Library, also called unrarlib) is a free library for C programmers to access RAR archives.

Another approach, which I just tested successfully, doesn't require the use of external libraries to decompress rar files. Use system() to invoke a command-line tool (such as unrar ) already installed on your system to do the job:

system("unrar x -ppassword protected_file.rar /destination_directory");

For instance, let's say the protected file was named file.rar, the password was 1234 and the destination directory was /home/user, you would call system() with the following parameters:

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