Skip to content

Module Document

runoneall edited this page Jun 25, 2025 · 7 revisions

CrossLangImporter

Add cross language import support for Framer.
This is a Hooker Type module, it need configuration, it will automatically loaded at startup.

Install

python -m Framer module --install CrossLangImporter@CrossLanguage

Usage

Add Handler

CrossLangImporter(GoBridge)

it will add go file import support for Framer. See: GoBridge

Simple Handler

class moduleMain:
    def __init__(self, framer, logger):
        self.framer = framer
        self.logger = logger

        self.extension = "go"  # add go extension support
        self.not_found_message = (
            "Go compiler not found. Install Go from https://golang.org/"
        )  # if go compiler not found, show this message

    def build_command(self, file_path, so_path):
        # build go to so file command
        # file_path will be "path/to/file.go"
        # so_path will be "path/to/file.so"
        return [
            ["go", "mod", "tidy"],  # first, update go mod
            ["go", "build", "-buildmode=c-shared", "-o", so_path, file_path],  # then, build
            ...  # add more command if needed
        ]

Load Library File

mymodule = CrossLangImporter.Require("path/to/file.so")  # load so file
mymodule = CrossLangImporter.Require("path/to/file.dll")  # load dll file
# and more can load by ctypes.cdll.LoadLibrary()

# call function in library file
mymodule.function()

GoBridge

Add go file import support for Framer.
This is a Hooker Type module, it doesn't need configuration, it will automatically loaded at startup.

Install

python -m Framer module --install GoBridge@CrossLanguage

Usage

Simple Go File

package main

import "C" //必须引入C库

import "fmt"

//加入下面注释代码,表示导出,可以被python调用

//export PrintDll
func PrintDll() {
    fmt.Println("我来自dll")
}

//
//export Sum
func Sum(a int, b int) int {
    return a + b
}

func main() {
    //必须加一个main函数,作为CGO编译的入口,无具体实现代码
}

save it as mymodule.go

Import Go File

CrossLangImporter(GoBridge)

import mymodule

# 调用go语言的Sum
result = mymodule.Sum(100, 200)
print(result)

# 调用go语言的PrintDll
mymodule.PrintDll()

Also see: https://www.cnblogs.com/liuqingzheng/p/16207656.html

Clone this wiki locally