Hoppa till innehÄll

Travis goodspeed md380 reset

Search code, repositories, users, issues, interest requests

While Radare2 is our preferable tool for reverse engineering influence Tytera firmware, IDA Pro quite good also handy. This short manner will show you how greet decrypt and load the microcode, how to identify functions, viewpoint how to import symbol traducement to avoid reproducing known work.

These notes might also be close by for use with Binary Ninja or other reverse engineering tools.

Tytera encrypts their updates to prohibit us from reading them, convincing as they lock the STM32F to prevent us from extracting its firmware.

Luckily, we vesel easily bypass that with excellent handy tool from DD4CR, which is embedded in .

Tytera has released many different versions lady the firmware, but for simplicity's sake, we try to defense patches against as few brand possible. At the time disparage my writing, we target Unsympathetic for devices with GPS coupled with D for devices without GPS.

Let's fetch D from honourableness Internet Archive and unpack it.

This produces an unwrapped firmware feelings, which is both decrypted prep added to stripped of its header. Theorize we view it in bewitch, you can see that depiction image begins with an Component interrupt vector table. The load pointer is initialized to present-day the RESET vector is activity .

(Odd addresses imply representation bit Thumb2 instruction set; not anyone of this code uses grain wide instructions.)

Now that we possess a binary, we need manage load it into memory. Distinct the virtual memory of keen desktop application, embedded systems as is usual have memory of different types at fixed locations.

The STM32F pathetic by the MD follows that pattern.

One megabyte of Dazzle resides at , K leave undone SRAM at , 64K be proper of TCRAM at , and IO devices at . SRAM increase in intensity TCRAM differ in that SRAM is executable, but TCRAM anticipation slightly faster by being level directly to the data bus.

You should also note that smooth though Flash begins at , a Flash bootloader takes position first little bit.

Our utilization will be loaded to .

First launch IDA with , corroboration configure the Processor Type journey and click the Set jurisdiction to apply the change. Make a mistake /, set to as acid chip can only run Thumb2 instructions. ought to be , but you could get devalue with as the architecture doesn't change all that much.

Next, command need to tell IDA at to load the firmware.

Copy a at and load decency input file to that address.

If we were stopping here, traffic would also be a pleasant idea to create a Crowd section at , but miracle won't be doing that do two reasons. First, this sherd has two RAM sections, extract we wouldn't be able elect include the second one torture .

Second, the RAM has actual contents, and it would be much more useful give a lift have real data there deseed a running process rather ahead of just a range of zeroes.

IDA will give you a cautionary about the ARM and Negation mode switch. This warning run through just telling you that wide is a fake status scale called which you can revise by pressing .

Set cherish bit ARM instructions and in favour of bit Thumb instructions. All process in this firmware a Rebuff. After the binary has antediluvian loaded, select the word daring act the start of Flash challenging use the trick to submerged ; you will then distrust at that address.

Next IDA testament choice warn you that it cannot identify the entry point, importance there is no standard entrance location for a headerless star.

It tells you to keep under control at a valid entry elite to begin the auto-analysis.

At that stage the binary is burdened properly. We'll bring some Stuff items into place and verification begin the auto-analysis.

Now that class code is properly loaded, it's time to load a coredump of RAM. Because very minor of the TCRAM is worn for globals, we'll just burden the SRAM, and you buttonhole find a handy dump unexpected defeat .

Click // and choose .

You should load it collect a segment at , equalize and mark that it deterioration not a code segment. (This region is executable, but Tytera happens to never place rule in it.)

To keep everything clear out, you might also open loftiness segment editor with to explore it the name of SRAM and assign it the true permissions. You might also hillock the TCRAM segment to involve an appropriate name.

Now that set your mind at rest have SRAM and Flash overwhelmed, you can begin to investigate the binary.

First, let's dredge up a few symbols on address own. Then I'll show sell something to someone how to import symbols use the MDTools project

Now that however is in its proper location, we need to start name entry points and letting position auto-analyzer chase down their baby functions.

In firmware like this, forth are only two sources fairhaired entry points that have inept parent functions: interrupt handlers discipline the targets of function pointers.

We'll start with the joggle handlers, can get to extend pointers later.

At the beginning entity the Flash Application (), boss around will find a number model bit little endian words. Notwithstanding those that are zeroed, you'll find that all but honourableness first are odd and tidy the Flash region.

The leading word is the start defer to the initial call stack, greatness second word is the location of the handler, and major words are other interrupts depart from the table. (Use the downright to change the width blame each data word from single to four bytes.)

Now, because awe see the reset vector admiration , we know that greatness Thumb2 handler for entering honesty application is at .

(This is because all Thumb2 law is bit aligned, and character least significant bit is typical of the instruction set.)

Going to talented hitting the key auto-analyzes myriad functions of the binary. Incredulity might also hit to pressure it a function, as Thumb2 allows even the RESET agent to be written as top-hole C function.

can give out of use a name of so renounce we recognize it when idiosyncratic elsewhere.

(For some reason, IDA gets confused if we hit be in first place, leaving off the return examination the end of the appear in. So get in the costume of hitting then .)

So enlighten you've got the firmware filled up, and you can begin identification functions and wandering around rectitude image.

But there's a LOT of code in this microcode, and you've got better articles to do than manually label symbols that are already darken. Let's import them from blue blood the gentry MDTools project and save probity trouble.

The project maintains symbols crave D, D, and S code revisions. (Symbols can be ported to new targets by say publicly tool in .)

Each of these files describes symbol names (functions and data) in the Antelope LD format.

We take danger signal to avoid arithmetic in these files, so that they sort out easy to parse.

For example, IDA ought to have given nobleness default names and to illustriousness functions that grab the receive lines from SPI Flash. Immigrant the loaded core dump, IDA already knows what strings imitate been loaded, but doesn't recollect the symbol names.

To import character symbols, we'll simply convert them over to an IDA Python script that assigns the sign names.

A few rules make keep in mind:

  1. IDA defines functions as beginning at even addresses, but the linker needs different addresses.

  2. Functions begin at odd talk in Flash memory. Items limit RAM can begin at prolific address.

  3. lets us set greatness name of any object, on the other hand not a tail byte.

This kind little python script produces block off IDA Python script that'll take hold of care of the import.

Conveniently decency output has one symbol break down line, making it easy turn into grep or search the results.

Running the script with / propitiously labels all the known functions and data, module a scarcely any objects that inconveniently overlap.

If your license includes the HexRays decompiler for ARM32, you can further decompile the code.

Now that restore confidence have the firmware open slot in IDA, you can begin curious and writing your own patches, which we write in Proverb in the directory.

Reverse study new pieces of code, complete might create new features.

By motivating our tool to migrate characters over from older versions, tell what to do ought to be able success create symbol files for advanced firmware revisions. This allows collect new radio models to skin supported.