flat assembler
Message board for the users of flat assembler.

flat assembler > Examples and Tutorials > Video Tutorial/Demonstration

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
m3ntal



Joined: 08 Dec 2013
Posts: 296
revolution: Thanks for your reply.
Quote:
ARM does not have a "call" instruction. So on that CPU "call" would be fine because it does not clash with anything predefined
Right, bx/bl/x, but a custom call wouldn't "clash" on X86 either. With one parameter, it would always do the same: call f. So, this idea is an extension.
Quote:
the value in edx is corrupted before it is pushed
I see: lea edx, buffer. That implementation of addr prevents the caller from using registers as parameters. In my ARM library, notice pusha/popa before/after some calls because the call itself alters a1-a4 even though they are preserved inside of the function.

I use the same call syntax on ARM, bytecode, M68k, Z80, 6502, etc. Name it anything else and you have to explain that it "calls something".


Last edited by m3ntal on 19 May 2014, 10:46; edited 1 time in total
Post 19 May 2014, 10:08
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16702
Location: In your JS exploiting you and your system
m3ntal wrote:
With one parameter, it would always do the same: call f.
That would suggest that we need to know the underlying implementation. Because if, say, f is a system API then we need to know how the linking is achieved before we can write the correct instruction:
Code:
call GetTickCount
;...
GetTickCount: jmp [DLLEntryGetTickCount]
DLLEntryGetTickCount dd DLLFunction    
vs
Code:
call [GetTickCount]
;...
GetTickCount dd DLLFunction    
Post 19 May 2014, 10:33
View user's profile Send private message Visit poster's website Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
The call macro needs to know linking information, not the caller. We only have to know function name and parameters.

Even if there is a situation where you'd want to specify convention, the fastcall/stdcall/invoke/cinvoke/etc macros would still be valid with the call extension that selects the prefix.
Post 19 May 2014, 11:23
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
Code:
convention 's' ; set standard stdcall convention    
Post 19 May 2014, 11:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16702
Location: In your JS exploiting you and your system
m3ntal wrote:
Code:
convention 's' ; set standard stdcall convention    
I think in abstract terms this type of thing can be good. But in practice it is rarely useful and can be harmful. For the most part, calling conventions of code are forced upon us by other factors out of our control so the ideal of freely changing conventions is usually not available.

When a program links to disparate libraries there is a need to use different conventions at different times. For example DLLs like zlib and msvcrt use C-call, but the Windows API uses stdcall. If one intersperses calls to the API and other calls to zlib we have to also remember to switch calling conventions before making each call. I find this type of thing, where we need to rely upon an external global state, to get the correct instructions to be confusing and prone to making easy errors. If I copy and paste a body of code into another place that has been set to use a different convention then I get incorrect code.

Your proposal of relying upon some unseen type information has the problem of R2L and L2R difficulties. While we can write a macro in such a way to avoid such things by producing extra corrective code I think this is the wrong solution. Instead the programmer could rewrite to match the convention functionality, and thus offering better opportunities to optimise and control the code generation. I would be fine with a macro named docall (or anything other than call) that does all the magic calling tricks and whatnot. But naming his do-everything macro as "call" adds a layer of abstraction (and equivalent layers of obscurity and confusion) to code.
Post 19 May 2014, 13:23
View user's profile Send private message Visit poster's website Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
Quote:
we have to also remember to switch calling conventions before making each call...
No, usage would be different: Set convention *once* before all imports or proc/function definitions.
Quote:
Instead the programmer could rewrite to match the convention functionality, and thus offering better opportunities to optimise and control the code generation.
Never needed to optimize the call to a function. fastcall removes the "overhead". Much greater speed can be achieved in other ways.
Quote:
I would be fine with a macro named docall (or anything other than call) that does all the magic calling tricks and whatnot. But naming his do-everything macro as "call" adds a layer of abstraction (and equivalent layers of obscurity and confusion) to code.
Name is unimportant/preference. "call" wouldn't cause any conflict or abstraction with the implementation I'm thinking of. My code uses no prefix or calla/callp (address/pointer) to refer to functions before they are defined. For a custom call, I'd use call/x (begins with call).

All this time I wasted talking about it, I could've wrote one good call macro that's compatible with FASM's proc+imports.
Post 19 May 2014, 16:41
View user's profile Send private message Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
Guys, can we shift this discussion? The topic title is entirely different from what's being discussed.... Smile
Post 20 May 2014, 08:46
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4203
Location: 2018
yep, calling convention is the main feature of any langage. and the topic is gentlly deviating from it's initial subject. i wonder how many post before "johnfound is dumbass" will be writen Laughing

answer, 6, 6 = 4+2, then, 42, the answer!
Post 20 May 2014, 09:55
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: 16702
Location: In your JS exploiting you and your system
sid123 wrote:
Guys, can we shift this discussion? The topic title is entirely different from what's being discussed.... Smile
Alright. Since you identified now you have to solve it. Twisted Evil And your on-topic comment is ... ?
Post 20 May 2014, 13:53
View user's profile Send private message Visit poster's website Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
sid123: Just wanted to inspire users to create videos. zhak and John changed the subject to language. call/import pertains to language/semantics: call f, a, b, c. I wouldn't have responded if no one else did.

edfed: "X is a dumbass"? All humans are intelligent in some ways and stupid in other ways.

_________________
New FASM Site, Examples, Graphics, Updated Libraries
Post 21 May 2014, 03:11
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
Universal call is working. call has been successfully extended/upgraded and maintains its original meaning:
Code:
call my.proc, a, b, c ; stdcall (proc)
call ExitProcess, 0   ; invoke (import 'i')
call strcpy, a, b     ; cinvoke (import 'c')
call l                ; call (label)
call eax              ; call
call [eax+ecx*4]      ; call    
call macro. proc+import only needs to define name#.$C$='?' (convention).
Code:
macro call f, [p] {
 common
  local c
  c=0
  match a b, f          ; 2+ tokens in
   \{ c=1 \}            ; name? use call
  if c=0                ; else
   if defined f#.$C$    ; convention?
    if f#.$C$='s'       ; select...
     stdcall f, p
    else if f#.$C$='i'
     invoke f, p
    else if f#.$C$='C'
     ccall f, p
    else if f#.$C$='c'
     cinvoke f, p
    else if f#.$C$='v'  ; variadic
     callv f, p
    end if
   else                 ; no convention.
    c=1                 ; use call
   end if
  end if
  if c=1                ; use call?
   call dword f
  end if
}

; import library. RVAs of dll names and
; tables, ending with 20 zero bytes

macro library [names] {
 forward dd 0,0,0,\
  RVA names#_name, RVA names#_table
 common dd 0,0,0,0,0
}

; import functions from dll. c=convention 'c'
; DLL name + import RVA table. each table ends
; with 0. finally, import names. dw 0 is
; "ordinal" (N/A)

macro import c, dll, [names] {
 common
  dll#_name \        ; text dll_name='DLL.DLL'
  db `dll#'.DLL', 0
  dll#_table:        ; dll_table:
 forward
  names#.$C$=c       ; convention
  if used names
   names \
    dd RVA _#names   ; import name RVAs
  end if
 common
  dd 0               ; end
 forward
  if used names
   _#names dw 0      ; import names
   db `names, 0      ; 'import'
  end if
}

; example usage:

data import

library KERNEL32, USER32, SHELL32, MSVCRT

import 'i', KERNEL32, ExitProcess
import 'i', USER32, MessageBoxA, wsprintfA
import 'i', SHELL32, ShellExecuteA
import 'c', MSVCRT, strlen, strcpy, strcat

end data    
Updated.


Last edited by m3ntal on 22 May 2014, 03:30; edited 1 time in total
Post 21 May 2014, 04:44
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
Universal call, proc, import + example


Description:
Download
Filename: call.7z
Filesize: 3.39 KB
Downloaded: 143 Time(s)

Post 22 May 2014, 03:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16702
Location: In your JS exploiting you and your system
What happens for:
Code:
call wsprintf,dest,'%u',1    
Question
Post 22 May 2014, 03:42
View user's profile Send private message Visit poster's website Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
Error, import uses exact names: wsprintfA. See EXAMPLE.ASM. That's just an example import table. I forgot which convention wsprintfA uses.
Post 22 May 2014, 03:52
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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-2019, Tomasz Grysztar.

Powered by rwasa.