1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
4 for INTEL64(R), AMD64(R)
6 Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
31 /* File Info -----------------------------------------------------------
35 ----------------------------------------------------------------------*/
37 #define DRD64_SRC_LIBGOBLIN_API
38 #include"drd64_libgoblin.h"
41 /***********************************************************************
42 ***********************************************************************/
45 LibGoblin_AnalyzeMainProgram(
49 LibGoblin_ProgramInfo *p_pginfo;
50 LibGoblin_BinaryInfo *p_binfo;
52 p_pginfo = ProgInfo_GetProgInfo( i_pgid );
53 if( NULL == p_pginfo ) {
57 p_binfo = BinaryInfo_GetBinInfo( p_pginfo->i_binfo_id );
58 if( NULL == p_binfo ) {
62 i_result = ELF_ReadELF_Phase2( p_binfo, (PtrValue)0x00000000 );
63 if( 0x00 != i_result ) {
71 /***********************************************************************
72 ***********************************************************************/
75 LibGoblin_AnalyzeLibrary(
78 PtrValue ptr_loadaddr )
81 LibGoblin_BinaryInfo *p_binfo;
83 p_binfo = BinaryInfo_GetBinInfo( i_bid );
84 if( NULL == p_binfo ) {
88 if( p_binfo->i_pginfo != i_pgid ) {
92 i_result = ELF_ReadELF_Phase2( p_binfo, ptr_loadaddr );
93 if( 0x00 != i_result ) {
101 /***********************************************************************
102 ***********************************************************************/
105 LibGoblin_GetUnresolv_ObjectFilePath(
107 LibGoblin_ObjectFilePath *p_objpath )
110 LibGoblin_ProgramInfo *p_pginfo;
111 LibGoblin_BinaryInfo *p_binfo;
112 LibGoblin_BinaryInfo *p_binfo_parent;
113 LibGoblin_BinaryFile *p_bfile;
115 if( NULL == p_objpath ) {
119 p_pginfo = ProgInfo_GetProgInfo( i_pgid );
120 if( NULL == p_pginfo ) {
124 p_binfo = BinaryInfo_GetBinInfo( p_pginfo->i_binfo_id );
125 while( NULL != p_binfo ) {
126 if( LIBGOBLIN_BINFO_PHASE_SETPROG > p_binfo->b_phase )
128 p_binfo = BinaryInfo_GetBinInfo( p_binfo->i_binfo_next );
132 if( NULL != p_binfo ) {
133 memset( p_objpath, 0x00, sizeof( LibGoblin_ObjectFilePath ) );
135 p_objpath->i_bid = p_binfo->i_id;
137 strncpy( p_objpath->str_filename, p_binfo->str_filename, DRD64_MAX_PATH );
139 if( -1 < p_binfo->i_binfo_parent ) {
140 p_binfo_parent = BinaryInfo_GetBinInfo( p_binfo->i_binfo_parent );
141 p_bfile = BinaryFile_GetBinaryFile( p_binfo_parent->i_binfile );
142 if( NULL != p_bfile ) {
143 strncpy( p_objpath->str_rpath, p_bfile->str_rpath, DRD64_MAX_PATH );
144 strncpy( p_objpath->str_runpath, p_bfile->str_runpath, DRD64_MAX_PATH );
148 i_result = p_binfo->i_id;
155 /***********************************************************************
156 ***********************************************************************/
159 LibGoblin_SetPathAndLoad_ObjectFilePath(
160 LibGoblin_ObjectFilePath *p_objpath )
163 LibGoblin_BinaryInfo *p_binfo;
165 p_binfo = BinaryInfo_GetBinInfo( p_objpath->i_bid );
166 if( NULL == p_binfo ) {
170 i_result = strncmp( p_objpath->str_filename,
171 p_binfo->str_filename, DRD64_MAX_PATH );
172 if( 0x00 != i_result ) {
176 i_result = BinaryInfo_SetProgramPath(
177 p_binfo, p_objpath->str_remotepath,
178 p_objpath->str_localpath );
179 if( 0x00 != i_result ) {
183 i_result = LoadProg_LoadBinaryInfo( p_binfo );
184 if( 0x00 != i_result ) {
193 /***********************************************************************
194 ***********************************************************************/
197 LibGoblin_LoadProgram_Main(
199 const char *pstr_remotefull,
200 const char *pstr_localfull )
203 LibGoblin_ProgramInfo *p_pginfo;
205 p_pginfo = ProgInfo_GetProgInfo( i_pgid );
206 if( NULL == p_pginfo ) {
210 if( NULL == pstr_localfull ) {
214 i_bid = LoadProgram_LoadMainProgram(
215 p_pginfo, pstr_remotefull, pstr_localfull );
216 if(( 0 > i_bid ) || ( NULL == pstr_localfull )) {
224 /***********************************************************************
225 ***********************************************************************/
228 LibGoblin_AllocBinInfo(
230 const char *pstr_filename )
232 LibGoblin_ProgramInfo *p_pginfo = NULL;
233 LibGoblin_BinaryInfo *p_binfo = NULL;
235 p_pginfo = ProgInfo_GetProgInfo( i_pgid );
237 p_binfo = BinaryInfo_AllocBinInfo( p_pginfo, pstr_filename, -1 );
238 if( NULL == p_binfo ) {
242 return p_binfo->i_id;
246 /***********************************************************************
247 ***********************************************************************/
250 LibGoblin_FreeBinInfo(
254 LibGoblin_BinaryInfo *p_binfo = NULL;
256 p_binfo = BinaryInfo_GetBinInfo( i_binfoid );
257 if( NULL == p_binfo ) {
261 i_result = BinaryInfo_FreeBinInfo( p_binfo );
262 if( 0x00 != i_result ) {
270 /***********************************************************************
271 ***********************************************************************/
272 LIBGOBLIN_API_PROGINFO
274 LibGoblin_AllocProgInfo(
278 LibGoblin_ProgramInfo *p_pginfo = NULL;
280 p_pginfo = ProgInfo_AllocProgInfo();
281 if( NULL == p_pginfo ) {
285 i_result = ObjectInfo_Init( p_pginfo, 0 );
286 if( 0x00 != i_result ) {
287 ProgInfo_FreeProgInfo( p_pginfo ); // None use return value.
291 return p_pginfo->i_id;
295 /***********************************************************************
296 ***********************************************************************/
297 LIBGOBLIN_API_PROGINFO
299 LibGoblin_FreeProgInfo(
303 LibGoblin_ProgramInfo *p_pginfo;
305 p_pginfo = ProgInfo_GetProgInfo( i_pgid );
306 if( NULL == p_pginfo ) {
309 assert( p_pginfo->i_id == i_pgid );
311 ObjectInfo_Term( p_pginfo ); // None use retrun value.
313 i_result = ProgInfo_FreeProgInfo( p_pginfo );
314 if( 0x00 != i_result ) {
322 /***********************************************************************
323 ***********************************************************************/
331 i_err = LibFileType_Init();
332 if( 0x00 != i_err ) { return i_err; }
334 i_err = ProgInfo_Init();
335 if( 0x00 != i_err ) { return i_err; }
337 i_err = BinaryInfo_Init();
338 if( 0x00 != i_err ) { return i_err; }
344 /***********************************************************************
345 ***********************************************************************/
353 i_err = BinaryInfo_Term();
354 if( 0x00 != i_err ) { return i_err; }
356 i_err = ProgInfo_Term();
357 if( 0x00 != i_err ) { return i_err; }
359 i_err = LibFileType_Term();
360 if( 0x00 != i_err ) { return i_err; }
366 /* EOF of drd64_.c ----------------------------------- */