From 96299d3d5dad6e57fb73a1fa6da74332961c9b06 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 3 May 2012 22:34:18 +0000 Subject: [PATCH] minor refactoring --- lib/core/common.py | 3 +++ lib/core/dump.py | 5 ++--- plugins/generic/enumeration.py | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 2c425fab5..4d8ab91ce 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -3207,3 +3207,6 @@ def resetCookieJar(cookieJar): errMsg += "cookies file ('%s')" % msg raise sqlmapGenericException, errMsg +def prioritySortColumns(columns): + _ = lambda x: x and "id" in x.lower() + return sorted(sorted(columns, key=len), lambda x, y: -1 if _(x) and not _(y) else 1 if not _(x) and _(y) else 0) diff --git a/lib/core/dump.py b/lib/core/dump.py index 774b16d61..1e798d274 100644 --- a/lib/core/dump.py +++ b/lib/core/dump.py @@ -19,6 +19,7 @@ from lib.core.common import dataToStdout from lib.core.common import getUnicode from lib.core.common import normalizeUnicode from lib.core.common import openFile +from lib.core.common import prioritySortColumns from lib.core.common import restoreDumpMarkedChars from lib.core.common import safeCSValue from lib.core.common import unsafeSQLIdentificatorNaming @@ -357,9 +358,7 @@ class Dump: field = 1 fields = len(tableValues) - 1 - columns = tableValues.keys() - _ = lambda x: x and "id" in x.lower() - columns = sorted(sorted(columns, key=len), lambda x, y: -1 if _(x) and not _(y) else 1 if not _(x) and _(y) else 0) + columns = prioritySortColumns(tableValues.keys()) for column in columns: if column != "__infos__": diff --git a/plugins/generic/enumeration.py b/plugins/generic/enumeration.py index ccddb3823..6b223c6d6 100644 --- a/plugins/generic/enumeration.py +++ b/plugins/generic/enumeration.py @@ -26,6 +26,7 @@ from lib.core.common import isTechniqueAvailable from lib.core.common import parsePasswordHash from lib.core.common import parseSqliteTableSchema from lib.core.common import popValue +from lib.core.common import prioritySortColumns from lib.core.common import pushValue from lib.core.common import randomStr from lib.core.common import readInput @@ -1608,9 +1609,7 @@ class Enumeration: else: query = rootQuery.inband.query % (colString, conf.db, tbl) elif Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL): - _ = lambda x: x and "id" in x.lower() - orderby = sorted(sorted(colList, key=len), lambda x, y: -1 if _(x) and not _(y) else 1 if not _(x) and _(y) else 0)[0] - query = rootQuery.inband.query % (colString, conf.db, tbl, orderby) + query = rootQuery.inband.query % (colString, conf.db, tbl, prioritySortColumns(colList)[0]) else: query = rootQuery.inband.query % (colString, conf.db, tbl)