如何获取网络缓冲区并将其传递到需要 C 中的 FILE 的函数中

发布于 2024-10-27 23:18:34 字数 407 浏览 2 评论 0原文

我希望能够通过网络套接字从 HTTP 服务器(A jpeg)下载文件。然后,我需要将下载的文件传递到 c-jpeg-steganography http://code。 google.com/p/c-jpeg-steganography/。我可以使用 libcurl 下载文件,然后将文件名传递到库中,但如果不需要,我宁愿不这样做。我可以下载该文件,然后轻松地将其直接传递到 c-jpeg-steganography 中吗?有没有一种简单的方法可以修改 c-jpeg-steganography 库以使其工作?写入临时文件不是一个坏方法吗?

我是个 C 菜鸟……请放轻松。我的大部分经验都是使用那些让我作弊并为我完成所有工作的语言。

I am looking to be able to download a file over a network socket from an HTTP server (A jpeg). I then need to pass the downloaded file into c-jpeg-steganography http://code.google.com/p/c-jpeg-steganography/ . I can use libcurl to download the file and then pass the filename into the library, but I would prefer to not do that if I don't have to. Can I download the file and then pass it directly into c-jpeg-steganography easily? Is there an easy way to modify the c-jpeg-steganography libraries to work? Is the writing to a temporary file not a bad way to do this?

I am very much a C noob... please go easy. Most of my experience is with languages that let me cheat and do all the work for me.

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

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

发布评论

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

评论(2

尹雨沫 2024-11-03 23:18:34

隐写术网站没有提供 AFAICS 的 API 详细信息,这很麻烦。


但是,从您的问题来看,似乎有一个隐写函数需要一个打开的 FILE * (您永远无法处理 FILE * ),其中包含未修改的图像,大概是您试图在图像中隐藏的信息。在这种情况下,您可以安排通过 libcurl 将文件下载到打开的文件中(可能没有名称);然后您可以倒回该 FILE * 并将其传递给隐写库。
下载该库

后,提供的两个主要函数是:

steganolab_encode

/**
 * Modifies specified jpeg file so that it contains given message.
 * @param file - jpeg file name
 * @param data - message to embed
 * @param len - message length
 * @param password - key string to cipher data and set up PRNG
 * @param DCT_radius - which DCT coefficients shall be used to carry
 *      information, i^2+j^2 <= R^2
 * @param stats - pointer to structure to put statistics to. The caller
 * must take care about freeing the structure properly. NULL pass
 * disables statistics output.  The object don't need to be freed if the
 * function fails, and it contains no message.
 * @return              0: All OK
 *                              not 0: Failed
 **/
int steganolab_encode(const char * file, const char * data,
        unsigned int len, const char * password, uint8_t DCT_radius,
        struct steganolab_statistics * stats);

steganolab_decode

/**
 * Reads steganographic message from specified file
 * @param file - jpeg file name
 * @param data - pointer to pointer to string to put data to
 * @param len - pointer to push obtained buffer length to
 * @param password - secred string for cipher and PRNG
 * @param DCT_radius - which DCT coefficients shall be used to carry
 *      information, i^2+j^2 <= R^2
 * @param stats - statistics object. Free is up to the caller.
 * NULL disables the feature.  The object don't need to be freed if the
 * function fails, and it contains no message.
 * @return      0: All OK
 *                      not 0: fail (no buffers need freeing in this case)
 */
int steganolab_decode(const char * file, char ** data,
        unsigned int * len, const char * password, uint8_t DCT_radius,
        struct steganolab_statistics * stats);

由于函数需要文件名,因此您必须提供文件名。或者您将不得不重写代码以获取您想要的任何内容 - 缓冲区或打开的文件流。

(旁白:代码坚持使用古老的非标准标头 来获取 size_t 的定义。如果您替换每个,它会编译为对象使用 引用 (或 "malloc.h"),理论上可以编译;如果唯一需要的声明是 size_t,则使用 。)

The steganography site doesn't give the API details AFAICS, which is a nuisance.


However, judging from your question, it appears that there is a steganographic function that takes an open FILE * (you never get to deal with FILE) which contains the unmodified image, and presumably the information you are trying to conceal in the image. In that case, you can arrange to download the file via libcurl into an open file (which may not have a name); you can then rewind that FILE * and pass it to the steganography library.

Having downloaded the library, the two main functions provided are:

steganolab_encode

/**
 * Modifies specified jpeg file so that it contains given message.
 * @param file - jpeg file name
 * @param data - message to embed
 * @param len - message length
 * @param password - key string to cipher data and set up PRNG
 * @param DCT_radius - which DCT coefficients shall be used to carry
 *      information, i^2+j^2 <= R^2
 * @param stats - pointer to structure to put statistics to. The caller
 * must take care about freeing the structure properly. NULL pass
 * disables statistics output.  The object don't need to be freed if the
 * function fails, and it contains no message.
 * @return              0: All OK
 *                              not 0: Failed
 **/
int steganolab_encode(const char * file, const char * data,
        unsigned int len, const char * password, uint8_t DCT_radius,
        struct steganolab_statistics * stats);

steganolab_decode

/**
 * Reads steganographic message from specified file
 * @param file - jpeg file name
 * @param data - pointer to pointer to string to put data to
 * @param len - pointer to push obtained buffer length to
 * @param password - secred string for cipher and PRNG
 * @param DCT_radius - which DCT coefficients shall be used to carry
 *      information, i^2+j^2 <= R^2
 * @param stats - statistics object. Free is up to the caller.
 * NULL disables the feature.  The object don't need to be freed if the
 * function fails, and it contains no message.
 * @return      0: All OK
 *                      not 0: fail (no buffers need freeing in this case)
 */
int steganolab_decode(const char * file, char ** data,
        unsigned int * len, const char * password, uint8_t DCT_radius,
        struct steganolab_statistics * stats);

Since the functions expect file names, you will have to provide file names. Or you will have to rewrite the code to take whatever it is you have in mind - a buffer or an open file stream.

(Aside: the code insists on using the archaic and non-standard header <malloc.h> to obtain a definition of size_t. It compiles to object if you replace each reference to <malloc.h> (or "malloc.h") with <stdlib.h>; it might in theory compile with <stddef.h> if the only needed declaration is size_t.)

落日海湾 2024-11-03 23:18:34

没有标准方法可以假装内存缓冲区是一个文件,因此您实际上仅限于您提出的两种解决方案之一:

  • 将信息写入文件,然后将文件名传递给库;或
  • 重写库以获取内存缓冲区。

我知道我最初会这样做,这是第一个选择。这是最简单的方法(如最快上市)。

从对源代码的检查来看,将其更改为进程内存而不是文件所涉及的工作并不简单。

encodedecodeestimate 函数都调用一个 worker 超级函数,该函数接收文件名、打开反过来,它又将文件句柄传递给其他函数。

这是可行的,但工作量比仅使用临时文件要大得多(尽管请记住,它只需要完成一次,然后生成的代码将可供全世界使用)。

There's no standard way to pretend that a memory buffer is a file so you really are limited to one of the two solutions you posit:

  • write the information to a file then pass the file name to the library; or
  • re-write the library to take an in-memory buffer.

I know the way I'd initially do it, that's the first option. That's the easiest way (as in quickest-to-market).

From examination of the source, the work involved in changing it to process memory rather than a file is non-trivial.

The encode, decode and estimate functions all call a single worker uber-function which receives the file name, opens it and, in turn, passes the file handle around quite a bit to other functions.

It's doable but the effort is substantially larger than just using a temporary file (although keep in mind it would only have to be done once, and the resultant code would then be available for all the world to use).

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