Skip to content

Commit 1b6847e

Browse files
committed
♌ feat: add DLL.ico
1 parent bd12f3b commit 1b6847e

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

assets.go

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/DLL.ico

58.5 KB
Binary file not shown.

cmd/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func main() {
2929
// path := `app.icns`
3030
// path := `FileZilla.icns`
3131
// path := `F:\安装包\android-studio-ide-401-201.6858069-mac.dmg`
32-
err = f2ico.F2ICO(w, path, f2ico.Config{Index: 11})
32+
err = f2ico.F2ICO(w, path, f2ico.Config{Index: 62})
3333
// err = f2ico.F2ICO(w, path, f2ico.Config{Format: "png"})
3434
// err = f2ico.F2ICO(w, path, f2ico.Config{Format: "png", Width: 48, Height: 48})
3535
// err = f2ico.F2ICO(w, path)

f2ico.go

+20-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"debug/pe"
77
"encoding/binary"
88
"errors"
9-
"fmt"
109
"image"
1110
"image/color"
1211
"image/png"
@@ -552,21 +551,25 @@ type ICONDIRENTRY struct {
552551
}
553552

554553
func defaultICO(w io.Writer, peFile *pe.File) error {
555-
// 如果没有资源段
556-
var subsystem uint16
557-
switch peFile.OptionalHeader.(type) {
558-
case *pe.OptionalHeader32:
559-
subsystem = peFile.OptionalHeader.(*pe.OptionalHeader32).Subsystem
560-
case *pe.OptionalHeader64:
561-
subsystem = peFile.OptionalHeader.(*pe.OptionalHeader64).Subsystem
562-
}
563-
564554
n := ""
565-
switch subsystem {
566-
case pe.IMAGE_SUBSYSTEM_WINDOWS_CUI, pe.IMAGE_SUBSYSTEM_OS2_CUI, pe.IMAGE_SUBSYSTEM_POSIX_CUI:
567-
n = "assets/CUI.ico"
568-
default: // pe.IMAGE_SUBSYSTEM_WINDOWS_GUI, pe.IMAGE_SUBSYSTEM_WINDOWS_CE_GUI
569-
n = "assets/GUI.ico"
555+
if peFile.FileHeader.Characteristics&pe.IMAGE_FILE_DLL > 0 {
556+
n = "assets/DLL.ico"
557+
} else {
558+
// 如果没有资源段
559+
var subsystem uint16
560+
switch peFile.OptionalHeader.(type) {
561+
case *pe.OptionalHeader32:
562+
subsystem = peFile.OptionalHeader.(*pe.OptionalHeader32).Subsystem
563+
case *pe.OptionalHeader64:
564+
subsystem = peFile.OptionalHeader.(*pe.OptionalHeader64).Subsystem
565+
}
566+
567+
switch subsystem {
568+
case pe.IMAGE_SUBSYSTEM_WINDOWS_CUI, pe.IMAGE_SUBSYSTEM_OS2_CUI, pe.IMAGE_SUBSYSTEM_POSIX_CUI:
569+
n = "assets/CUI.ico"
570+
default: // pe.IMAGE_SUBSYSTEM_WINDOWS_GUI, pe.IMAGE_SUBSYSTEM_WINDOWS_CE_GUI
571+
n = "assets/GUI.ico"
572+
}
570573
}
571574

572575
d, _ := Asset(n)
@@ -610,7 +613,7 @@ func PE2ICO(w io.Writer, path string, cfg ...Config) error {
610613
}
611614
}
612615

613-
// 如果没有图标,有资源段说明是GUI
616+
// 如果没有图标
614617
if len(grpIcons) <= 0 {
615618
return defaultICO(w, peFile)
616619
}
@@ -629,7 +632,7 @@ func PE2ICO(w io.Writer, path string, cfg ...Config) error {
629632
}
630633
}
631634

632-
// 如果没有图标,有资源段说明是GUI
635+
// 如果没有图标
633636
if gid.Count <= 0 {
634637
return defaultICO(w, peFile)
635638
}
@@ -644,7 +647,6 @@ func PE2ICO(w io.Writer, path string, cfg ...Config) error {
644647

645648
offset += len(r.Data)
646649
data = append(data, r.Data)
647-
fmt.Printf("%#x\n", r.Data)
648650
}
649651
}
650652

0 commit comments

Comments
 (0)