flat assembler
Message board for the users of flat assembler.

Index > Windows > [solved] Incorrect memory allocation

Author
Thread Post new topic Reply to topic
GREYSERGING



Joined: 03 Oct 2022
Posts: 4
GREYSERGING 03 Oct 2022, 09:05
Data section:
Code:
boundary db 8 dup (0)
header db 53 dup (0)
send_data dd ?
GetProcessHeapMem dd ?    

At the beginning of the program, I allocate memory to the send_data variable
Code:
invoke GetProcessHeap
mov [GetProcessHeapMem],eax
invoke HeapAlloc,[GetProcessHeapMem],0,1024
mov [send_data],eax    

Then I form a header to send the POST
Code:
invoke memcpy, header, header_no_boundary, 44
invoke memcpy, header + 44, boundary, 8

invoke memcpy, send_data, data1, 2
invoke memcpy, send_data + 2, boundary, 8
...    

And I'm sending it
Code:
invoke HttpSendRequestA, [hora], header, 52, send_data, 110    

The header itself is sent successfully, but send_data is not sent, I cannot allocate send_data fixed memory since the data can be either several kilobytes or hundreds of megobytes, but if I do so
Code:
send_data db 1024 dup (0)    

Then everything went well, I suspect that the problem is in HeapAlloc, but I can't say for sure, so tell me what's the matter?
Post 03 Oct 2022, 09:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20623
Location: In your JS exploiting you and your system
revolution 03 Oct 2022, 09:13
You are using send_data as both a buffer and a pointer.

Try something like this:
Code:
mov ebx.[send_data]
nvoke memcpy, ebx, data1, 2
nvoke memcpy, addr ebx+2, data1, 2
;...
invoke HttpSendRequestA, [hora], header, 52, [send_data], 110    
Post 03 Oct 2022, 09:13
View user's profile Send private message Visit poster's website Reply with quote
GREYSERGING



Joined: 03 Oct 2022
Posts: 4
GREYSERGING 03 Oct 2022, 09:19
It didn't help, this is my complete code


Last edited by GREYSERGING on 03 Oct 2022, 09:27; edited 1 time in total
Post 03 Oct 2022, 09:19
View user's profile Send private message Reply with quote
GREYSERGING



Joined: 03 Oct 2022
Posts: 4
GREYSERGING 03 Oct 2022, 09:27
Thank you, everything worked out, I initially misunderstood
Post 03 Oct 2022, 09:27
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 670
Location: Ukraine
Overclick 03 Oct 2022, 14:00
You cannot be sure registers still keeping your data after winapi. Also memcpy uses some extra instructions you dont't really need to complete the task. Use movsb(w,d,q) instead.
Code:
macro   memcopy Dest_addr,Source_addr,len
        {
                mov     rdi,Dest_addr
                mov     rsi,Source_addr
                mov     rcx,len
                rep movsb
        }
    

Or even better
Code:
macro   memcopy Dest_addr,Source_addr,len
        {
                mov     rdi,Dest_addr
                mov     rsi,Source_addr
                mov     rcx,len
                shr     rcx,3
                rep movsq
                mov     rcx,len
                and     rcx,7
                rep movsb
        }    
Post 03 Oct 2022, 14:00
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20623
Location: In your JS exploiting you and your system
revolution 03 Oct 2022, 14:14
Overclick wrote:
You cannot be sure registers still keeping your data after winapi.
The Windows API calling standard (stdcall for 32-bit) is well documented.

EBX, EDI, ESI & EBP are all guaranteed to be preserved upon return.
Post 03 Oct 2022, 14:14
View user's profile Send private message Visit poster's website Reply with quote
GREYSERGING



Joined: 03 Oct 2022
Posts: 4
GREYSERGING 03 Oct 2022, 16:58
Thanks
Post 03 Oct 2022, 16:58
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.