Run assembly scripts from your terminal without compiling

Source code:


<span style="color:#323232;">#!/usr/bin/env bash
</span><span style="color:#323232;">
</span><span style="color:#323232;"># runasm - Assemble, link, and run multiple assembly files, then delete them.
</span><span style="color:#323232;">if [[ $# -eq 0 ]]; then
</span><span style="color:#323232;">    echo "Usage: runasm  [ ...]"
</span><span style="color:#323232;">    echo "  - Assemble, link, and run multiple assembly files, then delete them."
</span><span style="color:#323232;">    echo "  - Name of executable is the name of the first file without extension."
</span><span style="color:#323232;">    exit 1
</span><span style="color:#323232;">fi
</span><span style="color:#323232;">
</span><span style="color:#323232;">object_files=()
</span><span style="color:#323232;">executable_file=${1%.*}
</span><span style="color:#323232;">
</span><span style="color:#323232;">for assembly_file in "$@"; do
</span><span style="color:#323232;">    # Avengers, assemble!
</span><span style="color:#323232;">    object_file="${assembly_file%.*}.o"
</span><span style="color:#323232;">    as "${assembly_file}" -o "${object_file}"
</span><span style="color:#323232;">    if [[ $? -ne 0 ]]; then
</span><span style="color:#323232;">        exit 1
</span><span style="color:#323232;">    fi
</span><span style="color:#323232;">    object_files+=("${object_file}")
</span><span style="color:#323232;">done
</span><span style="color:#323232;">
</span><span style="color:#323232;"># Link
</span><span style="color:#323232;">ld "${object_files[@]}" -o "${executable_file}"
</span><span style="color:#323232;">if [[ $? -ne 0 ]]; then
</span><span style="color:#323232;">    exit 1
</span><span style="color:#323232;">fi
</span><span style="color:#323232;">
</span><span style="color:#323232;"># Run, remove created files, and return exit code
</span><span style="color:#323232;">./"${executable_file}"
</span><span style="color:#323232;">exit_code=$?
</span><span style="color:#323232;">rm "${object_files[@]}" "${executable_file}" > /dev/null 2>&amp;1
</span><span style="color:#323232;">exit "${exit_code}"
</span>
RastislavKish,

Perhaps we should reconsider the definition of write-only scripts.

otl,
@otl@lemmy.sdf.org avatar

I’m still super confused by this user’s posts lol. I get that (some? most?) of it is satire… but then why all social media engagement farming hashtag nonsense? Or is this all part of the satire…?

OmnipotentEntity,
@OmnipotentEntity@beehaw.org avatar

Putting aside the misleading title…

Because this writes to and then runs an executable file with a known name, this script should never be used on a multiuser system in a directory where another user has write permissions. It is vulnerable to a timing attack where the attacker copies an executable they want run with your permissions between this script creating the file and running it.

sir_reginald,
@sir_reginald@lemmy.world avatar

I was going to click on this until I saw it was a video.

Poe,

Isn’t the whole point of assembly that there is no compiler?

stardreamer,
@stardreamer@lemmy.blahaj.zone avatar

I mean they’re not wrong…

This is why my next book will be titled “how to cook dinner without a compiler, GCC 4 to GCC 11 compatible!”

SpaceNoodle,

Right, they just use an assembler and a linker …

jsdz,

I have two reactions: 1. The headline is rather silly. 2. There’s no way this little script, although it might conceivably be useful to someone, needs to be a youtube video.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • linux@lemmy.ml
  • GTA5RPClips
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • Durango
  • cubers
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • ngwrru68w68
  • kavyap
  • tacticalgear
  • ethstaker
  • JUstTest
  • InstantRegret
  • Leos
  • normalnudes
  • everett
  • khanakhh
  • osvaldo12
  • cisconetworking
  • modclub
  • anitta
  • tester
  • megavids
  • provamag3
  • lostlight
  • All magazines