Skip to main content

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

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

SkyStaticAnalysis-0.0.4-py3-none-any.whl (52.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page