flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Examples and Tutorials > BASELIB: General purpose libs for beginners

Goto page Previous  1, 2, 3, 4, 5, 6, 7
Author
Thread Post new topic Reply to topic
fasmnewbie



Joined: 01 Mar 2011
Posts: 418
The ability to manipulate the memory directly is essential to X86 programmers. For that reason, I've introduced the "memview2" routine, as a small enhancement to current "memview" routine. This routine will also display the offsets, both in hex and decimal format, in addition to the addresses. This will enable a user to see the content of a memory and go to / manipulate a specific offset directly.

Now that the offsets is clearly visible, I've added "mem_insert" routine to enable one to insert any code or data of any size to a specific offset. This is even more effective if used in combination with "mem_load", like for example, you want to load a DLL. But I'm not going to show that here.

Below is a simple example, featuring both "memview2" and "mem_insert" combo, to extend a 0-ended string, past its 0 delimiter.


Code:
format PE64 console
include 'win64axp.inc'
entry main

section '.data' data readable writeable
msg db 'Hello Dunia. Apa khabar?',0ah,0
insert db 'Terima Kasih.',0

section '.code' code readable executable
main:
        mov     rbx,50h  ;size to view
        mov     rax,msg  ;starting address
        call    memview2 ;view mem + offsets

        mov     rdx,15
        mov     rcx,insert
        mov     rbx,25   ;insert starts at offsets 25
        mov     rax,msg
        call    mem_insert ;append string by overwriting 0 from msg

        call    prnline

        mov     rbx,50h
        mov     rax,msg
        call    memview2

call halt
call exitx



With this output: CONTENT | Address | Hex offset | Dec Offset



Code:
75 44 20 6F 6C 6C 65 48 |00000000004010000|0  ;initial memview2 output
61 70 41 20 2E 61 69 6E |00000000004010088|8
3F 72 61 62 61 68 6B 20 |000000000040101010|16
61 6D 69 72 65 54 00 0A |000000000040101818|24 ;byte 25 is 0. 
00 2E 68 69 73 61 4B 20 |000000000040102020|32
00 00 00 00 00 00 00 00 |000000000040102828|40
00 00 00 00 00 00 00 00 |000000000040103030|48
00 00 00 00 00 00 00 00 |000000000040103838|56
00 00 00 00 00 00 00 00 |000000000040104040|64
00 00 00 00 00 00 00 00 |000000000040104848|72

75 44 20 6F 6C 6C 65 48 |00000000004010000|0
61 70 41 20 2E 61 69 6E |00000000004010088|8
3F 72 61 62 61 68 6B 20 |000000000040101010|16
20 61 6D 69 72 65 54 0A |000000000040101818|24
00 00 2E 68 69 73 61 4B |000000000040102020|32
00 00 00 00 00 00 00 00 |000000000040102828|40
00 00 00 00 00 00 00 00 |000000000040103030|48
00 00 00 00 00 00 00 00 |000000000040103838|56
00 00 00 00 00 00 00 00 |000000000040104040|64
00 00 00 00 00 00 00 00 |000000000040104848|72



Hope this is useful.
Post 15 Jul 2017, 19:08
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 418
I just finished creating a minimal "sbase32w.asm" version of Win32 BASELIB source. Well this one is a very basic version (but working), missing many other functions of the original "sbase32w.asm".

Major difference: This one is developed by using high-level features of FASMW (proc, invoke, stdcall, .if etc).

I don't personally like it due to its high-level nature... but I think ignoring FASM's high-level features completely is not 'productive' either. Some day, you'd be required to come up with Line of Code (LOC) "costing" and knowing some of the high-level features would come handy.

But contrary to popular belief, ASM high-level features are actually NOT for beginners no matter how friendly they look. High features are for those who already appreciated how they work at the low-level layer. If you prefer the low-level, just download BASELIB at the first post.

Good luck with this one. Correct the bugs yourself Very Happy


Description: sbase32w.asm reloaded, with high-level features.
Download
Filename: bkernel.asm
Filesize: 42.46 KB
Downloaded: 20 Time(s)



Last edited by fasmnewbie on 18 Oct 2017, 10:11; edited 9 times in total
Post 06 Oct 2017, 18:16
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6597
Location: Kraków, Poland

fasmnewbie wrote:
But contrary to popular belief, ASM high-level features are actually NOT for beginners no matter how friendly they look. High features are for those who already appreciated how they work at the low-level layer. If you prefer the low-level, just download BASELIB at the first post.

A very wise words. I'd like to emphasize this myself - if you use high level without enough knowledge of what is under the hood, you're going to use it like a whimsical black box that can blow up any minute because you do not really know what it ends up doing in the low level.
Post 06 Oct 2017, 18:30
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 418
Thanks for the support Tomasz. I can see similar trend from the likes of MASM when they dropped some of the high-level features which were once crucial in 32-bit ML. Like "invoke" and .IF/.ENDIF. Microsoft decided to back to the low-level approach.
Post 13 Oct 2017, 18:28
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 418
Just added a new Win64 source file (core64.asm). This source is an equivalent of BASELIB's "base64w.asm", targetted for Win64. The source is in FASM syntax only. File is added in "core.zip" on Page 1.

The differences from "base64w.asm":

1. Partially ABI compliance.
2. Rely only on kernel32 as the main external.
3. Most of the routines now are callable from high-level languages, except those requiring XMM returns and arguments. (This is a future project, if I have time)
4. Routine changes:

Added
----------
mem_alloc2
mem_free2
dble2str
file_delete

Discarded
----------
memview2
memviewb
prnbinf
prndblr
prnfltr

Warning: Still quite ugly and could be buggy. "base64w.asm" and "core64.asm" although similar in functions, are not compatible with each other.

Linux64 version is on the horizon. Can't promise that soon, anyway Wink
Post 13 Oct 2017, 18:31
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 418
Updated the "bkernel.asm" above. Just finished with "fpu_stack".

Bug report: I think FASM's proc32 or stdcall scratches EDX when called/used from within a function and addressing local data via "ADDR" operator. Using the library provided above, here's how the issue emerges (observe dumpreg output of EDX);


Code:
format PE console
include 'win32axp.inc'
entry main

section '.data' data readable writeable
h db 'hello world',0ah,0

section '.text' code readable executable
main:
        call    foo

        ;mov     edx,-13
        ;call    dumpreg
        ;stdcall prnstrz,h       ;these, do not
        ;call    dumpreg

        call    halt
        call    exitx

;--------------------------
proc foo
     locals
        h db 'Hello World',0ah,0
     endl
        mov     edx,10h
        call    dumpreg

        stdcall prnstrz,addr h  ;this clobbers edx

        ;lea     edi,[h]
        ;stdcall prnstrz,edi     ;these do not

        call    dumpreg
        ret
endp

Post 16 Oct 2017, 13:29
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6597
Location: Kraków, Poland
See Windows header documentation, section 2.1:

Quote:
If the parameter is preceded by the addr word, it means that this value is an address and this address should be passed to procedure, even if it cannot be done directly - like in the case of local variables, which have addresses relative to EBP/RBP register. In 32-bit case the EDX register is used temporarily to calculate the value of address and pass it to the procedure.

Post 16 Oct 2017, 13:50
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 418
Ok, got it.

Thought it was a bug.
Post 16 Oct 2017, 13:57
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 418
I re-uploaded the "bkernel.asm" above to demonstrate the use of "DUP(x)" inside a LOCALS...ENDL instead of plain "RB" (reserve byte). Already has a lot of RB in there, but no DUP. If you know any other high-level features that can be included, do modify and share. Thanks.
Post 16 Oct 2017, 14:20
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5, 6, 7

< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.