This two macros extract words.Result is given by %ECHO
results are
Quote
PGETC machin.bidule
PGETC hConnect
PGET (machin.bidule
PGET hConnect)
PGET add a ( but PGETC don't do that.
Is there a soluce ?
Quote
mov edx,PGETC(machin.bidule,hConnect)
PGET(machin.bidule,hConnect)
Quote
PGETC MACRO pointer_name:REQ,decale:REQ
%ECHO PGETC pointer_name
%ECHO PGETC decale
count INSTR <pointer_name>,<.>
IF count
mov eax,count
ENDIF
EXITM <eax>
ENDM
PGET MACRO pointer_name:REQ,decale:REQ
%ECHO PGET pointer_name
%ECHO PGET decale
count INSTR <pointer_name>,<.>
IF count
;extraire le pointeur de la structure
;debugage %ECHO
;indirect = offset premiere structure = pointeur deuxieme structure
;pointer1 = pointeur sur premiere structure
bivalent SUBSTR <pointer_name>,count +1
pointer1 SUBSTR <pointer_name>,1,count -1
;
testeur CATSTR <DECLARE_>,pointer1
IF OPATTR testeur EQ 24h ;constant OR structure in data ?
computeoffset1 CATSTR <DECLARE_>,pointer1,<.>,bivalent
computeoffset CATSTR <DECLARE_>,bivalent,<.>,<decale>
mov edx,pointer1
mov edx,[edx].computeoffset1 ;pointeur sur deuxieme structure
ELSE
computeoffset CATSTR <DECLARE_>,bivalent,<.>,<decale>
mov edx,pointer_name ; en data: nom structure <>
ENDIF
ELSE
;ECHO PGET sans point
;STRUCTURE + nom interne
;computeoffsetpget CATSTR <DECLARE_>,<pointer_name>,<.>,<decale>
;mov edx,pointer_name
ENDIF
;-------- value dans edx ----------------
;%ECHO PGET computeoffsetpget = computeoffsetpget
count = sizeof computeoffsetpget
;IF count LE 2
; movzx edx,[edx+computeoffsetpget]
;ELSEIF count EQ 4
; mov edx,DWORD PTR [edx+computeoffsetpget]
;ELSEIF count EQ 8
; mov ecx,DWORD PTR [edx+computeoffsetpget]
; mov edx,DWORD PTR [edx+computeoffsetpget+4]
;ELSE
; .ERR <'PGET couldn't solve'>
;ENDIF
ENDM
PGET machin.bidule,hConnect
qui coûte 50 $ :bg
I need the ( with the invoke.
invoke arg1,PGETC(machin.bidule,hConnect),arg2 ;ok
invoke arg1,PGET machin.bidule,hConnect,arg2 ;too many arguments .....
dang ! :P
in that case, realize that the first parm will have a "(" and the last parm will have a ")"
parse them off
Quote from: ToutEnMasm on September 05, 2011, 05:42:33 PMinvoke arg1,PGET machin.bidule,hConnect,arg2
you can not call procedural macros like functions - you must use EXITM and add brackets to the call.
well - the problem seems to be that it is converting the parens as part of the literal string
there may be 2 ways to fix it
MacroName MACRO <pointer_name:REQ>,<decale:REQ>
then you have to remove the "<>" that you have inside the macro
or, you may be able to use TEXTEQU
MacroName MACRO pointer_name:REQ,decale:REQ
argPonterName TEXTEQU <pointer_name>
argDecale TEXTEQU <decale>
This one seem to work.
Need improvement
Quote
PGET (machin.bidule
PGET hConnect)
VERIF (
NEW machin.bidule
VERIF2 )
REDECALE hConnect
machin
Quote
PESSAI MACRO pointer_name:REQ,decale:REQ
%ECHO PGET pointer_name
%ECHO PGET decale
verif SUBSTR <pointer_name>,1,1
%ECHO VERIF verif
IFIDN verif,<(> ;si le premier caractere est "
new SUBSTR <pointer_name>,2
ELSE
new SUBSTR <pointer_name>,1
ENDIF
%ECHO NEW new
count SIZESTR <decale>
verif SUBSTR <decale>,count,1
%ECHO VERIF2 verif
IFIDN verif,<)> ;si le premier caractere est "
redecale SUBSTR <decale>,1,count - 1
ELSE
redecale SUBSTR <decale>,1
ENDIF
%ECHO REDECALE redecale
count INSTR new,<.>
IF count GT 0
pointeur SUBSTR new,1,count -1
ENDIF
%ECHO pointeur
ENDM
After some tests here is the final result.
Quote
Those macros allow to use pointers on structures in the same
way than structures in data.
They can also transfert data from structure to structure or variable
They can solve cases from BYTE to QWORD.
PVALG return value to invoke or registre
PADR return adress
PVALP transfert data between the two operandS
Restriction:
Don't use them directly in a if,(.if PVALG(appContext,dwDownloaded) ==)
mov eax,PVALG(appContext,dwDownloaded
.if ...
The jmp of the if can cut the added lines (random)
PVALG and PADR have an init arg.Use it (0) when the compiler tell you
there is two many arguments.
Macros usage:
declare_ the structure pointed by the dword as this:
DECLARE_context TEXTEQU <APP_CONTEXT>
You need also two buffers
;BUFIDR dd 10 dup (0) ;offset max 4 * 10 -4 =36
;passeqword dq 10 dup (0) ;offset max 10*8-8 = 72
First argument is the pointer on the structure
Second is an internal name of the structure.
Pointer can have a . This mean:
DECLARE_context TEXTEQU <APP_CONTEXT>
DECLARE_mainContext TEXTEQU <MAIN_CONTEXT>
APP_CONTEXT STRUCT
dwStructType DWORD ?
mainContext DWORD ? <<<<< here pointer on MAIN_CONTEXT
...
MAIN_CONTEXT STRUCT
dwStructType DWORD ?
HinternetOpen DWORD ?
hConnect DWORD ?
MAIN_CONTEXT ENDS
PVALG(context.mainContext,hConnect) get the hConnect value
nice, Yves :U
is this for some kind of debug code you are working on ? :P
I am working on an automised translate of c++ in masm.
Masm is really poor in macros working with pointers.Now with those macros i can read the c++ code with :
g_readIO->lpo.Offset = appContext->dwReadOffset
and translate it in masm
PVALP g_readIO,lpo.Offset ,appContext.dwReadOffset ;and it is made !
To be more explicit,here is the only one case where the macrros can failed.
It is a disassemly of an .exe
Quote
;added lines by the macro
push edx
push ecx
mov edx,dword ptr [ebp-20h]
mov edx,dword ptr [edx+14h] ;dwDownloaded
mov dword ptr ds:[40600Fh],edx
pop ecx
pop edx
;jmp of the last .elseif ; the added lines are not executed
jmp 00401BC9
;new .elseif with .elseif PVALG(appContext,dwDownloaded) != -1
cmp dword ptr ds:[40600Fh],0FFFFFFFFh