Create bin file linux

Creating bin/cue Files on Linux

I have tested this to be working a Fedora Core 8 distro. It should work on other distros that have cdrdao installed. The following commands should be performed as a root user.

1. Scan for your device ID

You should see an output similar to the following:

Cdrdao version 1.2.2 - (C) Andreas Mueller
SCSI interface library - (C) Joerg Schilling
Paranoia DAE library - (C) Monty
Check http://cdrdao.sourceforge.net/drives.html#dt for current driver tables.
Using libscg version 'schily-0.8'
3,0,0 : Imation , IMWDVRW8I , HSI3

Note the 3,0,0 at the bottom of the output. That’s the device ID you need for the next command.

2. Now you can start copying the CD/DVD into a set of bin/cue file.

$> cdrdao read-cd --read-raw --datafile cdimage.bin --device 3,0,0 cdimage.cue

The above command will produce an image of the CD at device 3,0,0 (which is what I have gotten during the previous cdrdao command) and write the image into cdimage.bin and cdimage.cue.

You should see an output similar to the following when the command executes:

Cdrdao version 1.2.2 - (C) Andreas Mueller
SCSI interface library - (C) Joerg Schilling
Paranoia DAE library - (C) Monty
Check http://cdrdao.sourceforge.net/drives.html#dt for current driver tables.
Using libscg version 'schily-0.8'
3,0,0: Imation IMWDVRW8I Rev: HSI3
Using driver: Generic SCSI-3/MMC - Version 2.0 (options 0x0000)
Reading toc and track data.
Track Mode Flags Start Length
1 DATA 4 00:00:00( 0) 00:06:00( 450)
2 DATA 4 00:06:00( 450) 78:59:14(355439)
Leadout DATA 4 79:05:14(355889)
PQ sub-channel reading (data track) is supported, data format is BCD.
Raw P-W sub-channel reading (data track) is supported.
Cooked R-W sub-channel reading (data track) is supported.
Copying data track 1 (MODE2_RAW): start 00:00:00, length 00:06:00 to "cdimage.bin".
Copying data track 2 (MODE2_RAW): start 00:06:00, length 78:59:14 to "cdimage.bin".
Reading of toc and track data finished successfully.

Now you can open bin/cue file in Windows using DAEMON Tools. Try opening the bin file if you have an error opening the cue file.

This is the homepage of a 30+ years old software technologist. To get in touch with me, drop me an email.
All rights reserved. Contents on this web site are not to be duplicated without explicit permission. Use of these contents is entirely at your own risk.
The views and opinions expressed here represent my own and not those of the people, institutions or organizations that I may or may not be related with.

Источник

How to Convert a Shell Script Into a Binary Executable

announcement - icon

The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.

To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.

Читайте также:  Virtualbox for linux oracle

Connect your cluster and start monitoring your K8s costs right away:

1. Introduction

As system administrators, we frequently use shell scripts to automate our operational tasks on Linux systems. It would be helpful to convert these scripts into binary form to improve their performance and security as well. Also, it will be helpful to bundle our scripts and share them with other devices where the interpreter isn’t available.

In this tutorial, we’ll focus on the steps involved in converting a shell script into a binary executable file using the shc compiler. We’ll also illustrate the installation of the shc compiler, binary file creation, and its successful execution.

Without any further ado, let’s get into the nitty-gritty of it.

2. Building a Shell Script

Let’s quickly build a shell script to ask for the user’s name and display the current date and time. The shebang line #!/bin/bash at the beginning of the script instructs the operating system to execute this script using the bash interpreter:

$ cat welcome.sh #!/bin/bash echo -n "Enter your name: " read max echo -e "\nHello $max, Welcome to Baeldung Blogs!" now=$(date +"%Y-%m-%d %H:%M:%S") echo -e "\nCurrent date and time: $now" echo -e "\nHappy Reading!"

Let’s grant executable permission to the script using the chmod command and execute the script:

$ chmod +x welcome.sh $ ./welcome.sh Enter your name: Sriram Ramanujam Hello Sriram Ramanujam, Welcome to Baeldung Blogs! Current date and time: 2023-03-19 17:04:33 Happy Reading! $

That’s pretty much what we need to build our first binary files for shell scripts using the shc compiler.

3. SHC Compiler Installation

Generally, we use the shc compiler module to convert a shell script into a binary executable file. Furthermore, shc performs two standard steps as part of this conversion process. First, it converts the shell scripts into equivalent C code (with *.c extensions), and second, it creates the binary executables (with *.x extensions) after compiling the C source code.

Before we get started with shc, there are a couple of things we need to take care of. First, we’ll have to add the relevant repository to the system package sources automatically by creating a new file in the /etc/apt/source.list.d/ directory. Also, we’ll need to update the package lists using the apt-get update command.

Lastly, we install the shc package using the apt-get install command:

$ sudo add-apt-repository ppa:neurobin/ppa $ sudo apt-get update $ sudo apt-get install shc -y

Let’s execute the shc command to get the basic usage information and also check the installation:

$ shc shc parse(-f): No source file specified shc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-o outfile] [-rvDSUHCABhs] -f script

Further, let’s use the which command to identify the installation path of the shc. We’ll need this in the next step:

Читайте также:  Linux максимальное имя файла

4. Create and Run the Binary File

Now, we can easily create the binary executable using the shc command by specifying the shell script and its path with the -f argument. Also, we’ll add -v for verbose output and -r to enable the redistributable feature so that we can use the executable on other machines:

By default, the generated binary comes with the .x extension. However, we’re using the -o option and forcing the binary output name to welcome:

$ ls -l | grep welcome -rwxrwxr-x 1 sriram sriram 11240 Mar 19 17:10 welcome -rwxrwxr-x 1 sriram sriram 384 Mar 19 17:02 welcome.sh -rw-rw-r-- 1 sriram sriram 17156 Mar 19 17:10 welcome.sh.x.c

We get only the encrypted special characters when we try to open the newly created binary file:

$ cat welcome ELF>` @(%@8 @@@@��888 . . output truncated . . 

Lastly, let’s execute the binary file and test the script’s functionality.

$ ./welcome Enter your name: Sriram Hello Sriram, Welcome to Baeldung Blogs! Current date and time: 2023-03-19 17:10:51 Happy Reading! $

5. Conclusion

In this tutorial, we’ve seen the detailed list of steps for converting a shell script into a binary executable file using the shc compiler.

We also covered compiler installation, binary file creation, and successful execution of the generated binary file.

Источник

How to Create Binary File from Shell Script

While working with the Linux systems, we used many of commands on daily basis. Most of the commands are available in binary format in /bin, /sbin , /usr/bin, /usr/sbin, etc directories. As a system administrator or student we wrote many of shell script to do few task or automate them. This article will help you to create binary file of your shell script, so no one can see the source code of your script and we can use them as a command. To create binary file from a script we use SHC compiler written by Francisco Javier Rosales García.

Follow the below steps to do this.

Step 1 – Prerequsities

First of all, You need to install required packages for SHC compiler.

For Ubuntu, Debian and LinuxMint

sudo apt-get install libc6-dev

For CentOS, RHEL & Fedora

sudo yum install glibc-devel

Step 2 – Download and Install SHC

Download the latest source code of SHC compiler from its official webpage or using below commands and extract on your system.

cd /usr/src wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9.tgz sudo tar xzf shc-3.8.9.tgz

Now compile the SHC source code on your system and install it using following command.

cd shc-3.8.9 make make install

Step 3 – Create Shell Script

Let’s create a shell script as per your requirement or skip this step if you already created. For this article we have created below sample script which add the integer values given on command line parameter and show the sum of them.

#!/bin/bash total=0 for i in $@; do if [ ! -z "$" ]; then echo "Please enter numeric only" exit 1 fi total=$(($total + $i)) done if [ $total -eq 0 ]; then echo "Plesae execute script like: $0 10 20 30" exit 0 fi echo $total

Step 4 – Create Binary of Script

At this stage we have installed SHC compiler and have a shell script named script.sh. Use the following command to create binary file of your script.

Читайте также:  Создать образ iso linux mint

The above command will create two files in current directory. One will be script.sh.x.c which is in C language format of your script. Second one will be script.sh.x which will be in binary format.

Step 5 – Test Binary Script:

If you try to open binary format of script, you will see that it is not in human readable format.

Now move this script under /usr/bin directory to use from anywhere in system. Also remove .sh.x from file name. So it will be available with simple name. Also set the execute permissions to everyone

mv script.sh.x /usr/bin/script chmod +x /usr/bin/script

Now type command ‘script’ from anywhere in system. You will see the same results as your shell script does.

script 10 20 30 60

Источник

How can I create a binary file using Bash?

Even if you probably simplified your example to make it shorter: This code doesn’t check for errors AND DON’T USE write(2) because it is perfectly ok not only to fail, but also to do only partial writes. Use fwrite(3) or similar instead

4 Answers 4

There’s only one byte you cannot pass as an argument in a Bash command line: 0

For any other value, you can just redirect it. It’s safe.

echo -n $'\x01' > binary.dat echo -n $'\x02' >> binary.dat . 

For the value 0, there’s another way to output it to a file

dd if=/dev/zero of=binary.dat bs=1c count=1 
dd if=/dev/zero oflag=append conv=notrunc of=binary.dat bs=1c count=1 

Just dd if=/dev/zero bs=1 count=1 wothout of and oflag outputs the NUL byte to stdout. So you can do a > or >> .

xxd: creates a hex dump of a given file or standard input. It can also convert a hex dump back to its original binary form.

For those wanting to know how to use xxd to write without having to go away and look it up (like I had to): echo «0000400: 4142 4344» | xxd -r — data.bin where 0000400 is the byte offset into the file and the hex bytes 41 thru 44 are what’s written (the embedded space is ignored). This example writes the string ‘ABCD’ at 1024 bytes into the file ‘data.bin’.

If you don’t mind to not use an existing command and want to describe you data in a text file, you can use binmake. That is a C++ program that you can compile and use like following:

First get and compile binmake (the binary will be in bin/ ):

git clone https://github.com/dadadel/binmake cd binmake make 

Create your text file file.txt :

big-endian 00010203 04050607 # Separated bytes not concerned by endianness 08 09 0a 0b 0c 0d 0e 0f 

Generate your binary file file.bin :

./binmake file.txt file.bin hexdump file.bin 0000000 0100 0302 0504 0706 0908 0b0a 0d0c 0f0e 0000008 

Note: you can also use it with standard input and standard output.

Источник

Оцените статью
Adblock
detector