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: 399
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
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.