@habababa: My code above shows that I push and pop the registers, again it works on emulator (if registers were overwritten and not saved, emulator would have crashed as well). I am using cracker's asm compiler (ARM ASM kit from
http://crackerscrap.com/index.php?p=docs)
@FAST6191
I am making a hack for 7th dragon. I implement the hack very similar to the tutorial, at 0x2380000 it branches (in arm7.bin) to my code at the end of the arm7.bin (so around 0x8FXXXXXX). I use 3 halfwords (12 bytes) to put "ldr r15,=0x8FXXXXXX" at 0x2380000, which when in the emulator it would run jump to my code. Then at my code, it would patch some arm9 code (2 bytes per instruction) and patch overwritten code (those 3 halfwords I had to overwrite to get here) and copy all my code to safe place in memory (which I tried 0x2C00000 that seems that the game doesn't overwrite this address). The arm9 places I overwrote early takes 5 lines of code to jump to 0x2C00000 and execute the hack and then comes back.
Overwriting thumb code (16 bit) in arm9
1. push {r0,r1} //r0 = address to jump to, r1 = the flag that tells my code what hack to run
2. mov r0,#0x2C
3. lsl r0,r0,#0x20 //r0 is now 0x2C00000
4. mov r1,#0x1 //r1, at my code it has a switch statement that branches to the part of my code that needs to handle the hack
5. bx r0 //branches to 0x2C00000 and swaps to arm mode I think (arm7 code?)
6. continue...
@0x2C00000 --- now running arm code (arm7, 32 bit instruction)
1. cmp r1,#0x1
2. b someplacetohandle
11. someplacetohandle:
12. pop {r0,r1}
13. //patch overwritten code for 5 lines
18. //Runs my hack for a few lines
28. bx r14 //goes back to where I left off and goes back to thumb mode (arm9 code), jumps back at 6 from above
I may have my arm and thumb mixed up but I know arm7, each instruction is a word long and arm9 is halfword for each instruction. That is how I hooked but it doesn't work on flash card (even with all the cheats, patches disabled).
I do not know but the emulator initially runs my code through arm, is it possible that the flash card is running at 0x2380000 with thumb code? There it is probably doing something stupid and crashing but this is my first time doing this so I am not sure if that is the case (I guess I can attempt it and see what happens). I also noticed that not affecting the arm7 code but just appending my code at the end causes the game to run on the flashcard (which is obvious).
If this doesn't answer your question I am sorry, I am kind of noob that just learned how to do this a couple of weeks ago and trying to "hack" at it.