supplierdeeply

finsig and other tools for thumb2 (was Re: chdk in the DIGIC6 world)

  • 71 Replies
  • 32902 Views
*

Offline reyalp

  • ******
  • 11592
Re: finsig and other tools for thumb2 (was Re: chdk in the DIGIC6 world)
« Reply #70 on: 02 / December / 2018, 21:46:22 »
Advertisements
I have a suggestion for a capdis feature:
When disassembling a function partially, it would be nice if capdis could (optionally) add an LDR PC instruction at the end that would point to the next instruction at the routine's original location.
I added an option -jfw which does this in r5134 (yeah, I'm a slacker  :-[)
Don't forget what the H stands for.

*

Offline srsa_4c

  • ******
  • 3728
Re: finsig and other tools for thumb2 (was Re: chdk in the DIGIC6 world)
« Reply #71 on: 08 / December / 2018, 18:17:21 »
I added an option -jfw which does this in r5134
Thanks.
While working on a completely unsupported dump, I've noticed that an unrecognized function listed in find_generic_funcs() prevents the rest of the functions from being used. Did not go as far as finding the piece of code that does this (the code is rather convoluted), but making add_generic_sig_match() return immediately when the first get_saved_sig_val() fails does seem to help.

edit:
patch below does what I wrote above plus fixes two possible memory leaks
Code: [Select]
Index: tools/finsig_thumb2.c
===================================================================
--- tools/finsig_thumb2.c (revision 5136)
+++ tools/finsig_thumb2.c (working copy)
@@ -663,10 +663,12 @@
     int k;
 
     char *s = n;
+    int mallocd = 0;
     if (suffix != 0)
     {
         s = malloc(strlen(n) + strlen(suffix) + 1);
         sprintf(s, "%s%s", n, suffix);
+        mallocd = 1;
     }
 
     for (k=0; sig_names[k].name != 0; k++)
@@ -677,10 +679,14 @@
             {
                 sig_names[k].val = eadr;
                 sig_names[k].flags |= EV_MATCH;
+                if (mallocd)
+                    free(s);
                 return;
             }
             else if (sig_names[k].val == eadr)     // same name, same address
             {
+                if (mallocd)
+                    free(s);
                 return;
             }
             else // same name, different address
@@ -2687,6 +2693,7 @@
 
     for(i=1; i<=64; i++) {
         if (!disasm_iter(fw,is)) {
+            free(blobs);
             return 0;
         }
         if (is->insn->id == ARM_INS_LDR && is->insn->detail->arm.operands[1].type == ARM_OP_MEM) {
@@ -4228,6 +4235,7 @@
     uint32_t adr=get_saved_sig_val(name);
     if(!adr) {
         printf("add_generic_sig_match: missing %s\n",name);
+        return;
     }
     add_generic_func_match(match_fns,match_fn_count,MAX_GENERIC_FUNCS,fn,adr);
     char veneer[128];
« Last Edit: 09 / December / 2018, 14:31:15 by srsa_4c »

 

Related Topics