Skip to main content

SkyStaticAnalysis

A pure-python (Python>=3.10) static analysis library providing various interfaces.

Documentation Website

Interfaces

Clang

Clang interface included some useful functionalities. For example:

The Demo C file "hello.c":

typedef struct
{
    int abc;
} StructA;

int a = 32;
int b = 444;
int c = 123;
int *p = 0;
StructA st = {0};
StructA *pst = {0};
extern int extvar = 0;

int f(int);

int use_global(int y, float z)
{
    int x;
    int c = *p + y;
    a = 1045;
    f(b);
}

int use_global_2(int y, float z)
{
    int x[1900];
    int q = a;
    x[q];
    x[a];
    if (y > 100)
    {
        f(x[y]);
    }
    else
    {
        f(x[(int)z]);
    }
}

int main()
{
    StructA not_global = {0};
    return 0;
}

This Python script could parse variable definitions、function parameter declarations and variable references:

c_file = os.path.join("")
root = parse_file(c_file).cursor

# extract local variables
assert {"c", "x"} == get_local_var_defs(func_decl).attributes("spelling").to_set()

# extract referenced variables
assert {"p", "y", "a", "b"} == get_var_refs(func_decl).attributes(
    "spelling"
).to_set()

# extract referenced variables with functions
assert {"p", "y", "a", "b", "f"} == get_var_refs(
    func_decl, include_funcs=True
).attributes("spelling").to_set()

# extract parameter variables
assert {"y", "z"} == get_param_decls(func_decl).attributes("spelling").to_set()

# extract all global values
assert {"a", "p", "b"} == get_global_ref_names(func_decl).to_set()

In-Repo Third Party Dependencies

JsonObject

As original project used Cython, it might not be compatible with platform without compilation toolchains. So I copied the source code into this project and made it runnable under pure-python.

PyC-CFG

Pyc-cfg is a pure python control flow graph builder for almost all Ansi C programming language.

As the original version only suitable for Python2, I copied its code and made it compatible for python 3.

Metadata

Release files for SkyStaticAnalysis 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for SkyStaticAnalysis 0.0.4
File Interpreter ABI Platform
SkyStaticAnalysis-0.0.4-py3-none-any.whl Python 3 none any Details

Release files / SkyStaticAnalysis-0.0.4-py3-none-any.whl

Download URL SkyStaticAnalysis-0.0.4-py3-none-any.whl
Size 52.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
91e6cc1016f855c882db896596b9a4afd152c3237d4ba8f9ca0d610f7b6f89d9
BLAKE2b-256 checksum
How to use checksums
2850f37cdef494e215acb5112002630b51efb3496f883fa7945d74516cab6800
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release history Release notifications | RSS feed

This release

0.0.4 This release

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page