-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (59 loc) · 1.81 KB
/
main.cpp
File metadata and controls
70 lines (59 loc) · 1.81 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
#define SFML_STATIC
#include <SFML/Graphics.hpp>
#include <unistd.h>
#include <optional>
#include <iostream>
#include "emoji_ok.h"
#include "emoji_fail.h"
#ifdef _WIN32
#include <windows.h>
#include <sddl.h> // parfois nécessaire pour les SID
#endif
#ifdef _WIN32
bool estAdmin() {
BOOL isAdmin = FALSE;
PSID adminGroup = nullptr;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
if (AllocateAndInitializeSid(&NtAuthority, 2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0, &adminGroup)) {
CheckTokenMembership(nullptr, adminGroup, &isAdmin);
FreeSid(adminGroup);
}
return isAdmin;
}
#endif
#ifndef _WIN32
#include <unistd.h>
bool estAdmin() { return geteuid() == 0; }
#endif
int main() {
bool admin = estAdmin();
sf::Color couleur = admin ? sf::Color::Green : sf::Color::Red;
sf::RenderWindow window(sf::VideoMode({300, 200}), "Alors cette escalade de privilège ! C'est...");
sf::Texture texture;
bool success = false;
if (admin)
success = texture.loadFromMemory(ok_png, ok_png_len);
else
success = texture.loadFromMemory(mort_png, mort_png_len);
if (!success) {
std::cerr << "impossible de charger l'image... Mais bon normalement y a le fond en couleur!" << std::endl;
return 1;
}
sf::Sprite emoji(texture);
emoji.setScale({0.5f, 0.5f});
emoji.setPosition({100.f, 50.f});
while (window.isOpen()) {
std::optional<sf::Event> event;
while ((event = window.pollEvent())) {
if (event->is<sf::Event::Closed>())
window.close();
}
window.clear(couleur);
window.draw(emoji);
window.display();
}
return 0;
}