Showing posts with label assembly. Show all posts
Showing posts with label assembly. Show all posts

Thursday, August 03, 2023

Sun SPARC binaries back to C source code

from h2oGPT [Model: llama] 

Yes, it is possible to reverse compile Sun SPARC binaries back to C source code using a tool called "objdump". Objdump is a command-line utility that comes with most Unix-like operating systems and can be used to disassemble machine code into assembly code or source code.

Here's an example of how to use objdump to reverse compile a Sun SPARC binary:

  1. First, you need to find the binary file you want to reverse compile. Let's assume you have a binary file called "myprogram" that you want to reverse compile.
  2. Open a terminal and navigate to the directory where your binary file is located.
  3. Use the following command to disassemble the binary file into assembly code:
    objdump -D myprogram
    This will produce an assembly code file called "myprogram.s" that contains the assembly code for the binary program.
  4. To reverse compile the assembly code back to C source code, you can use a tool called "gas". Gas is a GNU assembler that can take assembly code as input and generate C source code as output.
    Use the following command to reverse compile the assembly code:
    gas -C myprogram.s -o myprogram.c
    This will produce a C source code file called "myprogram.c" that contains the original C source code for the program.
    Note: The -C option tells gas to generate C source code, and the -o option specifies the output file name.
  5. Finally, you can compile the C source code using a C compiler like GCC to produce an executable file.
    For example, you can use the following command:
    gcc -o myprogram myprogram.c
    This will produce an executable file called "myprogram" that runs the original program.
    It's worth noting that the reverse compilation process may not always work perfectly, especially if the binary code has been heavily optimized or obfuscated. In some cases, the resulting C source code may contain errors or be difficult to understand. Therefore, it's important to use objdump and gas with caution and only for educational or debugging purposes.

(ChatGPT4) - response to the above



I'm afraid there might be some misunderstanding here. objdump and gas do not work quite as described in your example. Allow me to clarify:

  • objdump is indeed a very powerful tool, but it's not a decompiler. It can disassemble binary code into assembly code, not into C source code. The assembly output can be used for further reverse-engineering tasks, but turning that into high-level C code is a much more complex task. There's no direct option in objdump to generate C source code from a binary or assembly.

  • gas, the GNU Assembler, is used to convert assembly language into machine code, not to convert assembly into C code. It cannot generate C code from assembly code.

There are decompilers available that attempt to generate high-level language code (such as C) from binary, but they are often complex to use, imperfect, and the output requires a fair amount of manual interpretation and reworking. For example, Ghidra, an open-source software reverse engineering suite developed by the NSA, includes decompiling capabilities.

Recompiling the decompiled C code also does not ensure the same functionality, as many details about the original implementation can be lost during the initial compile process (such as variable names, specific optimization decisions, etc.).

Please also note the legal and ethical implications of decompiling software, as I mentioned in my previous response.


ME: Are there Sparc decompilers by now?



As of my last training data in September 2021, there were no decompilers specifically designed for the SPARC architecture that could generate high-level C code. However, you may use disassemblers like objdump or radare2 to translate machine code into assembly instructions for analysis and understanding. For decompiling to higher level languages like C, one of the more powerful tools is Ghidra, developed by the National Security Agency (NSA) of the United States. Ghidra supports a wide range of processor instruction sets and executable formats, but you would need to check if it has updated to support the SPARC architecture specifically. Please remember that decompiling is a complex process and the output will not look like the original C code. Much information (such as variable names, comments, and specific structure of the original code) is lost during compilation, and won't be restored by decompilation. Moreover, remember the legal and ethical implications of decompiling software without explicit permission. Decompiling is considered a form of reverse engineering and can potentially infringe copyright laws or end-user license agreements.


Saturday, February 22, 2014

Is this a Joke? Web development with Assembly




The more I looked the cooler this is though.  Suddenly a solid C platform that I can compiled C code and run in a remote browser.    What's been done so far is incredible, and I think it's the underlying engine for many future UI and VR experiences.


WebAssembly (Wasm) is an universal low level bytecode that runs on the web. It is a compilation target for languages like Rust, AssemblyScript (Typescript-like), Emscripten (C/C++), and much more! Wasm offer a compact binary format with predictable performance, and portability to run alongside Javascript and other host languages. Wasm is currently shipped in all major browsers, and has runtimes meant for running on servers or interfacing with systems using WASI.
https://wasmbyexample.dev/

Emscripten is a toolchain for compiling to asm.js and WebAssembly, built using LLVM, that lets you run C and C++ on the web at near-native speed without plugins.
https://emscripten.org/


Introducing Emscripten
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Emscripten/Introducing





WebAssembly Literacy   Google DOC - Ebook

You want to learn WebAssembly (Wasm) for coding web apps in [replace by your favorite language] instead of Javascript and are not interested by the WebAssembly Text Format (WAT) : THIS EBOOK IS NOT FOR YOU !
Indeed, there’re already many great tutorials about the amazing Emscripten project (C/C++) or about Rust or Go in order to enter new realms of web development without javascript and capitalizing on existing code bases.

Else you know javascript but not very well (use it just for jQuery plugins) : THIS EBOOK IS VERY PROBABLY NOT FOR YOU !


Thursday, September 15, 2011

Program Android apps using Assembly?

On Hack-A-Day
Have you got what it takes to code Android apps using Assembly?

Do you have a rooted Android device and a computer running Linux? If so, you’re already on your way to coding for Android in Assembly. Android devices use ARM processors, and [Vikram] makes the argument that ARM provides the least-complicated Assembly platform, making it a great choice for those new to Assembly programming. We think his eight-part tutorial does a great job of introducing the language and explaining how to get the development tools up and running. You’ll need to know some basic programming concepts, but from what we saw you don’t need any prior experience with ARM or Android.
So why learn Assembly at all? We took a stab at Assembly for AVR a few months ago and really learned a lot about the hardware that we just never needed to know writing in C. It’s a great way to optimise functions that waste too much time because of quirks with higher-level language compilers. That means you don’t need to write your entire application in Assembly. You can simply use it to streamline hairy parts of your code, then include those Assembly files at compile time.