리눅스 file 명령어에 사용되는 magic 라이브러리를 아시나요?

sacredone의 이미지

안녕하세요

file로 확장자/컨텐츠 불일치 탐지 모듈을 개발할려고하는데

ms 계열 제품중

엑셀 워드 ppt 를 구분을 잘못하네요...

혹시 magic에서 어떻게 손대야하는지

저 제품들 매직넘버 아시는지

여쭤봐도될까요?

ymir의 이미지

office 파일들은 그냥 zip 파일이라서.. 매직 넘버로는 어렵지 않을까 생각되네요.

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

sacredone의 이미지

office 파일들은 그냥 zip 파일이라서.. <- 잘이해가안되네요 ㅠ

오피스파일들은 왜 zip 파일인건지
zip 파일이 뭔지좀 알려주실수있으실까요

ymir의 이미지

확장자가 .docx, .pptx, .xlsx 로 되어 있기는 하지만, 실제로는 압축 파일인 zip format 으로 묶여 있다는 뜻입니다.
그냥 unzip 같은 걸로 풀어 보세요.

$ file test.pptx
test.pptx: Zip archive data, at least v2.0 to extract
$ file -i test.pptx
test.pptx: application/zip; charset=binary
$ mimetype test.pptx
test.pptx: application/vnd.openxmlformats-officedocument.presentationml.presentation
$ unzip -v test.pptx
Archive:  test.pptx
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
    3532  Defl:S      472  87% 1980-01-01 00:00 ed6d243d  [Content_Types].xml
     738  Defl:S      261  65% 1980-01-01 00:00 a174f868  _rels/.rels
     311  Defl:S      193  38% 1980-01-01 00:00 b4235c63  ppt/slides/_rels/slide1.xml.rels
     311  Defl:S      191  39% 1980-01-01 00:00 ec3df54b  ppt/slides/_rels/slide2.xml.rels
     311  Defl:S      191  39% 1980-01-01 00:00 ec3df54b  ppt/slides/_rels/slide3.xml.rels
     311  Defl:S      191  39% 1980-01-01 00:00 ec3df54b  ppt/slides/_rels/slide4.xml.rels
    1375  Defl:S      299  78% 1980-01-01 00:00 b68df3dd  ppt/_rels/presentation.xml.rels
    3321  Defl:S      612  82% 1980-01-01 00:00 0ff942c4  ppt/presentation.xml
   15177  Defl:S     2256  85% 1980-01-01 00:00 817ec53a  ppt/slides/slide3.xml
    4248  Defl:S     1110  74% 1980-01-01 00:00 f059c122  ppt/slides/slide2.xml
...............
     311  Defl:S      190  39% 1980-01-01 00:00 f192d1d5  ppt/slideLayouts/_rels/slideLayout5.xml.rels
    7101  Defl:S     1690  76% 1980-01-01 00:00 ca02064e  ppt/theme/theme1.xml
    7168  Stored     7168   0% 1980-01-01 00:00 2c88c8f6  docProps/thumbnail.jpeg
     651  Defl:S      337  48% 1980-01-01 00:00 aeaf2d0f  ppt/presProps.xml
     182  Defl:S      172   6% 1980-01-01 00:00 8f8dfdd8  ppt/tableStyles.xml
     829  Defl:S      392  53% 1980-01-01 00:00 84836d3e  ppt/viewProps.xml
     730  Defl:S      388  47% 1980-01-01 00:00 8b490369  docProps/core.xml
    1241  Defl:S      617  50% 1980-01-01 00:00 7ce165e2  docProps/app.xml
--------          -------  ---                            -------
  130245            37838  71%                            43 files

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

pogusm의 이미지

이런거 신기하네요

엑셀파일이 zip파일인거 첨 알았네요 ㅋ

세이군의 이미지

ymir, pogusm, sacredone // MS Office 파일은 오피스 97 ~ 2003과 2007/2010의 파일 형식이 다릅니다. zip 포맷은 2007 이후의 파일만 해당이 되며 파일확장자에 x가 추가된 확장자로 되어 있습니다. 97~2003 파일의 경우 file 명령의 결과가 위와는 다르게 나옵니다.

sacredone의 이미지

magic 파일을 보니까

파일 판별을 파일 시작부터 몇바이트 뒤에 (ex >4 4바이트 뒤에) 위치하는 1바이트 가지고 파일들을 판별하던데

1바이트만으로 파일들을 판별한다면

제가 위에 적은 문제점을 제외하고서라도

오탐이 많지않을까요? ㅠ

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.