This commit is contained in:
Print3M
2025-08-17 21:48:46 +02:00
parent 9ac684aab2
commit 84ebecbaa8
5 changed files with 27 additions and 10 deletions
BIN
View File
Binary file not shown.
+7 -2
View File
@@ -4,9 +4,13 @@ import (
"dllshimmer/cli"
"dllshimmer/dll"
"dllshimmer/output"
"embed"
"path/filepath"
)
//go:embed templates/*
var templatesFS embed.FS
func main() {
flags := cli.ParseCli()
@@ -17,8 +21,9 @@ func main() {
// params.Mutex = flags.Mutex
out := output.Output{
Dll: dll.ParseDll(flags.Input),
OutputDir: filepath.Clean(flags.Output),
Dll: dll.ParseDll(flags.Input),
OutputDir: filepath.Clean(flags.Output),
TemplatesFS: &templatesFS,
}
out.CreateCodeFile(flags.Mutex, flags.Static)
+20 -8
View File
@@ -3,6 +3,7 @@ package output
import (
"dllshimmer/def"
"dllshimmer/dll"
embed "embed"
"fmt"
"log"
"os"
@@ -12,8 +13,9 @@ import (
)
type Output struct {
Dll *dll.Dll
OutputDir string
Dll *dll.Dll
OutputDir string
TemplatesFS *embed.FS
}
func (o *Output) GetDefFileName() string {
@@ -43,13 +45,23 @@ type CodeFileParams struct {
DllName string
}
func (o *Output) CreateCodeFile(mutex bool, isStaticLinked bool) {
templateFile := "templates/dynamic-shim.c.template"
if isStaticLinked {
templateFile = "templates/static-shim.c.template"
func (o *Output) GetTemplate(filename string) *template.Template {
path := filepath.Join("templates/", filename)
content, err := o.TemplatesFS.ReadFile(path)
if err != nil {
log.Fatalf("[!] Error while reading embedded template file '%s': %v", path, content)
}
tmpl := template.Must(template.ParseFiles(templateFile))
return template.Must(template.New("new").Parse(string(content)))
}
func (o *Output) CreateCodeFile(mutex bool, isStaticLinked bool) {
templateFile := "dynamic-shim.cpp.template"
if isStaticLinked {
templateFile = "static-shim.cpp.template"
}
tmpl := o.GetTemplate(templateFile)
outputPath := filepath.Join(o.OutputDir, o.GetCodeFileName())
f, err := os.Create(outputPath)
@@ -143,7 +155,7 @@ type CompileScriptParams struct {
}
func (o *Output) CreateCompileScript(isStaticLinked bool) {
tmpl := template.Must(template.ParseFiles("templates/compile.sh.template"))
tmpl := o.GetTemplate("compile.sh.template")
outputPath := filepath.Join(o.OutputDir, o.GetCompileScriptName())
f, err := os.Create(outputPath)