Outils pour utilisateurs

Outils du site


blog

Go lang - compiler pour windows i386 32bits

Voir aussi :

sudo apt-get install gcc-multilib-i686-linux-gnu
 
export GOROOT=$HOME/opt/go-legacy-win7/
export PATH=$HOME/opt/go-legacy-win7/bin/:"$PATH"
 
env GOOS=windows GOARCH=386 CGO_ENABLED=1 CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ CGO_LDFLAGS="-lssp" go build -ldflags="-s -w" -o app1.exe main.go

Ou encore avec zig

env CGO_ENABLED=1 GOROOT=~/opt/go-legacy-win7/ GOOS=windows GOARCH=386 CC="zig cc -target i686-linux-musl" ~/opt/go-legacy-win7/bin/go build hello.go

FIXME: i686-linux-musl n'est pas cohérent avec GOOS

Test

mkdir -p ~/myapp/prefix
export WINEPREFIX=$HOME/myapp/prefix 
export WINEARCH=win32 
export WINEPATH=$HOME/myapp 
wineboot --init
 
env WINEARCH=win32 wine app1.exe
$ exiftool app1.exe 
ExifTool Version Number         : 13.50
File Name                       : app1.exe
Directory                       : .
File Size                       : 1266 kB
File Modification Date/Time     : 2026:04:23 19:18:49+02:00
File Access Date/Time           : 2026:04:23 19:19:08+02:00
File Inode Change Date/Time     : 2026:04:23 19:18:49+02:00
File Permissions                : -rwxrwxr-x
File Type                       : Win32 EXE
File Type Extension             : exe
MIME Type                       : application/octet-stream
Machine Type                    : Intel 386 or later, and compatibles
Time Stamp                      : 0000:00:00 00:00:00
Image File Characteristics      : Executable, No line numbers, No symbols, 32-bit, No debug
PE Type                         : PE32
Linker Version                  : 2.45
Code Size                       : 571904
Initialized Data Size           : 693248
Uninitialized Data Size         : 154624
Entry Point                     : 0x1460
OS Version                      : 6.1
Image Version                   : 1.0
Subsystem Version               : 6.1
Subsystem                       : Windows command line

FIXME

2026/04/23 19:32 · Jean-Baptiste

Réseau - Forger un paquet TCP UDP ou autre

Voir les outils :

To exclude packets 1, 5, 10 to 20 and 30 to 40 from the new file use:

editcap capture.pcapng exclude.pcapng 1 5 10-20 30-40

To select just packets 1, 5, 10 to 20 and 30 to 40 for the new file use:

editcap -r capture.pcapng select.pcapng 1 5 10-20 30-40

Source : https://www.wireshark.org/docs/man-pages/editcap.html

Les modifications d'adresses de tcprewrite se font par plage. Pour changer l'adresse de destination

tcprewrite  --dstipmap=10.170.24.203/0:10.0.1.113/0 -C -i filter.cap -o filter-2.cap

le -C est là pour recalculer les checksums UDP ou TCP

2026/04/22 10:20 · Jean-Baptiste

Wine Err bcryptprimitives.dll not found - Compilation Croisée Go lang

Étapes à reproduire

Source : https://d3ext.github.io/posts/malware-dev-0/

main.go

package main
 
import (
        "fmt"
        "unsafe"
 
        "golang.org/x/sys/windows"
)
 
func main() {
        user32 := windows.NewLazyDLL("user32.dll")
        MessageBox := user32.NewProc("MessageBoxW")
 
        r, _, _ := MessageBox.Call(
                0,
                uintptr(unsafe.Pointer(windows.StringToUTF16Ptr("Hello World!"))),
                uintptr(unsafe.Pointer(windows.StringToUTF16Ptr("Example"))),
                windows.MB_OK,
        )
 
        fmt.Println("Return code:", r)
}
env GOARCH=amd64 GOOS=windows go build main.go

Erreur

$ wine main.exe 
it looks like wine32 is missing, you should install it.
multiarch needs to be enabled first.  as root, please
execute "dpkg --add-architecture i386 && apt-get update &&
apt-get install wine32:i386"
wine: created the configuration directory '/home/jibe/.wine'
0050:err:ole:StdMarshalImpl_MarshalInterface Failed to create ifstub, hr 0x80004002
0050:err:ole:CoMarshalInterface Failed to marshal the interface {6d5140c1-7436-11ce-8034-00aa006009fa}, hr 0x80004002
0050:err:ole:apartment_get_local_server_stream Failed: 0x80004002
0050:err:ole:start_rpcss Failed to open RpcSs service
0048:err:ole:StdMarshalImpl_MarshalInterface Failed to create ifstub, hr 0x80004002
0048:err:ole:CoMarshalInterface Failed to marshal the interface {6d5140c1-7436-11ce-8034-00aa006009fa}, hr 0x80004002
0048:err:ole:apartment_get_local_server_stream Failed: 0x80004002
wine: failed to open L"C:\\windows\\syswow64\\rundll32.exe": c0000135
wine: configuration in L"/home/jibe/.wine" has been updated.
fatal error: bcryptprimitives.dll not found
runtime: panic before malloc heap initialized

runtime stack:
runtime.throw({0x1400e5c03?, 0x21fd58?})
        /usr/lib/go-1.26/src/runtime/panic.go:1229 +0x4d fp=0x21fca8 sp=0x21fc78 pc=0x140076fad
runtime.loadOptionalSyscalls()
        /usr/lib/go-1.26/src/runtime/os_windows.go:267 +0x349 fp=0x21fd90 sp=0x21fca8 pc=0x140041229
runtime.osinit()
        /usr/lib/go-1.26/src/runtime/os_windows.go:464 +0x3d fp=0x21fe10 sp=0x21fd90 pc=0x14004193d
runtime.rt0_go()
        /usr/lib/go-1.26/src/runtime/asm_amd64.s:372 +0x13e fp=0x21fe18 sp=0x21fe10 pc=0x14007b2be
$ env WINEARCH=win64 wine main.exe 
wine: could not load kernel32.dll, status c0000135

$ mkdir -p ~/myapp/prefix
$ env LANG=C WINEPREFIX=$HOME/myapp/prefix WINEARCH=win32 wine main.exe 
Application could not be started, or no application associated with the specified file.
ShellExecuteEx failed: Bad EXE format for Z:\home\jibe\go\winapi\main.exe.

Solution 1

Voir :

Utiliser une ancienne version de Go ou une recompilée pour être compatible avec windows 7 Comme : https://github.com/thongtech/go-legacy-win7

export GOROOT=~/opt/go-legacy-win7/
alias go='~/opt/go-legacy-win7/bin/go'
 
go env |grep '/'
rm -rf ~/.cache/go-build
go clean -cache -modcache -fuzzcache
 
env GOARCH=amd64 GOOS=windows GOROOT=~/opt/go-legacy-win7/ ~/opt/go-legacy-win7/bin/go build main.go

Solution 2

Patcher le exe avec GoWin7Fixer.exe. Voir : https://github.com/stunndard/golangwin7patch

Solution 3

Mettre à jour Wine

Ou télécharger bcryptprimitives.dll et la déposer dans ~/.wine/drive_c/windows/system32/

Voir : https://packages.debian.org/trixie/amd64/libwine/filelist

2026/04/21 23:16 · Jean-Baptiste

Makefile et variables d'environnement

Makefile

include env
 
exe:
        go build -o app1.exe main.go
 
dll:
        go build -buildmode=c-shared -o app1.dll main.go
 
clean:
        rm -f app1.exe app1.dll app1.h call.exe
 
all:    exe dll
 
test:   exe dll
        go build call.go
        wine call.exe

env

cat env 
export GOOS=windows
export GOARCH=amd64
export CGO_ENABLED=1
export CXX=x86_64-w64-mingw32-g++
export CC=x86_64-w64-mingw32-gcc
export GOROOT=$(shell printenv HOME)/opt/go-legacy-win7/
export PATH=$(shell printenv HOME)/opt/go-legacy-win7/bin/:$(shell printenv PATH)
2026/04/21 22:06 · Jean-Baptiste

Err Go lang et langage C

Err: could not determine what C.factorial refers to

# command-line-arguments
./maint.go:25:43: could not determine what C.factorial refers to
Solution

Remplacer

package main
 
// #include <stdio.h>
// #include <stdlib.h>
//
// uint factorial(uint N) {
//     int fact = 1, i;
//
//     // Loop from 1 to N to get the factorial
//     for (i = 1; i <= N; i++) {
//         fact *= i;
//     }
//
//     return fact;
// }
 
import "C"

Par

package main
 
// #include <stdio.h>
// #include <stdlib.h>
//
// uint factorial(uint N) {
//     int fact = 1, i;
//
//     // Loop from 1 to N to get the factorial
//     for (i = 1; i <= N; i++) {
//         fact *= i;
//     }
//
//     return fact;
// }
import "C"

Il ne faut pas d'espace entre le bloque du code C et import "C"

Err: cannot use i (variable of type int) as _Ctype_uint value in argument to (_Cfunc_factorial)

Solution

Il faut caster. Ici dans notre exemple avec C.uint()

package main
 
// #include <stdio.h>
// #include <stdlib.h>
//
// uint factorial(uint N) {
//     int fact = 1, i;
//
//     // Loop from 1 to N to get the factorial
//     for (i = 1; i <= N; i++) {
//         fact *= i;
//     }
//
//     return fact;
// }
import "C"
import "fmt"
 
func main() {
	for i := range 10 {
		//fmt.Printf("i: %.3d;, fact: %.6d\n", i, C.factorial(i))
		fmt.Printf("i: %.3d;, fact: %.6d\n", i, C.factorial(C.uint(i)))
		i++
	}
}

Err: go: no Go source files

Compilation croisée avec du code Go contenant du C

$ env GOOS=windows go build main.go 
go: no Go source files
Solution
$ env CGO_ENABLED=1 GOOS=windows go build main.go 
# runtime/cgo
gcc: error: unrecognized command-line option ‘-mthreads’; did you mean ‘-pthread’?
# runtime/cgo
gcc: error: unrecognized command-line option ‘-mthreads’; did you mean ‘-pthread’?

Installer les deps pour compiler

sudo apt-get install gcc-multilib gcc-mingw-w64

Lancer la compilation

$ env GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc go build main.go                                                                    
# command-line-arguments                                                                                                                                                                                          
./main.go:22:43: could not determine what C.factorial refers to                                                                                                                                                   
cgo:                                                                                                                                                                                                              
x86_64-w64-mingw32-gcc errors for preamble:                                                                                                                                                                       
./main.go:6:2: error: unknown type name 'uint'; did you mean 'int'?                                                                                                                                               
    6 | // uint factorial(uint N) {                                                                                                                                                                               
      |  ^~~~                                                                                                                                                                                                     
      |  int                                                                                                                                                                                                      
./main.go:6:17: error: unknown type name 'uint'; did you mean 'int'?
    6 | // uint factorial(uint N) {
      |                 ^~~~
      |                 int

Remplacer les unsigned int (uint) par des int

sed -i.bak -e 's/uint/int/g' main.go
env GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc go build main.go

C'est tout de même problématique

2026/04/21 21:07 · Jean-Baptiste
blog.txt · Dernière modification : de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki