Hacking a linked library for Cortex M - Page 1
Forum section: electronics / general

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: December 18, 2018, 10:08:37 am
content: Hi,There are several excellent libraries for ARM Cortex M parts, but some of them are restricted to a certain family, like for example the STM32 libraries, and I found that all of the ST libraries use the CRC engine to disable the library on none ST parts, maybe they have used something simple like this codeCode:while(! compute this CRC based on our CRC IO);So if it passes this test, it would continue with the init of the library, so I'm sure there is a way to manipulate the lib, so the question is how?For example see the attached libraries , they will work only on STM32 parts.change the extension of the file to .a

author: ajb
author_rank: Super Contributor
timestamp: December 20, 2018, 07:20:24 am
content: Sure it's possible to hack the library to make it work on other families. It may or may not be easy to do so. The question is, does the license under which the library was published permit you to do run it on other families? If they bothered to include protection against this exact thing, then the answer is clearly no.

author: Jeroen3
author_rank: Super Contributor
timestamp: December 20, 2018, 07:59:50 am
content: If you have already found how it validates the hardware. You can easily decompile it, replace all branch-if instructions after a MOV from the CRC, and recompile it. Right?I do not see if this is worth the effort. You're obviously violating some license agreement.This is probably not allowed to further discuss on this forum.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: December 20, 2018, 09:01:06 am
content: Ok, thanks for the info. I think it maybe useful for our code libraries too

author: hans
author_rank: Super Contributor
timestamp: December 20, 2018, 09:02:16 am
content: Agreed. 2 points:- The object files does not specify STM32 in any of filenames, instead it says ARMv4, so why would that indicate it's targetted for STM32 only CRC hardware?- You seem to post the library files of a commercial product made bySpirit DSP. Maybe you have taken it from an evaluation file delivery, but I don't think you own the copyright to post these files on this forum.If you really want to undertake any modification, know that you're probably doing something illegal and you're on your own.

author: nick_d
author_rank: Regular Contributor
timestamp: December 20, 2018, 10:06:48 am
content: Whilst I wouldn't have moral qualms about hacking into something like this, at least for personal use, it is really a bad investment to put ANY effort at all into a closed source solution. A lot of people take the view "oh thousands of hours of R&D have gone into this super special optimized code, you can't compete blahblah" but if you actually had the source code you would probably find it's not that special. And in this day and age no matter what you want to do there is an open source solution somewhere. It's often not complete or might be suboptimal or whatever. But overall you will get a better return on your investment if you take that, which maybe does 50-60% of what you want to do, and improve it -- than if you get a commercial version which does 90-95% of what you want and does it very well, but wastes a lot of time trying to understand the interface and requires elaborate workarounds to deal with the 5-10% that isn't what you need and can't be changed (or pray for good support...).cheers, Nick

author: rhb
author_rank: Super Contributor
timestamp: December 27, 2018, 06:13:34 pm
content: This depends entirely on the source and the target.The biggest issue is dependencies. It's common to encounter code that the code is portable, but the libraries it uses are not.

author: janoc
author_rank: Super Contributor
timestamp: December 27, 2018, 06:41:00 pm
content: Quote from: blueskull on December 26, 2018, 07:01:49 amBut this forum isn't hosted in Iran and debating how to break this sort of software protection here could be a good way for Dave (or his hosting) to get a legal nastygram from the actual copyright owners.So yes, one needs to care about such minutiae.

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 27, 2018, 07:13:20 pm
content: Yeah, I don't think encouraging people to "hack" copyrighted stuff is a good idea either. This is not a hackers' forum.As to the non-legal aspects of this, I don't think this is a good idea either. Using hacked libraries would make your developments a hell to maintain, and you'd get zero support nor any guarantee that it does what it's supposed to. I wouldn't invest any significant amount of development time with something I have no control over whatsoever, to the point of using it illegally. To me it's wasted time in the long run, and people's development time is much more valuable than development tools IMO.The op's best bet, especially on a forum like this one, would be to ask people for pointers to existing libraries that do what he needs done. There may even be open-source ones that he's not aware of. Would be more productive. I guess.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: December 27, 2018, 08:33:15 pm
content: Dear Guys, thanks for all your concerns, I do not do this hack, because There are lot's of other open source solutions out there, so why bother ?There is the MAD MP3 decoder and there is Lame for encoder

author: rstofer
author_rank: Super Contributor
timestamp: December 27, 2018, 09:59:17 pm
content: Even if the library could be opened and disassembled, all that would result is highly optimized assembly output from a compiler set to maximum optimization. The result is that even an experienced assembly language coder is going to have a terrible time following the logic flow.ARM specifies the core but the manufacturer implements the IO devices including addresses, registers, bit definitions, specifications - everything is unique to the manufacturer if they implement their own peripherals. They could license certain peripherals from ARM but they could still make sweeping changes. Maybe the documentation gives some insight into what the library code is doing but how the code gets it done will probably be a mystery.I see two choices: First, use the library and call it good or, second, create your own library from scratch. I don't see any chance of success by cracking the library protection.

author: abyrvalg
author_rank: Frequent Contributor
timestamp: December 28, 2018, 09:33:00 am
content: Simulate that missing CRC peripheral in data abort handler

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: December 28, 2018, 04:25:31 pm
content: Quotehow?Something like this?Code:void HardFault_Handler(void){//get the input data from what reg//calculate CRC//Send back the calculated CRC to what Reg}Some C to ARM ASM would help alot

author: Jeroen3
author_rank: Super Contributor
timestamp: December 29, 2018, 02:11:00 pm
content: You can’t return from a hardfault though. It makes a hardware stackframe.You must insert calls to a function that calculates crc.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: December 29, 2018, 02:50:41 pm
content: Code:You can’t return from a hardfault though. It makes a hardware stackframe.You must insert calls to a function that calculates crc.Thanks, any hints how that should be done is highly appreciated

author: donotdespisethesnake
author_rank: Super Contributor
timestamp: December 30, 2018, 08:37:14 am
content: I think circumventing copy protection violates the DMCA. You may not care if you are outside US jurisdiction, but it's just a bad idea for forum hosts to entertain discussion of it, it could be construed as "providing services".And anyway, if you have enough knowledge to circumvent it, you could probably write your own version of the library.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: December 30, 2018, 01:14:33 pm
content: QuoteI would not use if for anything, AS I said there are open source version for the lib, it's for education only, In here there has been several hacks like the rigol Scope etc...