flat assembler
Message board for the users of flat assembler.

Index > Main > listing file, line numbers

Author
Thread Post new topic Reply to topic
Kicer



Joined: 30 Apr 2005
Posts: 34
Location: Poland
Kicer
Hi!

I've simple asm program compiled to binary file. For my project i need to find link between line in my asm source file and address (in memory) of this line.

ie some line of listing file:
Code:
0000004E: [0000000000007C4E] 90                                                       nop
    

i need to know which line of source file contains this instruction (with given address).
it i quite simple if i have asm source without includes: i can just count which line of listing file it is. But if i use include directive, then whole external file it is attached to listing file and i can't just count the lines.
is there simply method to solve it ?
Post 29 Apr 2010, 08:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17287
Location: In your JS exploiting you and your system
revolution
In the download file there is a folder called "TOOLS", in there is "LISTING.INC". With that you can output listing files.
Post 29 Apr 2010, 10:30
View user's profile Send private message Visit poster's website Reply with quote
Kicer



Joined: 30 Apr 2005
Posts: 34
Location: Poland
Kicer
revolution wrote:
In the download file there is a folder called "TOOLS", in there is "LISTING.INC". With that you can output listing files.


yes yes i know.
i'll try to explain my problem more exactly:

i've asm source, something like this:

Code:
include "includes/symulator.finc"

use16
org 0x7c00
      mov bx,cs
   mov ds,bx
   
    lgdt [gdt_header]
    


this is only a simple program, my main project is to write a 386 simulator with debuger etc.

In my simulator I'd like to highlight the source line with given address (with instruction being actually executed).
So in given example i wanna highlight mov bx,cs when my 386 cpu is executing instruction from address 0x7c00.
So i used listing tool, but it generated file that contains whole included file ("includes/symulator.finc") so i can't simply guess where is end of included file and where code, that i'm interested in, starts.
Post 29 Apr 2010, 11:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17287
Location: In your JS exploiting you and your system
revolution
Have a look at the .fas output file.

http://board.flatassembler.net/topic.php?t=9792
Post 29 Apr 2010, 11:15
View user's profile Send private message Visit poster's website Reply with quote
Kicer



Joined: 30 Apr 2005
Posts: 34
Location: Poland
Kicer
heh i seen it but i thought there will some solution like:
"use patch xxx for listing.asm. That add extra option -x which causes that include files won't be attached to output file" Wink

thx anyway Smile
Post 29 Apr 2010, 11:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17287
Location: In your JS exploiting you and your system
revolution
No one else has asked about it before.

It looks like you will need to patch the listing.inc file yourself.

Post the changes needed here, so others that need the same can benefit also.
Post 29 Apr 2010, 11:39
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
A very quick-and-dirty patch to show you the direction. Find the place in LISTING.INC that looks like this:
Code:
      write_file_offset:
        call    write_hex_dword
        mov     ax,': '
        stosw
        call    list_address
        call    list_code
        jmp     code_listing_ok    

and add this piece of code just before the "call list_address" line:
Code:
        test    byte [esi+7],80h
        jnz     @f
        mov     al,'{'
        stosb
        mov     edx,[esi+8]
        call    write_hex_dword
        mov     ax,'} '
        stosw
      @@:    

It will break the precious alignment of the listing, but should be a tiny little bit helpful - it insert the line numbers written in hex (and enclosed with braces) just before the code bytes listing.
Post 29 Apr 2010, 13:30
View user's profile Send private message Visit poster's website Reply with quote
Kicer



Joined: 30 Apr 2005
Posts: 34
Location: Poland
Kicer
thx, i'll test it
Post 29 Apr 2010, 19:25
View user's profile Send private message Reply with quote
Kicer



Joined: 30 Apr 2005
Posts: 34
Location: Poland
Kicer
hmmm it generates something weird:

Code:
                                                                                use16
                                                                                org 0x7c00
00000000: {00000034} [0000000000007C00] 8C CB                                                 mov bx,cs
00000002: {0000003F} [0000000000007C02] 8E DB                                                mov ds,bx
    

i'll try to analyze it in some free time Wink
Post 30 Apr 2010, 14:35
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Kicer,

Those numbers are offsets into source file at which corresponding line starts. If you need line numbers, use [esi+4] instead of [esi+8].
Post 30 Apr 2010, 19:32
View user's profile Send private message Reply with quote
Kicer



Joined: 30 Apr 2005
Posts: 34
Location: Poland
Kicer
Tomasz Grysztar wrote:
A very quick-and-dirty patch to show you the direction.


I'm having problem with this patch today , i guess it's related to my already solved problems:
http://board.flatassembler.net/topic.php?t=11789

if i apply your patch and use -a argument i got message that listing was interrupted and the file is cutted on first instruction:
Code:
00000000: {00000002} [0000000000007C00]      8C CB                                              
    


gdb says:
Code:
(gdb) run -a test2.fas test2.lst
Starting program: ./listing -a test2.fas test2.lst

Program received signal SIGABRT, Aborted.
0xffffe430 in __kernel_vsyscall ()
(gdb) 
    


it used to work perfectly.

something wrong with linking libc version of listing ?
in windows (the same fasm version and the same patch) it's working
Post 07 Aug 2010, 07:16
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.