Disassebling of Debian file for extract opcodes - linux

I know debian files are just packages. But I need to have opcodes for some analysis. How can it be done?

dpkg -x name_of_deb.deb /tmp/datadir
while take the contents of name_of_deb and stick them in /tmp/datadir.
You can build dpkg from source on almost any system if you are trying to unpack a Deb on a non-Debian system, or if you have ar and tar, there's a more complex approach.
Then you can use something like objdump --disassemble to dump the binaries in /tmp/datadir/usr/bin and /tmp/datadir/usr/lib

Related

How to build ELF file for each applet in busybox?

Assume, my busybox has two applets: cat, touch and it runs on mips arch.
Now I want two ELF file (cat & touch) in order to run on mips, no shared lib, static.
How to do that?
According to this FAQ (see Installing Busybox), you can create symbolic links to one Busybox binary each with a name of the utility you need. Then Busybox will detect as which utility it was invoked and behave accordingly.

Getting the new Squeak 5 to run on 64 bit Linux

In short: how do I get Squeak 5 to run on x64 Linux?
I dont care whether the executable is 32 or 64 bit as long as it runs and opens the Squeak 5 image.
Here is what I tried:
When I try to run the executables from the Squeak 5 package i get: Running 32-bit Squeak on a 64-bit System. install-libs32 may install them - tried that. Wasn't found.
Then I went looking for a 64 bit executable. There are some from Squeak 4 but they can't open Squeak 5 images.
Looking through the Squeak 5 package:
The shell scripts squeak.sh in both these directories:
Squeak-5.0-All-in-One/
Squeak-5.0-All-in-One/Squeak-5.0-All-in-One.app/Contents/LinuxAndWindows/
Both return this error:
/usr/bin/ldd didn't produce any output and the system is 64 bit. You may need to (re)install the 32-bit libraries.
There are also misleading files named squeak (no .sh) in these directories:
Squeak-5.0-All-in-One/Squeak-5.0-All-in-One.app/Contents/LinuxAndWindows/Linux-i686
Squeak-5.0-All-in-One/Squeak-5.0-All-in-One.app/Contents/LinuxAndWindows/Linux-i686/bin
They are not the executable, just more shell scripts.
There is another squeak file in:
Squeak-5.0-All-in-One/Squeak-5.0-All-in-One.app/Contents/LinuxAndWindows/Linux-i686/lib/squeak/5.0-3397
Running ./squeak misleadingly says No such file or directory. It is misleading because the file does exist, it is just a 32-bit exe.
file squeak tells me: ELF 32-bit LSB executable, Intel 80386.
So how do I get it to run on 64-bit Linux? I could compile it myself but haven't tried assuming there are a lot of dependencies. Or has anyone tried it?
You already got all information you need:
You may need to (re)install the 32-bit libraries.
Squeak 5 is currently 32bit only. Hence, you need 32bit libraries.
It cannot use your 64bit libraries.
You may need thes:e packages (I use Debian/Ubuntu names, CentOS/RH/SuSE should be similar):
libc6:i386
libuuid1:i386
libkrb5-3:i386
libk5crypto3:i386
zlib1g:i386
libcomerr2:i386
libkrb5support0:i386
libkeyutils1:i386
libx11-6:i386
libgl1-mesa-glx:i386
libsm6:i386
libssl1.0.0:i386
(note the :i386 in the names)
This works in 64 bit Ubuntu 16.04:
In the directory where you unzipped the
Squeak-5.0-All-in-One.zip
archive, and that contains the squeak.sh file,
put the following into a file named libs32.sh :
#!/bin/bash
objdump -p ./Squeak-5.0-All-in-One.app/Contents/LinuxAndWindows/Linux-i686/lib/squeak/5.0-3397/*|
grep NEEDED|
awk '{print $2}'|
sort -u|
xargs dpkg -S|
awk '{print $1}'|
sort -u|
sed 's/:amd64:/:i386:/'|
sort -u|
sed 's/:$//'
Make that file executable:
chmod +x ./libs32.sh
Run it:
./libs32.sh
You will get a list of libraries that need to be installed.
Run
./lib32.sh | xargs sudo apt install
to see what would be installed.
Run
./lib32.sh | xargs sudo apt install -y
to install it.

how to make excutable files based on source codes

I write some programs on linux with C
I want to run these programs on many remote computers, which are installed with fedora or ubuntu
I compiled the program with gcc on local machine, however the excutable file is not workable on remote machines.
for example: I use
gcc -o udp_server udp_server.c
on local machine to get a excutable binary file udp_server and then I copy it to a remote machine and run it there, the error is:
-bash: ./udp_server: /lib64/ld-linux-x86-64.so.2: bad ELF interpreter: No such file or directory
the local machine: fedora
Fedora release 16 (Verne)
Kernel \r on an \m (\l)
3.6.10-2.fc16.x86_64 GNU/Linux
the remote machine:
Fedora release 12 (Constantine)
Kernel \r on an \m (\l)
2.6.32-36.onelab.x86_64 GNU/Linux
on these remote machines, there are no gcc compiler
so I hope I can make some excutable files so that they can be executed on those remote machines
so what kind of excutable files should I make, and how to make them?
any recommenation tools or procedures?
thanks!
To run a program written in C, you must first compile it to produce an executable file. On Linux, the C compiler is typically the "Gnu C Compiler", or gcc.
If you compile a C program on Linux, it should usually run on any other Linux computer. However, a few conditions must be met for this to work:
A compiled executable is compiled for a specific processor architecture. For example, if you compile for x86-x64, the program will not run on x86 or PowerPC.
If the program uses shared libraries, these must be installed on the target system. The C library, "libc" is installed everywhere, other libraries may not be.
As to how to compile: For a simple program, you can invoke gcc directly. For more complex programs, some build tool is advisable. There are many to choose from; two popular choices are GNU make (the traditional solution), and CMake.
To distribute the program: If it is only a single executable, you can just copy this executable around. If the program consists of multiple files (images, data files, etc.), you should package it as a software package. This allows users to install it using a package manager such as RPM or dpkg. How to do this is explained in various packaging guides for the different Linux distributions.
Finally, a piece of advice: You seem to know very little about software development in general and in C in particular. Consider reading some tutorial on programmin in C - this will answer these (and many other) questions. There are countless books and online tutorials - I can recommend "The C book", by gbdirect.
The issue you see is you are missing a dynamic library on the target machine. To see which libraries you need you need to use "ldd" program. Example (I just execute it against standard program "test" which is in every single linux distribution):
$ ldd /usr/bin/test
linux-vdso.so.1 => (0x00007fff5fdfe000)
libc.so.6 => /lib64/libc.so.6 (0x00000032d0600000)
/lib64/ld-linux-x86-64.so.2 (0x00000032cfe00000)
On Fedora and RHEL you can find which RPM package you want to install using the following command
$ rpm -q --whatprovides /lib64/ld-linux-x86-64.so.2
glibc-2.16-28.fc18.x86_64
And then you need to install it:
$ yum -y install glibc-2.16-28.fc18.x86_64
I dont use Ubuntu / Debian, not sure how to do this. Please note that on 32bit systems libraries for 64bits are not avaiable, but on 64bit systems these libraries have usualla i686 tag and are installable.
Usually, you can execute your program on different machines as long as you keep the architecture. E.g. you cannot execute 64bit program on a 32bit machine, and also vice versa (you can workaround this by installing 32bit libs but thats maybe too difficult).
If you have different distributions, or different versions of same linux distribution, this might be problem - you need to make sure you have all the dependencies in the same major versions.
Or you can link libraries statically which is not usual in the linux world at all, but you can do this. Learn how to use GCC and then you will find out how to do that.

single install document for multiple Linux distributions

We need to distribute binaries and installation instructions for multiple Linux distributions. Since the installation instructions are mostly similar among the distros, we would like to keep a single document that contains the common sections as well as distro-specific sections, say with special markings. We would like to be able to run some sort of command (nroff/groff?) to generate the distro specific installation docs on demand.
What is the best way to achieve this? I don't want to reinvent anything ...
How about using cpp, the C pre-processor? You can use defines to specify the distro:
Download the program.
#ifdef DEBIAN
Run:
sudo apt-get some_package
#endif
#ifdef REDHAT
Run:
yum install some_package
#endif
You can run the build on pretty much any GNU/Linux system:
cpp -P -DDEBIAN instructions.template
or:
cpp -P -DREDHAT instructions.template

rpmbuild generates RPM in which subdirectory

rpmbuild generates RPM under which directory?
I checked the RPMS directory:-
[root#tom adil]# ls /usr/src/redhat/
BUILD RPMS SOURCES SPECS SRPMS
[root#tom adil]# ls /usr/src/redhat/RPMS/
athlon i386 i486 i586 i686 noarch
[root#tom adil]#
How to decide rpmbuild outputs in which of the above sub-directories?
Is it controlled by spec file? What is the default option?
I thought uname -p but its not the case probable uname -i is used.
Linked to my last question Difference between "machine hardware" and "hardware platform"
The binary package is named according to the %_build_name_fmt macro. By default this macro contains %{ARCH}/ at the beginning, so that is where the binary package is placed.
Following on from your last comment, by default the RPM will go into the subdirectory that matches the platform you're building on. You can override this by passing the --target parameter to rpmbuild, but this only applies where valid; for example, you can use --target i386 on an x86_64 system to build a 32-bit RPM, but you can't build a 64-bit RPM on a 32-bit platform.
The RPM goes to the RPMS folder and the source RPM to the SRPMS. This is not controlled by the spec file - this is convention. What exactly are you trying to do?

Resources