HyperDbg Debugger
Loading...
Searching...
No Matches
common-utils.cpp File Reference

common utils More...

#include "pch.h"

Functions

BOOLEAN IsFileExists (const std::string &FileName)
 check if a file exist or not
 
BOOLEAN IsDirExists (const std::string &DirPath)
 check if a path exist or not
 
BOOLEAN CreateDirectoryRecursive (const std::string &Path)
 create a directory recursively
 
const std::vector< std::string > Split (const std::string &s, const char &c)
 general split command
 

Detailed Description

common utils

Author
Alee Amini (alee@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2021-06-10

Function Documentation

◆ CreateDirectoryRecursive()

BOOLEAN CreateDirectoryRecursive ( const std::string & Path)

create a directory recursively

Parameters
Pathpath of file
Returns
BOOLEAN
55{
56 size_t Pos = 0;
57 do
58 {
59 Pos = Path.find_first_of("\\/", Pos + 1);
60 CreateDirectoryA(Path.substr(0, Pos).c_str(), NULL);
61
62 } while (Pos != std::string::npos && Pos <= Path.size());
63
64 if (IsDirExists(Path))
65 return TRUE;
66
67 return FALSE;
68}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
BOOLEAN IsDirExists(const std::string &DirPath)
check if a path exist or not
Definition common-utils.cpp:34

◆ IsDirExists()

BOOLEAN IsDirExists ( const std::string & DirPath)

check if a path exist or not

Parameters
DirPathpath of dir
Returns
BOOLEAN shows whether the file exist or not
35{
36 DWORD Ftyp = GetFileAttributesA(DirPath.c_str());
37 if (Ftyp == INVALID_FILE_ATTRIBUTES)
38 return FALSE; // something is wrong with your path!
39
40 if (Ftyp & FILE_ATTRIBUTE_DIRECTORY)
41 return TRUE; // this is a directory!
42
43 return FALSE; // this is not a directory!
44}
unsigned long DWORD
Definition BasicTypes.h:22

◆ IsFileExists()

BOOLEAN IsFileExists ( const std::string & FileName)

check if a file exist or not

Parameters
FileNamepath of file
Returns
BOOLEAN shows whether the file exist or not
23{
24 struct stat buffer;
25 return (stat(FileName.c_str(), &buffer) == 0);
26}

◆ Split()

const std::vector< std::string > Split ( const std::string & s,
const char & c )

general split command

Parameters
starget string
csplitter (delimiter)
Returns
const vector<string>
79{
80 string buff {""};
81 vector<string> v;
82
83 for (auto n : s)
84 {
85 if (n != c)
86 buff += n;
87 else if (n == c && !buff.empty())
88 {
89 v.push_back(buff);
90 buff.clear();
91 }
92 }
93 if (!buff.empty())
94 v.push_back(buff);
95
96 return v;
97}