0 / 0 / 0
Регистрация: 28.09.2012
Сообщений: 37
1

Нашинковать файл по сигнатурам

23.06.2013, 17:07. Показов 1680. Ответов 19
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Добрый вечер уважаемые Участники.
Помогите написать маленькую тулзу.
Задача:
Есть некий файл, с некоим содержимым. В файле имеются сигнатуры "RIP"
Нужно порезать файл по этим сигнатурам, сейчас объясню.
Допустим вот файл. Скрин с WinHex-а:

Порезать файл на куски, идём по файлу, если находим RIP, то ищем следующий RIP - что бы узнать докуда кусок, и обрезаем первый кусок до следующего RIP, со следующим так же. Если остался 1 RIP, то значит отрезать целиком, т.е конец файла..
Нумеровать куски можно хоть как... хоть счетчиком.. 1,2,3...
Т.е в итоге получится 3 файла из моего примера:

Надеюсь понятно объяснила.
Если кто напишет, просьба выложить сорец, что бы я смогла изменить значения.
Компилировать буду MinGW-ом, линковать crinkler-ом
В общем спасибо всем кто отзовётся и поможет мне.
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
23.06.2013, 17:07
Ответы с готовыми решениями:

Дан файл, содержащий произвольные символы. Написать процедуру, проверяющую его на вирусы (по сигнатурам)
дан файл, содержащий произвольные символы, являющийся исполнительным в некоторой системе...

Вопросы по сигнатурам методов
using System; class Myclass { private int alpha; int beta; public int gamma; ...

Создать файл F из элементов массива M, переписать в файл G все компоненты которые меньше 5, прочитать файл G
создать файл F,компонентами которого являются элементы массива M,переписать в файл G все компоненты...

Дан текстовый файл F. Переписать файл F в файл G, вставляя в конец каждой строки ее порядковый номер.
решите)

19
415 / 411 / 95
Регистрация: 06.10.2011
Сообщений: 832
23.06.2013, 18:29 2
Скиньте этот файл, который на скрине.
0
0 / 0 / 0
Регистрация: 28.09.2012
Сообщений: 37
23.06.2013, 19:08  [ТС] 3
Цитата Сообщение от Olivеr Посмотреть сообщение
Скиньте этот файл, который на скрине.
Забыла уточнить, входной фал 1.6гб
Вложения
Тип файла: zip test1.zip (569 байт, 4 просмотров)
0
3176 / 1935 / 312
Регистрация: 27.08.2010
Сообщений: 5,131
Записей в блоге: 1
23.06.2013, 19:17 4
Примерно так (замените сигнатуру):

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma warning (disable: 4100)     // 'dwFoundAt' : unreferenced formal parameter
static void Finder
(
   void*             pParam,
   DWORD             dwFoundAt
)
{
   *(BYTE*)pParam |= 0xFF;
 
   dwOfsArr[iCnt++] = dwFoundAt;
}
 
int main(int argc,char** argv)
{
   if (argc != 2)
   {
      ShowHelp();
      return 0;
   }
 
   // Open eBook File
   MMF      eBook;
 
   if (!eBook.OpenReadOnly(argv[1]))
   {
      // Error !
      return -1;
   }
 
   // Do Actual Work
   const DWORD    dwPKZipSigz = 0x04034B50;
 
   bool     bFound = false;
 
   QuickSearch((BYTE*)&dwPKZipSigz,sizeof(DWORD),eBook.Buffer(),eBook.Size() - sizeof(dwPKZipSigz),&bFound,Finder);
 
   // Append false last entry
   dwOfsArr[iCnt++] = eBook.Size();
 
   char     pszZip      [_MAX_DRIVE];
   char     pszDrive    [_MAX_DRIVE];
   char     pszDir      [_MAX_DIR];
   char     pszFName    [_MAX_FNAME];
   char     pszExt      [_MAX_EXT];
 
   _splitpath(argv[1],pszDrive,pszDir,pszFName,pszExt);
 
   for (int ii = 0; ii < (iCnt - 1); ++ii)
   {
      char     pszTemp[MAX_PATH];
 
      wsprintf(pszTemp,"%s_%03d",pszFName,ii + 1);
      _makepath(pszZip,pszDrive,pszDir,pszTemp,"ZIP");
 
      HANDLE      hFile = CreateFile(pszZip);
 
      if (hFile == INVALID_HANDLE_VALUE)
      {
         // Error !
         continue;
      }
 
      if (!WriteBuffer(hFile,eBook.Buffer() + dwOfsArr[ii],dwOfsArr[ii + 1] - dwOfsArr[ii]))
      {
         // Error !
         CloseHandle(hFile);
         hFile = INVALID_HANDLE_VALUE;
         continue;
      }
 
      CloseHandle(hFile);
      hFile = INVALID_HANDLE_VALUE;
   }  
 
   // Cleanup
   eBook.Close();
 
   return 0;
}
Я это использовал для декомпиляции e-books.
Вложения
Тип файла: rar search_quick.rar (1.9 Кб, 10 просмотров)
0
0 / 0 / 0
Регистрация: 28.09.2012
Сообщений: 37
23.06.2013, 19:24  [ТС] 5
Не поняла насчет сигнатур
И при компиляции просит еще файлы:
search_quick.cpp:18:20: fatal error: stdafx.h: No such file or directory
0
500 / 474 / 63
Регистрация: 26.01.2011
Сообщений: 2,033
23.06.2013, 19:44 6
Цитата Сообщение от xinix Посмотреть сообщение
stdafx.h
это микрософская приблуда , убери её .
1
0 / 0 / 0
Регистрация: 28.09.2012
Сообщений: 37
23.06.2013, 19:51  [ТС] 7
Цитата Сообщение от Игорь с++ Посмотреть сообщение
это микрософская приблуда , убери её .
Убрала, но там еще есть #include "search_quick.h"
Если удалить эти строки...
search_quick.cpp:56:10: error: 'BYTE' does not name a type
search_quick.cpp:56:25: error: ISO C++ forbids declaration of 'pPattern' with no type [-fpermissive]
search_quick.cpp: In function 'void PreQS(const int*, int, int*)':
search_quick.cpp:66:9: error: name lookup of 'ii' changed for ISO 'for' scoping [-fpermissive]
search_quick.cpp:66:9: note: (if you use '-fpermissive' G++ will accept your code)
search_quick.cpp: At global scope:
search_quick.cpp:83:10: error: 'BYTE' does not name a type
search_quick.cpp:83:25: error: ISO C++ forbids declaration of 'pPattern' with no type [-fpermissive]
search_quick.cpp: In function 'void PreIQS(const int*, int, int*)':
search_quick.cpp:93:9: error: name lookup of 'ii' changed for ISO 'for' scoping [-fpermissive]
search_quick.cpp:95:34: error: 'toupper' was not declared in this scope
search_quick.cpp:96:34: error: 'tolower' was not declared in this scope
search_quick.cpp: At global scope:
search_quick.cpp:111:10: error: 'BYTE' does not name a type
search_quick.cpp:111:25: error: ISO C++ forbids declaration of 'pPattern' with no type [-fpermissive]
search_quick.cpp:113:10: error: 'BYTE' does not name a type
search_quick.cpp:113:25: error: ISO C++ forbids declaration of 'pText' with no type [-fpermissive]
search_quick.cpp:116:37: error: 'DWORD' has not been declared
search_quick.cpp: In function 'void QuickSearch(const int*, int, const int*, int, void*, void (*)(void*, int))':
search_quick.cpp:129:55: error: 'memcmp' was not declared in this scope
search_quick.cpp: At global scope:
search_quick.cpp:149:10: error: 'BYTE' does not name a type
search_quick.cpp:149:25: error: ISO C++ forbids declaration of 'pPattern' with no type [-fpermissive]
search_quick.cpp:151:10: error: 'BYTE' does not name a type
search_quick.cpp:151:25: error: ISO C++ forbids declaration of 'pText' with no type [-fpermissive]
search_quick.cpp:154:37: error: 'DWORD' has not been declared
search_quick.cpp: In function 'void QuickISearch(const int*, int, const int*, int, void*, void (*)(void*, int))':
search_quick.cpp:167:57: error: '_memicmp' was not declared in this scope
0
500 / 474 / 63
Регистрация: 26.01.2011
Сообщений: 2,033
23.06.2013, 19:53 8
Цитата Сообщение от xinix Посмотреть сообщение
#include "search_quick.h"
этот хедер как раз не надо убирать .
1
0 / 0 / 0
Регистрация: 28.09.2012
Сообщений: 37
23.06.2013, 19:56  [ТС] 9
Цитата Сообщение от Игорь с++ Посмотреть сообщение
этот хедер как раз не надо убирать .
Я просто не поняла где его взять?
Если не убрать, будет как и в первом случае:
search_quick.cpp(19) : fatal error C1083: Cannot open include file: 'search_quick.h': No such file or directory
0
500 / 474 / 63
Регистрация: 26.01.2011
Сообщений: 2,033
23.06.2013, 20:03 10
Ну всё правельно , хочет хедера , которого вам не дали.
1
3176 / 1935 / 312
Регистрация: 27.08.2010
Сообщений: 5,131
Записей в блоге: 1
23.06.2013, 20:30 11
Угу. Забыл.
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* ******************************************************************** **
** @@ Quick Search Header File
** @ Copyrt : [email]Chistian.Charras@dir.univ-rouen.fr[/email]
** @ Author : [email]Chistian.Charras@dir.univ-rouen.fr[/email]
** @ Modify : 
** @ Update : 22 Jan 2004
** @ Notes  : [url]http://www-igm.univ-mlv.fr/~lecroq/string/node19.html[/url]
** ******************************************************************** */
 
#ifndef _QSEARCH_HPP_
#define _QSEARCH_HPP_
 
#if _MSC_VER > 1000
#pragma once
#endif
 
/* ******************************************************************** **
** @@ internal defines
** ******************************************************************** */
 
typedef void (*QS_Callback)(void* pParam,DWORD dwFoundAt);
 
/* ******************************************************************** **
** @@ internal prototypes
** ******************************************************************** */
 
/* ******************************************************************** **
** @@ external global variables
** ******************************************************************** */
 
/* ******************************************************************** **
** @@ static global variables
** ******************************************************************** */
 
/* ******************************************************************** **
** @@ Global Function Prototypes
** ******************************************************************** */
 
void QuickSearch (const BYTE* const pPattern,int iPatternSize,const BYTE* const pText,int iTextSize,void* pParam,void (*QS_Callback)(void* pParam,DWORD dwFoundAt));
void QuickISearch(const BYTE* const pPattern,int iPatternSize,const BYTE* const pText,int iTextSize,void* pParam,void (*QS_Callback)(void* pParam,DWORD dwFoundAt));
 
#endif
 
/* ******************************************************************** **
** End of File
** ******************************************************************** */
1
0 / 0 / 0
Регистрация: 28.09.2012
Сообщений: 37
23.06.2013, 20:35  [ТС] 12
In file included from search_quick.cpp:19:0:
search_quick.h:21:42: error: 'DWORD' has not been declared
search_quick.h:39:25: error: 'BYTE' does not name a type
search_quick.h:39:37: error: ISO C++ forbids declaration of 'pPattern' with no type [-fpermissive]
search_quick.h:39:69: error: 'BYTE' does not name a type
search_quick.h:39:81: error: ISO C++ forbids declaration of 'pText' with no type [-fpermissive]
In file included from search_quick.cpp:19:0:
search_quick.h:39:147: error: 'DWORD' has not been declared
search_quick.h:40:25: error: 'BYTE' does not name a type
search_quick.h:40:37: error: ISO C++ forbids declaration of 'pPattern' with no type [-fpermissive]
search_quick.h:40:69: error: 'BYTE' does not name a type
search_quick.h:40:81: error: ISO C++ forbids declaration of 'pText' with no type [-fpermissive]
search_quick.h:40:147: error: 'DWORD' has not been declared
search_quick.cpp:56:10: error: 'BYTE' does not name a type
search_quick.cpp:56:25: error: ISO C++ forbids declaration of 'pPattern' with no type [-fpermissive]
search_quick.cpp: In function 'void PreQS(const int*, int, int*)':
search_quick.cpp:66:9: error: name lookup of 'ii' changed for ISO 'for' scoping [-fpermissive]
search_quick.cpp:66:9: note: (if you use '-fpermissive' G++ will accept your code)
search_quick.cpp: At global scope:
search_quick.cpp:83:10: error: 'BYTE' does not name a type
search_quick.cpp:83:25: error: ISO C++ forbids declaration of 'pPattern' with no type [-fpermissive]
search_quick.cpp: In function 'void PreIQS(const int*, int, int*)':
search_quick.cpp:93:9: error: name lookup of 'ii' changed for ISO 'for' scoping [-fpermissive]
search_quick.cpp:95:34: error: 'toupper' was not declared in this scope
search_quick.cpp:96:34: error: 'tolower' was not declared in this scope
search_quick.cpp: At global scope:
search_quick.cpp:111:10: error: 'BYTE' does not name a type
search_quick.cpp:111:25: error: ISO C++ forbids declaration of 'pPattern' with no type [-fpermissive]
search_quick.cpp:113:10: error: 'BYTE' does not name a type
search_quick.cpp:113:25: error: ISO C++ forbids declaration of 'pText' with no type [-fpermissive]
search_quick.cpp:116:37: error: 'DWORD' has not been declared
search_quick.cpp: In function 'void QuickSearch(const int*, int, const int*, int, void*, void (*)(void*, int))':
search_quick.cpp:129:55: error: 'memcmp' was not declared in this scope
search_quick.cpp: At global scope:
search_quick.cpp:149:10: error: 'BYTE' does not name a type
search_quick.cpp:149:25: error: ISO C++ forbids declaration of 'pPattern' with no type [-fpermissive]
search_quick.cpp:151:10: error: 'BYTE' does not name a type
search_quick.cpp:151:25: error: ISO C++ forbids declaration of 'pText' with no type [-fpermissive]
search_quick.cpp:154:37: error: 'DWORD' has not been declared
search_quick.cpp: In function 'void QuickISearch(const int*, int, const int*, int, void*, void (*)(void*, int))':
search_quick.cpp:167:57: error: '_memicmp' was not declared in this scope
Теперь так.
0
415 / 411 / 95
Регистрация: 06.10.2011
Сообщений: 832
23.06.2013, 20:44 13
@xinix, проверяйте
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <fstream>
#include <string> //to_string
 
using namespace std;
 
int main()
{
    ifstream file("test1.dat", ios::binary);
    ofstream out;
 
    int counter = 1;
    char a, b, c;
 
    if (!file.good()) return 1;
 
    noskipws(file);
 
    while ( file.good() ) {
 
        while ( file >> a && a != 'R' )
            out << a;
 
        if ( file >> b >> c && b == 'I' && c == 'P' ) {
            out.close();
            out.open( to_string(counter) + ".dat", ios::binary );
            ++counter;
            out << a << b << c;
        } else {
            file.unget();
            file.unget();
        }
    }
 
    out.close();
    return 0;
}
1
0 / 0 / 0
Регистрация: 28.09.2012
Сообщений: 37
23.06.2013, 20:49  [ТС] 14
C:\MinGW32\bin>g++.exe -DNOASM stf.cpp
stf.cpp: In function 'int main()':
stf.cpp:26:40: error: 'to_string' was not declared in this scope
Olivеr
Маленькая ошибка, может я не так компилирую?
0
415 / 411 / 95
Регистрация: 06.10.2011
Сообщений: 832
23.06.2013, 20:53 15
@xinix, к опциям еще
C++
1
-std=c++11
1
0 / 0 / 0
Регистрация: 28.09.2012
Сообщений: 37
23.06.2013, 20:56  [ТС] 16
Цитата Сообщение от Olivеr Посмотреть сообщение
@xinix, к опциям еще
C++
1
-std=c++11
cc1plus.exe: error: unrecognized command line option '-std=c++11'
Такс, пошла мингв обновлять - если дело в нём.
0
415 / 411 / 95
Регистрация: 06.10.2011
Сообщений: 832
23.06.2013, 21:00 17
Цитата Сообщение от xinix Посмотреть сообщение
cc1plus.exe: error: unrecognized command line option '-std=c++11'
Тогда так
C++
1
2
#include <cstdlib>
#include <cstring>
C++
1
2
3
4
5
6
7
8
9
10
11
12
        if ( file >> b >> c && b == 'I' && c == 'P' ) {
            out.close();
            char s[10] = {0};
            itoa(counter, s, 10);
            strcat(s, ".dat");
            out.open( s, ios::binary );
            ++counter;
            out << a << b << c;
        } else {
            file.unget();
            file.unget();
        }
1
0 / 0 / 0
Регистрация: 28.09.2012
Сообщений: 37
23.06.2013, 21:06  [ТС] 18
Так?
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
 
using namespace std;
 
int main()
{
    ifstream file("test1.dat", ios::binary);
    ofstream out;
 
    int counter = 1;
    char a, b, c;
 
    if (!file.good()) return 1;
 
    noskipws(file);
 
    while ( file.good() ) {
 
        while ( file >> a && a != 'R' )
            out << a;
 
        if ( file >> b >> c && b == 'I' && c == 'P' ) {
            out.close();
            char s[10] = {0};
            itoa(counter, s, 10);
            strcat(s, ".dat");
            out.open( s, ios::binary );
            ++counter;
            out << a << b << c;
        } else {
            file.unget();
            file.unget();
        }
 
    out.close();
    return 0;
}
Так тоже выдаёт:
C:\MinGW32\bin>g++.exe -DNOASM stf.cpp
stf.cpp: In function 'int main()':
stf.cpp:40:1: error: expected '}' at end of input
0
415 / 411 / 95
Регистрация: 06.10.2011
Сообщений: 832
23.06.2013, 21:07 19
Скобочку } перед
C++
1
2
3
    out.close();
    return 0;
}
пропустили
1
0 / 0 / 0
Регистрация: 28.09.2012
Сообщений: 37
23.06.2013, 21:43  [ТС] 20
Цитата Сообщение от Olivеr Посмотреть сообщение
Скобочку } перед
C++
1
2
3
    out.close();
    return 0;
}
пропустили
Ой, точно. Спасибо, скомпилировалось - сейчас буду тестить!

Добавлено через 27 минут
Olivеr спасибо!
Работает как часы! Спасибо!
0
23.06.2013, 21:43
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
23.06.2013, 21:43
Помогаю со студенческими работами здесь

Файл символов. Все цифры записать во второй файл, а остальные символы - в третий файл
Имеется файл, элементами которого являются отдельные символы. Все цифры записать во второй файл, а...

Файл: Скопировать текст в другой текстовый файл файл, но чётные строки должны быть с большой буквы...
Создать текстовый файл. Скопировать текст в другой текстовый файл файл, но чётные строки должны...

Дан символьный файл F. Подсчитать число вхождений в файл сочетаний АВ.Определить, входит ли в файл сочетание abcdef
Дан символьный файл F. подсчитать число вхождений в файл сочетаний АВ определить, входит ли в...

Создать файл произвольных символов: Вывести в один файл цифры, содержащиеся в файле, а в другой файл литеры
Создать файл произвольных символов. Вывести в один файл цифры, содержащиеся в файле, а в другой...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
20
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru