Quote:
Yes, just as arc said, it's alot more difficult to determine these things because of the few calling conventions and different programming techniques, You'd need a very mature disassembling engine for such a task.
|
That is true, I do have to know alot of about various calling methods and be able to check and double check if a functions meats the criteria of 'known' calling types, if these know types fail to recognize something then it should be noted and xref'd back to calle to see if that has a recognizable 'conventional behavior' about it...
That being said..genuine took a step without me, and looked at wikipedia..
So I guess I'll use it to

with a small update.. to use both functions..
Code:
int i = myfunc( 3,4,6 );
double j = myfunc2( 24.5, 5.5 );
return 0;
So this is a somewhat good example, it needs a bit more but this is a starting point
After compiling this with VC++ 2k5 on xp sp3(x86)..
code for myfunc...
Code:
004111E0 > 55 PUSH EBP
004111E1 8BEC MOV EBP,ESP
004111E3 81EC C0000000 SUB ESP,0C0
004111E9 53 PUSH EBX
004111EA 56 PUSH ESI
004111EB 57 PUSH EDI
004111EC 8DBD 40FFFFFF LEA EDI,DWORD PTR SS:[EBP-C0]
004111F2 B9 30000000 MOV ECX,30
004111F7 B8 CCCCCCCC MOV EAX,CCCCCCCC
004111FC F3:AB REP STOS DWORD PTR ES:[EDI]
004111FE 8B45 08 MOV EAX,DWORD PTR SS:[EBP+8]//param 1 to eax
00411201 0345 0C ADD EAX,DWORD PTR SS:[EBP+C]//add param 2 to eax
00411204 0345 10 ADD EAX,DWORD PTR SS:[EBP+10]//add param 3 to eax...
00411207 5F POP EDI
00411208 5E POP ESI
00411209 5B POP EBX
0041120A 8BE5 MOV ESP,EBP
0041120C 5D POP EBP
0041120D C3 RETN
This one is relatively easy to analyze visually to see 3 params, so that recognition falls under recognizable EBP code patters and the code would need to know those patters..this one has 3....

The Next Fuction is not so easily decipherable visually unless you know asm..
code for myfunc2
Code:
00411220 > 55 PUSH EBP
00411221 8BEC MOV EBP,ESP
00411223 81EC C0000000 SUB ESP,0C0
00411229 53 PUSH EBX
0041122A 56 PUSH ESI
0041122B 57 PUSH EDI
0041122C 8DBD 40FFFFFF LEA EDI,DWORD PTR SS:[EBP-C0]
00411232 B9 30000000 MOV ECX,30
00411237 B8 CCCCCCCC MOV EAX,CCCCCCCC
0041123C F3:AB REP STOS DWORD PTR ES:[EDI]
0041123E D9EE FLDZ
00411240 DC5D 10 FCOMP QWORD PTR SS:[EBP+10]//compare b 0
00411243 DFE0 FSTSW AX
00411245 F6C4 44 TEST AH,44
00411248 7B 0A JPO SHORT Test01.00411254//jmp to return 0
0041124A DD45 08 FLD QWORD PTR SS:[EBP+8]//parameter 1
0041124D DC75 10 FDIV QWORD PTR SS:[EBP+10]//div par1 by par2..
00411250 EB 04 JMP SHORT Test01.00411256
00411252 EB 02 JMP SHORT Test01.00411256
00411254 D9EE FLDZ
00411256 5F POP EDI
00411257 5E POP ESI
00411258 5B POP EBX
00411259 8BE5 MOV ESP,EBP
0041125B 5D POP EBP
0041125C C3 RETN
a funny double jmp appears ? minus the 'else'...
So this is still based on EBP patters, this also includes the FLD and FDIV EBP instructions.. the more patters I see the more I think to look at the callee, maybe this could make it easier, then checking various conditions all at once if double positives occur those cases need further handling....
I ended up with compiled code that looked like this for main..
I added visual analysis comments of what patters I see and would look for..
Code:
00411270 > 55 PUSH EBP
00411271 8BEC MOV EBP,ESP
00411273 81EC DC000000 SUB ESP,0DC
00411279 53 PUSH EBX
0041127A 56 PUSH ESI
0041127B 57 PUSH EDI
0041127C 8DBD 24FFFFFF LEA EDI,DWORD PTR SS:[EBP-DC]
00411282 B9 37000000 MOV ECX,37
00411287 B8 CCCCCCCC MOV EAX,CCCCCCCC
0041128C F3:AB REP STOS DWORD PTR ES:[EDI]
0041128E 6A 06 PUSH 6
00411290 6A 04 PUSH 4
00411292 6A 03 PUSH 3//3numeric pushes o0
00411294 E8 07FEFFFF CALL Test01.004110A0// then call myfunc
00411299 83C4 0C ADD ESP,0C//oh a verifier 0xc/0x4 = 0x3
0041129C 8945 F8 MOV DWORD PTR SS:[EBP-8],EAX
0041129F 83EC 08 SUB ESP,8//sub esp qword
004112A2 DD05 00414100FLD QWORD PTR DS:[__real@401600000000000>
004112A8 DD1C24 FSTP QWORD PTR SS:[ESP]//fill esp
004112AB 83EC 08 SUB ESP,8//sub another qword
004112AE DD05 F0404100 FLD QWORD PTR DS:[__real@403880000000000>
004112B4 DD1C24 FSTP QWORD PTR SS:[ESP]//fill esp
004112B7 E8 ADFDFFFF CALL Test01.00411069//myfunc2
004112BC 83C4 10 ADD ESP,10//a verifier 10/8 = 2
004112BF DD5D E8 FSTP QWORD PTR SS:[EBP-18]
004112C2 33C0 XOR EAX,EAX
004112C4 5F POP EDI
004112C5 5E POP ESI
004112C6 5B POP EBX
004112C7 81C4 DC000000 ADD ESP,0DC
004112CD 3BEC CMP EBP,ESP
004112CF E8 D6FDFFFF CALL Test01.004110AA
004112D4 8BE5 MOV ESP,EBP
004112D6 5D POP EBP
004112D7 C3 RETN
So to check function for cdecl you check the callee after call for cleanup of stack then you 'might' be able to 'guess at' the size and number based on basic mathmatic computations....
stdcall..is next
