阶段 2 完成
This commit is contained in:
@@ -7,7 +7,6 @@ import json
|
||||
import struct
|
||||
|
||||
from lib.utils.helpers import DetectFileType
|
||||
from lib.core.SymbolNode import SymbolNode
|
||||
from lib.core.Handles.HandlesBase import CTypeInfo
|
||||
from lib.includes import t
|
||||
from lib.constants.config import mode as _ConfigMode
|
||||
@@ -325,13 +324,11 @@ class PythonParserMixin:
|
||||
|
||||
if IsCenum:
|
||||
# 注册为 enum 类型
|
||||
EnumNode = SymbolNode.CreateClass(
|
||||
name=ClassName,
|
||||
TypeKind='enum',
|
||||
lineno=0
|
||||
)
|
||||
EnumNode = CTypeInfo()
|
||||
EnumNode.Name = ClassName
|
||||
EnumNode.IsEnum = True
|
||||
EnumNode.set('file', '<stdin>')
|
||||
self.SymbolTable[ClassName] = EnumNode.attributes
|
||||
self.SymbolTable[ClassName] = EnumNode
|
||||
|
||||
# 注册 enum 成员
|
||||
for item in node.body:
|
||||
@@ -393,25 +390,21 @@ class PythonParserMixin:
|
||||
if _ConfigMode == "strict":
|
||||
raise
|
||||
_vlog().warning(f"解析结构体成员失败: {_e}", "Exception")
|
||||
StructNode = SymbolNode.CreateClass(
|
||||
name=ClassName,
|
||||
TypeKind='struct',
|
||||
members=members,
|
||||
lineno=0,
|
||||
IsCpythonObject=IsCpythonObject
|
||||
)
|
||||
StructNode = CTypeInfo()
|
||||
StructNode.Name = ClassName
|
||||
StructNode.IsStruct = True
|
||||
StructNode.Members = members or {}
|
||||
StructNode.set('file', '<stdin>')
|
||||
StructNode.set('IsAnonymous', IsAnonymous)
|
||||
self.SymbolTable[ClassName] = StructNode.attributes
|
||||
StructNode.set('IsCpythonObject', IsCpythonObject)
|
||||
self.SymbolTable[ClassName] = StructNode
|
||||
elif isinstance(node, ast.FunctionDef):
|
||||
FuncName = node.name
|
||||
FuncNode = SymbolNode.CreateClass(
|
||||
name=FuncName,
|
||||
TypeKind='function',
|
||||
lineno=0
|
||||
)
|
||||
FuncNode = CTypeInfo()
|
||||
FuncNode.Name = FuncName
|
||||
FuncNode.IsFunction = True
|
||||
FuncNode.set('file', '<stdin>')
|
||||
self.SymbolTable[FuncName] = FuncNode.attributes
|
||||
self.SymbolTable[FuncName] = FuncNode
|
||||
elif isinstance(node, ast.AnnAssign):
|
||||
if isinstance(node.target, ast.Name):
|
||||
VarName = node.target.id
|
||||
@@ -445,14 +438,12 @@ class PythonParserMixin:
|
||||
if _ConfigMode == "strict":
|
||||
raise
|
||||
_vlog().warning(f"获取类型信息失败(ParsePythonFile): {_e}", "Exception")
|
||||
var_node = SymbolNode.CreateClass(
|
||||
name=VarName,
|
||||
TypeKind='variable',
|
||||
lineno=0
|
||||
)
|
||||
var_node = CTypeInfo()
|
||||
var_node.Name = VarName
|
||||
var_node.IsVariable = True
|
||||
var_node.set('IsPtr', IsPtr)
|
||||
var_node.set('file', '<stdin>')
|
||||
self.SymbolTable[VarName] = var_node.attributes
|
||||
self.SymbolTable[VarName] = var_node
|
||||
except Exception as e:
|
||||
print(f'Warning: Failed to parse Python file {FilePath}: {e}')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user