jiangzhengwenjz 发表于 2017-9-8 23:26:20

HackMew thumb.bat的shell实现与改良

本帖最后由 jiangzhengwenjz 于 2017-9-9 11:19 编辑

因为检测环境变量的原因,只能在linux下使用
使用方法:
首先确保devkitARM的bin目录在你的$PATH变量中,因为他所依赖的是它里面的as和objcopy
然后,拷贝下面的代码入一个文本文件,命名为thumb.sh(请确保可执行权限)
编译时只需./thumb.sh [输入源代码文件名] [输出二进制文件名(可选)]会自动用bash而不是sh执行

输入的文件必须是.s或.asm结尾!

其他与windows下thumb.bat功能类似,新增了少许错误提示。#!/usr/bin/env bash

AS=arm-none-eabi-as
OBJCOPY=arm-none-eabi-objcopy

function isInPath()
{
retval=1
IFS_=$IFS
IFS=:
for directory in $PATH
do
        if [[ -x ${directory}/${1} ]]
        then
                retval=0
                break
        fi
done
IFS=$IFS_
return $retval
}


isInPath ${AS}
let res=$?
isInPath ${OBJCOPY}
let res+=$?
dst=$2

if [[ ${1} = "" ]]
then
        echo "Lil' ARM/THUMB Assembler Shell Script"
        echo "Written by JZW"
        echo
        echo "Usage: ./thumb.sh source. "
        echo
elif [[ "${1##*.}" = "s"||"${1##*.}" = "asm" ]]
then
        if [[ ! -f ${1} ]]
        then
                echo "Cannot assemble ${1}: the file does not exist."
        elif [[ $(stat -c "%s" ${1}) = 0 ]]
        then
                echo "Cannot assemble ${1}: the file is empty."
        elif [[ res -gt 0 ]]
        then
                echo "Compiler Missing: make sure that you have devkitarm bins in your path variable."
        else
                if [[ -f "a.out" ]]
                then
                        rm a.out
                fi
                $(${AS} -mthumb -mthumb-interwork ${1})
                if [[ $? = 0 ]]
                then
                        if [[ ${2} = "" ]]
                        then
                                dst=${1%%.*}.bin
                        fi
                        $(${OBJCOPY} -O binary a.out ${dst})
                        if [[ $? != 0 || ! -f ${dst} ]]
                        then
                                rm a.out
                                echo "Cannot assemble ${1}: An error occurred."
                        else
                                echo "Assembled successfully."
                        fi
                       
                elif [[ -f "a.out" ]]
                then
                        rm a.out
                        echo "Cannot assemble ${1}: An error occurred."
                else
                        echo "Cannot assemble ${1}: An error occurred."
                fi
        fi
else
        echo "The input file should have the extension .asm or .s."
fi代码如果测试下来无太多问题的话,晚些时候会上传到github。
Github: https://github.com/jiangzhengwenjz/thumb.sh

1696774136 发表于 2017-9-9 08:23:54

那啥。。。这个可以干嘛??

Against 发表于 2017-9-9 09:40:02

{:5_doge18:}

Against 发表于 2017-9-9 09:40:28

1696774136 发表于 2017-9-9 08:23
那啥。。。这个可以干嘛??

可以搞基{:happyLugia:}
页: [1]
查看完整版本: HackMew thumb.bat的shell实现与改良