-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathlinux_interface.cpp
More file actions
42 lines (34 loc) · 1.1 KB
/
linux_interface.cpp
File metadata and controls
42 lines (34 loc) · 1.1 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
//
// This file is part of libdebug Python library (https://github.com/libdebug/libdebug).
// Copyright (c) 2024 Roberto Alessandro Bertolini. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
//
#include <nanobind/nanobind.h>
#include <sys/personality.h>
void disable_aslr()
{
int persona = personality(0xffffffff);
if (persona == -1) {
throw std::runtime_error("Reading personality failed");
}
persona |= ADDR_NO_RANDOMIZE;
if (personality(persona) == -1) {
throw std::runtime_error("Disabling ASLR failed");
}
}
void enable_aslr()
{
int persona = personality(0xffffffff);
if (persona == -1) {
throw std::runtime_error("Reading personality failed");
}
persona &= ~ADDR_NO_RANDOMIZE;
if (personality(persona) == -1) {
throw std::runtime_error("Enabling ASLR failed");
}
}
NB_MODULE(libdebug_linux_binding, m)
{
m.def("disable_aslr", &disable_aslr, "Disables ASLR for the current process.");
m.def("enable_aslr", &enable_aslr, "Enables ASLR for the current process.");
}