本帖最后由 Terrorblade 于 2015-8-20 01:10 编辑
0x00 前言 终于摆脱了冗余的java,来到了与ARM汇编正面交锋的第二题,验证代码在libclacSn.so文件的Java_com_ucweb_crackme140522_MainActivity_clacSnFuntion中,这里不得不说一句,计算的英文单词是calculate,能把calc写成clac,还有就是Function,这也能写成Funtion ,一个大公司,如此不严谨,看着也是有点醉了……
0x01 so调试前奏 1.以调试模式启动程序,命令: amstart -D -n com.ucweb.crackme140522/.MainActivity 图1.启动程序
2.启动android_server,这个文件在ida的dbgsrv文件夹中,需要上传到avd中,这里不多说,这些细节那两篇绝对说过的,命令: /data/local/tmp/android_server
图2.已经在监听23946端口了
3.启动ddms,就是sdk目录中的ddms.bat
图3.启动ddms
4.端口转发,另外启动一个cmd,执行命令:
图4.端口转发
5.此时可以启动ida了,debugger->attach ->remote arm linux /android debugger, 然后:
图5. 勾上3项
6.选中要调试的进程后,千万记得在debugger->debugger options中再次选中,那3项:
图6.再次选中3项
7.回到cmd,输入jdb -connect com.sun.jdi.SocketAttach:hostname=127.0.0.1,port=8700,回车
8.然后在ida中F9,接着就是选择本地文件映射:
图7.选择映射
9.计算出Java_com_ucweb_crackme140522_MainActivity_clacSnFuntion的地址,F2,再F9运行,期间会出现一个不相关的so文件,cancel就是了
0x02 算法 因为已经调试过了,所以我站在一个已知者角度调试,不多废话,看到起始处,F7进去 0000267C018 BL loc_21B4 ; 起始处
然后直接F4到loc_23E8: [Asm] 纯文本查看 复制代码 libclacSn.so:AD9F83E8loc_AD9F83E8 ; CODE XREF:libclacSn.so:JNI_OnLoad+598j
libclacSn.so:AD9F83E8LDRB R2, [R6,R3] ; imei
libclacSn.so:AD9F83ECLDRB R1, [R10,R3] ; un,username
libclacSn.so:AD9F83F0EOR R2, R1, R2 ; 逻辑异或
libclacSn.so:AD9F83F4STRB R2, [R6,R3] ; 计算结果,保存在R6中
libclacSn.so:AD9F83F8ADD R3, R3, #1 ; Rd = Op1 + Op2
libclacSn.so:AD9F83FCCMP R3, R4 ; R4为un长度
libclacSn.so:AD9F8400BNE loc_AD9F83E8 ; Branch
F4到loc_2404,此时先看看R6的计算结果: [Asm] 纯文本查看 复制代码 [heap]:B89C69D8DCB 0x64 ; d
[heap]:B89C69D9DCB 0x55 ; U
[heap]:B89C69DADCB 0x42 ; B
[heap]:B89C69DBDCB 0x42 ; B
[heap]:B89C69DCDCB 0x5F ; _
[heap]:B89C69DDDCB 0x42 ; B
[heap]:B89C69DEDCB 0x52 ; R
[heap]:B89C69DFDCB 0x5C ; \
[heap]:B89C69E0DCB 0x51 ; Q
[heap]:B89C69E1DCB 0x54 ; T
[heap]:B89C69E2DCB 0x55 ; U
[heap]:B89C69E3DCB 0x30 ; 0
[heap]:B89C69E4DCB 0x30 ; 0
[heap]:B89C69E5DCB 0x30 ; 0
[heap]:B89C69E6DCB 0x30 ; 0 这里只有15位,后面会有0x80补全16位!
看loc_2404代码: [Asm] 纯文本查看 复制代码 libclacSn.so:AD9F8404loc_AD9F8404 ;CODE XREF: libclacSn.so:JNI_OnLoad+578j
libclacSn.so:AD9F8404MOV R0, R9 ; Rd = Op2
libclacSn.so:AD9F8408BLX R11 ; Branch with Link andExchange (register indirect)
libclacSn.so:AD9F840CLDR R3, [SP,#0x50] ; Load from Memory
libclacSn.so:AD9F8410LDR R0, =0x66666667 ; Load from Memory
libclacSn.so:AD9F8414ADD R4, SP, #0x1AC ; Rd = Op1 + Op2
libclacSn.so:AD9F8418MOV R2, R3,ASR#31 ; Rd = Op2
libclacSn.so:AD9F841CSMULL R12, R1, R0, R3 ; Signed Multiply long
libclacSn.so:AD9F8420LDR R0, [R6] ; Load from Memory
libclacSn.so:AD9F8424RSB R2, R2, R1,ASR#3 ; Rd = Op2 - Op1
libclacSn.so:AD9F8428LDR R1, [SP,#0x10] ; Load from Memory
libclacSn.so:AD9F842CMOV R3, #0 ; Rd = Op2
libclacSn.so:AD9F8430ADD R12, R4, #4 ; Rd = Op1 + Op2
libclacSn.so:AD9F8434STR R3, [R12],#4 ; Store to Memory
libclacSn.so:AD9F8438STR R3, [R12],#4 ; Store to Memory
libclacSn.so:AD9F843CEOR LR, R2, R1 ; Rd = Op1 ^ Op2
libclacSn.so:AD9F8440EOR LR, R0, LR ; Rd = Op1 ^ Op2
libclacSn.so:AD9F8444STR R3, [R12],#4 ; Store to Memory
libclacSn.so:AD9F8448STR LR, [R6] ; Store to Memory
libclacSn.so:AD9F844CSTR R3, [R12] ; Store to Memory
libclacSn.so:AD9F8450LDR R12, =0x67452301 ; Load from Memory
libclacSn.so:AD9F8454ADD R5, SP, #0x154 ; Rd = Op1 + Op2
libclacSn.so:AD9F8458LDR R2, [SP,#0x14] ; Load from Memory
libclacSn.so:AD9F845CSTR R12, [SP,#0x154] ; Store to Memory
libclacSn.so:AD9F8460ADD R12, R12,#0x88000000 ; Rd = Op1 + Op2
libclacSn.so:AD9F8464ADD R12, R12, #0x880000 ; Rd = Op1 + Op2
libclacSn.so:AD9F8468ADD R12, R12, #0x8800 ; Rd = Op1 + Op2
libclacSn.so:AD9F846CADD R12, R12, #0x88 ; Rd = Op1 + Op2
libclacSn.so:AD9F8470STR R12, [SP,#0x158] ; Store to Memory
libclacSn.so:AD9F8474LDR R12, =0x98BADCFE ; Load from Memory
libclacSn.so:AD9F8478MOV R0, R5 ; Rd = Op2
libclacSn.so:AD9F847CMOV R1, R6 ; Rd = Op2
libclacSn.so:AD9F8480STR R12, [SP,#0x15C] ; Store to Memory
libclacSn.so:AD9F8484LDR R12, =0x10325476 ; Load from Memory
libclacSn.so:AD9F8488ADD R10, SP, #0x1D4 ; Rd = Op1 + Op2
libclacSn.so:AD9F848CSTR R3, [SP,#0x164] ; Store to Memory
libclacSn.so:AD9F8490STR R12, [SP,#0x160] ; Store to Memory
libclacSn.so:AD9F8494STR R3, [SP,#0x1AC] ; Store to Memory
libclacSn.so:AD9F8498STR R3, [SP,#0x168] ; Store to Memory
libclacSn.so:AD9F849CBL unk_AD9F7B78 ; 通过上面的计算,得到R5,虽说是通过计算,但是R5的内容是固定的:
libclacSn.so:AD9F849C ; [stack]:BEE8D42CDCB 1
libclacSn.so:AD9F849C ;[stack]:BEE8D42D DCB 0x23 ; #
libclacSn.so:AD9F849C ;[stack]:BEE8D42E DCB 0x45 ; E
libclacSn.so:AD9F849C ;[stack]:BEE8D42F DCB 0x67 ; g
libclacSn.so:AD9F849C ;[stack]:BEE8D430 DCB 0x89 ;
libclacSn.so:AD9F849C ;[stack]:BEE8D431 DCB 0xAB ;
libclacSn.so:AD9F849C ;[stack]:BEE8D432 DCB 0xCD ;
libclacSn.so:AD9F849C ;[stack]:BEE8D433 DCB 0xEF ;
libclacSn.so:AD9F849C ; [stack]:BEE8D434DCB 0xFE ;
libclacSn.so:AD9F849C ;[stack]:BEE8D435 DCB 0xDC ;
libclacSn.so:AD9F849C ;[stack]:BEE8D436 DCB 0xBA ;
libclacSn.so:AD9F849C ; [stack]:BEE8D437 DCB 0x98 ;
libclacSn.so:AD9F849C ;[stack]:BEE8D438 DCB 0x76 ; v
libclacSn.so:AD9F849C ;[stack]:BEE8D439 DCB 0x54 ; T
libclacSn.so:AD9F849C ;[stack]:BEE8D43A DCB 0x32 ; 2
libclacSn.so:AD9F849C ;[stack]:BEE8D43B DCB 0x10
libclacSn.so:AD9F849C ; 一个byte数组的逆序
libclacSn.so:AD9F84A0MOV R0, R10 ; Rd = Op2
libclacSn.so:AD9F84A4ADD R1, R5, #0x10 ; Rd = Op1 + Op2
libclacSn.so:AD9F84A8MOV R2, #8 ; Rd = Op2
libclacSn.so:AD9F84ACBL unk_AD9F7C64 ; Branch with Link
libclacSn.so:AD9F84B0LDR R2, [SP,#0x164] ; Load from Memory
libclacSn.so:AD9F84B4LDR R3, =0x4A70 ; Load from Memory
libclacSn.so:AD9F84B8MOV R0, R5 ; Rd = Op2
libclacSn.so:AD9F84BCMOV R2, R2,LSR#3 ; Rd = Op2
libclacSn.so:AD9F84C0AND R2, R2, #0x3F ; Rd = Op1 & Op2
libclacSn.so:AD9F84C4ADD R3, PC, R3 ; Rd = Op1 + Op2
libclacSn.so:AD9F84C8CMP R2, #0x37 ; Set cond. codes on Op1 - Op2
libclacSn.so:AD9F84CCSUB R3, R3, #0xFF0 ; Rd = Op1 - Op2
libclacSn.so:AD9F84D0SUB R1, R3, #8 ; Rd = Op1 - Op2
libclacSn.so:AD9F84D4RSBLS R2, R2, #0x38 ; Rd = Op2 - Op1
libclacSn.so:AD9F84D8RSBHI R2, R2, #0x78 ; Rd = Op2 - Op1
libclacSn.so:AD9F84DCBL unk_AD9F7B78 ; Branch with Link
libclacSn.so:AD9F84E0MOV R0, R5 ; Rd = Op2
libclacSn.so:AD9F84E4MOV R1, R10 ; Rd = Op2
libclacSn.so:AD9F84E8MOV R2, #8 ; Rd = Op2
libclacSn.so:AD9F84ECBL unk_AD9F7B78 ; 这里R5发生改变,F7一探究竟
libclacSn.so:AD9F84F0MOV R2, #0x10 ; Rd = Op2
libclacSn.so:AD9F84F4MOV R0, R4 ; Rd = Op2
libclacSn.so:AD9F84F8MOV R1, R5 ; Rd = Op2
libclacSn.so:AD9F84FCBL unk_AD9F7C64 ; R5的内容复制给R4
libclacSn.so:AD9F8500ADD R2, R5, #0x58 ; Rd = Op1 + Op2
libclacSn.so:AD9F8504MOV R3, #0 ; Rd = Op2
F7进入loc_1B78之后,直接F4来到loc_1BF0,这里是算法所在: [Asm] 纯文本查看 复制代码 libclacSn.so:AD9F712CLDRB R7, [R1,#2] ; iu的第3位,iu即imei^un
libclacSn.so:AD9F7130LDRB R8, [R1,#1] ; iu第2位
libclacSn.so:AD9F7134LDRB R6, [R1] ; iu的第1位
libclacSn.so:AD9F7138LDRB R5, [R1,#3] ; iu第4位
libclacSn.so:AD9F713CMOV R7, R7,LSL#16 ; lsl为逻辑左移
libclacSn.so:AD9F7140ORR R7, R7, R8,LSL#8 ; Rd = Op1 | Op2
libclacSn.so:AD9F7144ORR R6, R7, R6 ; Rd = Op1 | Op2
libclacSn.so:AD9F7148ADD R1, R1, #4 ; Rd = Op1 + Op2
libclacSn.so:AD9F714CORR R5, R6, R5,LSL#24 ; Rd = Op1 | Op2
libclacSn.so:AD9F7150CMP R1, R10 ; 16位比较完为止
libclacSn.so:AD9F7154STR R5, [R4],#4 ; Store to Memory
libclacSn.so:AD9F7158BNE loc_AD9F712C ; Branch
libclacSn.so:AD9F715CLDR R7, [SP,#0x18] ; iu前四位
libclacSn.so:AD9F7160LDR R6, [SP,#0xC] ; 16byte的后四位,即76,54,32,10
libclacSn.so:AD9F7164LDR R1, =0xD76AA478 ; Load from Memory
libclacSn.so:AD9F7168LDR R8, [SP,#0x10] ; iu后四位
libclacSn.so:AD9F716CBIC R5, R6, R3 ; Rd = Op1 & ~Op2
libclacSn.so:AD9F7170AND R4, R2, R3 ; Rd = Op1 & Op2
libclacSn.so:AD9F7174ADD R1, R7, R1 ; Rd = Op1 + Op2
libclacSn.so:AD9F7178ADD R1, R1, R8 ; Rd = Op1 + Op2
libclacSn.so:AD9F717CLDR R9, [SP,#0x1C] ; iu的四分之二
libclacSn.so:AD9F7180ORR R4, R5, R4 ; Rd = Op1 | Op2
libclacSn.so:AD9F7184LDR R5, =0xE8C7B756 ; Load from Memory
libclacSn.so:AD9F7188LDR R10, [SP,#0xC] ; Load from Memory
libclacSn.so:AD9F718CADD R4, R1, R4 ; 16byte的后4位
libclacSn.so:AD9F7190ADD R4, R3, R4,ROR#25 ; Rd = Op1 + Op2
libclacSn.so:AD9F7194BIC R6, R2, R4 ; Rd = Op1 & ~Op2
libclacSn.so:AD9F7198AND R1, R4, R3 ; Rd = Op1 & Op2
libclacSn.so:AD9F719CADD R5, R9, R5 ; Rd = Op1 + Op2
libclacSn.so:AD9F71A0ADD R5, R5, R10 ; Rd = Op1 + Op2
libclacSn.so:AD9F71A4LDR R11, [SP,#0x20] ; iu的四分之三
libclacSn.so:AD9F71A8ORR R1, R6, R1 ; Rd = Op1 | Op2
libclacSn.so:AD9F71ACLDR R8, =0x242070DB ; Load from Memory
libclacSn.so:AD9F71B0ADD R1, R5, R1 ; Rd = Op1 + Op2
libclacSn.so:AD9F71B4ADD R1, R4, R1,ROR#20 ; Rd = Op1 + Op2
libclacSn.so:AD9F71B8AND R5, R1, R4 ; Rd = Op1 & Op2
libclacSn.so:AD9F71BCBIC R6, R3, R1 ; Rd = Op1 & ~Op2
libclacSn.so:AD9F71C0ADD R8, R11, R8 ; Rd = Op1 + Op2
libclacSn.so:AD9F71C4ADD R8, R8, R2 ; Rd = Op1 + Op2
libclacSn.so:AD9F71C8ORR R6, R6, R5 ; Rd = Op1 | Op2
libclacSn.so:AD9F71CCADD R6, R8, R6 ; Rd = Op1 + Op2
libclacSn.so:AD9F71D0LDR R5, =0xC1BDCEEE ; Load from Memory
libclacSn.so:AD9F71D4LDR R8, [SP,#0x24] ; iu后4位
.
.
.
中间是个汉诺塔计算过程,最终计算结果会保存在r6,r2,r3,r4,所以去到下面代码,待会再回头分析这里
.
.
.
libclacSn.so:AD9F7A80STR R6, [R0,#0xC] ; Store to Memory
libclacSn.so:AD9F7A84STR R3, [R0,#4] ; Store to Memory
libclacSn.so:AD9F7A88STR R2, [R0,#8] ; Store to Memory
libclacSn.so:AD9F7A8CSTR R4, [R0] ; Store to Memory
libclacSn.so:AD9F7A90ADD R2, R12, #0x40 ; Rd = Op1 + Op2
libclacSn.so:AD9F7A94MOV R3, #0 ; Rd = Op2
存储后,R0的内容: [Asm] 纯文本查看 复制代码 [stack]:BEE8D454DCB 0xB2 ;
[stack]:BEE8D455DCB 0x52 ; R
[stack]:BEE8D456DCB 0x7A ; z
[stack]:BEE8D457DCB 0x16
[stack]:BEE8D458DCB 0
[stack]:BEE8D459DCB 0xD5 ;
[stack]:BEE8D45ADCB 0x8A ;
[stack]:BEE8D45BDCB 0x99 ;
[stack]:BEE8D45CDCB 0x5F ; _
[stack]:BEE8D45DDCB 0x21 ; !
[stack]:BEE8D45EDCB 0x1C
[stack]:BEE8D45FDCB 0x96 ;
[stack]:BEE8D460DCB 0xA2 ;
[stack]:BEE8D461DCB 0x48 ; H
[stack]:BEE8D462DCB 0xB8 ;
[stack]:BEE8D463DCB 0x3C ; <
跳出算法的关键部分以后,后续还有一些运算: [Asm] 纯文本查看 复制代码 libclacSn.so:AD9F851Cloc_AD9F851C ;CODE XREF: libclacSn.so:JNI_OnLoad+6D0j
libclacSn.so:AD9F851CLDRB R0, [R4,R3] ; 注册码第一运算
libclacSn.so:AD9F8520ADD R1, R2, #1 ; Rd = Op1 + Op2
libclacSn.so:AD9F8524EOR R2, R2, R0 ; Rd = Op1 ^ Op2
libclacSn.so:AD9F8528STRB R2, [R7,R3] ; 结果存储R7中
libclacSn.so:AD9F852CADD R3, R3, #1 ; Rd = Op1 + Op2
libclacSn.so:AD9F8530CMP R3, #0x10 ; 比较16次
libclacSn.so:AD9F8534AND R2, R1, #0xFF ; Rd = Op1 & Op2
libclacSn.so:AD9F8538BNE loc_AD9F851C ; Branch
libclacSn.so:AD9F853CNOP ;No Operation
libclacSn.so:AD9F8540LDR R10, =(unk_AD9F9C58 -0xAD9F8554) ; Load from Memory
libclacSn.so:AD9F8544LDR R5, [SP,#4] ; Load from Memory
libclacSn.so:AD9F8548MOV R4, #0 ; Rd = Op2
libclacSn.so:AD9F854CADD R10, PC, R10 ;unk_AD9F9C58 ; Rd = Op1 + Op2
libclacSn.so:AD9F8550
libclacSn.so:AD9F8550loc_AD9F8550 ;CODE XREF: libclacSn.so:JNI_OnLoad+70Cj
libclacSn.so:AD9F8550LDRB R2, [R7,R4] ; 注册码第二次运算
libclacSn.so:AD9F8554ADD R3, R4, #0x10 ; Rd = Op1 + Op2
libclacSn.so:AD9F8558MOV R0, R5 ; Rd = Op2
libclacSn.so:AD9F855CADD R4, R4, #1 ; Rd = Op1 + Op2
libclacSn.so:AD9F8560EOR R2, R2, R3 ; Rd = Op1 ^ Op2
libclacSn.so:AD9F8564MOV R1, R10 ; Rd = Op2
libclacSn.so:AD9F8568BL sprintf ; 将计算得出的16byte数据,直接拼接成string
libclacSn.so:AD9F856CCMP R4, #0x10 ; Set cond. codes on Op1 - Op2
libclacSn.so:AD9F8570ADD R5, R5, #2 ; Rd = Op1 + Op2
libclacSn.so:AD9F8574BNE loc_AD9F8550 ; Branch
libclacSn.so:AD9F8578MOV R0, R9 ; Rd = Op2
libclacSn.so:AD9F857CBLX R11 ; Branch with Link andExchange (register indirect)
libclacSn.so:AD9F8580LDR R1, [SP,#0x50] ; Load from Memory
libclacSn.so:AD9F8584LDR R0, =0x66666667 ; Load from Memory
libclacSn.so:AD9F8588LDR R12, [SP,#0x10] ; Load from Memory
libclacSn.so:AD9F858CMOV R3, R1,ASR#31 ; Rd = Op2
libclacSn.so:AD9F8590SMULL R7, R2, R0, R1 ; Signed Multiply long
libclacSn.so:AD9F8594MOV R0, R6 ; Rd = Op2
libclacSn.so:AD9F8598RSB R3, R3, R2,ASR#3 ;Rd = Op2 - Op1
libclacSn.so:AD9F859CLDR R2, [SP,#0x54] ; Load from Memory
libclacSn.so:AD9F85A0EOR R3, R12, R3 ; Rd = Op1 ^ Op2
libclacSn.so:AD9F85A4EOR R3, R2, R3 ; Rd = Op1 ^ Op2
libclacSn.so:AD9F85A8STR R3, [SP,#0x54] ; Store to Memory
libclacSn.so:AD9F85ACBL free ; Branch with Link
libclacSn.so:AD9F85B0LDR R0, [SP,#4] ; Load from Memory
libclacSn.so:AD9F85B4LDR R1, [SP,#0xC] ; Load from Memory
libclacSn.so:AD9F85B8MOV R2, R4 ; Rd = Op2
libclacSn.so:AD9F85BCBL memcmp ; 这里进行比较,R1存储着假码
libclacSn.so:AD9F85C0CMP R0, #0 ; Set cond. codes on Op1 -Op2
libclacSn.so:AD9F85C4BNE loc_AD9F8340 ; Branch
libclacSn.so:AD9F85C8NOP ;No Operation
libclacSn.so:AD9F85CCMOV R0, #1 ; Rd = Op2
libclacSn.so:AD9F85D0B loc_AD9F8344 ; Branch
来看看loc_25B0中,R0的内容: [Asm] 纯文本查看 复制代码 [stack]:BEE8D354DCB 0x42 ; B
[stack]:BEE8D355DCB 0x32 ; 2
[stack]:BEE8D356DCB 0x35 ; 5
[stack]:BEE8D357DCB 0x32 ; 2
[stack]:BEE8D358DCB 0x37 ; 7
[stack]:BEE8D359DCB 0x41 ; A
[stack]:BEE8D35ADCB 0x31 ; 1
[stack]:BEE8D35BDCB 0x36 ; 6
[stack]:BEE8D35CDCB 0x30 ; 0
[stack]:BEE8D35DDCB 0x30 ; 0
[stack]:BEE8D35EDCB 0x44 ; D
[stack]:BEE8D35FDCB 0x35 ; 5
[stack]:BEE8D360DCB 0x38 ; 8
[stack]:BEE8D361DCB 0x41 ; A
[stack]:BEE8D362DCB 0x39 ; 9
[stack]:BEE8D363DCB 0x39 ; 9
[stack]:BEE8D364DCB 0x35 ; 5
[stack]:BEE8D365DCB 0x46 ; F
[stack]:BEE8D366DCB 0x32 ; 2
[stack]:BEE8D367DCB 0x31 ; 1
[stack]:BEE8D368DCB 0x31 ; 1
[stack]:BEE8D369DCB 0x43 ; C
[stack]:BEE8D36ADCB 0x39 ; 9
[stack]:BEE8D36BDCB 0x36 ; 6
[stack]:BEE8D36CDCB 0x41 ; A
[stack]:BEE8D36DDCB 0x32 ; 2
[stack]:BEE8D36EDCB 0x34 ; 4
[stack]:BEE8D36FDCB 0x38 ; 8
[stack]:BEE8D370DCB 0x42 ; B
[stack]:BEE8D371DCB 0x38 ; 8
[stack]:BEE8D372DCB 0x33 ; 3
[stack]:BEE8D373DCB 0x43 ; C
至此,我们可以试一试,我们找到的注册码B2527A1600D58A995F211C96A248B83C,取前16位,验证结果如下:
图8.验证成功!
这里确实验证成功了,但是这个过程中会有彩蛋,只有自己走过一遍,看看能不能得到真正的注册码,才能知道彩蛋到底是什么!
最后,我们来说算法的关键部分sub_1100,先在ida中看看F5后的类C代码: [C] 纯文本查看 复制代码 int__fastcall sub_1100(int result, int a2)
{
int v2; // r2@1
int v3; // r3@1
int *v4; // r12@1
int v5; // r10@1
int *v6; // r4@1
int v7; // r5@2
int v8; // r6@2
int v9; // r4@3
int v10; // off@3
int v11; // r1@3
int v12; // off@3
int v13; // r6@3
int v14; // off@3
int v15; // r5@3
int v16; // off@3
int v17; // r4@3
int v18; // off@3
int v19; // r1@3
int v20; // off@3
int v21; // r6@3
int v22; // off@3
int v23; // r5@3
int v24; // off@3
int v25; // r4@3
int v26; // off@3
int v27; // r1@3
int v28; // off@3
int v29; // r6@3
int v30; // off@3
int v31; // r5@3
int v32; // off@3
int v33; // r4@3
int v34; // off@3
int v35; // r1@3
int v36; // off@3
int v37; // r10@3
int v38; // r6@3
int v39; // off@3
int v40; // r8@3
int v41; // r5@3
int v42; // off@3
int v43; // r8@3
int v44; // r10@3
int v45; // off@3
int v46; // r9@3
int v47; // off@3
int v48; // r8@3
int v49; // off@3
int v50; // r4@3
int v51; // off@3
int v52; // r1@3
int v53; // off@3
int v54; // r6@3
int v55; // off@3
int v56; // r5@3
int v57; // off@3
int v58; // r4@3
int v59; // off@3
int v60; // r1@3
int v61; // off@3
int v62; // r6@3
int v63; // off@3
int v64; // r5@3
int v65; // off@3
int v66; // r4@3
int v67; // off@3
int v68; // r1@3
int v69; // off@3
int v70; // r8@3
int v71; // off@3
int v72; // r6@3
int v73; // off@3
int v74; // r5@3
int v75; // off@3
int v76; // r4@3
int v77; // off@3
int v78; // r1@3
int v79; // off@3
int v80; // r6@3
int v81; // off@3
int v82; // r5@3
int v83; // off@3
int v84; // r4@3
int v85; // off@3
int v86; // r1@3
int v87; // off@3
int v88; // r6@3
int v89; // off@3
int v90; // r5@3
int v91; // off@3
int v92; // r4@3
int v93; // off@3
int v94; // r1@3
int v95; // off@3
int v96; // r6@3
int v97; // off@3
int v98; // r5@3
int v99; // off@3
int v100; // r4@3
int v101; // off@3
int v102; // r1@3
int v103; // off@3
int v104; // r6@3
int v105; // off@3
int v106; // r5@3
int v107; // off@3
int v108; // r4@3
int v109; // off@3
int v110; // r1@3
int v111; // off@3
int v112; // r6@3
int v113; // off@3
int v114; // r5@3
int v115; // off@3
int v116; // r4@3
int v117; // off@3
int v118; // r7@3
int v119; // off@3
int v120; // r1@3
int v121; // off@3
int v122; // r5@3
int v123; // off@3
int v124; // r4@3
int v125; // off@3
int v126; // r6@3
int v127; // off@3
int v128; // r1@3
int v129; // off@3
int v130; // r5@3
int v131; // off@3
int v132; // r4@3
int v133; // off@3
int v134; // r6@3
int v135; // off@3
int v136; // off@3
int v137; // r2@3
int v138; // r3@3
int v139; // off@3
int v140; // [sp+Ch] [bp-6Ch]@1
int v141; // [sp+10h] [bp-68h]@1
int v142; // [sp+18h] [bp-60h]@1
int v143; // [sp+1Ch] [bp-5Ch]@3
int v144; // [sp+20h] [bp-58h]@3
int v145; // [sp+24h] [bp-54h]@3
int v146; // [sp+28h] [bp-50h]@3
int v147; // [sp+2Ch] [bp-4Ch]@3
int v148; // [sp+30h] [bp-48h]@3
int v149; // [sp+34h] [bp-44h]@3
int v150; // [sp+38h] [bp-40h]@3
int v151; // [sp+3Ch] [bp-3Ch]@3
int v152; // [sp+40h] [bp-38h]@3
int v153; // [sp+44h] [bp-34h]@3
int v154; // [sp+48h] [bp-30h]@3
int v155; // [sp+4Ch] [bp-2Ch]@3
int v156; // [sp+50h] [bp-28h]@3
int v157; // [sp+54h] [bp-24h]@3
int v158; // [sp+58h] [bp-20h]@4
v141 = *(_DWORD *)result; // R4
v2 = *(_DWORD *)(result + 8); // R2
v3 = *(_DWORD *)(result + 4); // R3
v4 = &v142;
v140 = *(_DWORD *)(result + 12); // R6
v5 = a2 + 64; // R2, R12,#0x40
v6 = &v142;
do
{
v7 = *(_BYTE *)(a2 + 3); // LDRB R5, [R1,#3]
v8 = (*(_BYTE *)(a2 + 2) << 16) |(*(_BYTE *)(a2 + 1) << 8) | *(_BYTE *)a2;
a2 += 4;
*v6 = v8 | (v7 << 24); // ORR R5, R6, R5,LSL#24
++v6;
}
while ( a2 != v5 );
v10 = __ROR4__(v142 - 680876936 + v141 +(v140 & ~v3 | v2 & v3), 25);
v9 = v3 + v10;
v12 = __ROR4__(v143 - 389564586 + v140 + (v2& ~(v3 + v10) | (v3 + v10) & v3), 20);
v11 = v9 + v12;
v14 = __ROR4__(v144 + 606105819 + v2 + (v3& ~(v9 + v12) | (v9 + v12) & v9), 15);
v13 = v11 + v14;
v16 = __ROR4__(v145 - 1044525330 + v3 + (v9& ~(v11 + v14) | (v11 + v14) & v11), 10);
v15 = v13 + v16;
v18 = __ROR4__(v146 - 176418897 + v9 + (v11 &~(v13 + v16) | (v13 + v16) & v13), 25);
v17 = v15 + v18;
v20 = __ROR4__(v147 + 1200080426 + v11 + (v13& ~(v15 + v18) | (v15 + v18) & v15), 20);
v19 = v17 + v20;
v22 = __ROR4__(v148 - 1473231341 + v13 + (v15& ~(v17 + v20) | (v17 + v20) & v17), 15);
v21 = v19 + v22;
v24 = __ROR4__(v149 - 45705983 + v15 + (v17& ~(v19 + v22) | (v19 + v22) & v19), 10);
v23 = v21 + v24;
v26 = __ROR4__(v150 + 1770035416 + v17 + (v19& ~(v21 + v24) | (v21 + v24) & v21), 25);
v25 = v23 + v26;
v28 = __ROR4__(v151 - 1958414417 + v19 + (v21& ~(v23 + v26) | (v23 + v26) & v23), 20);
v27 = v25 + v28;
v30 = __ROR4__(v152 - 42063 + v21 + (v23& ~(v25 + v28) | (v25 + v28) & v25), 15);
v29 = v27 + v30;
v32 = __ROR4__(v153 - 1990404162 + v23 + (v25& ~(v27 + v30) | (v27 + v30) & v27), 10);
v31 = v29 + v32;
v34 = __ROR4__(v154 + 1804603682 + v25 + (v27& ~(v29 + v32) | (v29 + v32) & v29), 25);
v33 = v31 + v34;
v36 = __ROR4__(v155 - 40341101 + v27 + (v29& ~(v31 + v34) | (v31 + v34) & v31), 20);
v35 = v33 + v36;
v37 = ~(v33 + v36);
v39 = __ROR4__(v156 - 1502002290 + v29 + (v37& v31 | (v33 + v36) & v33), 15);
v38 = v35 + v39;
v40 = ~(v35 + v39);
v42 = __ROR4__(v157 + 1236535329 + v31 + (v40& v33 | (v35 + v39) & v35), 10);
v41 = v38 + v42;
v43 = (v38 + v42) & v40;
v45 = __ROR4__(v143 - 165796510 + v33 + ((v38+ v42) & v35 | v38 & v37), 27);
v44 = v41 + v45;
v47 = __ROR4__(v148 - 1069501632 + v35 +((v41 + v45) & v38 | v43), 23);
v46 = v44 + v47;
v49 = __ROR4__(v153 + 643717713 + v38 + ((v44+ v47) & v41 | v44 & ~v41), 18);
v48 = v46 + v49;
v51 = __ROR4__(v142 - 373897302 + v41 + ((v46+ v49) & v44 | v46 & ~v44), 12);
v50 = v48 + v51;
v53 = __ROR4__(v147 - 701558691 + v44 + ((v48+ v51) & v46 | v48 & ~v46), 27);
v52 = v50 + v53;
v55 = __ROR4__(v152 + 38016083 + v46 + ((v50+ v53) & v48 | v50 & ~v48), 23);
v54 = v52 + v55;
v57 = __ROR4__(v157 - 660478335 + v48 + ((v52+ v55) & v50 | v52 & ~v50), 18);
v56 = v54 + v57;
v59 = __ROR4__(v146 - 405537848 + v50 + ((v54+ v57) & v52 | v54 & ~v52), 12);
v58 = v56 + v59;
v61 = __ROR4__(v151 + 568446438 + v52 + ((v56+ v59) & v54 | v56 & ~v54), 27);
v60 = v58 + v61;
v63 = __ROR4__(v156 - 1019803690 + v54 +((v58 + v61) & v56 | v58 & ~v56), 23);
v62 = v60 + v63;
v65 = __ROR4__(v145 - 187363961 + v56 + ((v60+ v63) & v58 | v60 & ~v58), 18);
v64 = v62 + v65;
v67 = __ROR4__(v150 + 1163531501 + v58 +((v62 + v65) & v60 | v62 & ~v60), 12);
v66 = v64 + v67;
v69 = __ROR4__(v155 - 1444681467 + v60 +((v64 + v67) & v62 | v64 & ~v62), 27);
v68 = v66 + v69;
v71 = __ROR4__(v144 - 51403784 + v62 + ((v66+ v69) & v64 | v66 & ~v64), 23);
v70 = v68 + v71;
v73 = __ROR4__(v149 + 1735328473 + v64 +((v68 + v71) & v66 | v68 & ~v66), 18);
v72 = v70 + v73;
v75 = __ROR4__(v154 - 1926607734 + v66 +((v70 + v73) & v68 | v70 & ~v68), 12);
v74 = v72 + v75;
v77 = __ROR4__(v147 - 378558 + v68 + (v72 ^v70 ^ (v72 + v75)), 28);
v76 = v74 + v77;
v79 = __ROR4__(v150 - 2022574463 + v70 + (v74^ v72 ^ (v74 + v77)), 21);
v78 = v76 + v79;
v81 = __ROR4__(v153 + 1839030562 + v72 + (v76^ v74 ^ (v76 + v79)), 16);
v80 = v78 + v81;
v83 = __ROR4__(v156 - 35309556 + v74 + (v78 ^v76 ^ (v78 + v81)), 9);
v82 = v80 + v83;
v85 = __ROR4__(v143 - 1530992060 + v76 + (v80^ v78 ^ (v80 + v83)), 28);
v84 = v82 + v85;
v87 = __ROR4__(v146 + 1272893353 + v78 + (v82^ v80 ^ (v82 + v85)), 21);
v86 = v84 + v87;
v89 = __ROR4__(v149 - 155497632 + v80 + (v84^ v82 ^ (v84 + v87)), 16);
v88 = v86 + v89;
v91 = __ROR4__(v152 - 1094730640 + v82 + (v86^ v84 ^ (v86 + v89)), 9);
v90 = v88 + v91;
v93 = __ROR4__(v155 + 681279174 + v84 + (v88^ v86 ^ (v88 + v91)), 28);
v92 = v90 + v93;
v95 = __ROR4__(v142 - 358537222 + v86 + (v90^ v88 ^ (v90 + v93)), 21);
v94 = v92 + v95;
v97 = __ROR4__(v145 - 722521979 + v88 + (v92^ v90 ^ (v92 + v95)), 16);
v96 = v94 + v97;
v99 = __ROR4__(v148 + 76029189 + v90 + (v94 ^v92 ^ (v94 + v97)), 9);
v98 = v96 + v99;
v101 = __ROR4__(v151 - 640364487 + v92 + (v96^ v94 ^ (v96 + v99)), 28);
v100 = v98 + v101;
v103 = __ROR4__(v154 - 421815835 + v94 + (v98^ v96 ^ (v98 + v101)), 21);
v102 = v100 + v103;
v105 = __ROR4__(v157 + 530742520 + v96 +(v100 ^ v98 ^ (v100 + v103)), 16);
v104 = v102 + v105;
v107 = __ROR4__(v144 - 995338651 + v98 +(v102 ^ v100 ^ (v102 + v105)), 9);
v106 = v104 + v107;
v109 = __ROR4__(v142 - 198630844 + v100 +(((v104 + v107) | ~v102) ^ v104), 26);
v108 = v106 + v109;
v111 = __ROR4__(v149 + 1126891415 + v102 +(((v106 + v109) | ~v104) ^ v106), 22);
v110 = v108 + v111;
v113 = __ROR4__(v156 - 1416354905 + v104 +(((v108 + v111) | ~v106) ^ v108), 17);
v112 = v110 + v113;
v115 = __ROR4__(v147 - 57434055 + v106 +(((v110 + v113) | ~v108) ^ v110), 11);
v114 = v112 + v115;
v117 = __ROR4__(v154 + 1700485571 + v108 +(((v112 + v115) | ~v110) ^ v112), 26);
v116 = v114 + v117;
v119 = __ROR4__(v145 - 1894986606 + v110 + (((v114+ v117) | ~v112) ^ v114), 22);
v118 = v116 + v119;
v121 = __ROR4__(v152 - 1051523 + v112 +(((v116 + v119) | ~v114) ^ v116), 17);
v120 = v118 + v121;
v123 = __ROR4__(v143 - 2054922799 + v114 +(((v118 + v121) | ~v116) ^ v118), 11);
v122 = v120 + v123;
v125 = __ROR4__(v150 + 1873313359 + v116 +(((v120 + v123) | ~v118) ^ v120), 26);
v124 = v122 + v125;
v127 = __ROR4__(v157 - 30611744 + v118 +(((v122 + v125) | ~v120) ^ v122), 22);
v126 = v124 + v127;
v129 = __ROR4__(v148 - 1560198380 + v120 +(((v124 + v127) | ~v122) ^ v124), 17);
v128 = v126 + v129;
v131 = __ROR4__(v155 + 1309151649 + v122 +(((v126 + v129) | ~v124) ^ v126), 11);
v130 = v128 + v131;
v133 = __ROR4__(v146 - 145523070 + v124 +(((v128 + v131) | ~v126) ^ v128), 26);
v132 = v130 + v133;
v135 = __ROR4__(v153 - 1120210379 + v126 +(((v130 + v133) | ~v128) ^ v130), 22);
v134 = v132 + v135;
v136 = __ROR4__(v144 + 718787259 + v128 +(((v132 + v135) | ~v130) ^ v132), 17);
v137 = v2 + v134 + v136;
v138 = v134 + v136 + v3;
v139 = __ROR4__(v151 - 343485551 + v130 +(((v134 + v136) | ~v132) ^ v134), 11);
*(_DWORD *)(result + 12) = v140 + v134; // STR R6, [R0,#0xC]
*(_DWORD *)(result + 4) = v138 + v139; // STR R3, [R0,#4]
*(_DWORD *)(result + 8) = v137; // STR R2, [R0,#8]
*(_DWORD *)result = v141 + v132; // STR R4, [R0]
do
{
*(_BYTE *)v4 = 0;
v4 = (int *)((char *)v4 + 1);
}
while ( v4 != &v158 );
return result;
}
算法不难,但是很冗余!!我们以计算R6的地址为例: R6 =v140 + v134 = *(_DWORD *)(result + 12) + v132 + v135 = *(_DWORD *)(result + 12) + v130 + v133 +__ROR4__(v153 - 1120210379 + v126 + (((v130 + v133) | ~v128) ^ v130), 22) = .. |