Binject / universal

Universal Shared Library User-space Loader
GNU General Public License v3.0
219 stars 26 forks source link

load with multiple args failed #7

Open timwhitez opened 2 years ago

timwhitez commented 2 years ago

i want to load https://github.com/trustedsec/ELFLoader this program

package main

import (
    "github.com/Binject/universal"
    "io/ioutil"
    "log"
    "syscall"
    "unsafe"
)

func main() {
    image, err := ioutil.ReadFile("libELFLoader.so")

    loader, err := universal.NewLoader()
    if err != nil {
        log.Fatal(err)
    }

    library, err := loader.LoadLibrary("main", &image)
    if err != nil {
        log.Fatal(err)
    }

    g, _ := syscall.BytePtrFromString("go")

    f, _ := ioutil.ReadFile("whoami.o")

    inDataBuff := uintptr(unsafe.Pointer(&f[0]))
    inDataSize := uintptr(uint64(len(f)))

    val, err := library.Call("ELFRunner", uintptr(unsafe.Pointer(g)), inDataBuff, inDataSize, 0, 0)
    if err != nil {
        //log.Fatal(err)
    }
    log.Printf("%+v\n", val)
}

but didn't work

pinklettuce commented 1 year ago

You would have to modify it, taking a look at the source code I noticed that it uses: https://github.com/awgh/cppgo/blob/master/asmcall/cdecl/cdecl.go you can directly call it