I'v been trying to reverse-engineer a BLE "Smartlock" to open it using Python instead of the App that it came with.
I progressed quite far with disassembling the SDK they provide, identifying BLE packets, headers and all, but now I'm stuck. It contains a .so file inside the Java library which is reponsible for encoding and decoding the data that is sent from and to the lock. It takes two arguments and returns the en- or decrypted data:
// .java - The data as a byte array and a single byte to somehow encrypt it all
public static native byte[] decodeWithEncryptByte(byte[] dataByteArray, byte encryptByte);
Maybe it's even an algorighm that is well known/has a name, but I'm completely stuck. Any tip would be helpful, even in human-readable pseudocode!
The decodeWithEncriptByte
part follows:
.text:00000a20 <Java_com_scaf_android_client_CodecUtils_decodeWithEncrypt>:
.text:00000a20 55 push %ebp
.text:00000a21 57 push %edi
.text:00000a22 56 push %esi
.text:00000a23 53 push %ebx
.text:00000a24 e8 97 fb ff ff call 0x000005c0
.text:00000a29 81 c3 b7 25 00 00 add $0x25b7,%ebx
.text:00000a2f 8d 64 24 c4 lea -0x3c(%esp),%esp
.text:00000a33 8b 74 24 50 mov 0x50(%esp),%esi
.text:00000a37 0f b6 44 24 5c movzbl 0x5c(%esp),%eax
.text:00000a3c 8b 4c 24 58 mov 0x58(%esp),%ecx
.text:00000a40 88 44 24 2f mov %al,0x2f(%esp)
.text:00000a44 8b 06 mov (%esi),%eax
.text:00000a46 89 4c 24 04 mov %ecx,0x4(%esp)
.text:00000a4a c7 44 24 08 00 00 00 00 movl $0x0,0x8(%esp)
.text:00000a52 89 34 24 mov %esi,(%esp)
.text:00000a55 ff 90 e0 02 00 00 call *0x2e0(%eax)
.text:00000a5b 8b 7c 24 58 mov 0x58(%esp),%edi
.text:00000a5f 89 44 24 20 mov %eax,0x20(%esp)
.text:00000a63 8b 06 mov (%esi),%eax
.text:00000a65 89 7c 24 04 mov %edi,0x4(%esp)
.text:00000a69 89 34 24 mov %esi,(%esp)
.text:00000a6c ff 90 ac 02 00 00 call *0x2ac(%eax)
.text:00000a72 89 c5 mov %eax,%ebp
.text:00000a74 8b 06 mov (%esi),%eax
.text:00000a76 89 6c 24 04 mov %ebp,0x4(%esp)
.text:00000a7a 89 34 24 mov %esi,(%esp)
.text:00000a7d ff 90 c0 02 00 00 call *0x2c0(%eax)
.text:00000a83 8b 4c 24 20 mov 0x20(%esp),%ecx
.text:00000a87 89 c7 mov %eax,%edi
.text:00000a89 8b 06 mov (%esi),%eax
.text:00000a8b 89 4c 24 10 mov %ecx,0x10(%esp)
.text:00000a8f 89 6c 24 0c mov %ebp,0xc(%esp)
.text:00000a93 c7 44 24 08 00 00 00 00 movl $0x0,0x8(%esp)
.text:00000a9b 89 7c 24 04 mov %edi,0x4(%esp)
.text:00000a9f 89 34 24 mov %esi,(%esp)
.text:00000aa2 ff 90 40 03 00 00 call *0x340(%eax)
.text:00000aa8 8b 06 mov (%esi),%eax
.text:00000aaa c7 44 24 08 00 00 00 00 movl $0x0,0x8(%esp)
.text:00000ab2 89 7c 24 04 mov %edi,0x4(%esp)
.text:00000ab6 89 34 24 mov %esi,(%esp)
.text:00000ab9 ff 90 e0 02 00 00 call *0x2e0(%eax)
.text:00000abf 89 44 24 24 mov %eax,0x24(%esp)
.text:00000ac3 8b 06 mov (%esi),%eax
.text:00000ac5 89 7c 24 04 mov %edi,0x4(%esp)
.text:00000ac9 89 34 24 mov %esi,(%esp)
.text:00000acc ff 90 ac 02 00 00 call *0x2ac(%eax)
.text:00000ad2 89 44 24 28 mov %eax,0x28(%esp)
.text:00000ad6 85 c0 test %eax,%eax
.text:00000ad8 7e 3f jle 0x00000b19
.text:00000ada 8b 7c 24 24 mov 0x24(%esp),%edi
.text:00000ade 89 c1 mov %eax,%ecx
.text:00000ae0 89 74 24 50 mov %esi,0x50(%esp)
.text:00000ae4 0f b6 e8 movzbl %al,%ebp
.text:00000ae7 0f b6 74 24 2f movzbl 0x2f(%esp),%esi
.text:00000aec 89 f8 mov %edi,%eax
.text:00000aee 01 cf add %ecx,%edi
.text:00000af0 8b 8b fc ff ff ff mov -0x4(%ebx),%ecx
.text:00000af6 8d 76 00 lea 0x0(%esi),%esi
.text:00000af9 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
.text:00000b00 89 f2 mov %esi,%edx
.text:00000b02 83 c0 01 add $0x1,%eax
.text:00000b05 32 50 ff xor -0x1(%eax),%dl
.text:00000b08 88 50 ff mov %dl,-0x1(%eax)
.text:00000b0b 32 14 29 xor (%ecx,%ebp,1),%dl
.text:00000b0e 88 50 ff mov %dl,-0x1(%eax)
.text:00000b11 39 f8 cmp %edi,%eax
.text:00000b13 75 eb jne 0x00000b00
.text:00000b15 8b 74 24 50 mov 0x50(%esp),%esi
.text:00000b19 8b 7c 24 28 mov 0x28(%esp),%edi
.text:00000b1d 8b 06 mov (%esi),%eax
.text:00000b1f 89 34 24 mov %esi,(%esp)
.text:00000b22 89 7c 24 04 mov %edi,0x4(%esp)
.text:00000b26 ff 90 c0 02 00 00 call *0x2c0(%eax)
.text:00000b2c 8b 4c 24 24 mov 0x24(%esp),%ecx
.text:00000b30 8b 16 mov (%esi),%edx
.text:00000b32 89 7c 24 0c mov %edi,0xc(%esp)
.text:00000b36 89 4c 24 10 mov %ecx,0x10(%esp)
.text:00000b3a 89 44 24 04 mov %eax,0x4(%esp)
.text:00000b3e 89 34 24 mov %esi,(%esp)
.text:00000b41 c7 44 24 08 00 00 00 00 movl $0x0,0x8(%esp)
.text:00000b49 89 44 24 24 mov %eax,0x24(%esp)
.text:00000b4d ff 92 40 03 00 00 call *0x340(%edx)
.text:00000b53 8b 44 24 20 mov 0x20(%esp),%eax
.text:00000b57 8b 16 mov (%esi),%edx
.text:00000b59 89 34 24 mov %esi,(%esp)
.text:00000b5c 89 44 24 08 mov %eax,0x8(%esp)
.text:00000b60 8b 44 24 58 mov 0x58(%esp),%eax
.text:00000b64 c7 44 24 0c 00 00 00 00 movl $0x0,0xc(%esp)
.text:00000b6c 89 44 24 04 mov %eax,0x4(%esp)
.text:00000b70 ff 92 00 03 00 00 call *0x300(%edx)
.text:00000b76 8b 44 24 24 mov 0x24(%esp),%eax
.text:00000b7a 8d 64 24 3c lea 0x3c(%esp),%esp
.text:00000b7e 5b pop %ebx
.text:00000b7f 5e pop %esi
.text:00000b80 5f pop %edi
.text:00000b81 5d pop %ebp
.text:00000b82 c3 ret
.text:00000b83 8d b6 00 00 00 00 lea 0x0(%esi),%esi
.text:00000b89 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
Similarly, the encode process is probably very similar.
I have used a online disassembler to analyse the Assembly and the opened file is available over there as well, if anyone has a clue what's going on here!
Any help is greatly appreciated!
EDIT: The file is available here: https://github.com/ttlock/Android_SDK_Demo/blob/master/app/libs/ttlock-release-3.0.7.aar
To view the specific file in question, you only need to download it and extract it, inside is a folder named jni/
with the different architectures of the same thing
The device is a TTLock and I'm looking to reverse-engineer it to make it fully open-source, so that people can make custom gateways to the locks, permitting it to work locally (current Gateway only supports Web-operation... and phones China for that). I have 5 TTLocks here, although they're nice locks, it's a bummer that they don't work over LAN when the internet is down.