64-Bit binary execution error on 64-Bit Centos - 64-bit

While executing one of my C++ Application, I am getting a weird message on one of my Cento x64 box where at the same time another machine with similar configuration is perfectly running the Application.
Error message is:
/myapp: error while loading shared libraries: /myapp: wrong ELF class: ELFCLASS64
N.B: 'myapp' is not some shared library (.so) but actual application itself.
All 3rd party libs being linked with myapp have also been compiled on machine on which I am executing the application. I have compiled libmysqlpp, libthrift and libACE libraries and anything else necessary has been installed through yum.

Everything is resolved.
Actually I was trying to load my application dynamically using ld-linux.so.2 in order to make use of custom library folder but ld-linux.so.2 only executes 32-Bit binaries. Now I am using ld-linux-x86-64.so.2 and everything seems good :)

There is an excellent in depth article on the wider topic (e.g. running 32 bit compiled apps on 64 bit machines) over at http://www.debian-administration.org/articles/534 titled "Running 32-bit Applications on 64-bit Debian GNU/Linux". The short answer is the ia32 Suite.

Related

Is it possible to compile a Crystal script so it can run on any Linux machine without the user having to download Crystal

There is a Crystal equivalent of OCRA (One-Click Ruby Application Builder) but it's only for Windows and I use Linux.
Crystal unlike Ruby is not interpreted or executed in a virtual machine. Crystal is compiled to native code ahead of execution using the LLVM. Application is started by the operating system not with interpreter.
So yes, onсе compiled app can copy and run for any Linux machine with the same architecture. You may need to install system libs like libssl for use full featured stdlib but it is not critical.
Crystal app is already OCRA (all of included shards will builded into one binary) if you specially have not used dynamic linking.
What to read next:
List of supported platforms
Installation Crystal
Using the Compiler for build app
Crystal reference
And API documentation

Win32 Hooks DLL injection into Applications Built against "Any CPU"

I am working on a project which captures all User Interactions. MSDN tells (this)
SetWindowsHookEx can be used to inject a DLL into another process. A
32-bit DLL cannot be injected into a 64-bit process, and a 64-bit DLL
cannot be injected into a 32-bit process. If an application requires
the use of hooks in other processes, it is required that a 32-bit
application call SetWindowsHookEx to inject a 32-bit DLL into 32-bit
processes, and a 64-bit application call SetWindowsHookEx to inject a
64-bit DLL into 64-bit processes.
My Question is, what happens if an application was built against Any CPU. Do I need to call SetWindowsHookEx from a DLL built against Any CPU.
I have written HookLogger_32.exe loading HookFunctions_32.dll (both x86) and HookLogger_64.exe loading HookFunctions_64.dll (both x64) setting WH_CBT and WH_MOUSE globally (not a specific thread).
The HookLogger_32.exe, HookLogger_64.exe, HookFunctions_32.dll and HookFunctions_64.dll are written in C++.
When I click on a .NET application built against Any CPU, these DLLs get injected (through SetWindowHookEx). The Windows OS hangs & I have to forcefully restart my machine.
When the same .NET application is built against x86 or x64, and when I click on the application after the HookLoggers (both 32 & 64 bit) are started everything is working fine.
Any reasons for this undefined behavior.
The platform on which I am working is a 64-bit machine.
You need to inject from a DLL with a corresponding bitnse - i.e. "any CPU" becomes either 32 or 64 bit at runtime... and your DLL must match the runtime bitness !
Something useful in your situation is known as "side-by-side assembly" (two versions of the same assembly, one 32 and the other 64 bit)... I think you will find these helpful:
Using Side-by-Side assemblies to load the x64 or x32 version of a DLL
http://blogs.msdn.com/b/gauravseth/archive/2006/03/07/545104.aspx
http://www.thescarms.com/dotnet/Assembly.aspx
Here you can find a nice walkthrough which contains lots of helpful information pieces - it describes .NET DLL wrapping C++/CLI DLL referencing a native DLL
UPDATE:
To make hooking really easy and robust see this well-tested and free library - among other things it works with AnyCPU !
I guess your main problem is that you are trying to inject a .NET assembly to native process and that surely won't work. I'm not even sure if SetWindowsHookEx supports injecting .NET assembly in CLR process. The solution to your problem is:
Rewrite/Recompile your dll using native compiler such as C++/Delphi/VB etc, for x86 and x64 platform.
Make sure your dll depends on system libraries only. For example, it shouldn't depend on any dll that doesn't ship with windows, because you may crash target process. You can use "Dependency Walker" tool to identify dependencies.
As mentioned in MSDN, you should have an executable injector for each cpu you wish to support. In this case x86 and x64.
Or you could use a better injection/hooking library such as madCodeHook or Detours. This way you will overcome problem #3, not to mentioned dozens of pros they provide.
Just from your description of the problem my guess is...
Your Any CPU compiled program is loading an x86 stub which is firing your 32bit hook, then the x86 stub checks and sees that the environment has 64bit support and launches the 64bit CLR version.
In this scenario your 32bit hook dll is getting the WH_SHELL message and is trying to inject into a process (the x86 stub) that has already ended OR its injecting the 32bit hook into the 64bit CLR process. Thus your "very ambiguous and needs to be elaborated on" system crash.
If you care to elaborate about what your code is actually doing, then more help (and less generalizations and 'just use program A') will be given. Are you actually injecting code into the process or are you calling SetWindowsHookEx with the dwThreadId of the process.
On a 32-bit computer, it should be pretty obvious was bitness an Any CPU application takes on.
A 64-bit computer gets two separate installations of the .NET Framework: one for each bitness. A .NET application compiled as with Any CPU as the target normally runs on the 64-bit installation, but it can also run on the 32-bit installation if referenced by another application that directly targets x86. Thus, you can only be sure what you're getting if you know how the application is being run: as an independent process, or via reference.
I wouldn't make any assumptions. Don't assume the process is 64-bit on a 64-bit computer: it can potentially be 32-bit. Check it properly to see which mode it is running in. Then, inject from 32-bit or 64-bit accordingly.
The reason that you must use the same bitness as the target process is that, for technical reasons into which I won't get, such hooks cannot cross what is called the SysWOW barrier. SysWOW is what allows 32-bit applications to run on a 64-bit computer, 16-bit applications to run on a 32-bit computer, etc. You are "crossing the barrier" when you communicate between applications running on different sides of SysWOW--that is, one is running within SysWOW (32-bit), and the other is not (64-bit). Simply put, a process must be entirely in or out of SysWOW. Thus, you cannot have add 32-bit code to a 64-bit process, and vice versa.

Dlopen Error in Linux while using GLES 2 PowerVR libs?

I was using powervr sdk gles 2 libs in linux in gamekit/ogre for building an application. I get the error
"dlopen tries:libGL.so" after which application crashes.
I tried debugging using DDD etc but couldnt isolate much.
How do I fix this in linux(Ubuntu 10.10)?
Does linux refer to some default in built libs while running dlopen?
A library name like libGL.so is only used for linking at compile time. When run-time linking, you should be using the SONAME; something like libGL.so.1. If that library has any dependencies, they must also be available. Try running 'ldd /path/to/libGL.so.1' and see if there are any missing libraries. Also, make sure that you're pointing to the correct libGL; there could be a few versions on your system, each optimized for different graphics cards.

linking with cygwin1.dll

I have a little application running on Linux and want to port it to Windows. I found that with Cygwin i will be able to do it simple by linking the application with the cygwin1.dll library which make available a lot of the POSIX and other standard functions. I read the FAQ and the User Guide on the site of Cygwin but didn't find or didn't understand how can I link my source with this library.
My application uses GTK+ and I successfully compiled and link it on Windows with MinGW but I have to disable some of the functionality .Now that I find Cygwin I would like to link with it to make available again this functionality.
Generally you compile your source inside of Cygwin to produce the Windows binary. I'm pretty sure Cygwin will take care of linking to the proper dlls for you.
When you finally get the binary compiled, make sure that the cygwin1.dll is in the PATH specified by Windows.

anyway to write dlls in linux?

Is there anyway to write dlls in linux?
Do I have to install windows to write dlls in linux? Right now one of my courses requires me to write a dll for this.
You should take a look into 'shared libraries'
http://www.linux.org/docs/ldp/howto/Program-Library-HOWTO/shared-libraries.html
Lots of folks are getting near the right answer but not providing it: gcc can generate win32 PE/COFF files without problem, and of course can always build as a cross compiler on any platform it can target. The binutils port targets windows .exe and .dll files natively, and there's a "dlltool" utility for handling the edge cases where Unix and Windows linkage metaphors are different.
Additionally, the "mingw32" project provides a set of link libraries and header files for building C applications against the win32 API. These likewise install just fine on any Unix.
Here's a site I turned up after a quick google with instructions for building the toolchain.
Not really. Building any kind of executable intended for OS "A" while using OS "B" is a process commonly known as cross-compilation. In this partciluar case, you would need a cross-compiler running on Linux, but targetting Windows. I don't know any vendor selling such a product.

Resources