Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit facce2c

Browse files
committed
some more cleanup
1 parent d5e8008 commit facce2c

3 files changed

Lines changed: 22 additions & 31 deletions

File tree

lib/techniques/blind/inference.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
147147
hintlock = threading.Lock()
148148

149149
def tryHint(idx):
150-
hintlock.acquire()
151-
hintValue = kb.hintValue
152-
hintlock.release()
150+
with hintlock:
151+
hintValue = kb.hintValue
153152

154153
if hintValue is not None and len(hintValue) >= idx:
155154
if Backend.getIdentifiedDbms() in (DBMS.SQLITE, DBMS.ACCESS, DBMS.MAXDB, DBMS.DB2):
@@ -164,9 +163,8 @@ def tryHint(idx):
164163
if result:
165164
return hintValue[idx-1]
166165

167-
hintlock.acquire()
168-
kb.hintValue = None
169-
hintlock.release()
166+
with hintlock:
167+
kb.hintValue = None
170168

171169
return None
172170

@@ -373,10 +371,9 @@ def blindThread():
373371
else:
374372
break
375373

376-
kb.locks.value.acquire()
377-
threadData.shared.value[curidx - 1] = val
378-
currentValue = list(threadData.shared.value)
379-
kb.locks.value.release()
374+
with kb.locks.value:
375+
threadData.shared.value[curidx - 1] = val
376+
currentValue = list(threadData.shared.value)
380377

381378
if kb.threadContinue:
382379
if showEta:

lib/techniques/error/use.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,11 @@ def errorThread():
333333
threadData = getCurrentThreadData()
334334

335335
while kb.threadContinue:
336-
kb.locks.limits.acquire()
337-
try:
338-
num = threadData.shared.limits.next()
339-
except StopIteration:
340-
break
341-
finally:
342-
kb.locks.limits.release()
336+
with kb.locks.limits:
337+
try:
338+
num = threadData.shared.limits.next()
339+
except StopIteration:
340+
break
343341

344342
output = __errorFields(expression, expressionFields, expressionFieldsList, expected, num)
345343

@@ -349,9 +347,8 @@ def errorThread():
349347
if output and isinstance(output, list) and len(output) == 1:
350348
output = output[0]
351349

352-
kb.locks.outputs.acquire()
353-
threadData.shared.outputs.append(output)
354-
kb.locks.outputs.release()
350+
with kb.locks.outputs:
351+
threadData.shared.outputs.append(output)
355352

356353
runThreads(numThreads, errorThread)
357354

lib/techniques/union/use.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,11 @@ def unionThread():
283283
threadData = getCurrentThreadData()
284284

285285
while kb.threadContinue:
286-
kb.locks.limits.acquire()
287-
try:
288-
num = threadData.shared.limits.next()
289-
except StopIteration:
290-
break
291-
finally:
292-
kb.locks.limits.release()
286+
with kb.locks.limits:
287+
try:
288+
num = threadData.shared.limits.next()
289+
except StopIteration:
290+
break
293291

294292
if Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE):
295293
field = expressionFieldsList[0]
@@ -309,10 +307,9 @@ def unionThread():
309307
items = parseUnionPage(output)
310308
if isNoneValue(items):
311309
continue
312-
kb.locks.value.acquire()
313-
for item in arrayizeValue(items):
314-
threadData.shared.value.append(item)
315-
kb.locks.value.release()
310+
with kb.locks.value:
311+
for item in arrayizeValue(items):
312+
threadData.shared.value.append(item)
316313
else:
317314
items = output.replace(kb.chars.start, "").replace(kb.chars.stop, "").split(kb.chars.delimiter)
318315

0 commit comments

Comments
 (0)