54 lines
1.8 KiB
Ruby
54 lines
1.8 KiB
Ruby
class Capstone < Formula
|
|
desc "Multi-platform, multi-architecture disassembly framework"
|
|
homepage "https://www.capstone-engine.org/"
|
|
url "https://github.com/aquynh/capstone/archive/4.0.1.tar.gz"
|
|
sha256 "79bbea8dbe466bd7d051e037db5961fdb34f67c9fac5c3471dd105cfb1e05dc7"
|
|
head "https://github.com/aquynh/capstone.git"
|
|
|
|
bottle do
|
|
cellar :any
|
|
sha256 "edfcfa53bfa47505e095f4516623f31d46dc094b4184585a7751e450312b8ba2" => :catalina
|
|
sha256 "e792acf6f3c23be1853f8658f35766c87dc35f165b6d6728aca61596bc9de230" => :mojave
|
|
sha256 "2a8a4842ad2660dad079216a12efe8b6d6394b548c6e056f250aa6d6cdf3802d" => :high_sierra
|
|
sha256 "561639bc13e269d61af352e106b3d039a4c9b5fdadd45b04bcf9f8c9f99a53c6" => :sierra
|
|
end
|
|
|
|
def install
|
|
ENV["HOMEBREW_CAPSTONE"] = "1"
|
|
ENV["PREFIX"] = prefix
|
|
system "./make.sh"
|
|
system "./make.sh", "install"
|
|
end
|
|
|
|
test do
|
|
# code comes from https://www.capstone-engine.org/lang_c.html
|
|
(testpath/"test.c").write <<~EOS
|
|
#include <stdio.h>
|
|
#include <inttypes.h>
|
|
#include <capstone/capstone.h>
|
|
#define CODE "\\x55\\x48\\x8b\\x05\\xb8\\x13\\x00\\x00"
|
|
|
|
int main()
|
|
{
|
|
csh handle;
|
|
cs_insn *insn;
|
|
size_t count;
|
|
if (cs_open(CS_ARCH_X86, CS_MODE_64, &handle) != CS_ERR_OK)
|
|
return -1;
|
|
count = cs_disasm(handle, CODE, sizeof(CODE)-1, 0x1000, 0, &insn);
|
|
if (count > 0) {
|
|
size_t j;
|
|
for (j = 0; j < count; j++) {
|
|
printf("0x%"PRIx64":\\t%s\\t\\t%s\\n", insn[j].address, insn[j].mnemonic,insn[j].op_str);
|
|
}
|
|
cs_free(insn, count);
|
|
} else
|
|
printf("ERROR: Failed to disassemble given code!\\n");
|
|
cs_close(&handle);
|
|
return 0;
|
|
}
|
|
EOS
|
|
system ENV.cc, "test.c", "-L#{lib}", "-lcapstone", "-o", "test"
|
|
system "./test"
|
|
end
|
|
end
|