首页
社区
课程
招聘
[求助]IDA逆c++程序时,一个奇怪的函数调用方式,求帮助求解释
发表于: 2017-4-13 12:55 4156

[求助]IDA逆c++程序时,一个奇怪的函数调用方式,求帮助求解释

2017-4-13 12:55
4156

我先简单描述下我的问题,一个arm库,定义了一个c++函数,他有3个参数,第一个是this指针。

调用他的时候,按理说肯定要传3个参数,分别传给r0,r1,r2。

可是在分析了调用代码发现,调用这个函数时,只传了2个参数

参数1this没有传

参数2本来应该放入r1,他却放入了r0

参数3本来应该放入r2,他却放入了r1

怪事,求解释。。。

下面是代码片段


这是so库中定义的函数createListenServer,他的第一个参数是this,加了一个__hidden限定符?会不会和__hidden有关?

.text:0008C528 ; _DWORD __fastcall tsd::common::ipc::createListenServer(tsd::common::ipc *__hidden this, const char *, unsigned int)
.text:0008C528                 EXPORT _ZN3tsd6common3ipc18createListenServerEPKcj
.text:0008C528 _ZN3tsd6common3ipc18createListenServerEPKcj
.text:0008C528                 MOV             R12, SP
.text:0008C52C                 STMFD           SP!, {R4-R7,R11,R12,LR,PC}
.text:0008C530                 LDR             R4, =(_GLOBAL_OFFSET_TABLE_ - 0x8C548)
.text:0008C534                 SUBS            R5, R0, #0
.text:0008C538                 SUB             R11, R12, #4
.text:0008C53C                 MOV             R6, R1
.text:0008C540                 ADD             R4, PC, R4 ; _GLOBAL_OFFSET_TABLE_
.text:0008C544                 LDMEQFD         SP, {R4-R7,R11,SP,PC}
.text:0008C548                 LDR             R1, =(aShmold - 0xC719C)
.text:0008C54C                 MOV             R2, #7  ; n
.text:0008C550                 ADD             R1, R4, R1 ; "shmold:"
.text:0008C554                 BL              strncmp
.text:0008C558                 CMP             R0, #0
.text:0008C55C                 BEQ             loc_8C5F0
.text:0008C560                 LDR             R1, =(aShmmpx - 0xC719C)
.text:0008C564                 MOV             R0, R5  ; s1
.text:0008C568                 MOV             R2, #7  ; n
.text:0008C56C                 ADD             R1, R4, R1 ; "shmmpx:"
.text:0008C570                 BL              strncmp
.text:0008C574                 CMP             R0, #0
.text:0008C578                 BEQ             loc_8C600
.text:0008C57C                 LDR             R1, =(aShmext - 0xC719C)
.text:0008C580                 MOV             R0, R5  ; s1
.text:0008C584                 MOV             R2, #7  ; n
.text:0008C588                 ADD             R1, R4, R1 ; "shmext:"
.text:0008C58C                 BL              strncmp
.text:0008C590                 CMP             R0, #0
.text:0008C594                 BEQ             loc_8C5E0
.text:0008C598                 LDR             R1, =(aShm - 0xC719C)
.text:0008C59C                 MOV             R0, R5  ; s1
.text:0008C5A0                 MOV             R2, #4  ; n
.text:0008C5A4                 ADD             R1, R4, R1 ; "shm:"
.text:0008C5A8                 BL              strncmp
.text:0008C5AC                 CMP             R0, #0
.text:0008C5B0                 BEQ             loc_8C620
.text:0008C5B4                 LDR             R1, =(aQnx - 0xC719C)
.text:0008C5B8                 MOV             R0, R5  ; s1
.text:0008C5BC                 MOV             R2, #4  ; n
.text:0008C5C0                 ADD             R1, R4, R1 ; "qnx:"
.text:0008C5C4                 BL              strncmp
.text:0008C5C8                 CMP             R0, #0
.text:0008C5CC                 BEQ             loc_8C610
.text:0008C5D0                 MOV             R0, R5  ; this
.text:0008C5D4                 UXTH            R1, R6
.text:0008C5D8                 LDMFD           SP, {R4-R7,R11,SP,LR}
.text:0008C5DC                 B               j__ZN3tsd6common3ipc5posix24createSocketListenServerEPKct ; tsd::common::ipc::posix::createSocketListenServer(char const*,ushort)
.text:0008C5E0 ; ---------------------------------------------------------------------------
.text:0008C5E0
.text:0008C5E0 loc_8C5E0                               ; CODE XREF: tsd::common::ipc::createListenServer(char const*,uint)+6Cj
.text:0008C5E0                 ADD             R0, R5, #7 ; this
.text:0008C5E4                 MOV             R1, R6  ; char *
.text:0008C5E8                 LDMFD           SP, {R4-R7,R11,SP,LR}
.text:0008C5EC                 B               j__ZN3tsd6common3ipc5posix33createExtSharedMemoryListenServerEPKcj ; tsd::common::ipc::posix::createExtSharedMemoryListenServer(char const*,uint)
.text:0008C5F0 ; ---------------------------------------------------------------------------
.text:0008C5F0
.text:0008C5F0 loc_8C5F0                               ; CODE XREF: tsd::common::ipc::createListenServer(char const*,uint)+34j
.text:0008C5F0                 ADD             R0, R5, #7 ; this
.text:0008C5F4                 MOV             R1, R6  ; char *
.text:0008C5F8                 LDMFD           SP, {R4-R7,R11,SP,LR}
.text:0008C5FC                 B               j__ZN3tsd6common3ipc5posix30createSharedMemoryListenServerEPKcj ; tsd::common::ipc::posix::createSharedMemoryListenServer(char const*,uint)
.text:0008C600 ; ---------------------------------------------------------------------------
.text:0008C600
.text:0008C600 loc_8C600                               ; CODE XREF: tsd::common::ipc::createListenServer(char const*,uint)+50j
.text:0008C600                 ADD             R0, R5, #7 ; this
.text:0008C604                 MOV             R1, R6  ; char *
.text:0008C608                 LDMFD           SP, {R4-R7,R11,SP,LR}
.text:0008C60C                 B               j__ZN3tsd6common3ipc5posix39createMultiplexSharedMemoryListenServerEPKcj ; tsd::common::ipc::posix::createMultiplexSharedMemoryListenServer(char const*,uint)
.text:0008C610 ; ---------------------------------------------------------------------------
.text:0008C610
.text:0008C610 loc_8C610                               ; CODE XREF: tsd::common::ipc::createListenServer(char const*,uint)+A4j
.text:0008C610                 ADD             R0, R5, #4 ; this
.text:0008C614                 MOV             R1, R6  ; char *
.text:0008C618                 LDMFD           SP, {R4-R7,R11,SP,LR}
.text:0008C61C                 B               j__ZN3tsd6common3ipc3qnx21createQnxListenServerEPKcj ; tsd::common::ipc::qnx::createQnxListenServer(char const*,uint)
.text:0008C620 ; ---------------------------------------------------------------------------
.text:0008C620
.text:0008C620 loc_8C620                               ; CODE XREF: tsd::common::ipc::createListenServer(char const*,uint)+88j
.text:0008C620                 ADD             R0, R5, #4 ; this
.text:0008C624                 MOV             R1, R6  ; char *
.text:0008C628                 LDMFD           SP, {R4-R7,R11,SP,LR}
.text:0008C62C                 B               j__ZN3tsd6common3ipc5posix33createExtSharedMemoryListenServerEPKcj ; tsd::common::ipc::posix::createExtSharedMemoryListenServer(char const*,uint)
.text:0008C62C ; End of function tsd::common::ipc::createListenServer(char const*,uint)


下面是调用createListenServer的代码

可以看出只给r0和r1传了参数,分别对应createListenServer函数的参数2和参数3,this不知道用什么传的??

.text:001117E0                 LDR             R0, =(a0_0_0_0 - 0x1FA9E0)
.text:001117E4                 MOV             R1, #5555 ; char *
.text:001117E8                 ADD             R0, R6, R0 ; "0.0.0.0"
.text:001117EC                 BL              _ZN3tsd6common3ipc18createListenServerEPKcj ; tsd::common::ipc::createListenServer(char const*,uint)
.text:001117F0                 LDR             R0, =(aShmHmi - 0x1FA9E0)
.text:001117F4                 MOV             R1, #4096 ; char *
.text:001117F8                 ADD             R0, R6, R0 ; "shm:HMI"
.text:001117FC                 BL              _ZN3tsd6common3ipc18createListenServerEPKcj ; tsd::common::ipc::createListenServer(char const*,uint)
.text:00111800                 LDR             R0, =(aShmPicserver - 0x1FA9E0)
.text:00111804                 MOV             R1, #0x1000 ; char *
.text:00111808                 ADD             R0, R6, R0 ; "shm:PICSERVER"
.text:0011180C                 BL              _ZN3tsd6common3ipc18createListenServerEPKcj ; tsd::common::ipc::createListenServer(char const*,uint)
.text:00111810                 BL              sub_11137C
.text:00111814                 LDR             R0, =(aQnxRoot - 0x1FA9E0)
.text:00111818                 MOV             R1, #0  ; char *
.text:0011181C                 ADD             R0, R6, R0 ; "qnx:root"
.text:00111820                 BL              _ZN3tsd6common3ipc18createListenServerEPKcj ; tsd::common::ipc::createListenServer(char const*,uint)




[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 0
支持
分享
最新回复 (5)
雪    币: 8155
活跃值: (1880)
能力值: ( LV8,RANK:122 )
在线值:
发帖
回帖
粉丝
2
是不是像WIndow平台一样用ECX传递This一样,  用寄存器代替了
2017-4-13 16:06
0
雪    币: 54
活跃值: (75)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
那就说明函数里没有用到this呗,编译器优化了
2017-4-13 21:17
0
雪    币: 3758
活跃值: (3282)
能力值: ( LV15,RANK:500 )
在线值:
发帖
回帖
粉丝
4
你这里应该是一个静态类方法.
甚至这里可能是一个名称空间,  不是类.
2017-4-14 22:26
0
雪    币: 29
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5

 

2017-4-15 08:58
0
雪    币: 3758
活跃值: (3282)
能力值: ( LV15,RANK:500 )
在线值:
发帖
回帖
粉丝
6
静态  类方法  注意断句.  C++没有你想表达的"静态类"概念.  如果你拿出证据说有那肯定是CLR的.
你说的全局变量那是值类型实例.
C++的名称修饰不能区分名称空间和类和结构.  也不能区分有没有返回值(有时候返回值位数过大要占用第一个参数槽)
如果是类的函数,  它更不能区分是不是静态函数.  ARM的EABI规范可能你还没有楼主了解,  这里如果要用this确实会通过r0.
有没有push(STM/STR)跟传参方式没有关系,  不管什么call修饰在ARM里面都是同一个规范,  是不是用栈只跟参数数量和类型有关系.
至于通过vft调用的可能性,  它调用的时候需要ldr  reg,  [this,  #off],  blx  reg才可能,  这里bl的直接是"函数地址",  它就不会是一个vft  call.
剩下的可能性就是ipc是名称空间,  或者createListenServer它是static  ipc::createListenServer(r0,  r1)这样的声明.
至于编译器优化忽略参数,  非导出的是可以做的.  这是一个导出函数.  链接/运行时候是面向的毫不知情的第三方代码.
2017-4-15 23:02
0
游客
登录 | 注册 方可回帖
返回
//