Introduction
This post is an introductory post about diving into reversing code for connecting to Casio CTK-2500 using a 3.5MM jack in an attempt to upload songs to it using a PC. The Casio CTK-2500 is hereinafter referred to as keyboard or device interchangeably.
Background
I had a Casio CTK-2500 lying around so I thought I would tinker with it and explore additional features.
I play the keyboard now and then and was intrigued by functionality that I had never tried before Chordana play.
Chordana Play
Quick google search resulted in a Chordana app for Android and iOS which allows you to load a song into the system, the way to connect the Casio to program it was using a 3.5MM audio cable, which piqued my interest.
Found out that there’s no app for a PC to load the music using a PC. So I thought why not reverse engineer the app and create a command-line utility to load MIDI files into the keyboard using a PC.
if you read further you will find
- A high-level analysis of the app in question
- Reverse engineered code from Chordana app and native library that it uses.
- Extracted region of interest in a codebase that might enable us to write a utility to utilize the 3.5MM jack on my PC to load songs into the keyboard.
Tools of the trade
Tools that I will be using to reverse engineer the code base and figure out a region of interests
- Brain
- IDA Pro (With a decompiler) (To decompile and reverse native binary that’s used in the android application)
- Online APK Decompiler - This converts APK into jar files that can be fed into JD-GUI
- JD-GUI for viewing decompiled APK files. (JD-GUI requires JRE to function so you have to have it before moving forward.)
High-Level Analysis of Chordana App
Installing Chordana Play App on your Android/iOS device and playing around with it.
After using it for a while I came to the following conclusions
- A predefined song can be loaded into the app or a new midi file can be loaded using the song menu
- To transfer the song to Casio first I need to set up something called a keyboard link, To set up the keyboard link I need to put our device into
APP mode
, this can be done onCTK-2500
by pressing and holding the APP button. and then opening the app and turning on Keyboard Link as you can see in the above video.
After that, you can click onTransfer song
and begin to transfer the song to the device using audio in cable. fascinating.
Getting the APK and decompiling it
First I would search for the Chordana Play APK since Chordana Play is the only app that is capable of putting the device into app mode and load midi files into it.
A quick google search gets me to Chordana play APK Pure lands me here, I download the APK, upload it to Online APK Decompiler and get the resulting zip file back.
After loading the zip file in JD-GUI, I start by exploring the source code, if you have worked with Android before (or haven’t). A folder named sources
will surely pique your interest.
let’s browse through some code that I found along the way
|
|
Few other timer tasks that were fascinating.
|
|
|
|
song transfer routine.
|
|
Lot of native functions? Where could these be from?
I found a native library called libsssg.so
that was being used and all of these native functions were defined inside that.
|
|
Analysis of Native library used
Analysis of the C++ library used.
|
|
Few questions after going through the above code
- What is ucKeyboardLinkRing??
- What is ucBuffCmp??
- What is nGetDataSize??
|
|
Interesting lDataSize
is set inside rhyythmInitialize
|
|
|
|
So finally I have some clue of where and what ucBuffCmp is used for. I am yet to dig deeper into this, so the next articles will dive deeper into what ucBuffCmp is and what is the function, but I guess it is some kind of compressed buffer that is sent over to the keyboard, looking from the code.
So I now know what ucBuffCmp
(at least something about it) and what nGetDataSize
is, lets find out what ucKeyboardLinkRing
is used for?
Points of interest after going through the code
|
|
By finding xrefs on ucKeyboardLinkRing
I stumbled upon this function
|
|
Doing xrefs on iKLRingWPtr
landed me to
|
|
Solutions to creating a library.
- Reverse engineer whole code of
libsssg.so
and rewrite the required parts in C++ - Use an ARM device(Phone, raspberry pi) to use the library as-is. (Still will require documenting most of the functions. easier than rewriting.)