【问题标题】:IDA: Why does this function/sub has 4 arguments, and why is one a struct?IDA:为什么这个函数/子函数有 4 个参数,为什么一个是结构?
【发布时间】:2019-01-16 10:28:12
【问题描述】:

我真的(真的)是 IDA 新手(以及一般的调试),所以我想问一些方向。

我有这个子/功能:

sub_5AE50B      proc near               ; CODE XREF: sub_4F0E29+252p
.text:005AE50B                                         ; sub_5B81A9+36p
.text:005AE50B
.text:005AE50B var_548         = dword ptr -548h
.text:005AE50B var_544         = dword ptr -544h
.text:005AE50B var_540         = dword ptr -540h
.text:005AE50B var_53C         = dword ptr -53Ch
.text:005AE50B var_538         = dword ptr -538h
.text:005AE50B var_534         = dword ptr -534h
.text:005AE50B var_530         = dword ptr -530h
.text:005AE50B var_52C         = dword ptr -52Ch
.text:005AE50B var_528         = dword ptr -528h
.text:005AE50B var_524         = dword ptr -524h
.text:005AE50B var_520         = dword ptr -520h
.text:005AE50B var_51C         = dword ptr -51Ch
.text:005AE50B var_518         = dword ptr -518h
.text:005AE50B var_514         = dword ptr -514h
.text:005AE50B var_510         = dword ptr -510h
.text:005AE50B var_50C         = dword ptr -50Ch
.text:005AE50B var_508         = dword ptr -508h
.text:005AE50B var_504         = dword ptr -504h
.text:005AE50B var_500         = dword ptr -500h
.text:005AE50B var_4FC         = dword ptr -4FCh
.text:005AE50B var_4F8         = dword ptr -4F8h
.text:005AE50B var_4F4         = dword ptr -4F4h
.text:005AE50B var_4F0         = dword ptr -4F0h
.text:005AE50B var_4EC         = dword ptr -4ECh
.text:005AE50B var_4E8         = dword ptr -4E8h
.text:005AE50B var_4E4         = dword ptr -4E4h
.text:005AE50B var_4E0         = dword ptr -4E0h
.text:005AE50B var_4DC         = dword ptr -4DCh
.text:005AE50B var_4D8         = dword ptr -4D8h
.text:005AE50B var_4D4         = dword ptr -4D4h
.text:005AE50B var_4D0         = dword ptr -4D0h
.text:005AE50B var_4CC         = dword ptr -4CCh
.text:005AE50B var_4C8         = dword ptr -4C8h
.text:005AE50B var_4C4         = dword ptr -4C4h
.text:005AE50B var_4C0         = dword ptr -4C0h
.text:005AE50B var_4BC         = dword ptr -4BCh
.text:005AE50B var_4B8         = dword ptr -4B8h
.text:005AE50B var_4B4         = dword ptr -4B4h
.text:005AE50B var_4B0         = dword ptr -4B0h
.text:005AE50B var_4AC         = dword ptr -4ACh
.text:005AE50B var_4A8         = dword ptr -4A8h
.text:005AE50B var_4A4         = dword ptr -4A4h
.text:005AE50B var_4A0         = byte ptr -4A0h
.text:005AE50B var_49C         = dword ptr -49Ch
.text:005AE50B var_498         = dword ptr -498h
.text:005AE50B var_494         = dword ptr -494h
.text:005AE50B var_490         = dword ptr -490h
.text:005AE50B var_48C         = dword ptr -48Ch
.text:005AE50B var_488         = dword ptr -488h
.text:005AE50B var_484         = dword ptr -484h
.text:005AE50B var_480         = dword ptr -480h
.text:005AE50B var_47C         = dword ptr -47Ch
.text:005AE50B var_478         = dword ptr -478h
.text:005AE50B var_474         = dword ptr -474h
.text:005AE50B var_470         = dword ptr -470h
.text:005AE50B var_46C         = dword ptr -46Ch
.text:005AE50B var_468         = dword ptr -468h
.text:005AE50B var_464         = dword ptr -464h
.text:005AE50B var_460         = dword ptr -460h
.text:005AE50B var_45C         = dword ptr -45Ch
.text:005AE50B var_458         = dword ptr -458h
.text:005AE50B var_454         = dword ptr -454h
.text:005AE50B var_450         = dword ptr -450h
.text:005AE50B var_444         = dword ptr -444h
.text:005AE50B var_440         = dword ptr -440h
.text:005AE50B var_43C         = dword ptr -43Ch
.text:005AE50B var_438         = dword ptr -438h
.text:005AE50B var_434         = dword ptr -434h
.text:005AE50B var_430         = dword ptr -430h
.text:005AE50B var_42C         = dword ptr -42Ch
.text:005AE50B var_428         = dword ptr -428h
.text:005AE50B var_424         = dword ptr -424h
.text:005AE50B var_418         = dword ptr -418h
.text:005AE50B var_414         = dword ptr -414h
.text:005AE50B var_410         = dword ptr -410h
.text:005AE50B var_40C         = dword ptr -40Ch
.text:005AE50B var_408         = dword ptr -408h
.text:005AE50B var_404         = dword ptr -404h
.text:005AE50B var_400         = dword ptr -400h
.text:005AE50B var_3FC         = dword ptr -3FCh
.text:005AE50B var_3F8         = dword ptr -3F8h
.text:005AE50B var_3EC         = dword ptr -3ECh
.text:005AE50B var_3E8         = dword ptr -3E8h
.text:005AE50B var_3E4         = dword ptr -3E4h
.text:005AE50B var_3E0         = dword ptr -3E0h
.text:005AE50B var_3DC         = dword ptr -3DCh
.text:005AE50B var_3D8         = dword ptr -3D8h
.text:005AE50B var_3D4         = dword ptr -3D4h
.text:005AE50B var_3D0         = dword ptr -3D0h
.text:005AE50B var_3CC         = dword ptr -3CCh
.text:005AE50B var_3C8         = dword ptr -3C8h
.text:005AE50B var_3C4         = dword ptr -3C4h
.text:005AE50B var_3C0         = dword ptr -3C0h
.text:005AE50B var_3BC         = dword ptr -3BCh
.text:005AE50B var_3B8         = dword ptr -3B8h
.text:005AE50B var_3AC         = dword ptr -3ACh
.text:005AE50B var_3A8         = dword ptr -3A8h
.text:005AE50B var_3A4         = dword ptr -3A4h
.text:005AE50B var_3A0         = dword ptr -3A0h
.text:005AE50B var_39C         = dword ptr -39Ch
.text:005AE50B var_398         = dword ptr -398h
.text:005AE50B var_394         = dword ptr -394h
.text:005AE50B var_390         = dword ptr -390h
.text:005AE50B var_38C         = dword ptr -38Ch
.text:005AE50B var_380         = dword ptr -380h
.text:005AE50B var_37C         = dword ptr -37Ch
.text:005AE50B var_378         = dword ptr -378h
.text:005AE50B var_374         = dword ptr -374h
.text:005AE50B var_370         = dword ptr -370h
.text:005AE50B var_36C         = dword ptr -36Ch
.text:005AE50B var_368         = dword ptr -368h
.text:005AE50B var_364         = dword ptr -364h
.text:005AE50B var_360         = dword ptr -360h
.text:005AE50B var_35C         = dword ptr -35Ch
.text:005AE50B var_358         = dword ptr -358h
.text:005AE50B var_354         = dword ptr -354h
.text:005AE50B var_350         = dword ptr -350h
.text:005AE50B var_34C         = dword ptr -34Ch
.text:005AE50B var_348         = dword ptr -348h
.text:005AE50B var_344         = dword ptr -344h
.text:005AE50B var_340         = dword ptr -340h
.text:005AE50B var_33C         = dword ptr -33Ch
.text:005AE50B var_338         = dword ptr -338h
.text:005AE50B var_334         = dword ptr -334h
.text:005AE50B var_330         = dword ptr -330h
.text:005AE50B var_32C         = dword ptr -32Ch
.text:005AE50B var_328         = dword ptr -328h
.text:005AE50B var_324         = dword ptr -324h
.text:005AE50B var_320         = dword ptr -320h
.text:005AE50B var_31C         = dword ptr -31Ch
.text:005AE50B var_318         = dword ptr -318h
.text:005AE50B var_314         = dword ptr -314h
.text:005AE50B var_310         = dword ptr -310h
.text:005AE50B var_30C         = dword ptr -30Ch
.text:005AE50B var_308         = dword ptr -308h
.text:005AE50B var_304         = dword ptr -304h
.text:005AE50B v               = dword ptr -2FCh
.text:005AE50B var_2F8         = dword ptr -2F8h
.text:005AE50B var_2F4         = dword ptr -2F4h
.text:005AE50B var_2F0         = dword ptr -2F0h
.text:005AE50B var_2EC         = dword ptr -2ECh
.text:005AE50B var_2E8         = dword ptr -2E8h
.text:005AE50B var_2E4         = dword ptr -2E4h
.text:005AE50B var_2E0         = dword ptr -2E0h
.text:005AE50B var_2DC         = dword ptr -2DCh
.text:005AE50B var_2D8         = dword ptr -2D8h
.text:005AE50B var_2D4         = dword ptr -2D4h
.text:005AE50B var_2D0         = dword ptr -2D0h
.text:005AE50B var_2CC         = dword ptr -2CCh
.text:005AE50B var_2C8         = dword ptr -2C8h
.text:005AE50B var_2C4         = dword ptr -2C4h
.text:005AE50B var_2C0         = dword ptr -2C0h
.text:005AE50B var_2BC         = dword ptr -2BCh
.text:005AE50B var_2B8         = dword ptr -2B8h
.text:005AE50B var_2B4         = dword ptr -2B4h
.text:005AE50B var_2B0         = dword ptr -2B0h
.text:005AE50B var_2AC         = dword ptr -2ACh
.text:005AE50B var_2A8         = dword ptr -2A8h
.text:005AE50B var_2A4         = dword ptr -2A4h
.text:005AE50B var_298         = dword ptr -298h
.text:005AE50B var_294         = dword ptr -294h
.text:005AE50B var_290         = dword ptr -290h
.text:005AE50B var_28C         = dword ptr -28Ch
.text:005AE50B var_288         = dword ptr -288h
.text:005AE50B var_284         = dword ptr -284h
.text:005AE50B var_280         = dword ptr -280h
.text:005AE50B var_274         = dword ptr -274h
.text:005AE50B var_270         = dword ptr -270h
.text:005AE50B var_26C         = dword ptr -26Ch
.text:005AE50B var_268         = dword ptr -268h
.text:005AE50B var_264         = dword ptr -264h
.text:005AE50B var_260         = dword ptr -260h
.text:005AE50B var_25C         = dword ptr -25Ch
.text:005AE50B var_250         = dword ptr -250h
.text:005AE50B var_24C         = dword ptr -24Ch
.text:005AE50B var_248         = dword ptr -248h
.text:005AE50B var_244         = dword ptr -244h
.text:005AE50B var_240         = dword ptr -240h
.text:005AE50B var_23C         = dword ptr -23Ch
.text:005AE50B var_238         = dword ptr -238h
.text:005AE50B var_22C         = dword ptr -22Ch
.text:005AE50B var_228         = dword ptr -228h
.text:005AE50B var_224         = dword ptr -224h
.text:005AE50B var_220         = dword ptr -220h
.text:005AE50B var_21C         = dword ptr -21Ch
.text:005AE50B var_218         = dword ptr -218h
.text:005AE50B var_214         = dword ptr -214h
.text:005AE50B var_210         = dword ptr -210h
.text:005AE50B var_20C         = dword ptr -20Ch
.text:005AE50B var_208         = dword ptr -208h
.text:005AE50B var_204         = dword ptr -204h
.text:005AE50B var_200         = dword ptr -200h
.text:005AE50B var_1FC         = dword ptr -1FCh
.text:005AE50B var_1F0         = dword ptr -1F0h
.text:005AE50B var_1EC         = dword ptr -1ECh
.text:005AE50B var_1E8         = dword ptr -1E8h
.text:005AE50B var_1E4         = dword ptr -1E4h
.text:005AE50B var_1E0         = dword ptr -1E0h
.text:005AE50B var_1DC         = dword ptr -1DCh
.text:005AE50B var_1D8         = dword ptr -1D8h
.text:005AE50B var_1CC         = dword ptr -1CCh
.text:005AE50B var_1C8         = dword ptr -1C8h
.text:005AE50B var_1C4         = dword ptr -1C4h
.text:005AE50B var_1C0         = dword ptr -1C0h
.text:005AE50B var_1BC         = dword ptr -1BCh
.text:005AE50B var_1B0         = dword ptr -1B0h
.text:005AE50B var_1AC         = dword ptr -1ACh
.text:005AE50B var_1A8         = dword ptr -1A8h
.text:005AE50B var_1A4         = dword ptr -1A4h
.text:005AE50B var_1A0         = dword ptr -1A0h
.text:005AE50B var_19C         = dword ptr -19Ch
.text:005AE50B var_198         = dword ptr -198h
.text:005AE50B var_194         = dword ptr -194h
.text:005AE50B var_190         = dword ptr -190h
.text:005AE50B var_184         = dword ptr -184h
.text:005AE50B var_180         = dword ptr -180h
.text:005AE50B var_17C         = dword ptr -17Ch
.text:005AE50B var_178         = dword ptr -178h
.text:005AE50B var_174         = dword ptr -174h
.text:005AE50B var_170         = dword ptr -170h
.text:005AE50B var_16C         = dword ptr -16Ch
.text:005AE50B var_168         = dword ptr -168h
.text:005AE50B var_164         = dword ptr -164h
.text:005AE50B var_160         = dword ptr -160h
.text:005AE50B var_154         = dword ptr -154h
.text:005AE50B var_150         = dword ptr -150h
.text:005AE50B var_14C         = dword ptr -14Ch
.text:005AE50B var_148         = dword ptr -148h
.text:005AE50B var_144         = dword ptr -144h
.text:005AE50B var_140         = dword ptr -140h
.text:005AE50B var_13C         = dword ptr -13Ch
.text:005AE50B var_138         = dword ptr -138h
.text:005AE50B var_134         = dword ptr -134h
.text:005AE50B var_130         = dword ptr -130h
.text:005AE50B var_12C         = dword ptr -12Ch
.text:005AE50B var_128         = dword ptr -128h
.text:005AE50B var_124         = dword ptr -124h
.text:005AE50B var_120         = dword ptr -120h
.text:005AE50B var_11C         = dword ptr -11Ch
.text:005AE50B var_118         = dword ptr -118h
.text:005AE50B var_114         = dword ptr -114h
.text:005AE50B var_110         = dword ptr -110h
.text:005AE50B var_10C         = dword ptr -10Ch
.text:005AE50B var_108         = dword ptr -108h
.text:005AE50B var_104         = dword ptr -104h
.text:005AE50B var_100         = dword ptr -100h
.text:005AE50B var_FC          = dword ptr -0FCh
.text:005AE50B var_F8          = dword ptr -0F8h
.text:005AE50B var_F4          = dword ptr -0F4h
.text:005AE50B var_F0          = dword ptr -0F0h
.text:005AE50B var_EC          = dword ptr -0ECh
.text:005AE50B var_E8          = dword ptr -0E8h
.text:005AE50B var_E4          = dword ptr -0E4h
.text:005AE50B var_E0          = dword ptr -0E0h
.text:005AE50B var_DC          = dword ptr -0DCh
.text:005AE50B var_D8          = dword ptr -0D8h
.text:005AE50B var_D4          = dword ptr -0D4h
.text:005AE50B var_D0          = dword ptr -0D0h
.text:005AE50B var_CC          = dword ptr -0CCh
.text:005AE50B var_C8          = dword ptr -0C8h
.text:005AE50B var_C4          = dword ptr -0C4h
.text:005AE50B var_C0          = dword ptr -0C0h
.text:005AE50B var_BC          = dword ptr -0BCh
.text:005AE50B var_B8          = dword ptr -0B8h
.text:005AE50B var_B4          = dword ptr -0B4h
.text:005AE50B var_B0          = dword ptr -0B0h
.text:005AE50B var_AC          = dword ptr -0ACh
.text:005AE50B var_A8          = dword ptr -0A8h
.text:005AE50B var_A4          = dword ptr -0A4h
.text:005AE50B var_A0          = dword ptr -0A0h
.text:005AE50B var_9C          = dword ptr -9Ch
.text:005AE50B var_98          = dword ptr -98h
.text:005AE50B var_94          = dword ptr -94h
.text:005AE50B var_90          = dword ptr -90h
.text:005AE50B var_84          = dword ptr -84h
.text:005AE50B var_80          = dword ptr -80h
.text:005AE50B var_7C          = dword ptr -7Ch
.text:005AE50B var_78          = dword ptr -78h
.text:005AE50B var_74          = dword ptr -74h
.text:005AE50B var_70          = dword ptr -70h
.text:005AE50B var_6C          = dword ptr -6Ch
.text:005AE50B var_68          = dword ptr -68h
.text:005AE50B var_64          = dword ptr -64h
.text:005AE50B var_60          = dword ptr -60h
.text:005AE50B var_5C          = dword ptr -5Ch
.text:005AE50B var_58          = dword ptr -58h
.text:005AE50B var_54          = dword ptr -54h
.text:005AE50B var_50          = dword ptr -50h
.text:005AE50B var_4C          = dword ptr -4Ch
.text:005AE50B var_48          = dword ptr -48h
.text:005AE50B var_44          = dword ptr -44h
.text:005AE50B var_40          = dword ptr -40h
.text:005AE50B var_3C          = dword ptr -3Ch
.text:005AE50B var_38          = dword ptr -38h
.text:005AE50B var_34          = dword ptr -34h
.text:005AE50B var_30          = dword ptr -30h
.text:005AE50B var_2C          = dword ptr -2Ch
.text:005AE50B var_28          = dword ptr -28h
.text:005AE50B var_24          = dword ptr -24h
.text:005AE50B var_20          = dword ptr -20h
.text:005AE50B var_1C          = dword ptr -1Ch
.text:005AE50B alpha           = dword ptr -18h
.text:005AE50B var_14          = dword ptr -14h
.text:005AE50B var_10          = dword ptr -10h
.text:005AE50B var_C           = dword ptr -0Ch
.text:005AE50B var_4           = dword ptr -4
.text:005AE50B arg_0           = dword ptr  8
.text:005AE50B arg_C           = dword ptr  14h
.text:005AE50B
.text:005AE50B                 push    ebp
.text:005AE50C                 mov     ebp, esp
.text:005AE50E                 push    0FFFFFFFFh
.text:005AE510                 push    offset loc_876BAE
.text:005AE515                 mov     eax, large fs:0
.text:005AE51B                 push    eax
.text:005AE51C                 mov     large fs:0, esp
.text:005AE523                 sub     esp, 524h
.text:005AE529                 mov     eax, [ebp+arg_0]
.text:005AE52C                 mov     ecx, [eax+30h]
.text:005AE52F                 imul    ecx, 0F4h
.text:005AE535                 mov     edx, dword_596CB28
.text:005AE53B                 add     edx, ecx
.text:005AE53D                 mov     [ebp+var_10], edx
.text:005AE540                 mov     byte ptr [ebp+var_14], 1
.text:005AE544                 cmp     dword_7B46AF4, 0
.text:005AE54B                 jnz     short loc_5AE567
.text:005AE54D                 cmp     dword_7B46AF4, 0
.text:005AE554                 jnz     loc_5B817B
.text:005AE55A                 mov     eax, [ebp+arg_0]
.text:005AE55D                 cmp     dword ptr [eax+3Ch], 0FFFFFFFEh
.text:005AE561                 jz      loc_5B817B
.text:005AE567
.text:005AE567 loc_5AE567:                             ; CODE XREF: sub_5AE50B+40j
.text:005AE567                 cmp     [ebp+arg_C], 0Ah
.text:005AE56B                 jnz     loc_5AE7C9
.text:005AE571                 mov     [ebp+alpha], 3F000000h
.text:005AE578                 mov     [ebp+var_1C], 0
.text:005AE57F                 jmp     short loc_5AE58A

它有很多 vars,从 var_548 递减 4 x 4 直到您在图像上看到的内容。

现在我知道这应该是一个看起来像这样的函数:

void __cdecl sub_5DE260(STRUCT *lpInfo, int a1, int a2, int a3)

(我知道这是因为其他人在论坛上发布了它)

现在,这是我的疑问(对不起,如果它很愚蠢),为什么函数有 4 个参数? (我在那里只看到 2 arg_,那么不应该是 2 吗?)我知道为什么会这样.. 但我不确定.. 我看到 vars 下降了 4 x 4,并且 args 是 _0_C 这意味着如果它也是 4 x 4,那么中间还会有 2 个 args.. 但我真的不知道。

第二个问题,你怎么知道第一个参数是一个结构?我在这里唯一的想法是它与那里的“Alpha”有关。我也会问如何获得该结构,但这可能很难,所以我想先了解更基本的部分。 :)


编辑:抱歉添加了图片,我现在复制了文字。

此函数有 2 个调用,我现在将两个都添加:

loc_4F1058:                             ; CODE XREF: sub_4F0E29+219j
.text:004F1058                 push    0
.text:004F105A                 push    0
.text:004F105C                 mov     ecx, [ebp+var_64]
.text:004F105F                 mov     edx, [ecx]
.text:004F1061                 mov     ecx, [ebp+var_64]
.text:004F1064                 call    dword ptr [edx+18h]
.text:004F1067
.text:004F1067 loc_4F1067:                             ; CODE XREF: sub_4F0E29+206j
.text:004F1067                                         ; sub_4F0E29+22Dj
.text:004F1067                 cmp     [ebp+var_60], 0
.text:004F106B                 jz      short loc_4F1083
.text:004F106D                 push    0
.text:004F106F                 mov     eax, [ebp+arg_8]
.text:004F1072                 push    eax
.text:004F1073                 mov     cl, [ebp+var_38]
.text:004F1076                 push    ecx
.text:004F1077                 mov     edx, [ebp+arg_4]
.text:004F107A                 push    edx
.text:004F107B                 call    sub_5AE50B
.text:004F1080                 add     esp, 10h
.text:004F1083
.text:004F1083 loc_4F1083:                             ; CODE XREF: sub_4F0E29+242j
.text:004F1083                 jmp     short loc_4F109B

另一个看起来像这样:

loc_5B81CF:                             ; CODE XREF: sub_5B81A9+22j
.text:005B81CF                 mov     ecx, [ebp+arg_C]
.text:005B81D2                 push    ecx
.text:005B81D3                 mov     edx, [ebp+arg_8]
.text:005B81D6                 push    edx
.text:005B81D7                 mov     al, [ebp+arg_4]
.text:005B81DA                 push    eax
.text:005B81DB                 mov     ecx, [ebp+arg_0]
.text:005B81DE                 push    ecx
.text:005B81DF                 call    sub_5AE50B
.text:005B81E4                 add     esp, 10h
.text:005B81E7
.text:005B81E7 loc_5B81E7:                             ; CODE XREF: sub_5B81A9+24j
.text:005B81E7                 pop     ebp
.text:005B81E8                 retn
.text:005B81E8 sub_5B81A9      endp

这有帮助吗? 我仍然不知道如何使用该函数,因为我不明白参数应该是什么样子。论坛上的这个人发布了我上面写的函数,但它有一个我不知道的结构.

【问题讨论】:

  • 如果call 指令在反汇编中显示以确保为调用设置了什么,这将有所帮助。 (或者这是被调用的函数本身;很难说因为你没有显示地址。)
  • 不可能说,因为你还没有展示整个功能。也不要发布图片,剪切和粘贴反汇编代码。
  • @OP:带有STRUCT *lpInfo 的C 签名显示了一个指向 结构的指针,而不是结构arg。如果 arg 一个按值传递的结构,它可能会大于 4 个字节,并且(至少在某些 32 位 x86 调用约定中)被调用者复制到堆栈中,而不是通过引用传递。说到调用约定,我们可以排除 __fastcall 作为仅对 2 个命名堆栈 args 的解释,除非第一个寄存器 arg 未被使用,因为函数写入 ECX 而不先读取它。所以没有注册参数; gcc -mregparm=2 也可以被排除在破坏 EAX 之外。
  • 我已经编辑了第一篇文章,替换了图片并添加了 2 个函数调用。

标签: assembly x86 reverse-engineering calling-convention ida


【解决方案1】:

您发布的 sn-p 没有足够的证据来判断 mov ecx, [eax+30h] 是数组还是结构访问。因此,从您显示的内容来看,第一个 arg 可能是 int *arg_0

ebp+14h 处有一个 arg,与 ebp+8 处的第一个 arg 指针末尾有 8 个字节的间隙,这告诉我们,要么

  • 第一个 arg 实际上是一个占 12 个字节的按值结构
  • 反汇编不完整,没有看到使用中间 args 的代码

  • 有 4 个 dword 大小的 args,但中间两个未使用。 (或者有一个未使用的double arg)。实际上,正常的调用约定需要填充 arg 以填充 dword 堆栈槽,因此我们不能排除像中间 args 具有 charfloatshortvoid* 类型的东西。没有理由假设他们是int

    事实上,调用者正在做mov al, stuff / push eax,所以看起来未使用的args 之一 charuint8_t


如果 [ebp+14h] 不是 arg,那么代码将读取其调用者拥有的堆栈内存,这没有任何意义。

cmp [ebp+arg_C], 0Ah / jnz loc_5AE7C9 如果 dword arg 为 != 10 则跳转。起初我在想它可能实际上是 char arg(并检查换行符),但 IDA 省略了操作数大小唯一暗示大小的是arg_C,它被定义为dword ptr。所以也许它是在int 中传递的一个字符,或者它出于其他原因正在检查10

【讨论】:

  • 嗨!因此,如果不使用参数,它们不会显示?很高兴知道。该函数在两个地方被调用,我在原始帖子中添加了两个。这是否有助于建立更多信息?
  • @user1913644:我不使用 IDA,但它看起来是这样的。它无法决定是一个 8 字节的 arg 还是两个 4 字节的 arg,或者两个 char args 填充到 4 字节的堆栈槽中,因此不显示任何内容是完全合理的。跨度>
  • 我使它与 int *a, 2 non used in the middle 和 int d 一起工作。还不知道中间的 2 是什么,其中一个可以与 int 或 char 一起使用,尽管当被钩住时,这两种情况都只是 null 或 0。
【解决方案2】:

你必须熟悉calling convention (CC)的概念。
CC 会告诉你一个函数需要多少个参数。

手写汇编函数可能不遵守任何现有的标准 CC,从而使每个函数都有自己的 CC。
在这种情况下,需要对该函数进行完整的逆向工程,以及调用站点周围的上下文。

由于被控函数中有SEH 处理程序,因此您在Windows 下。

在 Windows 中,主要的 CC 是:

  • 标准调用
  • cdecl
  • 伯兰
  • 这个电话

如果您查看调用站点并假设该函数不会使堆栈失衡,您会看到在调用之前压入堆栈的四个 DWORD 将丢失通话后立即(由于add esp, 10h 指令)。
如果函数不使用它们,那将是一个毫无意义的操作。 事实上,虽然许多恶意软件是由无数长长的指令序列组成,但结果却什么都不做,这种模式是 cdecl 约定的教科书签名。

它也可能是 thiscallfastcall 但幸运的是我们看到 ecx 已加载推送,所以它不是一个独立的参数(就像这两个 CC 要求的那样)。 borland CC 也是如此。

因为在 cdecl 中是清理堆栈的调用者,add esp, 10h 告诉我们使用了 10h / 4 = 4 个参数。


IDA 尽力而为,但根据我的经验,它不是一个自动工具。

如果你只是函数的第一部分:

                              push    ebp
.text:005AE50C                 mov     ebp, esp                    ;Prolog

.text:005AE50E                 push    0FFFFFFFFh
.text:005AE510                 push    offset loc_876BAE           ;Watch this, SEH handlers can be used to escape a debugger
.text:005AE515                 mov     eax, large fs:0
.text:005AE51B                 push    eax
.text:005AE51C                 mov     large fs:0, esp             ;Set SEH handler

.text:005AE523                 sub     esp, 524h                   ;Allocated 524h bytes of stack

.text:005AE529                 mov     eax, [ebp+arg_0]
.text:005AE52C                 mov     ecx, [eax+30h]              ;Common pattern: load a value and access an offset
                                                                   ;this usually is: array (rare, the are iterated),
                                                                   ;struct (possible) or C++ vtable (very likely considering the
                                                                   ;code around the call site)

您会看到一个常见的模式,即从内存中加载一个值 (mov eax, [ebp+arg_0]),然后将其用作间接访问 (mov ecx, [eax+30h])。
这是一个指针访问。

正如我所评论的,arg_0 可能是一个数组,但很少发生代码需要访问数组中的随机元素,您通常会看到循环中使用的数组。
它可以是一个结构体,也可以是一个 C++ 类(除了 vtable 之外,在这个级别上是同一个东西)。

考虑到此代码出现在调用站点之一:

.text:004F1058                 push    0
.text:004F105A                 push    0
.text:004F105C                 mov     ecx, [ebp+var_64]
.text:004F105F                 mov     edx, [ecx]
.text:004F1061                 mov     ecx, [ebp+var_64]
.text:004F1064                 call    dword ptr [edx+18h]

地点:

  • 通过偏移寄存器 ([edx+18h]) 进行间接调用
  • ecx 在调用之前加载(提示:ecx 的双重加载意味着这是在编译时优化了)。

我们可以推测这是对 C++ 成员函数的 fastcall,因此该程序很可能是 C++ 程序,因此 arg 是一个类。

但是我们无法确定有限的示例,它可能是 C++ 程序中的结构,或者该调用可能是 COM 调用。

IDA 发现的 alphaarg_0 无关,因为它是 ebp 的偏移量,因此是本地变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-25
    • 2012-02-10
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 2016-09-23
    • 1970-01-01
    相关资源
    最近更新 更多