Minor improvement of getRevisionNumber logic

This commit is contained in:
Miroslav Stampar 2026-01-27 11:11:01 +01:00
parent f31ea1e2f5
commit 51b56820f7
3 changed files with 27 additions and 31 deletions

View File

@ -187,9 +187,9 @@ a033f92d136c707a25927c2383125ddb004d4283db62c004dcd67c3fc242bb1c lib/core/dump.
49c0fa7e3814dfda610d665ee02b12df299b28bc0b6773815b4395514ddf8dec lib/core/profiling.py
03db48f02c3d07a047ddb8fe33a757b6238867352d8ddda2a83e4fec09a98d04 lib/core/readlineng.py
48797d6c34dd9bb8a53f7f3794c85f4288d82a9a1d6be7fcf317d388cb20d4b3 lib/core/replication.py
3574639db4942d16a2dc0a2f04bb7c0913c40c3862b54d34c44075a760e0c194 lib/core/revision.py
0b8c38a01bb01f843d94a6c5f2075ee47520d0c4aa799cecea9c3e2c5a4a23a6 lib/core/revision.py
888daba83fd4a34e9503fe21f01fef4cc730e5cde871b1d40e15d4cbc847d56c lib/core/session.py
0072bbc61a2a9129b25736f97ccd2a326ca977ef707f8a9dd8db67b41f7553a0 lib/core/settings.py
7f08f592c49c3534afc931a7fb9e1915ffa7425e66ada1d58e56e3383758440f lib/core/settings.py
cd5a66deee8963ba8e7e9af3dd36eb5e8127d4d68698811c29e789655f507f82 lib/core/shell.py
bcb5d8090d5e3e0ef2a586ba09ba80eef0c6d51feb0f611ed25299fbb254f725 lib/core/subprocessng.py
d35650179816193164a5f177102f18379dfbe6bb6d40fbb67b78d907b41c8038 lib/core/target.py

View File

@ -22,43 +22,39 @@ def getRevisionNumber():
retVal = None
filePath = None
_ = os.path.dirname(__file__)
directory = os.path.dirname(__file__)
while True:
filePath = os.path.join(_, ".git", "HEAD")
if os.path.exists(filePath):
candidate = os.path.join(directory, ".git", "HEAD")
if os.path.exists(candidate):
filePath = candidate
break
else:
filePath = None
if _ == os.path.dirname(_):
break
else:
_ = os.path.dirname(_)
while True:
if filePath and os.path.isfile(filePath):
with openFile(filePath, "r") as f:
content = getText(f.read())
filePath = None
if content.startswith("ref: "):
try:
filePath = os.path.join(_, ".git", content.replace("ref: ", "")).strip()
except UnicodeError:
pass
if filePath is None:
match = re.match(r"(?i)[0-9a-f]{32}", content)
retVal = match.group(0) if match else None
break
else:
parent = os.path.dirname(directory)
if parent == directory:
break
directory = parent
if filePath:
with openFile(filePath, "r") as f:
content = getText(f.read()).strip()
if content.startswith("ref: "):
ref_path = content.replace("ref: ", "").strip()
filePath = os.path.join(directory, ".git", ref_path)
if os.path.exists(filePath):
with openFile(filePath, "r") as f_ref:
content = getText(f_ref.read()).strip()
match = re.match(r"(?i)[0-9a-f]{40}", content)
retVal = match.group(0) if match else None
if not retVal:
try:
process = subprocess.Popen("git rev-parse --verify HEAD", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process = subprocess.Popen(["git", "rev-parse", "--verify", "HEAD"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, _ = process.communicate()
match = re.search(r"(?i)[0-9a-f]{32}", getText(stdout or ""))
match = re.search(r"(?i)[0-9a-f]{40}", getText(stdout or ""))
retVal = match.group(0) if match else None
except:
pass

View File

@ -19,7 +19,7 @@ from lib.core.enums import OS
from thirdparty import six
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.10.1.58"
VERSION = "1.10.1.59"
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)