flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
UCM 16 Aug 2006, 19:44
Because the DLL is mapped into the host program's addressing space, it can access the host program's memory (in fact, only within the host program). What you are probably getting wrong is that first, you you forgot to put a "ret" at the end of your procedure, and because DataLen is the address of the variable, not the variable contents (like in MASM). In addition, [dataBuffer] is only the pointer to the data, so you must first load it into a register. The correct code, then, should be like this:
Code: proc proc Encrypt dataBuffer,dataLenght xor ecx,ecx mov esi,[dataBuffer] ecryptLoop: mov eax, dword [esi + ecx] xor eax, 'DSCX' mov dword [esi + ecx],eax add ecx,4 cmp ecx,[dataLenght] jne ecryptLoop ret endp ;and in the EXE: invoke Encrypt,DataBuffer,[DataLen] ;getting the value of DataLen, not the address ... DataBuffer rb 1025 DataLen dd 1024 In fact, there are many things which could be optimized in your procedure, but I will not cover those, for now. |
|||
![]() |
|
DustWolf 16 Aug 2006, 21:23
UCM wrote:
This can't be right. That would move the contens of the data buffer, namely the first 4 bytes into ESI. You will notice the code works with the offset, not with the contens (or the contens is dealt with only in the 3 lines where it is loaded into eax, xored and sent back). Also, the intention of the DataLen part was to pass the offset to the variable value to the DLL since FASM disagreed with me providing the value there directly. Code: cmp ecx,dataLenght throws: Invalid value "cmp ecx,..arg?0000641" If you use: Code: invoke Encrypt,DataBuffer,[DataLen] ;and then this cmp ecx,[dataLenght] ...this would mean that the offset at DataLen would have to contain the offset to the top counter value, which is not the case as: Code: DataLen dd 1024 indicates. Have I got this all wrong? Does passing the parameters with invoke and proc automatically make turn them into offsets to the data provided? |
|||
![]() |
|
UCM 16 Aug 2006, 21:57
You, in fact, are indeed getting it all wrong. Within the procedure, [dataBuffer] may as well be DataBuffer from the main executable. (Sorry, I can't explain this properly at the moment.) Just try it.
|
|||
![]() |
|
DustWolf 16 Aug 2006, 22:25
UCM wrote: You, in fact, are indeed getting it all wrong. Within the procedure, [dataBuffer] may as well be DataBuffer from the main executable. (Sorry, I can't explain this properly at the moment.) Just try it. Okay I got it. when you refer to something in a proc, it doesn't pass on the actual values but always pointers to those values even if the values themselves are pointers. You mentioned optimization earlier... could you show me something of that? The code as it is now runs at 100 MB in 30 seconds and it is held back heavily by the speed of my RAID array (2% CPU usage). I wonder just how fast can this code be. I am especially puzzled about this optimization since FASM's own optimizer left my code mostly unchanged. Last edited by DustWolf on 16 Aug 2006, 23:03; edited 1 time in total |
|||
![]() |
|
UCM 16 Aug 2006, 22:31
If the function was called with "invoke DLLCall,DataBuffer" then within the procedure (defined as "proc DLLCall ProcDataBuffer" to avoid confusion) "[ProcDataBuffer]" is the same as "DataBuffer". If the function was called with "invoke DLLCall,[DataBuffer]" then within the function "[ProcDataBuffer]" is equal to "[DataBuffer]". So, [ProcDataBuffer] is the same as the argument passed to it.
|
|||
![]() |
|
DustWolf 16 Aug 2006, 23:05
UCM wrote: If the function was called with "invoke DLLCall,DataBuffer" then within the procedure (defined as "proc DLLCall ProcDataBuffer" to avoid confusion) "[ProcDataBuffer]" is the same as "DataBuffer". If the function was called with "invoke DLLCall,[DataBuffer]" then within the function "[ProcDataBuffer]" is equal to "[DataBuffer]". So, [ProcDataBuffer] is the same as the argument passed to it. That's weird. ![]() ![]() |
|||
![]() |
|
daluca 17 Aug 2006, 06:21
Quote:
arguments are passed to a dll in the stack. they are pushed in it with the push instruction, and they are accessed by the dll through the EBP register so inside your proc you always have to access your arguments as if you were reading memory: in the [ ] way so: Code: mov eax,dword [dataBuffer + ecx] after this gets executed you are loading in eax the pointer to the data not the first four bytes of it. so as UCM said you must first load it into a register do you can access the data through the register. although this is just a convention you can pass arguments in registers too. proc is a macro that deals with this convention Code: mov esi,[dataBuffer] would move the contens of the data buffer, namely the first 4 bytes into ESI as you said, but this is true only outside the proc/endp and as long as you have a label with this name |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.