@@ -476,10 +476,8 @@ def __on_enoexec(self, exception):
476
476
binfmt helpers installed for QEMU.
477
477
"""
478
478
# Get the ELF binary for the target executable
479
- with context .quiet :
480
- # XXX: Cyclic imports :(
481
- from pwnlib .elf import ELF
482
- binary = ELF (self .executable )
479
+ from pwnlib .elf import ELF
480
+ binary = ELF (self .executable )
483
481
484
482
# If we're on macOS, this will never work. Bail now.
485
483
# if platform.mac_ver()[0]:
@@ -892,15 +890,15 @@ def maps(self):
892
890
"""maps() -> [mapping]
893
891
894
892
Returns a list of process mappings.
895
-
893
+
896
894
A mapping object has the following fields:
897
895
addr, address (addr alias), start (addr alias), end, size, perms, path, rss, pss, shared_clean, shared_dirty, private_clean, private_dirty, referenced, anonymous, swap
898
896
899
897
perms is a permissions object, with the following fields:
900
898
read, write, execute, private, shared, string
901
899
902
900
Example:
903
-
901
+
904
902
>>> p = process(['cat'])
905
903
>>> p.sendline(b"meow")
906
904
>>> p.recvline()
@@ -937,16 +935,16 @@ def maps(self):
937
935
pmmap_ext = namedtuple(
938
936
'pmmap_ext', 'addr perms ' + ' '.join(pmmap_grouped._fields))
939
937
940
-
941
- Here is an example of a pmmap_ext entry:
938
+
939
+ Here is an example of a pmmap_ext entry:
942
940
943
941
.. code-block:: python
944
942
945
943
pmmap_ext(addr='15555551c000-155555520000', perms='r--p', path='[vvar]', rss=0, size=16384, pss=0, shared_clean=0, shared_dirty=0, private_clean=0, private_dirty=0, referenced=0, anonymous=0, swap=0)
946
944
"""
947
945
948
946
permissions = namedtuple ("permissions" , "read write execute private shared string" )
949
- mapping = namedtuple ("mapping" ,
947
+ mapping = namedtuple ("mapping" ,
950
948
"addr address start end size perms path rss pss shared_clean shared_dirty private_clean private_dirty referenced anonymous swap" )
951
949
# addr = address (alias) = start (alias)
952
950
@@ -976,11 +974,11 @@ def get_mapping(self, path_value, single=True):
976
974
single(bool=True): Whether to only return the first
977
975
mapping matched, or all of them.
978
976
979
- Returns found mapping(s) in process memory according to
977
+ Returns found mapping(s) in process memory according to
980
978
path_value.
981
979
982
980
Example:
983
-
981
+
984
982
>>> p = process(['cat'])
985
983
>>> mapping = p.get_mapping('[stack]')
986
984
>>> mapping.path == '[stack]'
@@ -1039,7 +1037,7 @@ def stack_mapping(self, single=True):
1039
1037
1040
1038
"""
1041
1039
return self .get_mapping ('[stack]' , single )
1042
-
1040
+
1043
1041
def heap_mapping (self , single = True ):
1044
1042
"""heap_mapping(single=True) -> mapping
1045
1043
heap_mapping(False) -> [mapping]
@@ -1071,7 +1069,7 @@ def heap_mapping(self, single=True):
1071
1069
1072
1070
"""
1073
1071
return self .get_mapping ('[heap]' , single )
1074
-
1072
+
1075
1073
def vdso_mapping (self , single = True ):
1076
1074
"""vdso_mapping(single=True) -> mapping
1077
1075
vdso_mapping(False) -> [mapping]
@@ -1100,7 +1098,7 @@ def vdso_mapping(self, single=True):
1100
1098
1101
1099
"""
1102
1100
return self .get_mapping ('[vdso]' , single )
1103
-
1101
+
1104
1102
def vvar_mapping (self , single = True ):
1105
1103
"""vvar_mapping(single=True) -> mapping
1106
1104
vvar_mapping(False) -> [mapping]
@@ -1129,7 +1127,7 @@ def vvar_mapping(self, single=True):
1129
1127
1130
1128
"""
1131
1129
return self .get_mapping ('[vvar]' , single )
1132
-
1130
+
1133
1131
def libc_mapping (self , single = True ):
1134
1132
"""libc_mapping(single=True) -> mapping
1135
1133
libc_mapping(False) -> [mapping]
@@ -1139,7 +1137,7 @@ def libc_mapping(self, single=True):
1139
1137
mapping matched, or all of them.
1140
1138
1141
1139
Returns either the first libc mapping found in process memory,
1142
- or all libc mappings, depending on "single".
1140
+ or all libc mappings, depending on "single".
1143
1141
1144
1142
Example:
1145
1143
@@ -1183,7 +1181,7 @@ def libc_mapping(self, single=True):
1183
1181
if 'libc.so' in lib_basename or ('libc-' in lib_basename and '.so' in lib_basename ):
1184
1182
l_mappings .append (mapping )
1185
1183
return l_mappings
1186
-
1184
+
1187
1185
def musl_mapping (self , single = True ):
1188
1186
"""musl_mapping(single=True) -> mapping
1189
1187
musl_mapping(False) -> [mapping]
@@ -1193,7 +1191,7 @@ def musl_mapping(self, single=True):
1193
1191
mapping matched, or all of them.
1194
1192
1195
1193
Returns either the first musl mapping found in process memory,
1196
- or all musl mappings, depending on "single".
1194
+ or all musl mappings, depending on "single".
1197
1195
"""
1198
1196
all_maps = self .maps ()
1199
1197
@@ -1203,14 +1201,14 @@ def musl_mapping(self, single=True):
1203
1201
if 'musl.so' in lib_basename or ('musl-' in lib_basename and '.so' in lib_basename ):
1204
1202
return mapping
1205
1203
return None
1206
-
1204
+
1207
1205
m_mappings = []
1208
1206
for mapping in all_maps :
1209
1207
lib_basename = os .path .basename (mapping .path )
1210
1208
if 'musl.so' in lib_basename or ('musl-' in lib_basename and '.so' in lib_basename ):
1211
1209
m_mappings .append (mapping )
1212
1210
return m_mappings
1213
-
1211
+
1214
1212
def elf_mapping (self , single = True ):
1215
1213
"""elf_mapping(single=True) -> mapping
1216
1214
elf_mapping(False) -> [mapping]
@@ -1274,10 +1272,10 @@ def lib_size(self, path_value):
1274
1272
1275
1273
# Expecting this to be sorted
1276
1274
lib_mappings = self .get_mapping (path_value , single = False )
1277
-
1275
+
1278
1276
if len (lib_mappings ) == 0 :
1279
1277
return 0
1280
-
1278
+
1281
1279
is_contiguous = True
1282
1280
total_size = lib_mappings [0 ].size
1283
1281
for i in range (1 , len (lib_mappings )):
@@ -1293,7 +1291,7 @@ def lib_size(self, path_value):
1293
1291
1294
1292
def address_mapping (self , address ):
1295
1293
"""address_mapping(address) -> mapping
1296
-
1294
+
1297
1295
Returns the mapping at the specified address.
1298
1296
1299
1297
Example:
@@ -1333,10 +1331,8 @@ def libs(self):
1333
1331
maps_raw = self .poll () is not None and memory_maps (self .pid )
1334
1332
1335
1333
if not maps_raw :
1336
- import pwnlib .elf .elf
1337
-
1338
- with context .quiet :
1339
- return pwnlib .elf .elf .ELF (self .executable ).maps
1334
+ from pwnlib .elf import ELF
1335
+ return ELF (self .executable , checksec = False ).maps
1340
1336
1341
1337
# Enumerate all of the libraries actually loaded right now.
1342
1338
maps = {}
@@ -1358,7 +1354,7 @@ def libs(self):
1358
1354
return maps
1359
1355
1360
1356
@property
1361
- def libc (self ):
1357
+ def libc (self , checksec = False ):
1362
1358
"""libc() -> ELF
1363
1359
1364
1360
Returns an ELF for the libc for the current process.
@@ -1378,7 +1374,7 @@ def libc(self):
1378
1374
for lib , address in self .libs ().items ():
1379
1375
lib_basename = os .path .basename (lib )
1380
1376
if 'libc.so' in lib_basename or ('libc-' in lib_basename and '.so' in lib_basename ):
1381
- e = ELF (lib )
1377
+ e = ELF (lib , checksec )
1382
1378
e .address = address
1383
1379
return e
1384
1380
@@ -1388,8 +1384,8 @@ def elf(self):
1388
1384
1389
1385
Returns an ELF file for the executable that launched the process.
1390
1386
"""
1391
- import pwnlib .elf . elf
1392
- return pwnlib . elf . elf . ELF (self .executable )
1387
+ from pwnlib .elf import ELF
1388
+ return ELF (self .executable )
1393
1389
1394
1390
@property
1395
1391
def corefile (self ):
@@ -1479,7 +1475,7 @@ def writemem(self, address, data):
1479
1475
data(bytes): Data to write to the address
1480
1476
1481
1477
Example:
1482
-
1478
+
1483
1479
Let's write data to the beginning of the mapped memory of the ELF.
1484
1480
1485
1481
>>> context.clear(arch='i386')
0 commit comments