* Added basic guidelines in TODO.decompiler

* r2 now support -s and -b with ut64/ut32 offsets
* Remove 'goto' statement
This commit is contained in:
pancake 2010-06-21 21:08:43 +02:00
parent 255504b79c
commit 790491a707
3 changed files with 107 additions and 55 deletions

View File

@ -1,19 +1,81 @@
http://www.pivotaltracker.com/
Decompiler for radare2 trackline
================================
Objectives
==========
- Name local variables argments and global vars
- Cv ...
- Detect and propagate variable types
- Identify switch statements
- Symbol Recognising
- Loop detection (for/while/do)
- enum detection/support (load from .h ?) #define /enum parse only
- Name local variables argments and global vars (Cv ...)
- Common construct detection (if/switch/for/while/do)
- Enum detection/support (load from .h ?) #define /enum parse only
- Detect sign of variables (depending on the conditionals used)
- change operations to ease reading ('\n' instead of 0xa.. sub<->add)
- Change operations to ease reading ('\n' instead of 0xa.. sub<->add)
- Detect and propagate variable types
- Symbol recognition
UI
==
- Walk along the decompiled program code
Core (RAnal, RMeta, RBin, ...)
==============================
* Language: C
* Analyze opcodes
* Detect numeric sign
* Detect data type and size by analyzing the accesses
* Analyze conditionals (if () goto .., labels, ...)
* Support push+ret constructions
* Analyze function calls (fast/slowcall, parameters, data types, return values..)
* Define data types (as 'pm' structs (memory format string))
* Analyze common constructions
Plugin (Radare.Decompiler class)
================================
* Language: Vala
* Using visitor paradigm
* Bidirectional sync methods for core
- Caches data and code from the core
- Comments must be syncronized too
* Independent structure compared to core
* Optimize sequences of opcodes
* Optimize AST (remove unaccessible code, join nodes, ...)
* Polimorph operations to simplify reading (shl eax, 1 => eax *= 2)
* Remove stack-related operations
* Resolve and propagate data types
* Parse .h files in order to import function signatures, defines, enums, ..
* Support to decompile single function or full program
* Each node must have a to_string() method to serialize
* Indent resulting code
* Remove trash code
UI (Gtk+)
=========
* Language: Vala
* Implemented as a Gtk.Widget
* Walk along the decompiled program code
- change variable names (read/write value)
- go xrefs
- change variable names
Future
======
* Floating point support
* Support high-level language constructions (objective-C, gobject, c++, ...)
External linkz
==============
* http://www.pivotaltracker.com/
-------------8<-------------------------------------------- -- - - - - -
+-------------------+
| Plugin API design |
+-------------------+
public class RadareDecompiler.AST { }
public class RadareDecompiler.Node { }
public class RadareDecompiler.Function { }
public class RadareDecompiler.Variable { }
public class RadareDecompiler.Constant { }
public class RadareDecompiler.Conditional { }
public class RadareDecompiler.Enum { }
public class Radare.Decompiler {
public class Decompiler(RCore core) {
...
}
public void sync(bool write) { ... }
}

View File

@ -38,8 +38,8 @@ int main(int argc, char **argv) {
int run_rc = 1;
int debug = 0;
int fullfile = 0;
int bsize = 0;
int seek = 0; // XXX use 64
ut32 bsize = 0;
ut64 seek = 0;
if (argc < 2)
return main_help (1);
@ -80,10 +80,10 @@ int main(int argc, char **argv) {
perms = R_IO_READ | R_IO_WRITE;
break;
case 'b':
bsize = atoi (optarg); // XXX use r_num
bsize = (ut32) r_num_math (r.num, optarg);
break;
case 's':
seek = atoi (optarg); // XXX use r_num
seek = r_num_math (r.num, optarg);
break;
case 'L':
r_lib_list (r.lib);
@ -127,7 +127,7 @@ int main(int argc, char **argv) {
if (prj && *prj) {
char *file = r_core_project_info (&r, prj);
if (file) fh = r_core_file_open (&r, file, perms);
else fprintf (stderr, "No file\n");
else eprintf ("No file\n");
}
}
}
@ -162,11 +162,8 @@ int main(int argc, char **argv) {
if (seek)
r_core_seek (&r, seek, 1);
if (fullfile)
r_core_block_size (&r, r.file->size);
else
if (bsize)
r_core_block_size (&r, bsize);
if (fullfile) r_core_block_size (&r, r.file->size);
else if (bsize) r_core_block_size (&r, bsize);
// Load the binary information from rabin2
{
@ -176,51 +173,45 @@ int main(int argc, char **argv) {
r_str_free (cmd);
}
if (run_rc)
if (r_config_get_i (r.config, "cfg.fortunes")) {
if (run_rc && r_config_get_i (r.config, "cfg.fortunes")) {
r_core_cmd (&r, "fo", 0);
r_cons_flush ();
}
{
{ /* check if file.sha1 has changed */
char *path = strdup (r_config_get (r.config, "file.path"));
r_core_project_open (&r, r_config_get (r.config, "file.project"));
/* check if file.sha1 has changed */
{
const char *npath, *nsha1;
char *sha1 = strdup (r_config_get (r.config, "file.sha1"));
char *cmd = r_str_dup_printf (".!rahash2 -r %s", r.file->filename);
r_core_project_open (&r, r_config_get (r.config, "file.project"));
r_core_cmd (&r, cmd, 0);
nsha1 = r_config_get (r.config, "file.sha1");
npath = r_config_get (r.config, "file.path");
if (sha1 && *sha1 && strcmp (sha1, nsha1))
fprintf (stderr, "WARNING: file.sha1 change: %s => %s\n", sha1, nsha1);
eprintf ("WARNING: file.sha1 change: %s => %s\n", sha1, nsha1);
if (path && *path && strcmp (path, npath))
fprintf (stderr, "WARNING: file.path change: %s => %s\n", path, npath);
eprintf ("WARNING: file.path change: %s => %s\n", path, npath);
r_str_free (cmd);
free (sha1);
free (path);
}
}
mainloop:
do {
ret = r_core_prompt (&r);
if (ret == -1)
for (;;) {
do { if ((ret = r_core_prompt (&r))==-1)
eprintf ("Invalid command\n");
} while (ret != R_CORE_CMD_EXIT);
} while (ret != R_CORE_CMD_EXIT);
if (debug) {
if (r_cons_yesno ('y', "Do you want to quit? (Y/n)")) {
if (r_cons_yesno ('y', "Do you want to kill the process? (Y/n)"))
r_debug_kill (r.dbg, 9); // KILL
{
const char *prj = r_config_get (r.config, "file.project");
if (prj && *prj)
if (r_cons_yesno ('y', "Do you want to save the project? (Y/n)"))
r_core_project_save (&r, prj);
}
} else goto mainloop;
if (debug) {
if (r_cons_yesno ('y', "Do you want to quit? (Y/n)")) {
if (r_cons_yesno ('y', "Do you want to kill the process? (Y/n)"))
r_debug_kill (r.dbg, 9); // KILL
{
const char *prj = r_config_get (r.config, "file.project");
if (prj && *prj && r_cons_yesno ('y', "Do you want to save the project? (Y/n)"))
r_core_project_save (&r, prj);
}
} else continue;
}
break;
}
/* capture return value */
ret = r.num->value;

View File

@ -1,10 +1,9 @@
r_meta
======
RMeta api
=========
** Should we store traces here??..or do we have to use r_trace
** xrefs stuff should be delegated to the flags?
- we can generate xrefs metadata from flags analysis
- we can use r_meta as 'static storage' and flags as playground.
** xrefs stuff should be delegated to the flags? (dont think so..)
- we can generate xrefs metadata from flags analysis
- we can use r_meta as 'static storage' and flags as playground.
** data_* api should be refactored to use less functions with more
flexible arguments.
** We can store multiple linked lists depending on type of data, to