News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Memory help

Started by ecube, September 16, 2006, 11:23:29 PM

Previous topic - Next topic

ecube

First off hutch someone named Daniel Craig spammed my inbox with porn links and other non-sense, you might want to look into that. My question though is how do I essentially strcat file data to a string in a memory block.

I have a file memory mapped and I tried doing the following

;string length+filesize=alloc'd memory size
invoke GetFileSize,Hfile,NULL
mov myfilesize,eax
invoke lstrlen,addr xbody       <---null terminating string
mov mystringlen,eax
add eax,myfilesize
mov NEWsize,eax

INVOKE VirtualAlloc, NULL, NEWsize, MEM_COMMIT OR MEM_RESERVE, PAGE_EXECUTE_READWRITE
mov Mymem,eax

invoke RtlMoveMemory,Mymem,addr xbody, mystringlen  ;move string into mem buf
mov ecx,mystringlen  ;add the string size to the memory offset
inc ecx
invoke RtlMoveMemory,[Mymem+ecx],hMap, myfilesize  ;move file data into mem buf

this doesn't work... any help would be much appreciated, thanks.

hutch--

cube,

we solved the problem with "Daniel" some time ago. We are also hoping that a member in Hawaii may apply the appliance shown in the photo directly to "Daniel" so he does not do it again.

Check each value to ensure you are getting the correct result, file length, string length then test the return value of VirtualAlloc() to ensure the memory is allocated properly and to at least the size you require.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ecube

Good to hear about Daniel. All the functions return correct values the problem is

invoke RtlMoveMemory,[Mymem+ecx],hMap, myfilesize <---this line errors

it errors out my app same goes for CopyMemory. Is that not the correct way to specify an offset? I just don't want the file data to overwrite the data already existing in the alloc'd memory, want to append it after. i'm positive the alloc'd memory is large enough to hold both the string and file data.

PBrennick

The GeneSys Project is available from:
The Repository or My crappy website

ecube

this code focuses specifically on the problem

.386
.model flat, stdcall
option casemap:none  ; Case sensitive

include  \Masm32\include\windows.inc
include  \Masm32\include\kernel32.inc
include  \Masm32\include\user32.inc
include  \Masm32\include\masm32.inc
includelib  \Masm32\lib\kernel32.lib
includelib  \Masm32\lib\masm32.lib
includelib  \Masm32\lib\user32.lib
HandleError proto :DWORD

.data
teststring     byte 'Mozilla',0 
Error          byte 'Error',0


.data?
zMem       dd ?
NEWsize    dd ?
stringsize dd ?



.code
start:

INVOKE VirtualAlloc, NULL, 400, MEM_COMMIT OR MEM_RESERVE, PAGE_EXECUTE_READWRITE
mov zMem,eax

invoke lstrlen,addr teststring
mov stringsize,eax

invoke RtlMoveMemory,[zMem],addr teststring,stringsize
mov ecx,stringsize
invoke RtlMoveMemory,[zMem+ecx],addr teststring,stringsize ;<--crashes here

invoke HandleError,addr Error ; <--don't even make it to this line

invoke ExitProcess,0




HandleError proc lpTitle:DWORD
     
    LOCAL lpMsgBuffer     : LPVOID
     
    mov cx, SUBLANG_DEFAULT
    shl ecx, 10

     
    push NULL               
    push 0                     
                         
    lea  eax, lpMsgBuffer         
    push eax                 
    push ecx                 
    invoke GetLastError           
    push eax                 
    push NULL                 
    mov edx, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM
    push edx               
    call FormatMessage             
     

    invoke MessageBox, NULL, lpMsgBuffer, lpTitle, MB_OK or MB_ICONSTOP
     

    invoke LocalFree, lpMsgBuffer
    ret
HandleError endp


end start

sinsi

Quote
invoke RtlMoveMemory,[zMem+ecx],addr teststring,stringsize ;<--crashes here

[zMem+ecx] gets translated as [offset of zMem + ecx] and not as [contents of zMem + ecx], so use

  mov ecx,stringsize
  add ecx,Zmem
  invoke RtlMoveMemory,ecx,addr teststring,stringsize
Light travels faster than sound, that's why some people seem bright until you hear them.

ecube

Thankyou sir, that fixed it. :thumbu