compilation - Compiling libmagic statically (c/c++ file type detection) -


Thanks for those people who did me with my help (links for reference only).

I type fileTypeTest.cpp , libmagic.a , and magic in a file, and I G + + -lmagic fileTypeTest I can compile CPP FileType Test Later, I will test to see if it runs in compiled windows with Mingad.

I am planning to use it in a small GUI application, and I want to compile it for distribution consistently. My problem is that the libmagic external file, magic is required. (I'm actually using my small and compiled version, Magic_Short.MGC, but I want to revert.)

To codify the file in a Hummy solution file, create an external file ( And delete) as needed. How can I avoid it?

Added for clarity:

Magic is a text file that describes the properties of different file types. When called to identify a file, libmagic searches through magic . There is a compiled version, magic.mgc that works faster My application only needs to identify some types of file types before deciding what to do with those people, Code> magic_short to make the file magic_short.mgc .

It is difficult, I think you can do this ... by the way, I downloaded it Have a Libmagic source and see it ...

There is a function called magic_read_entries inside minifile.c (this is the pure vanilla source I have external file From where you have downloaded it.

You can attach the magic file (which is found in the / etc directory) at the end of the library code, such as it cat ADU> libmagic.a . In my system, magic is 474443 bytes, libmagic.a is 38588 bytes.

< In the code> magic.c file, you will need to change the magichandle_t * magic_init (unsigned flags) function at the end of the function, add line magic_read_entries and To draw data, modify the function to read on the offset of the library; keep it as a pointer for all four as a porter; ) And use it instead of reading from the file. Since you know where the library data to read offset, it should not be difficult.

Now the function magic_read_entries will no longer be used, because it is not going to be read any more from a file anymore. The function `magichandle_t * magic_init (unsigned flags) 'will take care of loading entries and you should be right there.

If you need more help then let me know,

Edit: I used the old 'libmagic' from Sourceforge.net and Here I have done this:

  1. The downloaded archive will be removed in my home directory, creating a folder called ungzipping / untarring archive libmagic .
  2. Create a folder within libmagic and test
  3. original magic and minifile.c In Test
  4. Using the attached fluff output to highlight the difference, apply it to Magic C source.
 48a49,51> # MAGIC_DATA_OFFSET 0x971C> Define #define MAGIC_STAT_LIB_NAME "libmagic.a" & gt; 125a129,130 ​​& gt; / * Magic_Red_entry is obsolete ... * /> Magic_reddy_editry (mh, magic_STAT_LIB_NAME); 251c256,262 & lt; --- & gt; & Gt; If (! Fseek (fp, MAGIC_DATA_OFFSET, SEEK_SET)) {& gt; If (ftell (fp)! = MAGIC_DATA_OFFSET) 0; & Gt; } Other {& gt; Return 0; & Gt; } & Gt; 
  • Then create
  • Magic file (which I copied from / etc, under Slackware Linux 12.2) The Libmagic.a file has been added, i.e. cat magic & gt; & Gt; Libmagic.a . SHA checksum (4abf536f2ada050ce945fbba796564342d6c9a61 magic) for magic, here is the exact data for magic (-RR-R1 root root 474443 2007-06-03 00:52 / etc / file / magic) As my system
  • This difference is for the source minifile.c , apply it and make create executable by running again Re-create for
40c40 & lt; Magic_read_entries (MH, "magic"); --- & gt; / * Magic_ready_editry (mh, "magic"); * /

It should work then. If not, then you need to adjust the offset in the library to read and modify MAGIC_DATA_OFFSET. If you want, you can put the magic data file in the paste bin. let me know.

Hope it helps, Best wishes, Tom.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -