Skip to content

Commit

Permalink
chore: Update build files and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
suifei committed May 27, 2024
1 parent e1e95b5 commit 0e77d87
Show file tree
Hide file tree
Showing 11 changed files with 746 additions and 140 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ link/
tmp/

build/
build-riscv/
fyne_metadata_init.go

asm2hex
ASM to HEX Converter.app
Expand Down
2 changes: 1 addition & 1 deletion FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Website = "https://github.com/suifei/asm2hex"
Name = "ASM to HEX Converter"
ID = "suifei.asm2hex.app"
Version = "1.2.0"
Build = 58
Build = 59
56 changes: 52 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ endif

help:
@echo "Available targets:"
@echo " help - Show this help message"
@echo " clean - Clean up temporary files"
@echo " lib - Build and install Capstone and Keystone libraries"
@echo " build - Build the project"
@echo " help - Show this help message"
@echo " clean - Clean up temporary files"
@echo " lib - Build and install Capstone and Keystone libraries"
@echo " build - Build the project"
@echo " lib_riscv - Build and install Capstone and Keystone libraries for RISC-V"
@echo " build_riscv - Build the project for RISC-V"

clean:
@rm -rf tmp build && \
Expand Down Expand Up @@ -88,6 +90,52 @@ lib:
echo "Libraries installed successfully for $(PLATFORM)"; \
fi


lib_riscv:
@if [ -d "$(INSTALL_PREFIX)/lib" ] && \
[ -f "$(INSTALL_PREFIX)/lib/libcapstone.a" ] && \
[ -f "$(INSTALL_PREFIX)/lib/libkeystone.a" ]; then \
echo "Capstone and Keystone libraries are already installed"; \
else \
mkdir -p ./tmp && \
cd ./tmp && \
if [ ! -d "capstone" ]; then \
git clone https://github.com/capstone-engine/capstone.git && \
cd capstone && \
git checkout $(CAPSTONE_VERSION) && \
mkdir build && \
cd build && \
cmake $(CMAKE_FLAGS) .. && \
$(SUDO) cmake --build . --config Release --target install; \
else \
echo "Capstone library is already built, skipping build"; \
fi && \
cd ../.. && \
if [ ! -d "keystone" ]; then \
git clone https://github.com/null-cell/keystone.git keystone-riscv && \
cd keystone-riscv && \
git checkout 0.9.3.dev2 && \
mkdir build && \
cd build && \
$(KEYSTONE_BUILD_CMD); \
else \
echo "Keystone library is already built, skipping build"; \
fi && \
cd ../.. && \
echo "Libraries installed successfully for $(PLATFORM)"; \
fi

build_riscv:
@mkdir -p ./build-riscv && \
CGO_ENABLED=1 \
CGO_CFLAGS="$(CGO_CFLAGS)" \
CGO_LDFLAGS="$(CGO_LDFLAGS)" \
fyne package --release --target $(TARGET) --icon ./theme/icons/asm2hex.png -tags build_riscv && \
rm -rf ./build-riscv/$(if $(filter $(PLATFORM),Windows),*.exe,*.app) && \
mv -fv $(if $(filter $(PLATFORM),Windows),*.exe,*.app) ./build-riscv && \
echo "Build completed for $(PLATFORM)"


build:
@mkdir -p ./build && \
CGO_ENABLED=1 \
Expand Down
110 changes: 110 additions & 0 deletions archs/arch.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !build_riscv

package archs

import (
Expand All @@ -8,6 +10,114 @@ import (
"github.com/suifei/asm2hex/bindings/keystone"
)


var WithRiscv = false
type Option struct {
Const uint64
Name string
}

type OptionSlice []Option

var KeystoneArchOptions = OptionSlice{
{uint64(keystone.ARCH_ARM), "ARM"},
{uint64(keystone.ARCH_ARM64), "ARM64"},
{uint64(keystone.ARCH_MIPS), "MIPS"},
{uint64(keystone.ARCH_X86), "X86"},
{uint64(keystone.ARCH_PPC), "PPC"},
{uint64(keystone.ARCH_SPARC), "SPARC"},
{uint64(keystone.ARCH_SYSTEMZ), "SYSTEMZ"},
{uint64(keystone.ARCH_HEXAGON), "HEXAGON"},
}

var KeystoneModeList = OptionSlice{}
var KeystoneModeOptions = map[uint64]OptionSlice{
uint64(keystone.ARCH_ARM): {{uint64(keystone.MODE_ARM), "ARM"}, {uint64(keystone.MODE_THUMB), "THUMB"}, {uint64(keystone.MODE_V8), "V8"}},
uint64(keystone.ARCH_ARM64): {{uint64(keystone.MODE_LITTLE_ENDIAN), "LITTLE_ENDIAN"}},
uint64(keystone.ARCH_MIPS): {{uint64(keystone.MODE_MICRO), "MICRO"}, {uint64(keystone.MODE_MIPS3), "MIPS3"}, {uint64(keystone.MODE_MIPS32R6), "MIPS32R6"}, {uint64(keystone.MODE_MIPS32), "MIPS32"}, {uint64(keystone.MODE_MIPS64), "MIPS64"}},
uint64(keystone.ARCH_X86): {{uint64(keystone.MODE_16), "16"}, {uint64(keystone.MODE_32), "32"}, {uint64(keystone.MODE_64), "64"}},
uint64(keystone.ARCH_PPC): {{uint64(keystone.MODE_PPC32), "PPC32"}, {uint64(keystone.MODE_PPC64), "PPC64"}, {uint64(keystone.MODE_QPX), "QPX"}},
uint64(keystone.ARCH_SPARC): {{uint64(keystone.MODE_SPARC32), "SPARC32"}, {uint64(keystone.MODE_SPARC64), "SPARC64"}, {uint64(keystone.MODE_V9), "V9"}},
uint64(keystone.ARCH_SYSTEMZ): {{uint64(keystone.MODE_BIG_ENDIAN), "BIG_ENDIAN"}},
uint64(keystone.ARCH_HEXAGON): {{uint64(keystone.MODE_BIG_ENDIAN), "BIG_ENDIAN"}},
}

// var KeystoneSyntaxList = OptionSlice{}
// var KeystoneSyntaxOptions = map[uint64]OptionSlice{
// uint64(keystone.ARCH_ARM): {{uint64(keystone.OPT_SYNTAX_INTEL), "Intel"}, {uint64(keystone.OPT_SYNTAX_ATT), "ATT"}},
// uint64(keystone.ARCH_ARM64): {{uint64(keystone.OPT_SYNTAX_INTEL), "Intel"}, {uint64(keystone.OPT_SYNTAX_ATT), "ATT"}},
// uint64(keystone.ARCH_MIPS): {{uint64(keystone.OPT_SYNTAX_INTEL), "Intel"}, {uint64(keystone.OPT_SYNTAX_ATT), "ATT"}},
// uint64(keystone.ARCH_X86): {{uint64(keystone.OPT_SYNTAX_INTEL), "Intel"}, {uint64(keystone.OPT_SYNTAX_ATT), "ATT"}, {uint64(keystone.OPT_SYNTAX_NASM), "NASM"}, {uint64(keystone.OPT_SYNTAX_MASM), "MASM"}, {uint64(keystone.OPT_SYNTAX_GAS), "GAS"}, {uint64(keystone.OPT_SYNTAX_RADIX16), "Radix16"}},
// uint64(keystone.ARCH_PPC): {{uint64(keystone.OPT_SYNTAX_INTEL), "Intel"}, {uint64(keystone.OPT_SYNTAX_ATT), "ATT"}},
// uint64(keystone.ARCH_SPARC): {{uint64(keystone.OPT_SYNTAX_INTEL), "Intel"}, {uint64(keystone.OPT_SYNTAX_ATT), "ATT"}},
// uint64(keystone.ARCH_SYSTEMZ): {{uint64(keystone.OPT_SYNTAX_INTEL), "Intel"}, {uint64(keystone.OPT_SYNTAX_ATT), "ATT"}},
// uint64(keystone.ARCH_HEXAGON): {{uint64(keystone.OPT_SYNTAX_INTEL), "Intel"}},
// }

var CapstoneArchOptions = OptionSlice{
{uint64(capstone.ARCH_ARM), "ARM"},
{uint64(capstone.ARCH_ARM64), "ARM64"},
{uint64(capstone.ARCH_MIPS), "MIPS"},
{uint64(capstone.ARCH_X86), "X86"},
{uint64(capstone.ARCH_PPC), "PPC"},
{uint64(capstone.ARCH_SPARC), "SPARC"},
{uint64(capstone.ARCH_SYSZ), "SYSZ"},
{uint64(capstone.ARCH_XCORE), "XCORE"},
{uint64(capstone.ARCH_M68K), "M68K"},
{uint64(capstone.ARCH_TMS320C64X), "TMS320C64X"},
{uint64(capstone.ARCH_M680X), "M680X"},
{uint64(capstone.ARCH_EVM), "EVM"},
{uint64(capstone.ARCH_MOS65XX), "MOS65XX"},
{uint64(capstone.ARCH_WASM), "WASM"},
{uint64(capstone.ARCH_BPF), "BPF"},
{uint64(capstone.ARCH_RISCV), "RISCV"},
{uint64(capstone.ARCH_SH), "SH"},
{uint64(capstone.ARCH_TRICORE), "TRICORE"},
}

var CapstoneModeList = OptionSlice{}
var CapstoneModeOptions = map[uint64]OptionSlice{
uint64(capstone.ARCH_ARM): {{uint64(capstone.MODE_ARM), "ARM"}, {uint64(capstone.MODE_THUMB), "THUMB"}, {uint64(capstone.MODE_MCLASS), "MCLASS"}, {uint64(capstone.MODE_V8), "V8"}},
uint64(capstone.ARCH_ARM64): {{uint64(capstone.MODE_LITTLE_ENDIAN), "LITTLE_ENDIAN"}},
uint64(capstone.ARCH_MIPS): {{uint64(capstone.MODE_MIPS32), "MIPS32"}, {uint64(capstone.MODE_MIPS64), "MIPS64"}, {uint64(capstone.MODE_MICRO), "MICRO"}, {uint64(capstone.MODE_MIPS3), "MIPS3"}, {uint64(capstone.MODE_MIPS32R6), "MIPS32R6"}, {uint64(capstone.MODE_MIPS2), "MIPS2"}},
uint64(capstone.ARCH_X86): {{uint64(capstone.MODE_16), "16"}, {uint64(capstone.MODE_32), "32"}, {uint64(capstone.MODE_64), "64"}},
uint64(capstone.ARCH_PPC): {{uint64(capstone.MODE_LITTLE_ENDIAN), "LITTLE_ENDIAN"}, {uint64(capstone.MODE_QPX), "QPX"}, {uint64(capstone.MODE_SPE), "SPE"}, {uint64(capstone.MODE_BOOKE), "BOOKE"}},
uint64(capstone.ARCH_SPARC): {{uint64(capstone.MODE_V9), "V9"}},
uint64(capstone.ARCH_SYSZ): {{uint64(capstone.MODE_BIG_ENDIAN), "BIG_ENDIAN"}},
uint64(capstone.ARCH_XCORE): {{uint64(capstone.MODE_LITTLE_ENDIAN), "LITTLE_ENDIAN"}},
uint64(capstone.ARCH_M68K): {{uint64(capstone.MODE_M68K_000), "M68K_000"}, {uint64(capstone.MODE_M68K_010), "M68K_010"}, {uint64(capstone.MODE_M68K_020), "M68K_020"}, {uint64(capstone.MODE_M68K_030), "M68K_030"}, {uint64(capstone.MODE_M68K_040), "M68K_040"}, {uint64(capstone.MODE_M68K_060), "M68K_060"}},
uint64(capstone.ARCH_M680X): {{uint64(capstone.MODE_M680X_6301), "M680X_6301"}, {uint64(capstone.MODE_M680X_6309), "M680X_6309"}, {uint64(capstone.MODE_M680X_6800), "M680X_6800"}, {uint64(capstone.MODE_M680X_6801), "M680X_6801"}, {uint64(capstone.MODE_M680X_6805), "M680X_6805"}, {uint64(capstone.MODE_M680X_6808), "M680X_6808"}, {uint64(capstone.MODE_M680X_6809), "M680X_6809"}, {uint64(capstone.MODE_M680X_6811), "M680X_6811"}, {uint64(capstone.MODE_M680X_CPU12), "M680X_CPU12"}, {uint64(capstone.MODE_M680X_HCS08), "M680X_HCS08"}},
uint64(capstone.ARCH_EVM): {{uint64(capstone.MODE_BIG_ENDIAN), "BIG_ENDIAN"}},
uint64(capstone.ARCH_MOS65XX): {{uint64(capstone.MODE_MOS65XX_6502), "MOS65XX_6502"}, {uint64(capstone.MODE_MOS65XX_65C02), "MOS65XX_65C02"}, {uint64(capstone.MODE_MOS65XX_W65C02), "MOS65XX_W65C02"}, {uint64(capstone.MODE_MOS65XX_65816), "MOS65XX_65816"}, {uint64(capstone.MODE_MOS65XX_65816_LONG_M), "MOS65XX_65816_LONG_M"}, {uint64(capstone.MODE_MOS65XX_65816_LONG_X), "MOS65XX_65816_LONG_X"}, {uint64(capstone.MODE_MOS65XX_65816_LONG_MX), "MOS65XX_65816_LONG_MX"}},
uint64(capstone.ARCH_WASM): {{uint64(capstone.MODE_LITTLE_ENDIAN), "LITTLE_ENDIAN"}},
uint64(capstone.ARCH_BPF): {{uint64(capstone.MODE_BPF_CLASSIC), "BPF_CLASSIC"}, {uint64(capstone.MODE_BPF_EXTENDED), "BPF_EXTENDED"}},
uint64(capstone.ARCH_RISCV): {{uint64(capstone.MODE_RISCV32), "RISCV32"}, {uint64(capstone.MODE_RISCV64), "RISCV64"}, {uint64(capstone.MODE_RISCVC), "RISCVC"}},
uint64(capstone.ARCH_SH): {{uint64(capstone.MODE_SH2), "SH2"}, {uint64(capstone.MODE_SH2A), "SH2A"}, {uint64(capstone.MODE_SH3), "SH3"}, {uint64(capstone.MODE_SH4), "SH4"}, {uint64(capstone.MODE_SH4A), "SH4A"}, {uint64(capstone.MODE_SHFPU), "SHFPU"}, {uint64(capstone.MODE_SHDSP), "SHDSP"}},
uint64(capstone.ARCH_TRICORE): {{uint64(capstone.MODE_TRICORE_110), "TRICORE_110"}, {uint64(capstone.MODE_TRICORE_120), "TRICORE_120"}, {uint64(capstone.MODE_TRICORE_130), "TRICORE_130"}, {uint64(capstone.MODE_TRICORE_131), "TRICORE_131"}, {uint64(capstone.MODE_TRICORE_160), "TRICORE_160"}, {uint64(capstone.MODE_TRICORE_161), "TRICORE_161"}, {uint64(capstone.MODE_TRICORE_162), "TRICORE_162"}},
}

// var CapstoneSyntaxList = OptionSlice{}
// var CapstoneSyntaxOptions = map[uint64]OptionSlice{
// uint64(capstone.ARCH_ARM): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}, {uint64(capstone.OPT_SYNTAX_NOREGNAME), "NOREGNAME"}},
// uint64(capstone.ARCH_ARM64): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}, {uint64(capstone.OPT_SYNTAX_NOREGNAME), "NOREGNAME"}},
// uint64(capstone.ARCH_MIPS): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}, {uint64(capstone.OPT_SYNTAX_NOREGNAME), "NOREGNAME"}},
// uint64(capstone.ARCH_X86): {{uint64(capstone.OPT_SYNTAX_INTEL), "Intel"}, {uint64(capstone.OPT_SYNTAX_ATT), "ATT"}, {uint64(capstone.OPT_SYNTAX_MASM), "MASM"}},
// uint64(capstone.ARCH_PPC): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}, {uint64(capstone.OPT_SYNTAX_NOREGNAME), "NOREGNAME"}},
// uint64(capstone.ARCH_SPARC): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}, {uint64(capstone.OPT_SYNTAX_NOREGNAME), "NOREGNAME"}},
// uint64(capstone.ARCH_SYSZ): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}, {uint64(capstone.OPT_SYNTAX_NOREGNAME), "NOREGNAME"}},
// uint64(capstone.ARCH_XCORE): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}, {uint64(capstone.OPT_SYNTAX_NOREGNAME), "NOREGNAME"}},
// uint64(capstone.ARCH_M68K): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}, {uint64(capstone.OPT_SYNTAX_NOREGNAME), "NOREGNAME"}, {uint64(capstone.OPT_SYNTAX_MOTOROLA), "Motorola"}},
// uint64(capstone.ARCH_TMS320C64X): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}, {uint64(capstone.OPT_SYNTAX_NOREGNAME), "NOREGNAME"}},
// uint64(capstone.ARCH_M680X): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}, {uint64(capstone.OPT_SYNTAX_NOREGNAME), "NOREGNAME"}, {uint64(capstone.OPT_SYNTAX_MOTOROLA), "Motorola"}},
// uint64(capstone.ARCH_EVM): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}},
// uint64(capstone.ARCH_MOS65XX): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}, {uint64(capstone.OPT_SYNTAX_MOTOROLA), "Motorola"}},
// uint64(capstone.ARCH_WASM): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}},
// uint64(capstone.ARCH_BPF): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}},
// uint64(capstone.ARCH_RISCV): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}},
// uint64(capstone.ARCH_SH): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}},
// uint64(capstone.ARCH_TRICORE): {{uint64(capstone.OPT_SYNTAX_DEFAULT), "Default"}},
// }

func Disassemble(arch capstone.Architecture, mode capstone.Mode, code []byte, offset uint64, bigEndian bool /*syntaxValue capstone.OptionValue, */, addAddress bool) (string, uint64, bool, error) {
defer func() {
if r := recover(); r != nil {
Expand Down
Loading

0 comments on commit 0e77d87

Please sign in to comment.