Skip to content

Instantly share code, notes, and snippets.

main ()
{
    /* Are we little or big endian? Originally from Harbison and Steele. */
    union {
        long l;
        char c[sizeof (long)];
    } u;
    u.l = 1;
    exit (u.c[sizeof (long) -1] == 1);
@jstaursky
jstaursky / GAS-asm-to-raw-binary.org
Last active December 14, 2020 18:18
GAS to hex, RAW binary instruction, instruction to binary, GASM

How to compile AT&T assembly syntax to binary (not as an ELF file) using GNU GAS assembler as

;; File example.s (MUST end in '.s' otherwise GAS assembler 'as' won't recognize)

.code32  ;; Not needed, still must compile asm w/ the 32 bit options regardless.
         ;; Only included as a reminder that this is 32 bit binary code.

.global _start
@jstaursky
jstaursky / compiling_asm.md
Created December 14, 2020 17:08 — forked from yellowbyte/compiling_asm.md
how to assemble assembly with NASM assembler to 32-bit or 64-bit ELF binary with or without libc

32-bit ELF binary

how to assemble and link:

nasm -f elf32 -o <filename>.o <filename>.asm
ld -m elf_i386 -o <filename> <filename>.o

template code (hello world):

section .text
global _start
@jstaursky
jstaursky / c-program-with-no-glibc.org
Last active January 16, 2021 19:18
IA32, 32-bit, x86

C lang program w/out glibc

SYSV ABI requirement

See http://www.sco.com/developers/devspecs/abi386-4.pdf page 54 for diagram. This tells us 1 implementation of the stack layout of a SYSV compliant system (At the moment the only one I am aware of). However the spec. mentions this to only be a potiential implementation that is complient. To quote,

Argument strings, environment strings, and the auxiliary information appear in no specific order within the information block; the system makes no guarantees about their arrangement

/*
* tl;dr: C program initialization, written in C!
*
* This applies to an executable dynamically linked with glibc.
* It is current as of glibc 2.26.
*
* A LOT of information has been omitted for simplicity; hell,
* some of it might be flat-out wrong (I wrote this after about
* 3 hours of experimenting with GDB). If you want to know EXACTLY
* what goes on under the covers, I advise you to read the
// Credit: https://stackoverflow.com/questions/189725/what-is-a-trampoline-function
#include <stdio.h>
typedef struct _trampoline_data {
void(*callback)(struct _trampoline_data*);
void* parameters;
} trampoline_data;
void trampoline(trampoline_data* data) {

May only need sudo apt-get install libc6-dev-i386 gcc-multilib g++-multilib but if there is a version mismatch between this gcc and the x64 gcc then there will be issues. So check update-alternatives --config gcc and use that info to find gcc-<version>-multilib and then install it.

credit to https://askubuntu.com/questions/453681/gcc-wont-link-with-m32

First make sure you install the dependencies

  • cmake
  • sudo apt install llvm-11 libclang-11-dev llvm-11 llvm-11-dev llvm-11-runtime llvm-11-tools

(may or may not be missing one, but they are all in the repositories, no need to manually install or build from src)

  1. git clone https://github.com/Andersbakken/rtags
  2. git submodule init
  3. git submodule update

and finally,


@jstaursky
jstaursky / README.org
Last active September 7, 2022 20:04
Ghidra plugin development with emacs
  1. Need to create ghidra.jar and place into the lib directory.
  2. run below script to create the directory structure
  3. put the following contents in the src/main/java/MyProject.java file
    import ghidra.app.script.GhidraScript;
    
      public class MyProject extends GhidraScript {
    
      @Override
      public void run() throws Exception {
        

Simplest java maven hello-world style project.

  1. create the directory structure

mkdir -p tutorial/src/main/java/hello then touch tutorial/src/main/java/hello/Main.java

  1. put in the java file tutorial/src/main/java/hello/Main.java
package hello;
public class Main {