Skip to content

Commit

Permalink
chore: Add ASM2HEX tool with Go and Fyne framework
Browse files Browse the repository at this point in the history
  • Loading branch information
suifei committed May 20, 2024
1 parent 06625a0 commit ab4c2c6
Show file tree
Hide file tree
Showing 19 changed files with 1,861 additions and 2 deletions.
85 changes: 85 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,go
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,macos,go

### Go ###
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

asm2hex

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,go

# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)

16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"cwd": "${workspaceFolder}",
}
]
}
8 changes: 8 additions & 0 deletions FyneApp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Website = "https://github.com/suifei/asm2hex"

[Details]
Icon = "./theme/icons/asm2hex.png"
Name = "ASM to HEX Converter"
ID = "suifei.asm2hex.app"
Version = "1.0.0"
Build = 3
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# --target value, --os value
#The operating system to target (android, android/arm, android/arm64, android/amd64, android/386, darwin, freebsd, ios, linux, netbsd, openbsd, windows)
release:
fyne release -os macOS -appID suifei.asm2hex.app -appVersion 1.0 -appBuild 1 -category tools
fyne release -os iOS -appID suifei.asm2hex.app -appVersion 1.0 -appBuild 1
177 changes: 175 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,175 @@
# asm2hex
ASM2HEX 是一款功能强大的汇编语言与十六进制机器码相互转换工具。它提供了一个直观的图形界面,让用户可以轻松地在汇编指令和对应的机器码之间进行转换。无论你是处理 ARM64、ARM 还是 Thumb 指令集,ASM2HEX 都能提供准确可靠的转换结果。ASM2HEX is a powerful tool for bidirectional conversion between assembly language and hexadecimal machine code.
# ASM2HEX

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

## 功能特点

- 支持ARM64、ARM和Thumb指令集的汇编语言与十六进制机器码的双向转换
- 可自定义偏移地址,支持大端和小端两种字节序
- 使用Keystone作为汇编引擎,Capstone作为反汇编引擎,转换准确可靠
- 基于Fyne框架开发的现代化图形界面,操作简单直观
- 跨平台支持,可在Windows、macOS和Linux等多种操作系统上运行

## 安装方法

1. 安装Go语言开发环境。

2. 获取ASM2HEX的源代码:

```
git clone https://github.com/suifei/asm2hex.git
```

3. 进入项目目录,下载依赖包:

```
cd asm2hex
go get ./...
```

4. 编译生成可执行文件:

```
go build
```

现在可以直接运行生成的可执行文件,享受ASM2HEX带来的便利!

## 使用说明

![](screenshots/01.png)

![](screenshots/02.png)

![](screenshots/03.png)

1. 在左侧的输入框中输入汇编指令或十六进制机器码。多条指令/数据可以分行输入。

2. 在偏移量输入框中可以指定初始地址的偏移量。偏移量需要以十六进制格式输入。

3. 点击"0x"选框,可以控制十六进制机器码是否包含"0x"前缀。

4. 点击"GDB/LLDB"选框可以控制字节序,勾选表示使用大端字节序,未勾选则使用小端字节序。

5. 点击"转换"按钮,ASM2HEX会自动完成转换,并将结果实时显示在右侧的ARM64、ARM和Thumb三个选项卡中。

6. 可以通过"清除"按钮清空输入输出,方便进行下一次转换。

7. "切换模式"按钮可以切换工具当前的工作模式。默认模式是汇编转十六进制,切换后即成为十六进制转汇编模式。

8. 单击每个选项卡右上角的复制图标,即可将该选项卡的内容复制到剪贴板,方便使用。

## 致谢

ASM2HEX的开发得益于以下开源项目:

- Fyne: 基于Go的跨平台图形界面框架

- Keystone: 轻量级的多架构汇编引擎

- Capstone: 多架构支持的反汇编引擎

感谢这些优秀项目的贡献者和维护者!

## 许可证

ASM2HEX采用MIT许可证进行发布,详情参见LICENSE文件。

## 联系方式

如果您在使用过程中遇到任何问题,或者有任何建议和反馈,欢迎通过以下方式联系我:

- 邮箱: c3VpZmUgQGdtYWlsIGRvdGNvbQ==
- QQ群: 555354813
- GitHub: https://github.com/suifei/asm2hex

希望ASM2HEX能够成为您的汇编开发和学习的得力助手!

---

## 英文版 README.md

# ASM2HEX

ASM2HEX is a graphical tool for bidirectional conversion between assembly language and hexadecimal machine code, written in Go and based on the Fyne framework. It supports three instruction sets: ARM64, ARM, and Thumb.

## Features

- Supports bidirectional conversion between assembly language and hexadecimal machine code for ARM64, ARM, and Thumb instruction sets
- Customizable offset address, supporting both big-endian and little-endian byte orders
- Uses Keystone as the assembly engine and Capstone as the disassembly engine for accurate and reliable conversion
- Modern graphical interface developed based on the Fyne framework, simple and intuitive to operate
- Cross-platform support, can run on various operating systems such as Windows, macOS, and Linux

## Installation

1. Install the Go language development environment.

2. Get the source code of ASM2HEX:

```
git clone https://github.com/suifei/asm2hex.git
```

3. Enter the project directory and download the dependency packages:

```
cd asm2hex
go get ./...
```

4. Compile to generate the executable file:

```
go build
```

Now you can directly run the generated executable file and enjoy the convenience brought by ASM2HEX!

## Usage

![](screenshots/01.png)

![](screenshots/02.png)

![](screenshots/03.png)

1. Enter assembly instructions or hexadecimal machine code in the input box on the left. Multiple instructions/data can be entered in separate lines.

2. You can specify the offset of the initial address in the offset input box. The offset needs to be entered in hexadecimal format.

3. Click the "0x" checkbox to control whether the hexadecimal machine code includes the "0x" prefix.

4. Click the "GDB/LLDB" checkbox to control the byte order. Checking it indicates using big-endian byte order, while unchecking it uses little-endian byte order.

5. Click the "Convert" button, and ASM2HEX will automatically complete the conversion and display the results in real-time in the ARM64, ARM, and Thumb tabs on the right.

6. You can clear the input and output using the "Clear" button, making it convenient for the next conversion.

7. The "Toggle Mode" button can switch the current working mode of the tool. The default mode is assembly to hexadecimal, and after switching, it becomes hexadecimal to assembly mode.

8. Click the copy icon in the upper right corner of each tab to copy the content of that tab to the clipboard for easy use.

## Acknowledgements

The development of ASM2HEX has benefited from the following open-source projects:

- Fyne: Cross-platform graphical interface framework based on Go
- Keystone: Lightweight multi-architecture assembly engine
- Capstone: Disassembly engine with multi-architecture support

Thanks to the contributors and maintainers of these excellent projects!

## License

ASM2HEX is released under the MIT license. For details, see the LICENSE file.

## Contact

If you encounter any problems during use or have any suggestions and feedback, please feel free to contact me through the following ways:

- Email: c3VpZmUgQGdtYWlsIGRvdGNvbQ==
- QQ Group: 555354813
- GitHub: https://github.com/suifei/asm2hex

I hope ASM2HEX can become a powerful assistant for your assembly development and learning!
67 changes: 67 additions & 0 deletions archs/arm32.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package archs

import (
"fmt"

"github.com/keystone-engine/keystone/bindings/go/keystone"
"github.com/suifei/asm2hex/bindings/capstone"
)

func Arm32Disasm(encoding []byte, offset uint64, bigEndian bool) (code string, stat_count uint64, ok bool, err error) {
//panic
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("%v", r)
ok = false
return
}
}()

engine, err := capstone.New(capstone.ARCH_ARM, capstone.MODE_ARM)
engine.Option(capstone.OPT_TYPE_SYNTAX, capstone.OPT_SYNTAX_ATT)
if err == nil {
defer engine.Close()

if bigEndian {
encoding = bigEndian32Bytes(encoding)
}
insns, err := engine.Dis(encoding, offset, 0)

if err == nil {
for _, insn := range insns {
code += fmt.Sprintf("%08X:\t%-6s\t%-20s\n", insn.Addr(), insn.Mnemonic(), insn.OpStr())
}
stat_count = uint64(len(insns))
ok = true
return code, stat_count, ok, err
}
return code, stat_count, ok, err
}
return code, stat_count, ok, err
}

func Arm32(code string, offset uint64, bigEndian bool) (encoding []byte, stat_count uint64, ok bool, err error) {
//panic
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("%v", r)
ok = false
return
}
}()

var ks *keystone.Keystone
ks, _ = keystone.New(keystone.ARCH_ARM, keystone.MODE_ARM)
// ks.Option(keystone.OPT_SYNTAX, keystone.OPT_SYNTAX_GAS)
encoding, stat_count, ok = ks.Assemble(code, offset)
err = ks.LastError()
ks.Close()

if ok {
if bigEndian {
encoding = bigEndian32Bytes(encoding)
}
}

return encoding, stat_count, ok, err
}
Loading

0 comments on commit ab4c2c6

Please sign in to comment.