1 /*
2 ** relinject.c for elfsh
3 **
4 ** Started on  Fri Mar 28 14:58:57 2003 mayhem
5 ** Last update Wed Apr 16 16:24:17 2003 mayhem
6 */
7 #include "elfsh.h"
8 
9 
10 /* Inject a .o into an executable */
cmd_relinject()11 int		cmd_relinject()
12 {
13   elfshobj_t	*host;
14   elfshobj_t	*rel;
15   int		idx;
16 
17   /* Load host file */
18   idx = atoi(world.args.param[0]);
19   host = (idx ? vm_getfile(idx) : hash_get(&file_hash, world.args.param[0]));
20   if (host == NULL)
21     {
22       host = elfsh_map_obj(world.args.param[0]);
23       if (host == NULL)
24 	ELFSH_SETERROR("[elfsh:cmd_relinject] Cannot map host file\n", -1);
25     }
26 
27   /* Load relocatable file */
28   idx = atoi(world.args.param[1]);
29   rel = (idx > 0 ? vm_getfile(idx) : hash_get(&file_hash, world.args.param[1]));
30   if (rel == NULL)
31     {
32       rel = elfsh_map_obj(world.args.param[1]);
33       if (rel == NULL)
34 	ELFSH_SETERROR("[elfsh:cmd_relinject] Cannot map relocatable file\n",
35 		       -1);
36     }
37 
38   /* Call libelfsh relocatable object injector */
39   idx = elfsh_inject_etrel(host, rel);
40   if (idx < 0)
41     return (-1);
42 
43   /* Success : put the modified object as current */
44   world.current = host;
45   if (!world.state.vm_quiet)
46     printf(" [*] ET_REL %s injected succesfully in ET_EXEC %s\n\n",
47 	   rel->name, host->name);
48   return (0);
49 }
50