Re: [NewIO-developers] Importing API's into NewIO
Status: Alpha
Brought to you by:
cnystrom
|
From: Jason R. <ja...@ne...> - 2009-03-01 12:12:44
|
Interesting news.
I have something that can identify api and sub-api level functions and we
can probably use as a linker with the right type of code. I can reformat
this output almost any way you like as well.
-------------CUT HERE--------------
#!/usr/bin/perl
# This code is really ugly. I sort of just hacked it together.
# Its a nice layout thing if you think about it. really gross
# hack though. I should learn more perlre.
use strict;
use Getopt::Long qw(GetOptions);
my $binary = '';
GetOptions('bin=s' => \$binary);
if (!$binary) {
print "specify --bin=/path/to/binary\n";
exit(1);
} else {
print "Re-mapping $binary...\n";
my $funcs = `objdump -d $binary|grep \\\>\\\:|sed s/\\\://g`;
print "Functions mapped..";
my $asm = `objdump -d $binary`;
print "..Disassembled!\n";
while ($funcs =~ /([0-9a-f]+).*\<(.*)\>/g) {
my $ptr = $1;
my $func = $2;
$ptr =~ s/08/8/;
print "$ptr points to $func\n";
while ($asm =~ /([0-9a-f]+):.*call.*$ptr/g) {
my $caller = $1;
my $infunc = `grep "\>\\:\\|$caller"
file2|grep -B1 $caller|head -1|awk '{print \$2}'`;
$infunc =~ s/:\n//g;
print "\t$caller in \`$infunc\'\n";
}
}
}
-------------CUT HERE--------------
So we may actually be able to do this whole api-wrapping thing after all.
This will work on ELF formatted
executables. I will explain here how to make it work with a .so file:
The output of the above application for a .so file will be flat because .so
files are flat binaries. What this
means is that the memory addresses start from 0x0.
Additionally, to make this work with an executable, newIO could
theoretically do this as well. Not sure
what reason you'd have except to port it to windows ;) hehehehe....
Anywho, since you're starting from 0x00000000, you'll have to find wherever
the .so is loaded in memory.
If it hasn't been loaded, we'll have to load it ourselves. Basically what
we'll need to do is add each "function
pointer" to the base pointer of the .so which is loaded into memory to find
the absolute pointer. At this point
we can just call it like:
int (*func)();
func = &ptr;
(int)(*func)();
Or something like that, I believe. The catch is you have to add it with hex
math, but there's all sorts of hex
to ascii apps for that. Thoughts? I know this is a crufty hack. I'm going
back and re-doing it already. Its
just somewhere to start.
On Thu, Jan 29, 2009 at 9:58 PM, Chris Nystrom <cny...@gm...> wrote:
> On Wed, Jan 28, 2009 at 3:15 AM, Jason Reynolds <ja...@ne...> wrote:
> > Hey guys,
> >
> > Something I've realized about the current source tree is that it would be
> > easy (using the msg_send_[TYPE] functions and the header files to
> implement
> > functions) to write a parser to grab API's out of compiled binaries (ELF,
> > PE, etc) and parse them into usable NewIO C code to add functionality to
> the
> > client. You could really just prefix all the functions with
> _nio_[LIBNAME]
> > or something and add a switch to define I/O types (SDL, AGAR, OpenGL)
> > efficiently.
> >
> > Automated API imports can be difficult to actually release as a feature
> > though, and I haven't found a decent ELF parsing library (objdump's
> doesn't
> > actually look very nice).
> > Could definately make porting code a might bit simpler, though.
> Thoughts?
>
> That is an interesting idea. There must be a huge number of APIs out
> in the wild though right?
>
> Chris
>
> --
> E-Mail: Chris Nystrom <cny...@gm...>
> Saving the world from web programming.
> http://www.newio.org - G-Talk: cnystrom
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> NewIO-developers mailing list
> New...@li...
> https://lists.sourceforge.net/lists/listinfo/newio-developers
>
|