forked from vic4key/Vutils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSample.Misc.h
More file actions
142 lines (107 loc) · 4.92 KB
/
Sample.Misc.h
File metadata and controls
142 lines (107 loc) · 4.92 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#pragma once
#include "Sample.h"
#include <iomanip>
DEF_SAMPLE(Misc)
{
vu::Box(vu::GetConsoleWindow(), _T("I'm %s. I'm %d years old."), _T("Vic P"), 26);
vu::Msg(_T("I'm %s. I'm %d years old."), _T("Vic P"), 26);
std::tcout << vu::Fmt(_T("I'm %s. I'm %d years old. (A)"), _T("Vic P"), 26) << std::endl;
std::tcout << vu::LowerString(_T("I Love You")) << std::endl;
std::tcout << vu::UpperString(_T("I Love You")) << std::endl;
std::tcout << vu::TrimString(_T(" THIS IS A TRIM STRING ")) << std::endl;
std::tcout << vu::LastError() << std::endl;
std::vector<std::tstring> l;
l.clear();
l = vu::SplitString(_T("THIS IS A SPLIT STRING"), _T(" "));
for (auto e : l) std::tcout << e << _T("|");
std::tcout << std::endl;
l.clear();
l = vu::MultiStringToList(_T("THIS\0IS\0A\0MULTI\0STRING\0\0"));
for (auto& e : l) std::tcout << e << _T("|");
std::tcout << std::endl;
std::tcout << vu::DateTimeToString(time(NULL)) << std::endl;
std::cout << vu::ToStringA(L"THIS IS A WIDE STRING") << std::endl;
std::wcout << vu::ToStringW("THIS IS AN ANSI STRING") << std::endl;
std::tcout << _T("Enviroment `PATH`") << std::endl;
std::tstring envValue = vu::GetEnviroment(_T("PATH"));
auto env = vu::SplitString(envValue, _T(";"));
for (auto e : env) {
std::tcout << '\t' << e << std::endl;
}
std::tcout << vu::ReplaceString(_T("Written in C++ and for C++"), _T("C++"), _T("Cpp")) << std::endl;
std::tcout << vu::StartsWith(_T("Written in C++ and for C++"), _T("C++")) << std::endl;
std::tcout << vu::StartsWith(_T("Written in C++ and for C++"), _T("Written")) << std::endl;
std::tcout << vu::EndsWith(_T("Written in C++ and for C++"), _T("C++")) << std::endl;
std::tcout << vu::EndsWith(_T("Written in C++ and for C++"), _T("Written")) << std::endl;
std::vector<vu::ulong> PIDs;
PIDs.clear();
PIDs = vu::NameToPID(_T("Explorer.exe"));
for (auto& PID : PIDs) {
std::tcout << PID << std::endl;
}
if (!PIDs.empty()) {
std::tcout << vu::PIDToName(*PIDs.begin()) << std::endl;
}
// std::vector<vu::ulong> pids;
// pids = vu::NameToPID(_T("notepad.exe")); // 64-bit
// pids = vu::NameToPID(_T("JRuler.exe")); // 32-bit
// assert(!pids.empty());
// vu::InjectDLL(pids.back(), _T("path\\to\\32-bit-dll"), true);
// vu::InjectDLL(pids.back(), _T("path\\to\\64-bit-dll"), true);
static std::wstring LES[] = { // List Encoding Short
L"ANSI/UTF-8", L"UTF-8 BOM",
L"Unicode", L"Unicode BE",
L"Unicode BOM", L"Unicode BE BOM",
L"UTF-32 LE BOM", L"UTF-32 BE BOM"
};
static std::wstring LEL[] = { // List Encoding Long
L"ANSI/UTF-8", L"UTF-8 BOM",
L"UTF-16 Little Endian", L"UTF-16 Big Endian",
L"UTF-16 Little Endian BOM", L"UTF-16 Big Endian BOM",
L"UTF-32 Little Endian BOM", L"UTF-32 Big Endian BOM"
};
vu::CFileSystem::Iterate(_T("path\\to\\example"), _T("*.txt"), [](const vu::TFSObject& FSObject) -> bool
{
auto filePath = FSObject.Directory + FSObject.Name;
auto data = vu::CFileSystem::QuickReadAsBuffer(filePath);
auto result = vu::DetermineEncodingType(data.GetpData(), data.GetSize());
auto es = result == -1 ? L"Unknown" : LES[result];
auto el = result == -1 ? L"Unknown" : LEL[result];
std::wcout
<< std::left
<< std::setw(15) << es
<< " | "
<< std::setw(25) << el
<< " | "
<< FSObject.Name.c_str()
<< std::endl;
return true;
});
auto type = vu::eStdByte::SI;
auto digits = 2;
std::tcout << vu::FormatBytes(912, type, digits) << std::endl; // B/Bi
std::tcout << vu::FormatBytes(91234, type, digits) << std::endl; // KB/KiB
std::tcout << vu::FormatBytes(9123456, type, digits) << std::endl; // MB/MiB
std::tcout << vu::FormatBytes(9123456789, type, digits) << std::endl; // GB/GiB
std::tcout << vu::FormatBytes(9123456789101, type, digits) << std::endl; // TB/TiB
std::tcout << vu::FormatBytes(9123456789101213, type, digits) << std::endl; // PB/PiB
std::tcout << vu::FormatBytes(9123456789101213145, type, digits) << std::endl; // EB/EiB*/
vu::CBuffer data;
auto result = vu::FindPattern(data, _T("11 ?? 33 ?? 44 ?? 55"));
std::tcout << _T("Result is ") << result.first << _T(" at Offset ") << result.second << std::endl;
std::string s = "0123456789";
vu::CBuffer slicer(s.data(), s.size());
std::cout << slicer(0, 0).ToStringA() << std::endl;
std::cout << slicer(9, 9).ToStringA() << std::endl;
std::cout << slicer(0, 9).ToStringA() << std::endl;
std::cout << slicer(3, 7).ToStringA() << std::endl;
std::cout << slicer(-7, -2).ToStringA() << std::endl;
std::cout << slicer(2, -2).ToStringA() << std::endl;
std::cout << slicer(0, -8).ToStringA() << std::endl;
std::cout << slicer(0, -9).ToStringA() << std::endl;
std::cout << slicer(0, -10).ToStringA() << std::endl;
std::cout << slicer(-8, 10).ToStringA() << std::endl;
std::cout << slicer(-9, 10).ToStringA() << std::endl;
std::cout << slicer(-10, 10).ToStringA() << std::endl;
return vu::VU_OK;
}