@@ -476,10 +476,7 @@ 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
+ binary = pwnlib .elf .ELF (self .executable )
483
480
484
481
# If we're on macOS, this will never work. Bail now.
485
482
# if platform.mac_ver()[0]:
@@ -892,15 +889,15 @@ def maps(self):
892
889
"""maps() -> [mapping]
893
890
894
891
Returns a list of process mappings.
895
-
892
+
896
893
A mapping object has the following fields:
897
894
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
895
899
896
perms is a permissions object, with the following fields:
900
897
read, write, execute, private, shared, string
901
898
902
899
Example:
903
-
900
+
904
901
>>> p = process(['cat'])
905
902
>>> p.sendline(b"meow")
906
903
>>> p.recvline()
@@ -937,16 +934,16 @@ def maps(self):
937
934
pmmap_ext = namedtuple(
938
935
'pmmap_ext', 'addr perms ' + ' '.join(pmmap_grouped._fields))
939
936
940
-
941
- Here is an example of a pmmap_ext entry:
937
+
938
+ Here is an example of a pmmap_ext entry:
942
939
943
940
.. code-block:: python
944
941
945
942
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
943
"""
947
944
948
945
permissions = namedtuple ("permissions" , "read write execute private shared string" )
949
- mapping = namedtuple ("mapping" ,
946
+ mapping = namedtuple ("mapping" ,
950
947
"addr address start end size perms path rss pss shared_clean shared_dirty private_clean private_dirty referenced anonymous swap" )
951
948
# addr = address (alias) = start (alias)
952
949
@@ -976,11 +973,11 @@ def get_mapping(self, path_value, single=True):
976
973
single(bool=True): Whether to only return the first
977
974
mapping matched, or all of them.
978
975
979
- Returns found mapping(s) in process memory according to
976
+ Returns found mapping(s) in process memory according to
980
977
path_value.
981
978
982
979
Example:
983
-
980
+
984
981
>>> p = process(['cat'])
985
982
>>> mapping = p.get_mapping('[stack]')
986
983
>>> mapping.path == '[stack]'
@@ -1039,7 +1036,7 @@ def stack_mapping(self, single=True):
1039
1036
1040
1037
"""
1041
1038
return self .get_mapping ('[stack]' , single )
1042
-
1039
+
1043
1040
def heap_mapping (self , single = True ):
1044
1041
"""heap_mapping(single=True) -> mapping
1045
1042
heap_mapping(False) -> [mapping]
@@ -1071,7 +1068,7 @@ def heap_mapping(self, single=True):
1071
1068
1072
1069
"""
1073
1070
return self .get_mapping ('[heap]' , single )
1074
-
1071
+
1075
1072
def vdso_mapping (self , single = True ):
1076
1073
"""vdso_mapping(single=True) -> mapping
1077
1074
vdso_mapping(False) -> [mapping]
@@ -1100,7 +1097,7 @@ def vdso_mapping(self, single=True):
1100
1097
1101
1098
"""
1102
1099
return self .get_mapping ('[vdso]' , single )
1103
-
1100
+
1104
1101
def vvar_mapping (self , single = True ):
1105
1102
"""vvar_mapping(single=True) -> mapping
1106
1103
vvar_mapping(False) -> [mapping]
@@ -1129,7 +1126,7 @@ def vvar_mapping(self, single=True):
1129
1126
1130
1127
"""
1131
1128
return self .get_mapping ('[vvar]' , single )
1132
-
1129
+
1133
1130
def libc_mapping (self , single = True ):
1134
1131
"""libc_mapping(single=True) -> mapping
1135
1132
libc_mapping(False) -> [mapping]
@@ -1139,7 +1136,7 @@ def libc_mapping(self, single=True):
1139
1136
mapping matched, or all of them.
1140
1137
1141
1138
Returns either the first libc mapping found in process memory,
1142
- or all libc mappings, depending on "single".
1139
+ or all libc mappings, depending on "single".
1143
1140
1144
1141
Example:
1145
1142
@@ -1183,7 +1180,7 @@ def libc_mapping(self, single=True):
1183
1180
if 'libc.so' in lib_basename or ('libc-' in lib_basename and '.so' in lib_basename ):
1184
1181
l_mappings .append (mapping )
1185
1182
return l_mappings
1186
-
1183
+
1187
1184
def musl_mapping (self , single = True ):
1188
1185
"""musl_mapping(single=True) -> mapping
1189
1186
musl_mapping(False) -> [mapping]
@@ -1193,7 +1190,7 @@ def musl_mapping(self, single=True):
1193
1190
mapping matched, or all of them.
1194
1191
1195
1192
Returns either the first musl mapping found in process memory,
1196
- or all musl mappings, depending on "single".
1193
+ or all musl mappings, depending on "single".
1197
1194
"""
1198
1195
all_maps = self .maps ()
1199
1196
@@ -1203,14 +1200,14 @@ def musl_mapping(self, single=True):
1203
1200
if 'musl.so' in lib_basename or ('musl-' in lib_basename and '.so' in lib_basename ):
1204
1201
return mapping
1205
1202
return None
1206
-
1203
+
1207
1204
m_mappings = []
1208
1205
for mapping in all_maps :
1209
1206
lib_basename = os .path .basename (mapping .path )
1210
1207
if 'musl.so' in lib_basename or ('musl-' in lib_basename and '.so' in lib_basename ):
1211
1208
m_mappings .append (mapping )
1212
1209
return m_mappings
1213
-
1210
+
1214
1211
def elf_mapping (self , single = True ):
1215
1212
"""elf_mapping(single=True) -> mapping
1216
1213
elf_mapping(False) -> [mapping]
@@ -1274,10 +1271,10 @@ def lib_size(self, path_value):
1274
1271
1275
1272
# Expecting this to be sorted
1276
1273
lib_mappings = self .get_mapping (path_value , single = False )
1277
-
1274
+
1278
1275
if len (lib_mappings ) == 0 :
1279
1276
return 0
1280
-
1277
+
1281
1278
is_contiguous = True
1282
1279
total_size = lib_mappings [0 ].size
1283
1280
for i in range (1 , len (lib_mappings )):
@@ -1293,7 +1290,7 @@ def lib_size(self, path_value):
1293
1290
1294
1291
def address_mapping (self , address ):
1295
1292
"""address_mapping(address) -> mapping
1296
-
1293
+
1297
1294
Returns the mapping at the specified address.
1298
1295
1299
1296
Example:
@@ -1358,7 +1355,7 @@ def libs(self):
1358
1355
return maps
1359
1356
1360
1357
@property
1361
- def libc (self ):
1358
+ def libc (self , checksec = False ):
1362
1359
"""libc() -> ELF
1363
1360
1364
1361
Returns an ELF for the libc for the current process.
@@ -1378,7 +1375,7 @@ def libc(self):
1378
1375
for lib , address in self .libs ().items ():
1379
1376
lib_basename = os .path .basename (lib )
1380
1377
if 'libc.so' in lib_basename or ('libc-' in lib_basename and '.so' in lib_basename ):
1381
- e = ELF (lib )
1378
+ e = ELF (lib , checksec )
1382
1379
e .address = address
1383
1380
return e
1384
1381
@@ -1388,8 +1385,7 @@ def elf(self):
1388
1385
1389
1386
Returns an ELF file for the executable that launched the process.
1390
1387
"""
1391
- import pwnlib .elf .elf
1392
- return pwnlib .elf .elf .ELF (self .executable )
1388
+ return pwnlib .elf .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