0

I have used shc on an x86-64 machine to convert a bash script to executable binary. This runs fine on my machine, but I am making this with the intention of pushing it to a aarch64 machine. After copying the binary to the aarch64 machine I get this error:

cannot execute binary file: Exec format error

This appears to be caused by the binary file not being formatted to run on this OS. Does anyone know of a tool that will give me a binary file that can be executed on aarch64 (it doesn't appear that shc can do this).

EDIT: the file command prints this out (on the aarch machine):

ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=f6f72e60c9ae8c2fd3abe5aa47f9ba6be7000be6, stripped

Just confirming that the file is for x86-46

2
  • 1
    Should build the component on the target operating system (write once compile anywhere) or choose a different approach (write once run anywhere) i.e. java (among others) which is platform independent (executes on the Java Virtual Machine). Commented Nov 6, 2018 at 17:57
  • Why would you use shc on a Raspberry Pi? You don't get any meaningful security/confidentiality benefit (the ptrace-evading "secure" mode is trivial to bypass, by using literally any syscall-tracing mechanism other than ptrace), but the result is considerably slower to execute... and on a Pi, you need that performance. Commented Nov 6, 2018 at 18:35

2 Answers 2

1

The short answer is to compile the binary on the target operating system. From the man page:

shc itself is not a compiler such as cc, it rather encodes and encrypts a shell script and generates C source code with the added expiration capability. It then uses the system compiler to compile a stripped binary which behaves exactly like the original script.

Compilation produces an object file containing the machine code. Machine code "may be regarded as the lowest-level representation of a compiled or assembled computer program or as a primitive and hardware-dependent programming language" (ref. https://en.wikipedia.org/wiki/Machine_code). Machine code resulting from compiling the source code on SunOS 11.3 SPARCv4 will not contain the same instructions as machine code resulting from compiling the same source code on AIX PowerPC8.

Sign up to request clarification or add additional context in comments.

Comments

0

Thanks masseyb. I was just trying that when I saw your comment. It works now that I have used the compiler on the arm machine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.