flat assembler
Message board for the users of flat assembler.

Index > Windows > Fasm x64 pe64 win32 program

Author
Thread Post new topic Reply to topic
B.Dubious



Joined: 04 Apr 2020
Posts: 17
B.Dubious
I've been trying to learn some assembly using fasm and windows. I've currently hit a wall, I've spent hours trying to debug this problem, I've gone off and studied some more and come back to it and still I can't figure it out. As far as I can see I'm giving it all the right things, and while before it was returning an error 6 using GetLastError I fixed the problem with the DC. I'm trying to use StretchDIBits but although it runs without error it returns zero, and the desired behaviour isn't achieved. I've tried stepping through the code again and again and again, I've checked all my parameters several times, but I just can't find the problem. It's truly driving me crazy. I've checked the sizes of the arguments and everything seems to be correct. Please advise...


Description: .data and .data sections
Download
Filename: main_data.asm
Filesize: 1.68 KB
Downloaded: 36 Time(s)

Description: main.asm file with .code section
Download
Filename: main.asm
Filesize: 3.88 KB
Downloaded: 35 Time(s)

Post 09 Apr 2020, 18:00
View user's profile Send private message Reply with quote
B.Dubious



Joined: 04 Apr 2020
Posts: 17
B.Dubious
Wait, I see what's probably my mistake... I'm using a bitmapinfoheader not a bitmapinfo... eejit. I'll try checking if that's the problem.
Post 09 Apr 2020, 18:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Since your code is very short, you can make it more accessible for people by pasting it directly into your message inside code tags.
Post 09 Apr 2020, 18:08
View user's profile Send private message Visit poster's website Reply with quote
B.Dubious



Joined: 04 Apr 2020
Posts: 17
B.Dubious
Sorry, I'll do that in future.
I had to stop for dinner but I've been trying to make the changes based on my thought that the bitmapinfo/bitmapinfoheader was the source of my problem, but I still can't get it going. I'll keep debugging for a while.

Is there a clean way to initialize to zero?
in c/c++ you can do
mystruct a = {};
and it would initialize the fields to zero. What's the proper way to initialize with fasm?

The reason I ended up using bitmapinfoheader before in the first place is because bitmapinfo isn't defined in the standard headers that ship with fasm, but bitmapinfoheader does. I've defined a struct using the same syntax that they use in the include with bitmapinfoheader and an rgbquad which i defined the same way as four bytes rgb reserved. But when I tried to initialize the bitmapinfo struct i was having trouble and it kept failing to build. currently i've just defined a new bitmapinfo struct with all the fields of bitmapinfoheadear and then four bytes at the end to be set to zero. It builds but it doesn't yet work.

Writing assembly that uses windows is more painful than I imagined. Hopefully as I get familiar with it there will be less friction...
Post 09 Apr 2020, 20:42
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
In assembly to zero out any memory buffer there is rep stosq. Set RAX=0, RCX the qword count, and RDI the destination. This is what many HLL libraries use to do the job, but they generally hide that from you.
Post 09 Apr 2020, 20:45
View user's profile Send private message Visit poster's website Reply with quote
B.Dubious



Joined: 04 Apr 2020
Posts: 17
B.Dubious
That's a cool tip, I can definitely make use of that. I think I've seen it before on godbolt or in the disassembly of some c/c++ when using a for loop to zero out a buffer, though I don't really look at it closely enough that I learned what that was until just now!
I don't think I can use that in the .data section though, in the .data section is everything zeroed by default? Like with static in c/c++ ?

If you set rax=n would that repeat the operation and initialize every quadword to n?
Post 09 Apr 2020, 20:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
If your .data section is writeable then you can zero it out at any time. Windows will initialise all undefined data as zero at startup, but there can be times when you need to re-zero things at runtime. This is assembly you can do whatever you want.

Setting RAX to some data pattern is fine. Usually zero is the most convenient, but you are free to set it to any value. The CPU won't care what you set it to, it just follows your instructions.
Post 09 Apr 2020, 21:12
View user's profile Send private message Visit poster's website Reply with quote
B.Dubious



Joined: 04 Apr 2020
Posts: 17
B.Dubious
I see, cool! I just wish I knew how to make it do the things I want it to do, haha

When setting struc's I'm a little confused. I can do something like the following:
struct v2i
x dd ?
y dd ?
ends

then if i had another struct that was two v2i fields, i can do this:

my_instance twovecs 0,0
but is there some short hand to set those structs?
my_instance twovecs {0,0}, {0,0}

or something along those lines, or do I have to define two separate v2i and then set those that way like:
my_instance twovecs v1, v2
Post 09 Apr 2020, 21:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Let's be clear here. struct with a final "t" is a macro in the fasm package. But struc without the find "t" is the raw structure that uses curly brackets {} to define it. They operate differently.

Also, if you are allocating the structure at runtime then you need to set the values in your code. But if you are instantiating the structure at assembly time then the initial values can be set in the structure.

So we need to differentiate those situations to know how to write the code.
Post 09 Apr 2020, 21:29
View user's profile Send private message Visit poster's website Reply with quote
B.Dubious



Joined: 04 Apr 2020
Posts: 17
B.Dubious
Sorry about using them interchangeably! I'm using the struct/ends to define the windows types, but for my own side of things I'm using a struc{} to define a draw_buffer, which has dimensions, a pointer to the pixel buffer, and a pointer to the BITMAPINFO struct/ends that is just a copy paste of the BITMAPINFOHEADER from the fasm includes with four additional bytes I intend to leave zeroed. I was wanting to defined the struct/ends to have another struct/ends as a field, then have a pointer to that in my struc{}

I call an Init proc early on at runtime, but I'd like to know how to initialise at assembly time cleanly too.

I was hoping to know how to do something of the sort:

struct v2i
x dd ?
y dd ?
ends

struct bounds
upperLeft v2i ?
lowerRight v2i ?
ends

when initialising bounds in the .data section I can do

mybounds bounds 0,0
but I don't know how to set the fields of the v2i's

Other than the use of ? and the names and . what are the differences between struc{} and struct/ends
Post 10 Apr 2020, 17:14
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 344
Ali.Z
i hope this help:

- struc
- struct

_________________
Asm For Wise Humans
Post 10 Apr 2020, 23:32
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
For defined data in an initialised section you can do this:
Code:
struct v2i
x dd ?
y dd ?
ends

struct bounds
upperLeft v2i ?
lowerRight v2i ?
ends

mybounds bounds <0xa5a5a5a5,0x5a5a5a5a>,<0xc3c3c3c3,0xb1b1b1b1>    
Post 10 Apr 2020, 23:49
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:  


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

Powered by rwasa.