CSDN博客

img IceMe

VB中字符串处理函数反汇编对比

发表于2004/10/22 13:36:00  2434人阅读

简单代码用于反汇编测试对比:

不带$的字符串处理函数测试代码:
Dim s As String

Private Sub Command1_Click()
s = Left("test str", 3)
End Sub

SC可知Command1_Click的入口点:00401A30

反汇编代码:
00401A84   . C745 C0 CC1640>MOV DWORD PTR SS:[EBP-40],WITHOUTI.00401>;  UNICODE "test str"
00401A8B   . C745 B8 080000>MOV DWORD PTR SS:[EBP-48],8
00401A92   . FF15 6C104000  CALL DWORD PTR DS:[<&MSVBVM60.__vbaVarDu>;  MSVBVM60.__vbaVarDup
00401A98   . 8D55 D8        LEA EDX,DWORD PTR SS:[EBP-28]
00401A9B   . 6A 03          PUSH 3
00401A9D   . 8D45 C8        LEA EAX,DWORD PTR SS:[EBP-38]
00401AA0   . 52             PUSH EDX
00401AA1   . 50             PUSH EAX
00401AA2   . FF15 70104000  CALL DWORD PTR DS:[<&MSVBVM60.#617>]     ;  MSVBVM60.rtcLeftCharVar
00401AA8   . 8D4D C8        LEA ECX,DWORD PTR SS:[EBP-38]
00401AAB   . 51             PUSH ECX
00401AAC   . FF15 08104000  CALL DWORD PTR DS:[<&MSVBVM60.__vbaStrVa>;  MSVBVM60.__vbaStrVarMove
00401AB2   . 8BD0           MOV EDX,EAX
00401AB4   . 8D4D E8        LEA ECX,DWORD PTR SS:[EBP-18]
00401AB7   . FF15 78104000  CALL DWORD PTR DS:[<&MSVBVM60.__vbaStrMo>;  MSVBVM60.__vbaStrMove
00401ABD   . 8BD0           MOV EDX,EAX
00401ABF   . 8D4E 34        LEA ECX,DWORD PTR DS:[ESI+34]
00401AC2   . FF15 5C104000  CALL DWORD PTR DS:[<&MSVBVM60.__vbaStrCo>;  MSVBVM60.__vbaStrCopy
00401AC8   . 8D4D E8        LEA ECX,DWORD PTR SS:[EBP-18]
00401ACB   . FF15 88104000  CALL DWORD PTR DS:[<&MSVBVM60.__vbaFreeS>;  MSVBVM60.__vbaFreeStr
00401AD1   . 8D55 C8        LEA EDX,DWORD PTR SS:[EBP-38]
00401AD4   . 8D45 D8        LEA EAX,DWORD PTR SS:[EBP-28]
00401AD7   . 52             PUSH EDX
00401AD8   . 50             PUSH EAX
00401AD9   . 6A 02          PUSH 2
00401ADB   . FF15 0C104000  CALL DWORD PTR DS:[<&MSVBVM60.__vbaFreeV>;  MSVBVM60.__vbaFreeVarList
00401AE1   . 83C4 0C        ADD ESP,0C
00401AE4   . 897D FC        MOV DWORD PTR SS:[EBP-4],EDI
00401AE7   . 68 0C1B4000    PUSH WITHOUTI.00401B0C
00401AEC   . EB 1D          JMP SHORT WITHOUTI.00401B0B
00401AEE   . 8D4D E8        LEA ECX,DWORD PTR SS:[EBP-18]
00401AF1   . FF15 88104000  CALL DWORD PTR DS:[<&MSVBVM60.__vbaFreeS>;  MSVBVM60.__vbaFreeStr
00401AF7   . 8D4D C8        LEA ECX,DWORD PTR SS:[EBP-38]
00401AFA   . 8D55 D8        LEA EDX,DWORD PTR SS:[EBP-28]
00401AFD   . 51             PUSH ECX
00401AFE   . 52             PUSH EDX
00401AFF   . 6A 02          PUSH 2
00401B01   . FF15 0C104000  CALL DWORD PTR DS:[<&MSVBVM60.__vbaFreeV>;  MSVBVM60.__vbaFreeVarList

带$的字符串处理函数测试代码:
Dim s As String

Private Sub Command1_Click()
s = Left("test str", 3)
End Sub

SC可知Command1_Click的入口点:004019E0


反汇编代码:
00401A24   . 68 B4164000    PUSH WITHIT.004016B4                     ;  UNICODE "test str"
00401A29   . 897D E8        MOV DWORD PTR SS:[EBP-18],EDI
00401A2C   . FF15 64104000  CALL DWORD PTR DS:[<&MSVBVM60.#616>]     ;  MSVBVM60.rtcLeftCharBstr
00401A32   . 8BD0           MOV EDX,EAX
00401A34   . 8D4D E8        LEA ECX,DWORD PTR SS:[EBP-18]
00401A37   . FF15 6C104000  CALL DWORD PTR DS:[<&MSVBVM60.__vbaStrMo>;  MSVBVM60.__vbaStrMove
00401A3D   . 8BD0           MOV EDX,EAX
00401A3F   . 8D4E 34        LEA ECX,DWORD PTR DS:[ESI+34]
00401A42   . FF15 54104000  CALL DWORD PTR DS:[<&MSVBVM60.__vbaStrCo>;  MSVBVM60.__vbaStrCopy
00401A48   . 8D4D E8        LEA ECX,DWORD PTR SS:[EBP-18]
00401A4B   . FF15 7C104000  CALL DWORD PTR DS:[<&MSVBVM60.__vbaFreeS>;  MSVBVM60.__vbaFreeStr
00401A51   . 897D FC        MOV DWORD PTR SS:[EBP-4],EDI
00401A54   . 68 661A4000    PUSH WITHIT.00401A66
00401A59   . EB 0A          JMP SHORT WITHIT.00401A65
00401A5B   . 8D4D E8        LEA ECX,DWORD PTR SS:[EBP-18]
00401A5E   . FF15 7C104000  CALL DWORD PTR DS:[<&MSVBVM60.__vbaFreeS>;  MSVBVM60.__vbaFreeStr


可以看出,不带$的函数比带$的函数的反汇编代码要罗嗦很多,而且资源释放也比带$的麻烦,其效率可想比带$的函数差很多

两类函数只差一个$,所以建议大家使用带$的那类函数

阅读全文
0 0

相关文章推荐

img
取 消
img