ZIP파일 시그니처 비트 관련 질문 입니다.

esaram5의 이미지

C언어로 zip파일을 분석하는 프로그램을 만들고 있습니다.

다름이 아니라 파일의 내부 hex값에서 End of central directory record의 위치를 먼저 알아내려는 작업을 하려 합니다.

그런데 시그니처 비트인 0x06054b50가 파일안에 여러 번 존재해서 오류가 발생합니다.

마지막에 발견한 0x06054b50을 시그니처로 사용하기엔 .ZIP file comment (variable size) 내부에도 0x06054b50가 존재할 가능성이 있어 코드를 짜는데 어려움이 있습니다.

혹시 시그니처 비트를 효과적으로 탐색할 수 있는 방법이 있을까요?
현재는

int find_end_C_D(FILE file) {
	ulong signature=0;
	int result;
	while ((result = feof(&file)) == 0) {
		fread(&signature, sizeof(signature), 1, &file);
		fseek(&file, -3, SEEK_CUR);
		if (signature == 0x06054b50) {
 
			printf("%08x\n", signature);
 
			continue;
		}
	}
 
 
}

이 코드에서
fread(&signature, sizeof(signature), 1, &file);
fseek(&file, -3, SEEK_CUR);

이렇게 한칸 씩 비교해가고 있습니다만 100MB파일을 처리하는데 시간이 너무 오래 걸립니다. 이 처리를 효율적으로 할 방법이 있을까요?

제 생각에는 한번에 여러 줄을 메모리에 읽어오고 시그니처 코드 뒤로 파일 포인터를 이동하여 구조체로 읽어오는 방법을 생각하고 있습니다.

최종적으로 분석해야 하는 파일은 6GB정도의 파일입니다.

라스코니의 이미지

주로 느려지는 이유는 fread()로 너무 적은 파일 사이즈를 읽어오기 때문입니다. 머신은 한번에 약 수십 Mbytes를 읽어올 수 있는데 반해 4 bytes 단위로 읽어오기 때문입니다.

fread()로 한 4 X 1000 X 1000 = 4 Mbytes 씩 읽어서 처리해 보세요.

그럼에도 불구하고 기대보다 느리다면 멀티 쓰레드로 한 쓰레드는 파일에서 읽고, 다른 쓰레드(들)에서는 비교하고 그런 식으로 할 수도 있겠네요. 6GB를 몇분(초) 내에 처리해야 하는지에 따라 적당한 방법을 찾아야 합니다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.