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_AnalyzeProgram(
49 LibGoblin_ProgramInfo *p_pginfo;
51 p_pginfo = ProgInfo_GetProgInfo( i_pgid );
52 if( NULL == p_pginfo ) {
56 i_result = ELF_ReadELF_Phase2( p_pginfo->p_binfo[LIBGOBLIN_BINFO_FILE_EXEC] );
57 if( 0x00 != i_result ) {
65 /***********************************************************************
66 ***********************************************************************/
69 LibGoblin_GetUnresolv_ObjectFilePath(
71 LibGoblin_ObjectFilePath *p_objpath )
74 LibGoblin_ProgramInfo *p_pginfo;
75 LibGoblin_BinaryInfo *p_binfo;
76 LibGoblin_BinaryInfo *p_binfo_parent;
77 LibGoblin_BinaryFile *p_bfile;
79 if( NULL == p_objpath ) {
83 p_pginfo = ProgInfo_GetProgInfo( i_pgid );
84 if( NULL == p_pginfo ) {
88 p_binfo = p_pginfo->p_binfo[LIBGOBLIN_BINFO_FILE_EXEC];
89 while( NULL != p_binfo ) {
90 if( LIBGOBLIN_BINFO_PHASE_SETPROG > p_binfo->b_phase )
92 p_binfo = BinaryInfo_GetBinInfo( p_binfo->i_binfo_next );
96 if( NULL != p_binfo ) {
97 memset( p_objpath, 0x00, sizeof( LibGoblin_ObjectFilePath ) );
99 p_objpath->i_bid = p_binfo->i_id;
101 strncpy( p_objpath->str_filename, p_binfo->str_filename, DRD64_MAX_PATH );
103 if( -1 < p_binfo->i_parent_bid ) {
104 p_binfo_parent = BinaryInfo_GetBinInfo( p_binfo->i_parent_bid );
105 p_bfile = BinaryFile_GetBinaryFile( p_binfo_parent->i_binfile );
106 if( NULL != p_bfile )
107 { strncpy( p_objpath->str_rpath, p_bfile->str_rpath, DRD64_MAX_PATH ); }
117 /***********************************************************************
118 ***********************************************************************/
121 LibGoblin_SetPathAndLoad_ObjectFilePath(
122 LibGoblin_ObjectFilePath *p_objpath )
125 LibGoblin_BinaryInfo *p_binfo;
127 p_binfo = BinaryInfo_GetBinInfo( p_objpath->i_bid );
128 if( NULL == p_binfo ) {
132 i_result = strncmp( p_objpath->str_filename,
133 p_binfo->str_filename, DRD64_MAX_PATH );
134 if( 0x00 != i_result ) {
138 i_result = BinaryInfo_SetProgramPath(
139 p_binfo, p_objpath->str_remotepath,
140 p_objpath->str_localpath );
141 if( 0x00 != i_result ) {
145 i_result = LoadProg_LoadBinaryInfo( p_binfo );
146 if( 0x00 != i_result ) {
155 /***********************************************************************
156 ***********************************************************************/
159 LibGoblin_LoadProgram_Main(
161 const char *pstr_remotefull,
162 const char *pstr_localfull )
165 LibGoblin_ProgramInfo *p_pginfo;
167 p_pginfo = ProgInfo_GetProgInfo( i_pgid );
168 if( NULL == p_pginfo ) {
172 if( NULL == pstr_localfull ) {
176 i_result = LoadProgram_LoadMainProgram(
177 p_pginfo, pstr_remotefull, pstr_localfull );
178 if( NULL == pstr_localfull ) {
186 /***********************************************************************
187 ***********************************************************************/
190 LibGoblin_AllocBinInfo(
192 const char *pstr_filename )
194 LibGoblin_ProgramInfo *p_pginfo = NULL;
195 LibGoblin_BinaryInfo *p_binfo = NULL;
197 p_pginfo = ProgInfo_GetProgInfo( i_pgid );
199 p_binfo = BinaryInfo_AllocBinInfo( p_pginfo, pstr_filename, -1 );
200 if( NULL == p_binfo ) {
204 return p_binfo->i_id;
208 /***********************************************************************
209 ***********************************************************************/
212 LibGoblin_FreeBinInfo(
216 LibGoblin_BinaryInfo *p_binfo = NULL;
218 p_binfo = BinaryInfo_GetBinInfo( i_binfoid );
219 if( NULL == p_binfo ) {
223 i_result = BinaryInfo_FreeBinInfo( p_binfo );
224 if( 0x00 != i_result ) {
232 /***********************************************************************
233 ***********************************************************************/
234 LIBGOBLIN_API_PROGINFO
236 LibGoblin_AllocProgInfo(
239 LibGoblin_ProgramInfo *p_pginfo = NULL;
241 p_pginfo = ProgInfo_AllocProgInfo();
242 if( NULL == p_pginfo ) {
246 return p_pginfo->i_id;
250 /***********************************************************************
251 ***********************************************************************/
252 LIBGOBLIN_API_PROGINFO
254 LibGoblin_FreeProgInfo(
258 LibGoblin_ProgramInfo *p_pginfo;
260 p_pginfo = ProgInfo_GetProgInfo( i_pgid );
261 if( NULL == p_pginfo ) {
264 assert( p_pginfo->i_id == i_pgid );
266 i_result = ProgInfo_FreeProgInfo( p_pginfo );
267 if( 0x00 != i_result ) {
275 /***********************************************************************
276 ***********************************************************************/
284 i_err = LibFileType_Init();
285 if( 0x00 != i_err ) { return i_err; }
287 i_err = ProgInfo_Init();
288 if( 0x00 != i_err ) { return i_err; }
290 i_err = BinaryInfo_Init();
291 if( 0x00 != i_err ) { return i_err; }
293 i_err = LibGoblin_SymWork_Init();
294 if( 0x00 != i_err ) { return i_err; }
300 /***********************************************************************
301 ***********************************************************************/
309 i_err = LibGoblin_SymWork_Term();
310 if( 0x00 != i_err ) { return i_err; }
312 i_err = BinaryInfo_Term();
313 if( 0x00 != i_err ) { return i_err; }
315 i_err = ProgInfo_Term();
316 if( 0x00 != i_err ) { return i_err; }
318 i_err = LibFileType_Term();
319 if( 0x00 != i_err ) { return i_err; }
325 /* EOF of drd64_.c ----------------------------------- */