Mail.ruПочтаМой МирОдноклассникиВКонтактеИгрыЗнакомстваНовостиКалендарьОблакоЗаметкиВсе проекты

приведите примеры системных программ и объяснить их назначение

Анастасия Монахова Ученик (152), на голосовании 9 лет назад
Голосование за лучший ответ
arbeshnik Мыслитель (9158) 9 лет назад
c++, delphi - системное программирование.
∯E(r)dxdy = 4π∰ρdxdydz Мастер (1857) 9 лет назад
#include <windows.h>
#include <iostream>

#pragma comment(linker, "/SUBSYSTEM:CONSOLE")

using namespace std;

LPVOID Map(HANDLE hFile, HANDLE *hMapping, char choice)
{
switch (choice)
{
case 0:
*hMapping = CreateFileMapping(hFile, 0, PAGE_READONLY, 0, 0, 0);
return MapViewOfFile(*hMapping, FILE_MAP_READ, 0, 0, 0);
break;
case 1:
*hMapping = CreateFileMapping(hFile, 0, PAGE_READWRITE, 0, 0, 0);
return MapViewOfFile(*hMapping, FILE_MAP_WRITE, 0, 0, 0);
break;
}
return 0;
}

void Unmap(void *Addr, HANDLE hMapping)
{
UnmapViewOfFile(Addr);
CloseHandle(hMapping);
}

DWORD GetLastSymbolPos(int code, int len)
{
int j, i;
for (i = 0, j = 1; j <= len; j++)
i = i + (code * j);
return i;
}

void Read(HANDLE hFile)
{
HANDLE hMapping;
char *Addr = reinterpret_cast<char*>(Map(hFile, &hMapping, 0));
int code;
cout << "Integer code for steganography algorithm> ";
cin >> code;
int len;
cout << "Text len: ";
cin >> len;
if (GetFileSize(hFile, 0) >= GetLastSymbolPos(code, len))
{
int i, j;
for (int i = 0, j = 1; j <= len; j++)
{
i = i + (code * j);
printf("%c", Addr[i]);
}
}
else cout << "File size is too small for this parameters, sorry.\n";

Unmap(Addr, hMapping);
}

void Write(HANDLE hFile)
{
HANDLE hMapping;
char *Addr = reinterpret_cast<char*>(Map(hFile, &hMapping, 1));

char Text[255];
cout << "Text> ";
cin.ignore();
cin.getline(Text, 255);
cout << "Integer code for steganography algorithm> ";
int code;
cin >> code;
int len = strlen(Text);
DWORD Min = GetLastSymbolPos(code, len);
if (GetFileSize(hFile, 0) >= Min)
{
int i, j, k = 0;
for (int i = 0, j = 1; j <= len; j++, k++)
{
i = i + (code * j);
Addr[i] = Text[k];
}
cout << "Success\nText len: " << len << "\nCode: " << code << endl;
}
else cout << "File size is too small for this parameters, sorry.\nYour file must be bigger then " << Min << endl;

Unmap(Addr, hMapping);
}

int main()
{
char FileName[255];
int register fl = 0;
do
{
if (fl > 0) cout << "File not found\n";
cout << "FileName> ";
fl++;
cin.getline(FileName, 255);
} while (GetFileAttributes(FileName) == -1);
HANDLE hFile = CreateFile(FileName, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
cout << "0 - Read Information\n1 - Write Information\n> ";
int choice;
cin >> choice;
switch (choice)
{
case 0:
Read(hFile);
break;
case 1:
Write(hFile);
break;
default:
cout << "Unknown value\n";
}
CloseHandle(hFile);
system("pause >nul");
}

Стеганографическая программа, прячет определенную информацию, по определенному коду, в файле.
Похожие вопросы