Skip to content

Commit a34b253

Browse files
committed
chore: Update build files and dependencies
1 parent 7bd345f commit a34b253

File tree

14 files changed

+1004
-440
lines changed

14 files changed

+1004
-440
lines changed

FyneApp.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Website = "https://github.com/suifei/asm2hex"
55
Name = "ASM to HEX Converter"
66
ID = "suifei.asm2hex.app"
77
Version = "1.1.0"
8-
Build = 53
8+
Build = 54

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ clean:
5151
rm -rf $(INSTALL_PREFIX)/include/keystone && \
5252
rm -f $(INSTALL_PREFIX)/lib/libcapstone* && \
5353
rm -f $(INSTALL_PREFIX)/lib/libkeystone* && \
54-
echo "Cleaned up temporary files" && \
55-
echo "Removed Capstone and Keystone libraries" && \
56-
echo "Removed build files" && \
54+
go clean -cache && \
5755
echo "Cleaned up successfully"
5856

5957
lib:

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,65 @@
1818

1919
ASM2HEX是一款用Go语言编写的,基于Fyne框架开发的汇编语言与十六进制机器码相互转换的图形化工具。它支持ARM64、ARM和Thumb三种指令集。
2020

21+
## 支持的汇编指令集
22+
23+
下表列出了当前版本支持的汇编指令集以及对应的汇编器(Keystone)和反汇编器(Capstone)的支持情况:
24+
25+
| 指令集 | 架构 | 汇编(Keystone) | 反汇编(Capstone) |
26+
|------------|------------|----------------|-----------------|
27+
| ARM | ARM |||
28+
| ARM64 | ARM64 |||
29+
| MIPS | MIPS |||
30+
| X86 | X86 |||
31+
| PPC | PPC |||
32+
| SPARC | SPARC |||
33+
| SystemZ | SYSTEMZ |||
34+
| Hexagon | HEXAGON |||
35+
| EVM | EVM |||
36+
| XCORE | XCORE |||
37+
| M68K | M68K |||
38+
| TMS320C64X | TMS320C64X |||
39+
| M680X | M680X |||
40+
| MOS65XX | MOS65XX |||
41+
| WASM | WASM |||
42+
| BPF | BPF |||
43+
| RISCV | RISCV |||
44+
| SH | SH |||
45+
| TriCore | TRICORE |||
46+
47+
✓ 表示支持该指令集,✗ 表示不支持该指令集。
48+
49+
50+
## v1.2.0 版本更新说明
51+
52+
### 新增功能
53+
54+
- 增加了对多种指令集,架构汇编、反汇编的支持,现在可以在主界面上选择。
55+
- 支持多种汇编指令集,包括 ARM、ARM64、MIPS、X86、PPC、SPARC、SystemZ、Hexagon 和 EVM。
56+
- 提供了统一的接口,可以方便地进行汇编和反汇编操作。
57+
58+
59+
![](screenshots/v1.2-01.png)
60+
61+
![](screenshots/v1.2-02.png)
62+
63+
64+
### 改进
65+
66+
- 优化了代码结构,提高了代码的可读性和可维护性。
67+
- 改进了错误处理机制,提供更友好的错误提示信息。
68+
- 发布了 github actions 自动化构建流程,保证了代码质量和稳定性。
69+
70+
### 修复
71+
72+
- 修复了一些潜在的 bug 和稳定性问题。
73+
74+
### 其他
75+
76+
- 更新了文档和示例代码,方便用户快速上手使用。
77+
78+
希望这次更新能够为用户带来更好的使用体验,如果您在使用过程中遇到任何问题或有任何建议,欢迎向我们反馈。
79+
2180
[**Full Changelog**](https://github.com/suifei/asm2hex/compare/v1.1...main)
2281

2382
## 功能特点

archs/arch.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package archs
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/suifei/asm2hex/bindings/capstone"
8+
"github.com/suifei/asm2hex/bindings/keystone"
9+
)
10+
11+
func Disassemble(arch capstone.Architecture, mode capstone.Mode, code []byte, offset uint64, bigEndian bool /*syntaxValue capstone.OptionValue, */, addAddress bool) (string, uint64, bool, error) {
12+
defer func() {
13+
if r := recover(); r != nil {
14+
return
15+
}
16+
}()
17+
18+
engine, err := capstone.New(arch, mode)
19+
if err != nil {
20+
return "", 0, false, err
21+
}
22+
defer engine.Close()
23+
24+
// if syntaxValue != 0 {
25+
// engine.Option(capstone.OPT_SYNTAX, capstone.OptionValue(syntaxValue))
26+
// }
27+
28+
if bigEndian {
29+
code, err = capstoneToBigEndian(code, arch, mode)
30+
if err != nil {
31+
return "", 0, false, err
32+
}
33+
}
34+
35+
insns, err := engine.Disasm(code, offset, 0)
36+
if err != nil {
37+
return "", 0, false, err
38+
}
39+
40+
var result string
41+
for _, insn := range insns {
42+
if addAddress {
43+
result += fmt.Sprintf("%08X:\t%-6s\t%-20s\n", insn.Address(), insn.Mnemonic(), insn.OpStr())
44+
} else {
45+
result += fmt.Sprintf("%-6s\t%-20s\n", insn.Mnemonic(), insn.OpStr())
46+
}
47+
}
48+
49+
return result, uint64(len(insns)), true, nil
50+
}
51+
func Assemble(arch keystone.Architecture, mode keystone.Mode, code string, offset uint64, bigEndian bool /*, syntaxValue keystone.OptionValue*/) ([]byte, uint64, bool, error) {
52+
defer func() {
53+
if r := recover(); r != nil {
54+
return
55+
}
56+
}()
57+
58+
code = strings.TrimSpace(code)
59+
if code == "" {
60+
return nil, 0, false, fmt.Errorf("empty code")
61+
}
62+
if strings.HasPrefix(code, ";") {
63+
return nil, 0, false, fmt.Errorf("commented code")
64+
}
65+
if idx := strings.Index(code, ";"); idx > 0 {
66+
code = code[:idx]
67+
}
68+
69+
ks, err := keystone.New(keystone.Architecture(arch), keystone.Mode(mode))
70+
if err != nil {
71+
return nil, 0, false, err
72+
}
73+
defer ks.Close()
74+
75+
// if syntaxValue != 0 {
76+
// ks.Option(keystone.OPT_SYNTAX, keystone.OptionValue(syntaxValue))
77+
// }
78+
79+
encoding, stat_count, ok := ks.Assemble(code, offset)
80+
if err := ks.LastError(); err != nil {
81+
return nil, 0, false, err
82+
}
83+
84+
if ok && bigEndian {
85+
encoding, err = keystoneToBigEndian(encoding, arch, mode)
86+
if err != nil {
87+
return nil, 0, false, err
88+
}
89+
}
90+
91+
return encoding, stat_count, ok, nil
92+
}

archs/arch_test.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package archs
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/require"
8+
"github.com/suifei/asm2hex/bindings/capstone"
9+
"github.com/suifei/asm2hex/bindings/keystone"
10+
)
11+
12+
func TestDisassemble(t *testing.T) {
13+
code := []byte{0x48, 0x83, 0x3d, 0x01, 0x02, 0x03, 0x04, 0x05}
14+
arch := capstone.ARCH_X86
15+
mode := capstone.MODE_64
16+
syntaxValue := capstone.OPT_SYNTAX_INTEL
17+
str, count, ok, err := Disassemble(arch, mode, code, 0x100, false, syntaxValue)
18+
require.NoError(t, err)
19+
require.True(t, ok)
20+
require.Equal(t, 1, int(count))
21+
require.Equal(t, "cmpq\t$0x4030201020304,0x105\t;0x100\n", str)
22+
}
23+
24+
func TestAssemble_x86_64_code_big_endian(t *testing.T) {
25+
code := "mov rax, 1"
26+
encoding, count, ok, err := Assemble(keystone.ARCH_X86, keystone.MODE_64, code, 0x100, true, keystone.OPT_SYNTAX_ATT)
27+
assert.Nil(t, err)
28+
assert.Equal(t, uint64(1), count)
29+
assert.True(t, ok)
30+
assert.Equal(t, []byte{0x48, 0xc7, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00}, encoding)
31+
}
32+
33+
func TestAssemble_x86_64_code_little_endian(t *testing.T) {
34+
code := "mov rax, 1"
35+
encoding, count, ok, err := Assemble(keystone.ARCH_X86, keystone.MODE_64, code, 0x100, false, keystone.OPT_SYNTAX_ATT)
36+
assert.Nil(t, err)
37+
assert.Equal(t, uint64(1), count)
38+
assert.True(t, ok)
39+
assert.Equal(t, []byte{0xc7, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x48}, encoding)
40+
}
41+
42+
func TestAssemble_x86_32_code_big_endian(t *testing.T) {
43+
code := "mov eax, 1"
44+
encoding, count, ok, err := Assemble(keystone.ARCH_X86, keystone.MODE_32, code, 0x100, true, keystone.OPT_SYNTAX_ATT)
45+
assert.Nil(t, err)
46+
assert.Equal(t, uint64(1), count)
47+
assert.True(t, ok)
48+
assert.Equal(t, []byte{0x66, 0x3d, 0x01, 0x00, 0x00, 0x00}, encoding)
49+
}
50+
51+
func TestAssemble_x86_32_code_little_endian(t *testing.T) {
52+
code := "mov eax, 1"
53+
encoding, count, ok, err := Assemble(keystone.ARCH_X86, keystone.MODE_32, code, 0x100, false, keystone.OPT_SYNTAX_ATT)
54+
assert.Nil(t, err)
55+
assert.Equal(t, uint64(1), count)
56+
assert.True(t, ok)
57+
assert.Equal(t, []byte{0x01, 0x3d, 0x66, 0x00, 0x00, 0x00}, encoding)
58+
}
59+
60+
func TestAssemble_ARM_code_big_endian(t *testing.T) {
61+
code := "mov r1, 1"
62+
encoding, count, ok, err := Assemble(keystone.ARCH_ARM, keystone.MODE_ARM, code, 0x100, true, keystone.OPT_SYNTAX_ATT)
63+
assert.Nil(t, err)
64+
assert.Equal(t, uint64(4), count)
65+
assert.True(t, ok)
66+
assert.Equal(t, []byte{0x0, 0x0, 0xa0, 0xe3}, encoding)
67+
}
68+
69+
func TestAssemble_ARM_code_little_endian(t *testing.T) {
70+
code := "mov r1, 1"
71+
encoding, count, ok, err := Assemble(keystone.ARCH_ARM, keystone.MODE_ARM, code, 0x100, false, keystone.OPT_SYNTAX_ATT)
72+
assert.Nil(t, err)
73+
assert.Equal(t, uint64(4), count)
74+
assert.True(t, ok)
75+
assert.Equal(t, []byte{0xe3, 0xa0, 0x0, 0x0}, encoding)
76+
}
77+
78+
func TestAssemble_ARM64_code_big_endian(t *testing.T) {
79+
code := "mov w1, 1"
80+
encoding, count, ok, err := Assemble(keystone.ARCH_ARM64, keystone.MODE_ARM, code, 0x100, true, keystone.OPT_SYNTAX_ATT)
81+
assert.Nil(t, err)
82+
assert.Equal(t, uint64(4), count)
83+
assert.True(t, ok)
84+
assert.Equal(t, []byte{0x0, 0x0, 0x20, 0x1f}, encoding)
85+
}
86+
87+
func TestAssemble_ARM64_code_little_endian(t *testing.T) {
88+
code := "mov w1, 1"
89+
encoding, count, ok, err := Assemble(keystone.ARCH_ARM64, keystone.MODE_ARM, code, 0x100, false, keystone.OPT_SYNTAX_ATT)
90+
assert.Nil(t, err)
91+
assert.Equal(t, uint64(4), count)
92+
assert.True(t, ok)
93+
assert.Equal(t, []byte{0x1f, 0x20, 0x0, 0x0}, encoding)
94+
}

archs/arm32.go

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)