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 > Linux > fasdump : program to dump contents of fas files

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
fasdump : program to dump contents of fas files
Hi all,

To teach myself the structure of the fas file format, I whipped up a small program to display the contents of these symbolic info files (generated with fasm -s). I wrote it in C because I'm more familiar with C than with assembly, though I'm planning on converting it to assembly later.

Just in case this is useful to anyone, maybe as a sort of readelf/objdump like utility, I'm posting it here. I've tried to keep it as portable as possible (C99), but I've only tested it on linux/elf. If anyone has any questions or finds any bugs, just let me know.


Description:
Download
Filename: fasdump.tar.gz
Filesize: 5.13 KB
Downloaded: 99 Time(s)

Post 04 Apr 2009, 21:38
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7111
Location: Slovakia
I don't think it is anyhow important to convert it into assembly. You will just lose portability.
Post 05 Apr 2009, 10:05
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
Yes, that's true, but it just feels like cheating when posting a C program on an assembly forum Smile

Anyway, I thought it might be a good exercise for myself, because even though it's a simple C program it will be a lot harder for me to do it in assembly when I have to do without printf(), malloc() etc. The absence of a standard library will force me to write some useful asm routines (or start to use an assembly library Smile ).
Post 05 Apr 2009, 19:05
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6198
Location: Kraków, Poland
I've added it to the official list.
Post 05 Apr 2009, 21:00
View user's profile Send private message Visit poster's website Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
Wow thanks, I made the official list Shocked Now to hope that no horrible bugs are discovered Smile
Post 05 Apr 2009, 21:07
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7111
Location: Slovakia
Or you can just call standard C library from assembly. (Since libc is only defined at C source code level, and doesn't have ABI, you may need to include a very thin layer to achieve portability between various libc implementations. But that is not a problem)
Post 05 Apr 2009, 21:29
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
Well, this is something I've been thinking about (and maybe will start another thread about), what std library to use for assembly programming: libc, an asm lib, or write everything from scratch? On one hand, I think if you use libc, then why not just write in C, right? With today's compilers, for probably like 95% of the time, you get code that is very acceptable when compared to hand-coded assembly. On the other hand, writing everything from scratch would take an awful long time before you get a 'workable' library and can start to speed up your assembly development. Maybe something like a libasm is the solution?
Post 05 Apr 2009, 21:58
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2149
Location: Estonia
I'm having quite a few problems with your code:
1) There's no getopt.h on my machine and seems that its not even C99, but some call it POSIX?!

After I got my GNU C header from the net, I stumbled on another problem:
2) inttypes.h missing from my maching Sad
Seems that Intel Compiler isn't C99 compliant, though my string is: "icl /Qstd=c99 fasdump.c"
After I got my hands on Visual Studio's C9x inttypes.h, there was a third problem...
3) It needed the stdint.h file, but this was made by Paul Hsieh

Now the headers are a total mess Very Happy because I couldn't find the right ones and the result is something like this:

EDIT: I posted my improvements in the next post.


Last edited by Madis731 on 06 Apr 2009, 07:51; edited 1 time in total
Post 06 Apr 2009, 06:37
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14504
Location: WTC Building 7
Is there an SSSO version of C? Twisted Evil
Post 06 Apr 2009, 06:50
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2149
Location: Estonia
Yeah I've wondered that myself too. They say C is portable. My a$$ it is Smile I went the lengths of downloading some GNU C headers (they're not easily available and now I've got myself a Cygwin, but these headers don't make life easier:
EDIT:

Step-by-step:
1) List of files:
fasdump.c
fasdump.h
getopt.h
getopt.c
inttypes.h
stdint.h
getopt.c
2) icl /c /Qstd=c99 getopt.c
Files added:
+getopt.obj ~3KB
3) icl /Qstd=c99 fasdump.c /link getopt.obj
Files added:
+fasdump.obj ~30KB

Only one dependancy remaining:

Code:

D:\>icl /Qstd=c99 fasdump.c /link getopt.obj
Intel(RC++ Compiler for applications running on Intel(R64Version 10.1    B
uild 20080312 Package IDw_cc_p_10.1.021
Copyright (C1985-2008 Intel Corporation.  All rights reserved.

fasdump.c
fasdump.c(273): warning #181argument is incompatible with corresponding format
 string conversion
                printf("%-*s %-*s %-*s %s\n"sizeof(s_name), s_name,
                                              ^

fasdump.c(274): warning #181argument is incompatible with corresponding format
 string conversion
                        sizeof(s_dsize), s_dsizesizeof(s_sectn), s_sectn,
                        ^

fasdump.c(274): warning #181argument is incompatible with corresponding format
 string conversion
                        sizeof(s_dsize), s_dsizesizeof(s_sectn), s_sectn,
                                                  ^

Microsoft (RIncremental Linker Version 8.00.40310.39
Copyright (CMicrosoft Corporation.  All rights reserved.

-out:fasdump.exe
getopt.obj
fasdump.obj
fasdump.obj : error LNK2019unresolved external symbol getopt_long referenced i
n function main
fasdump.exe : fatal error LNK11201 unresolved externals




I will post a solution if I ever get to that Wink
Maybe this source compiled for Cygwin and executed under Windows will work? Still there's the problem of getting it to compile...
Post 06 Apr 2009, 07:35
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7111
Location: Slovakia
C99 is in fact a bad idea for portability. For example, one of reasons would be that none of existing compilers supports it completely to date. The real standard is C89/C90, and even that has some problems (MSVC doesn't support some of quite important features, like stdint or getopt).

Madis: I'd suggest you to download mingw C++ (that is GNU C++ ported to win32, not cygwin), and use that to compile linux C code.

buzzkill: Your chain of thoughts leads to the conclusion everyone arrives to after some time: for most of applications today writing them in asm is not a best idea. Exceptions are things where size of code really matters (firmware), or computationally difficult tasks where speed needs to be completely maxed out (distributed computing, like SETI@Home or Folding@Home). In most such cases, reasons for using assembly are also reasons not to use any generic code library, but to craft all code for your specific purpose. Otherwise, with just _knowing_ assembly and writing C code, you are in most cases more productive, with only insignificant decrease in size/speed of resultant code.
Post 06 Apr 2009, 08:12
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2149
Location: Estonia
Okay, got it working. I dl-ed the MinGW and ran gcc. <errno.h> is not needed. Makes the executable double the size (28 vs. 56KB).
fasmdump will output some macro-magic example just fine, but the EFI-example hangs for a few seconds and I guess it ends with some memory violation.
Post 06 Apr 2009, 09:35
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
Madis731,

Sorry to hear you're having problems with the code, I should have made it clearer that it was intended for *nix as-is, and would need some work on other platforms. Something like eg getopt is used in pretty much all linux cli programs, so I didn't go through the trouble of developing another cross-platform solution myself. errno.h is needed for me, for "errno" in line 464, I don't know why you don't need it. inttypes.h is C99, and includes stdint.h.

If you, or anybody else, wants to port fasdump to other platforms, please do, I only have access to linux atm.

Can you post the "EFI-example" you mention, so I can test this myself?


vid:
Yes, that sums it up nicely. That's also the reason why I wrote fasdump in C instead of asm. Still, it's fun to program in assembly, even if it is just small, educational programs.
Post 06 Apr 2009, 12:25
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 208
Location: Budapest, Hungary
Is defining variables in header file just another phantasmagoria of yours or is there also any reason for it?
Post 08 Apr 2009, 10:13
View user's profile Send private message Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
Don't get your panties in a wad, it's just some sloppy cut-n-pasting going from src->src+header. And in this case the result is the same, so it doesn't really matter, but yes, this time you've actually got a valid point, the globals are in the wrong place.
Post 08 Apr 2009, 17:13
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2149
Location: Estonia
Post 08 Apr 2009, 17:15
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands

Madis731 wrote:



Hmm yes, that's not an elf binary, so I'm not surprised it doesn't work. My little program only handles elf binaries on linux, that's why I posted it in the linux section of the forum. Since I only run linux myself, that means that if anybody wants support for other platforms/binary formats, they will have to add this themselves. So I'm sorry if this is not what you wanted to hear, but my program was only written to teach myself about the fas format (as it applies to elf), nothing else. I tried to make this clear in my initial post.

Tomasz: perhaps you should either remove this program from your official list, or else add a warning that it's linux/elf only?
Post 08 Apr 2009, 18:16
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6198
Location: Kraków, Poland
I changed the description.
Post 08 Apr 2009, 18:40
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2149
Location: Estonia
Don't worry, buzzkill, as you may have read, the source finally compiled when I downloaded the right tools Wink So that is a No-Bug...

I understood that this is Linux/ELF-only, but still one could use that program with simple binaries (headerless) files, as I did with a macro-based image generator. The output isn't very useful, but still... Very Happy it works!
Post 09 Apr 2009, 15:47
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
Glad to hear you get some use out of it Smile
Post 09 Apr 2009, 16:46
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

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