Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Interpreting Assembly

by misc (Friar)
on Dec 01, 2019 at 21:41 UTC ( [id://11109516]=perlquestion: print w/replies, xml ) Need Help??

misc has asked for the wisdom of the Perl Monks concerning the following question:

Oh fellow monks,
I've digged the net for several hours now.

Strangely, I couldn't find what I'm looking for.

Essentially, I'd like to either interpret a C file with perl;
or interpret/convert the assembly generated by e.g. gcc.

Haven't been able to find anything yet.

So, I guess, compiling the c source to asm,
and converting the asm to perl might be the way to go.

Essentially creating a virtual x86 cpu, with ram, and so on might be trivial.

To my surprise, I didn't find anything at all.
Someone could please help me out?

(Background: I'm close to finishing sort of a cryptopad.
I believe, perl is the language of choice,
adding some obfuscation, self encryptiom, honeypots,
and even a full memory dump
might be a xdream to debug. :)

I'd like to add a small terminal editor.
Which I already have, written in C.
So, now there's the problem of how to be able running this editor
within perl..)

Best wishes, Michael

Addendum:
It's a personal project, and I did this before.
In the version I used for nearly 15 years I did the encryption stuff within perl,
and used vi as editor.

However, times have changed, and it might be possible to bruteforce the passwords nowaday
within reasonable time.

So I need a improved version,
and if concerned with security, it might be better going into full paranoia mode..
I'm also thinking about, what e.g. AI is able to do in 10 years.

So, at the moment, I believe I'm going to chain several encryption algorythms,
and take some precautions to prevent a brute force attack.
(Being in full paranoia mode, I shouldn't explain further..)

Replies are listed 'Best First'.
Re: Interpreting Assembly
by LanX (Saint) on Dec 01, 2019 at 21:59 UTC
    I once played around using Perl as a DSL for 6502 assembler.

    I basically represented every command as sub and had to fiddle out how to represent addressing modes as arguments.

    Like sub LDA {...}

    You'd need to transform the ASM syntax a little to make it valid Perl code.

    Can't tell much about x86, always hated addressing there after learning 68000.

    Not sure I understand what your goals are, but I hope this helps giving you an idea.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      The goal is to "port" an simple terminal text editor, written in C, to perl.

      Besides, ideally the resulting code should be a pain in the ass to understand.

      :)) the acme of wtf for the one, looking at the memory dump.

      Addressing I'm least concerned with.
      I believe, a simple perl string is enough for emulating the ram.

      Each register is a variable, and that's it.

      Strangely I wasn't able to find anything yet at all
        > Strangely I wasn't able to find anything yet at all

        Because it is a WTF idea? ;)

        If your sole intention is obfuscation, try giving XS or Inline::C a chance.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        > Addressing I'm least concerned with. I believe, a simple perl string is enough for emulating the ram.

        You might be confused what Addressing Modes are.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re: Interpreting Assembly
by marto (Cardinal) on Dec 04, 2019 at 16:02 UTC

    You may be interested in the perl advent calendar entry for today featuring FFI::Platypus: "Platypus is a library for creating interfaces to machine code libraries written in languages like C, C++, Fortran, Rust, Pascal. Essentially anything that gets compiled into machine code.".

      Thank for the link. It was a fun tutorial. Two minor issues:

      1. It doesn't tell you to save the shared lib with a .go extension.
      2. A few typos depict "WishMerryChristmas" as "MerryChristmas".

Re: Interpreting Assembly
by Anonymous Monk on Dec 01, 2019 at 23:49 UTC

    search dump

    Devel::PeekPoke - All your bytes are belong to us

    PeekPoke - Perl extension for reading and writing memory

    Inline::ASM - Write Perl Subroutines in assembler.

    Asm::X86 - List of instructions and registers of x86-compatible processors, validating and converting instructions and memory references. This module provides the user with the ability to check whether a given string represents an x86 processor register or instruction. It also provides lists of registers and instructions and allows to check if a given expression is a valid addressing m...

    BOGDRO/Asm-X86-0.29 - 24 Nov 2019 14:11:47 GMT

    FFI::Platypus::Lang::ASM - Documentation and tools for using Platypus with the Assembly Setting your lang to "ASM" includes no native type aliases, so types like "int" or "unsigned long" will not work. You need to specify instead "sint32" or "sint64". Although intended for use with Assembly it could also be used for other languages if y...

    PLICEASE/FFI-Platypus-1.01 - 16 Nov 2019 14:19:02 GMT

    CPU::Emulator::Z80 implements a Z80 emulator. See its manpage for nitty-gritty details about interfacing with it. This manpage, by contrast, serves as a HOWTO.

Re: Interpreting Assembly
by misc (Friar) on Dec 02, 2019 at 00:28 UTC
      .. having recherched further.

      There would be the MIPS I emulator, written in perl.
      And, things like retrobsd, a port to MIPS 4;

      Also other alien OS's.

      http://retrobsd.org/wiki/doku.php
      https://hackaday.com/2012/03/28/building-the-worst-linux-pc-ever/

      NUTTX could possibly even run at the Z80 emulator, written in perl.
      http://nuttx.org/doku.php?id=documentation:about


      This would increase the wtf-factor immensely, however, seems to me,
      the additional layer(s) give a clean separation, which don't add anything to obfuscation or security.

      I might give nuttx a try, just out of curiosity.

      But at the moment I believe I'm going to either compile the editor into MIPS asm,
      and write a "translator" to get perl code again.
      DSL might be another term for what I'm going to do, I didn't know the concept yet.

      Or I'll translate the texteditor from c to perl by hand.
      Overall, it's only about 600 loc, not counting comments.
      ;) btw., the link to the editor. https://github.com/michael105/et

        times have changed, and it might be possible to bruteforce the passwords nowaday within reasonable time.

        If I knew it was a text editor and that it's password protected, I might just write my own text editor in C. I don't really see the point of obfuscating a text editor. If you want to take over the world, there's got to be an easier way! LOL

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11109516]
Approved by LanX
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-19 17:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found