golang 调用第三方dll(逆向)?

dll来源: https://www.irfanview.com/plugins.htm#UpdatedPlugins
我想调用WebP.dll来解析webp的图片提供给web页面展示,webp只是测试,目标格式为psd、jxl等浏览器不支持的格式

IDA:

Name    Address    Ordinal
GetPlugInInfo    00000001800012E0    1
ReadAnimatedWebP_W    0000000180001380    2
ReadWebP_W    0000000180001840    3
SaveWebP_W    0000000180002000    4
ScanWEBP_W    00000001800023E0    5
ShowPlugInSaveOptions_W    0000000180002580    6
DllEntryPoint    0000000180066DFC    [main entry]

比如这个

ScanWEBP_W

; Exported entry   5. ScanWEBP_W



; __int64 __fastcall ScanWEBP_W(wchar_t *FileName)
public ScanWEBP_W
ScanWEBP_W proc near

var_128= qword ptr -128h
var_120= qword ptr -120h
var_118= byte ptr -118h
var_10C= dword ptr -10Ch
var_50= dword ptr -50h
var_28= qword ptr -28h
var_18= qword ptr -18h
arg_8= qword ptr  10h
arg_10= qword ptr  18h

; __unwind { // __GSHandlerCheck
push    rbx
push    rbp
sub     rsp, 138h
mov     rax, cs:__security_cookie
xor     rax, rsp
mov     [rsp+148h+var_28], rax
mov     rbx, rcx
lea     rcx, [rsp+148h+var_118]
mov     edx, 209h
xor     ebp, ebp
call    sub_180003AD0
test    eax, eax
jz      loc_180002562

ReadWebP_W

; Exported entry   3. ReadWebP_W


; Attributes: bp-based frame fpd=0F0h

; __int64 __usercall ReadWebP_W@<rax>(wchar_t *FileName@<rcx>, __int64)
public ReadWebP_W
ReadWebP_W proc near

var_1D0= dword ptr -1D0h
var_1C0= byte ptr -1C0h
var_1BF= byte ptr -1BFh
var_1BE= byte ptr -1BEh
Block= qword ptr -1B8h
var_1B0= qword ptr -1B0h
var_1A8= qword ptr -1A8h
hMem= qword ptr -1A0h
var_198= qword ptr -198h
var_190= qword ptr -190h
var_180= byte ptr -180h
var_170= dword ptr -170h
var_16C= dword ptr -16Ch
var_158= qword ptr -158h
var_150= qword ptr -150h
var_148= dword ptr -148h
var_130= dword ptr -130h
var_12C= dword ptr -12Ch
var_128= dword ptr -128h
var_124= dword ptr -124h
var_120= dword ptr -120h
var_108= dword ptr -108h
var_104= dword ptr -104h
var_100= dword ptr -100h
Src= qword ptr -0F8h
var_F0= dword ptr -0F0h
var_74= dword ptr -74h
var_70= dword ptr -70h
var_6C= dword ptr -6Ch
var_68= dword ptr -68h
var_40= qword ptr -40h
var_30= qword ptr -30h
arg_8= qword ptr  18h
arg_20= qword ptr  30h

; __unwind { // __GSHandlerCheck
push    rbp
push    rbx
push    rsi
push    rdi
push    r13
push    r15
lea     rbp, [rsp-0C8h]
sub     rsp, 1C8h
mov     rax, cs:__security_cookie
xor     rax, rsp
mov     [rbp+0F0h+var_40], rax
mov     rsi, [rbp+0F0h+arg_20]
mov     rdi, r8
xor     r8d, r8d
mov     r15, rcx
lea     rcx, aUnknownWebpFil ; "Unknown WebP file"
mov     rdx, rdi
mov     r13, r9
mov     [rsp+1F0h+var_1A8], r8
sub     rdx, rcx
xchg    ax, ax

但我尝试调用程序就崩溃了(我没有相关知识,代码来源网络)

handle, _ := syscall.LoadLibrary("d:/WebP.dll")
defer syscall.FreeLibrary(handle)

p, _ := syscall.GetProcAddress(handle, "ScanWEBP_W")

wcFileName, _ := syscall.UTF16PtrFromString("d:/0.webp")

ret, _, err := syscall.SyscallN(p, uintptr(unsafe.Pointer(wcFileName)))

// // 检查错误
// if err != nil {
//     panic(err)
// }
// r1, r2, errorNo := syscall.SyscallN(p)
fmt.Println(int64(ret), err)

请问我该怎么调用呢?
谢谢

阅读 2k
1 个回答

WebP.dll不确定这个dll是否正确。

如果你要用go解析webp或者psd等格式的图片转为png,可以使用go的库完成。

webp转为png

package main

import (
    "fmt"
    "github.com/chai2010/webp"
    "image"
    "image/png"
    "os"
)

func webpToPng(webpPath string, pngPath string) {
    // 打开 webp 文件
    file, err := os.Open(webpPath)
    if err!= nil {
        fmt.Println("Error opening webp file:", err)
        return
    }
    defer file.Close()

    // 解码 webp 图像
    img, err := webp.Decode(file)
    if err!= nil {
        fmt.Println("Error decoding webp image:", err)
        return
    }

    // 创建 png 文件
    outFile, err := os.Create(pngPath)
    if err!= nil {
        fmt.Println("Error creating png file:", err)
        return
    }
    defer outFile.Close()

    // 编码为 png 格式
    err = png.Encode(outFile, img)
    if err!= nil {
        fmt.Println("Error encoding to png:", err)
        return
    }
}

func main() {
    webpFile := "your_webp_file.webp"
    pngFile := "converted.png"
    webpToPng(webpFile, pngFile)
}

psd转为png

package main

import (
    "fmt"
    "github.com/akavel/rsrc"
    "image"
    "image/png"
    "os"
)

func parsePSDToPNG(psdPath string, pngPath string) {
    // 打开 PSD 文件
    file, err := os.Open(psdPath)
    if err!= nil {
        fmt.Println("Error opening PSD file:", err)
        return
    }
    defer file.Close()

    img, _, err := image.Decode(file)
    if err!= nil {
        fmt.Println("Error decoding PSD image:", err)
        return
    }

    // 创建 PNG 文件
    outFile, err := os.Create(pngPath)
    if err!= nil {
        fmt.Println("Error creating PNG file:", err)
        return
    }
    defer outFile.Close()

    // 编码为 PNG 格式
    err = png.Encode(outFile, img)
    if err!= nil {
        fmt.Println("Error encoding to PNG:", err)
        return
    }
}

func main() {
    psdFile := "your_psd_file.psd"
    pngFile := "converted.png"
    parsePSDToPNG(psdFile, pngFile)
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏