@@ -177,6 +177,37 @@ def which_binutils(util, check_version=False):
177
177
Exception: Could not find 'as' installed for ContextType(arch = 'msp430')
178
178
"""
179
179
arch = context .arch
180
+ machine = platform .machine ()
181
+
182
+ if arch == "amd64" :
183
+ pattern = "*86*64*-*-{}" .format (util )
184
+
185
+ for dir in environ ["PATH" ].split (os .pathsep ):
186
+ for res in sorted (glob (path .join (dir , pattern ))):
187
+ if check_version :
188
+ ver = check_binutils_version (res )
189
+ return res , ver
190
+ return res
191
+
192
+ # if target is native, try native command (e.g. "as")
193
+ if machine in ("x86_64" , "amd64" ):
194
+ for dir in environ ["PATH" ].split (os .pathsep ):
195
+ res = path .join (dir , util )
196
+ if os .path .exists (res ) and os .access (res , os .X_OK ):
197
+ if check_version :
198
+ ver = check_binutils_version (res )
199
+ return res , ver
200
+ return res
201
+
202
+ pattern = "i*86*-*-{}" .format (util )
203
+ for dir in environ ["PATH" ].split (os .pathsep ):
204
+ for res in sorted (glob (path .join (dir , pattern ))):
205
+ if check_version :
206
+ ver = check_binutils_version (res )
207
+ return res , ver
208
+ return res
209
+
210
+ print_binutils_instructions (util , context )
180
211
181
212
# Fix up pwntools vs Debian triplet naming, and account
182
213
# for 'thumb' being its own pwntools architecture.
@@ -195,7 +226,6 @@ def which_binutils(util, check_version=False):
195
226
196
227
# If one of the candidate architectures matches the native
197
228
# architecture, use that as a last resort.
198
- machine = platform .machine ()
199
229
machine = 'i386' if machine == 'i686' else machine
200
230
try :
201
231
with context .local (arch = machine ):
0 commit comments