Cursor improvements parts 1 and 2

This commit is contained in:
carlospolop
2025-05-19 06:36:35 +02:00
parent ea9b930fdb
commit 9820c18697
29 changed files with 971 additions and 195 deletions
+99 -55
View File
@@ -36,89 +36,133 @@ class LinpeasModule:
if not (self.is_base or self.is_function or self.is_variable or self.is_check):
raise Exception(f"Module {path} doesn't belong to any section")
# Initi data
self.title = None
self.id = None
self.author = None
self.last_update = None
self.description = None
self.version = None
self.functions_used = None
self.global_variables = None
self.initial_functions = None
self.generated_global_variables = None
self.is_fat = None
self.is_small = None
self.sh_code = ""
is_description = False
for i,line in enumerate(self.module_text.splitlines()):
if i == 0:
if not line.startswith("# Title:"):
raise Exception(f"Wrong title in module {path}. It should start with '# Title: '")
self.title = line[8:].strip()
elif i == 1:
if not line.startswith("# ID:"):
raise Exception(f"Wrong ID in module {path}. It should start with '# ID: '")
self.id = line[5:].strip()
if line.startswith("# Title:"):
self.title = line[8:].strip()
is_description = False
elif line.startswith("# ID:"):
self.id = line[5:].strip()
is_description = False
if re.sub('^[0-9]+_', '', os.path.basename(path).replace(".sh", "")) not in [self.id, self.id[3:]]:
raise Exception(f"Wrong ID in module {path}. It should be the same as the filename")
elif i == 2:
if not line.startswith("# Author:"):
raise Exception(f"Wrong author in module {path}. It should start with '# Author: '")
elif line.startswith("# Author:"):
is_description = False
self.author = line[10:].strip()
elif i == 3:
if not line.startswith("# Last Update:"):
raise Exception(f"Wrong last update in module {path}. It should start with '# Last Update: '")
elif line.startswith("# Last Update:"):
is_description = False
self.last_update = line[15:].strip()
elif i == 4:
if not line.startswith("# Description:"):
raise Exception(f"Wrong description in module {path}. It should start with '# Description: '")
elif line.startswith("# Description:"):
self.description = line[15:].strip()
is_description = True
elif i == 5:
if not line.startswith("# License:"):
raise Exception(f"Wrong license in module {path}. It should start with '# License: '")
elif i == 6:
if not line.startswith("# Version:"):
raise Exception(f"Wrong version in module {path}. It should start with '# Version: '")
elif line.startswith("# Version:"):
is_description = False
self.version = line[11:].strip()
elif i == 7:
if not line.startswith("# Functions Used:"):
raise Exception(f"Wrong functions used in module {path}. It should start with '# Functions Used: '")
elif line.startswith("# Functions Used:"):
is_description = False
self.functions_used = line[17:].split(",")
self.functions_used = [f.strip() for f in self.functions_used if f.strip()]
if "/variables/" in path and self.functions_used:
raise Exception(f"Variables shouldn't user functions, so functions in module {path} should be empty")
elif i == 8:
if not line.startswith("# Global Variables:"):
raise Exception(f"Wrong global variables in module {path}. It should start with '# Global Variables: '")
elif line.startswith("# Global Variables:"):
is_description = False
self.global_variables = line[19:].split(",")
self.global_variables = [f.strip().replace("$", "") for f in self.global_variables if f.strip()]
elif i == 9:
if not line.startswith("# Initial Functions:"):
raise Exception(f"Wrong initial functions in module {path}. It should start with '# Initial Functions: '")
elif line.startswith("# Initial Functions:"):
is_description = False
self.initial_functions = line[20:].split(",")
self.initial_functions = [f.strip() for f in self.initial_functions if f.strip()]
elif i == 10:
if not line.startswith("# Generated Global Variables:"):
raise Exception(f"Wrong generated global variables in module {path}. It should start with '# Generated Global Variables: '")
elif line.startswith("# Generated Global Variables:"):
is_description = False
self.generated_global_variables = line[29:].split(",")
self.generated_global_variables = [f.strip().replace("$", "") for f in self.generated_global_variables if f.strip()]
elif i == 11:
if not line.startswith("# Fat linpeas:"):
raise Exception(f"Wrong generated global variables in module {path}. It should start with '# Generated Global Variables: '")
elif line.startswith("# Fat linpeas:"):
is_description = False
self.is_fat = bool(int(line[15]))
elif i == 12:
if not line.startswith("# Small linpeas:"):
raise Exception(f"Wrong generated global variables in module {path}. It should start with '# Generated Global Variables: '")
elif line.startswith("# Small linpeas:"):
is_description = False
self.is_small = bool(int(line[17]))
elif i == 13:
if line != "":
raise Exception(f"Wrong module {path}. Line 12 should be a new line")
elif is_description:
if line.strip():
self.description += line + "\n"
else: # If line empty, outside of description
is_description = False
else:
self.sh_code += line + "\n"
if line.strip():
self.sh_code += line + "\n"
if self.title is None:
raise Exception(f"Wrong title in module {path}. Some metadata should start with '# Title: '")
if self.id is None:
raise Exception(f"Wrong ID in module {path}. Some metadata should start with '# ID: '")
if self.author is None:
raise Exception(f"Wrong author in module {path}. Some metadata should start with '# Author: '")
if self.last_update is None:
raise Exception(f"Wrong last update in module {path}. Some metadata should start with '# Last Update: '")
if self.description is None:
raise Exception(f"Wrong description in module {path}. Some metadata should start with '# Description: '")
if self.version is None:
raise Exception(f"Wrong version in module {path}. Some metadata should start with '# Version: '")
if self.functions_used is None:
raise Exception(f"Wrong functions used in module {path}. Some metadata should start with '# Functions Used: '")
if self.global_variables is None:
raise Exception(f"Wrong global variables in module {path}. Some metadata should start with '# Global Variables: '")
if self.initial_functions is None:
raise Exception(f"Wrong initial functions in module {path}. Some metadata should start with '# Initial Functions: '")
if self.generated_global_variables is None:
raise Exception(f"Wrong generated global variables in module {path}. Some metadata should start with '# Generated Global Variables: '")
if self.is_fat is None:
raise Exception(f"Wrong fat linpeas in module {path}. Some metadata should start with '# Fat linpeas: '")
if self.is_small is None:
raise Exception(f"Wrong small linpeas in module {path}. Some metadata should start with '# Small linpeas: '")
if self.sh_code == "":
raise Exception(f"Wrong sh code in module {path}. No code found.")
self.sh_code = self.sh_code.strip()
self.defined_funcs = self.extract_function_names()
@@ -126,15 +170,15 @@ class LinpeasModule:
# Check if the indicated dependencies are actually being used
for func in self.functions_used:
if func not in self.sh_code and func not in self.initial_functions and not "peass{" in self.sh_code:
raise Exception(f"Used function '{func}' in module {path} doesn't exist in the final code")
raise Exception(f"Used function '{func}' in module {path} doesn't exist in the module code")
for var in self.global_variables:
if var not in self.sh_code and not "peass{" in self.sh_code:
raise Exception(f"Used variable '{var}' in module {path} doesn't exist in the final code")
raise Exception(f"Used variable '{var}' in module {path} doesn't exist in the module code")
for var in self.generated_global_variables:
if var not in self.sh_code:
raise Exception(f"Generated variable '{var}' in module {path} doesn't exist in the final code")
raise Exception(f"Generated variable '{var}' in module {path} doesn't exist in the module code")
# Check for funcs and vars imported from itself
for func in self.defined_funcs:
@@ -169,7 +213,7 @@ class LinpeasModule:
if len(var) > 2 and not var in linux_global_vars and var not in self.global_variables and var not in self.generated_global_variables:
if not var.startswith("PSTORAGE_"):
if not main_base or var not in main_base.generated_global_variables:
raise Exception(f"Variable '{var}' in module {path} is not defined")
raise Exception(f"Global Variable '{var}' in module {path} is not defined inside the 'Generated Global Variables' metadata")
def __eq__(self, other):