How to write a query to find the function call path in python #12064
-
I am writing a query to find the call path about the imported functions/methods. from http.server import HTTPServer,BaseHTTPRequestHandler
import yaml
from nvflare.lighter import provision
class helloHandler(BaseHTTPRequestHandler):
def do_GET(self): ...
provision.main() ...
project_data = yaml.safe_load(...) ...
def main():
server = HTTPServer(("0.0.0.0",8000),helloHandler)
server.serve_forever()
if __name__ == '__main__':
main() The query as below: from Value val, CallNode call, Scope scope
where val.getACall() = call and
call.getLocation().getFile().toString().matches("%/VersionTestProject1/%") and
(scope = val.(CallableValue).getScope() or
scope = val.(ClassValue).getScope() )
select call, val, scope The query can only find the main(). from CallableValue call
where call.getACall().getLocation().getFile().toString().matches("%/VersionTestProject1/%")
select call The query only shows the main() and some build-in functions such as str() len() open()... I have tried CallableValue, MethodCallNode::flowsTo() and all of them failed to find the function call. from Call call1, PointsToContext caller, ObjectInternal value
where call1.getLocation().getFile().toString().matches("%/VersionTestProject1/%") and
InterProceduralPointsTo::call(call1.getAFlowNode(),caller,value)
select call1,caller, value it can find the call of "provision.main()" as "call: Attribute(), caller: runtime, value: Unknown value" I was wondering if there is a way to find the CALL to the import function properly as well as get the location information of that import function. Thank you so much |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks to @atorralba for helping on the editing. It might be the reason I cannot find any non built-in functions and methods via the various value classes like BoundMethodValue, CallableValue, FunctionValue, ModuleValue and PythonFunctionValue. Not sure how to make the "venv/" folder being included during the database generating process. Does any one can help on these two problem? |
Beta Was this translation helpful? Give feedback.
Thanks to @atorralba for helping on the editing.
I found another related problem which is the CodeQL didn't extract the non built-in method from site-packages such as "nvflare" and "yaml".
I got the log as:
[build-stdout] Excluding the following directories from extraction, since they look like virtual environments: ['C:\Users\Administrator\PycharmProjects\VersionTestProject1\venv']
This indicated all the packages installed in "venv\Lib\site-packages" are not extracted.
It might be the reason I cannot find any non built-in functions and methods via the various value classes like BoundMethodValue, CallableValue, FunctionValue, ModuleValue and PythonFunctionValue.
Not sure how to make the "…