An Assembler Question

Questions about programming languages and debugging
Post Reply
User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

An Assembler Question

Post by maboroshi »

Here is an example of Python Assembler for use as a Shellcode example

Code: Select all

from pyasm.x86asm import assembler
from pyasm.x86cpToCoff import *

a = assembler()
a.AP("_main")
a.AI("XOR EAX, EAX")
a.AI("MOV EBX, 0x7d4d14e0")
a.AI("MOV AX, 5000")
a.AI("PUSH EAX")
a.AI("CALL EBX")
a.EP()

cp = a.Compile()
coff = CpToCoff(cp).makeReleaseCoff()
f = file("D:\\worktests\\obj.obj", "wb")
coff.WriteToFile(f)
f.close()
This outputs an obj file when dumped with objdump returns some hex code

This next piece of code returns a different hex value I am guessing because it is a different assembler, "Nasm" and different output format elf instead of CDECL

Code: Select all

;sleep.asm
[SECTION .text]

global _start


_start:
        xor eax,eax
        mov ebx, 0x7d4d14e0 ;address of Sleep
        mov ax, 5000        ;pause for 5000ms
        push eax
        call ebx        ;Sleep(ms);
My question is do they do the same thing? it would seem they do but I just need some help to verify by someone familiar with Assembler

User avatar
blackice116
Newbie
Newbie
Posts: 2
Joined: 29 Aug 2006, 16:00
17

Post by blackice116 »

although im not super famillier with python, if it just outputs the opcodes of the instructions you pass it, then it should do the same thing as nasm

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

cool

Post by maboroshi »

Cool, thanks for verifying. And welcome to suck-o

Cheers


Maboroshi

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

yep, as you've guessed the difference in hex values is due to different assemblers, assembly is one level above machine language so still two assemblers CAN have some dissimilarities(only little though)

like your python assembler's code starts from

Code: Select all

from pyasm.x86asm import assembler
from pyasm.x86cpToCoff import *

a = assembler()
a.AP("_main") 
....
nasm:

Code: Select all

[SECTION .text]

global _start


_start: 
...
That's the reason for different hex codes.
:wink:

p.s sorry for late reply, been very busy lately

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

No worries

Post by maboroshi »

No worries pseudo thanks for the detailed info cheers maboroshi ;)

Post Reply