// libfiletype_main.c API ------------------------------------------
LIBFILETYPE_FUNC
int LibFileType_CheckFileType(
- LibFileType_FileType *p_filetype, char *pstr_filename, int i_argfd );
+ LibFileType_FileType *p_filetype, const char *pstr_filename, int i_argfd );
LIBFILETYPE_FUNC
int LibFileType_CheckMemoryType(
LibFileType_FileType *p_filetype, Byte *pb_data, int i_size );
#include"./drd64_defines.h"
#include"./drd64_error.h"
-
typedef struct {
- int i_start;
- int i_end;
- char str_libfilepath[DRD64_MAX_SOFILES][DRD64_MAX_PATH];
- char str_librealpath[DRD64_MAX_SOFILES][DRD64_MAX_PATH];
- char str_rpath[DRD64_MAX_SOFILES][DRD64_MAX_PATH];
-} LibGoblin_LibraryFileList;
-
+ char str_remotepath[DRD64_MAX_PATH];
+ char str_localpath[DRD64_MAX_PATH];
+ char str_filename[DRD64_MAX_PATH];
+ char str_rpath[DRD64_MAX_PATH];
+ int i_bid;
+} LibGoblin_ObjectFilePath;
#ifdef DRD64_HEADER_LIBGOBLIN_MAIN
#define LIBGOBLIN_FUNC
#endif
-#ifdef DRD64_SRC_LIBGOBLIN_SYSTEM
- #define LIBGOBLIN_API_SYSTEM
+#ifdef DRD64_SRC_LIBGOBLIN_API
+ #define LIBGOBLIN_API
#else
- #define LIBGOBLIN_API_SYSTEM extern
+ #define LIBGOBLIN_API extern
#endif
-LIBGOBLIN_API_SYSTEM
+LIBGOBLIN_API
+ int LibGoblin_GetUnresolv_ObjectFilePath( int i_pgid, LibGoblin_ObjectFilePath *p_objpath );
+LIBGOBLIN_API
+ int LibGoblin_SetPathAndLoad_ObjectFilePath( LibGoblin_ObjectFilePath *p_objpath );
+LIBGOBLIN_API
+ int LibGoblin_AllocBinInfo( int i_pgid, const char *pstr_filename );
+LIBGOBLIN_API
+ int LibGoblin_FreeBinInfo( int i_binfoid );
+LIBGOBLIN_API
+ int LibGoblin_AllocProgInfo( void );
+LIBGOBLIN_API
+ int LibGoblin_FreeProgInfo( int i_pgid );
+LIBGOBLIN_API
int LibGoblin_Init( void );
-LIBGOBLIN_API_SYSTEM
+LIBGOBLIN_API
int LibGoblin_Term( void );
#ifdef DRD64_SRC_LIBGOBLIN_PROGINFO
#else
#define LIBGOBLIN_API_PROGINFO extern
#endif
-LIBGOBLIN_API_PROGINFO
- LibGoblin_LibraryFileList *LibGoblin_GetLibraryFileListArea( int i_pgid );
-LIBGOBLIN_API_PROGINFO
- int LibGoblin_AllocProgInfo( void );
-LIBGOBLIN_API_PROGINFO
- int LibGoblin_FreeProgInfo( int i_pgid );
#ifdef DRD64_SRC_LIBGOBLIN_BINFO
#define LIBGOBLIN_API_BINFO
#endif
LIBGOBLIN_API_BINFO
const char *LibGoblin_GetRPath_fromBinInfo( int i_bid, char *pstr_rpath );
-LIBGOBLIN_API_BINFO
- int LibGoblin_AllocBinInfo( int i_pgid, const char *pstr_filename, const char *pstr_path );
-LIBGOBLIN_API_BINFO
- int LibGoblin_FreeBinInfo( int i_binfoid );
#ifdef DRD64_SRC_LIBGOBLIN_LOADPROG
#define LIBGOBLIN_API_LOADPROG
#define LIBGOBLIN_API_LOADPROG extern
#endif
LIBGOBLIN_API_LOADPROG
- int LibGoblin_LoadProgram_Library( int i_pgid, LibGoblin_LibraryFileList *p_libflist );
-LIBGOBLIN_API_LOADPROG
int LibGoblin_LoadProgram_Main(
- int i_pgid, const char *pstr_progpath, const char *pstr_realpath,
- LibGoblin_LibraryFileList *p_libflist );
+ int i_pgid, const char *pstr_progpath, const char *pstr_realpath );
goto_LibBrownie_GetLibraryPath_setting:
strncpy( pstr_solibpath, pstr_nowpath, DRD64_MAX_PATH );
- strncat( pstr_solibpath, "/", DRD64_MAX_PATH );
- strncat( pstr_solibpath, pstr_solibname, DRD64_MAX_PATH );
return 0x00;
}
int
LibFileType_CheckFileType(
LibFileType_FileType *p_filetype,
- char *pstr_filename,
+ const char *pstr_filename,
int i_argfd )
{
struct stat t_stat;
FLAGS_DEBUG = -g -Wall
TARGET = libgoblin.a
-OBJS = drd64_libgoblin_system.o \
+OBJS = drd64_libgoblin_api.o \
drd64_libgoblin_proginfo.o \
drd64_libgoblin_binfo.o \
drd64_libgoblin_binaryfile.o \
TEST_TARGET = test_libgoblin
TEST_HEADER = test_libgoblin.h
TEST_OBJS = test_libgoblin.o \
- test_libgoblin_system.o \
+ test_libgoblin_api.o \
test_libgoblin_proginfo.o \
test_libgoblin_binaryfile.o \
test_libgoblin_loadprog.o \
ranlib $(TARGET)
cp $(TARGET) ..
-drd64_libgoblin_system.o: drd64_libgoblin_system.c $(HEADER)
- $(CC) -c -o drd64_libgoblin_system.o $(FLAGS_DEBUG) \
- drd64_libgoblin_system.c
+drd64_libgoblin_api.o: drd64_libgoblin_api.c $(HEADER)
+ $(CC) -c -o drd64_libgoblin_api.o $(FLAGS_DEBUG) \
+ drd64_libgoblin_api.c
drd64_libgoblin_proginfo.o: drd64_libgoblin_proginfo.c $(HEADER)
$(CC) -c -o drd64_libgoblin_proginfo.o $(FLAGS_DEBUG) \
drd64_libgoblin_proginfo.c
$(CC) -c -o test_libgoblin.o \
$(FLAGS_DEBUG) $(FLAGS_COMPILE) $(TEST_FLAGS_COMPILE) \
test_libgoblin.c
-test_libgoblin_system.o: test_libgoblin_system.c $(HEADER) $(TEST_HEADER)
- $(CC) -c -o test_libgoblin_system.o \
+test_libgoblin_api.o: test_libgoblin_api.c $(HEADER) $(TEST_HEADER)
+ $(CC) -c -o test_libgoblin_api.o \
$(FLAGS_DEBUG) $(FLAGS_COMPILE) $(TEST_FLAGS_COMPILE) \
- test_libgoblin_system.c
+ test_libgoblin_api.c
test_libgoblin_binfo.o: test_libgoblin_binfo.c $(HEADER) $(TEST_HEADER)
$(CC) -c -o test_libgoblin_binfo.o \
$(FLAGS_DEBUG) $(FLAGS_COMPILE) $(TEST_FLAGS_COMPILE) \
--- /dev/null
+/*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
+
+ D r . D e a m o n 6 4
+ for INTEL64(R), AMD64(R)
+
+ Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
+DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
+
+/* File Info -----------------------------------------------------------
+File: drd64_.c
+Function:
+Comment:
+----------------------------------------------------------------------*/
+
+#define DRD64_SRC_LIBGOBLIN_API
+#include"drd64_libgoblin.h"
+
+
+/***********************************************************************
+***********************************************************************/
+LIBGOBLIN_API
+int
+ LibGoblin_GetUnresolv_ObjectFilePath(
+ int i_pgid,
+ LibGoblin_ObjectFilePath *p_objpath )
+{
+ int i_result;
+ LibGoblin_ProgramInfo *p_pginfo;
+ LibGoblin_BinaryInfo *p_binfo;
+ LibGoblin_BinaryInfo *p_binfo_parent;
+ LibGoblin_BinaryFile *p_bfile;
+
+ if( NULL == p_objpath ) {
+ return -0x01;
+ }
+
+ p_pginfo = LibGoblin_ProgInfo_GetProgInfo( i_pgid );
+ if( NULL == p_pginfo ) {
+ return -0x02;
+ }
+
+ p_binfo = p_pginfo->p_binfo[0];
+ while( NULL != p_binfo ) {
+ if( LIBGOBLIN_BINFO_PHASE_SETPROG > p_binfo->b_phase )
+ { break; }
+ p_binfo = (LibGoblin_BinaryInfo *)p_binfo->pv_binfo_next;
+ }
+
+ i_result = 0x00;
+ if( NULL != p_binfo ) {
+ memset( p_objpath, 0x00, sizeof( LibGoblin_ObjectFilePath ) );
+
+ p_objpath->i_bid = p_binfo->i_id;
+
+ strncpy( p_objpath->str_filename, p_binfo->str_filename, DRD64_MAX_PATH );
+
+ if( -1 < p_binfo->i_parent_bid ) {
+ p_binfo_parent = LibGoblin_BinInfo_GetBinInfo( p_binfo->i_parent_bid );
+ p_bfile = p_binfo_parent->p_binfile;
+ if( NULL != p_bfile )
+ { strncpy( p_objpath->str_rpath, p_bfile->str_rpath, DRD64_MAX_PATH ); }
+ }
+
+ i_result = 0x01;
+ }
+
+ return i_result;
+}
+
+
+/***********************************************************************
+***********************************************************************/
+LIBGOBLIN_API
+int
+ LibGoblin_SetPathAndLoad_ObjectFilePath(
+ LibGoblin_ObjectFilePath *p_objpath )
+{
+ int i_result;
+ LibGoblin_BinaryInfo *p_binfo;
+
+ p_binfo = LibGoblin_BinInfo_GetBinInfo( p_objpath->i_bid );
+ if( NULL == p_binfo ) {
+ return -0x01;
+ }
+
+ i_result = strncmp( p_objpath->str_filename,
+ p_binfo->str_filename, DRD64_MAX_PATH );
+ if( 0x00 != i_result ) {
+ return -0x02;
+ }
+
+ i_result = LibGoblin_BinInfo_SetProgramPath(
+ p_binfo, p_objpath->str_remotepath,
+ p_objpath->str_localpath );
+ if( 0x00 != i_result ) {
+ return -0x03;
+ }
+
+ i_result = LibGoblin_LoadProg_LoadBinaryInfo( p_binfo );
+ if( 0x00 != i_result ) {
+ return -0x04;
+ }
+
+ return 0x00;
+}
+
+
+/***********************************************************************
+***********************************************************************/
+LIBGOBLIN_API
+int
+ LibGoblin_AllocBinInfo(
+ int i_pgid,
+ const char *pstr_filename )
+{
+ LibGoblin_ProgramInfo *p_pginfo = NULL;
+ LibGoblin_BinaryInfo *p_binfo = NULL;
+
+ p_pginfo = LibGoblin_ProgInfo_GetProgInfo( i_pgid );
+
+ p_binfo = LibGoblin_BinInfo_AllocBinInfo( p_pginfo, pstr_filename, -1 );
+ if( NULL == p_binfo ) {
+ return -0x01;
+ }
+
+ return p_binfo->i_id;
+}
+
+
+/***********************************************************************
+***********************************************************************/
+LIBGOBLIN_API
+int
+ LibGoblin_FreeBinInfo(
+ int i_binfoid )
+{
+ int i_result;
+ LibGoblin_BinaryInfo *p_binfo = NULL;
+
+ p_binfo = LibGoblin_BinInfo_GetBinInfo( i_binfoid );
+ if( NULL == p_binfo ) {
+ return -0x01;
+ }
+
+ i_result = LibGoblin_BinInfo_FreeBinInfo( p_binfo );
+ if( 0x00 != i_result ) {
+ return -0x02;
+ }
+
+ return i_result;
+}
+
+
+/***********************************************************************
+***********************************************************************/
+LIBGOBLIN_API_PROGINFO
+int
+ LibGoblin_AllocProgInfo(
+ void )
+{
+ LibGoblin_ProgramInfo *p_pginfo = NULL;
+
+ p_pginfo = LibGoblin_ProgInfo_AllocProgInfo();
+ if( NULL == p_pginfo ) {
+ return -0x01;
+ }
+
+ return p_pginfo->i_id;
+}
+
+
+/***********************************************************************
+***********************************************************************/
+LIBGOBLIN_API_PROGINFO
+int
+ LibGoblin_FreeProgInfo(
+ int i_pgid )
+{
+ int i_result;
+ LibGoblin_ProgramInfo *p_pginfo;
+
+ p_pginfo = LibGoblin_ProgInfo_GetProgInfo( i_pgid );
+ if( NULL == p_pginfo ) {
+ return -0x01;
+ }
+ assert( p_pginfo->i_id == i_pgid );
+
+ i_result = LibGoblin_ProgInfo_FreeProgInfo( p_pginfo );
+ if( 0x00 != i_result ) {
+ return -0x02;
+ }
+
+ return 0x00;
+}
+
+
+/***********************************************************************
+***********************************************************************/
+LIBGOBLIN_API
+int
+ LibGoblin_Init(
+ void )
+{
+ int i_err;
+
+ i_err = LibFileType_Init();
+ if( 0x00 != i_err ) { return i_err; }
+
+ i_err = LibGoblin_ProgInfo_Init();
+ if( 0x00 != i_err ) { return i_err; }
+
+ i_err = LibGoblin_BinInfo_Init();
+ if( 0x00 != i_err ) { return i_err; }
+
+ i_err = LibGoblin_SymWork_Init();
+ if( 0x00 != i_err ) { return i_err; }
+
+ return 0x00;
+}
+
+
+/***********************************************************************
+***********************************************************************/
+LIBGOBLIN_API
+int
+ LibGoblin_Term(
+ void )
+{
+ int i_err;
+
+ i_err = LibGoblin_SymWork_Term();
+ if( 0x00 != i_err ) { return i_err; }
+
+ i_err = LibGoblin_BinInfo_Term();
+ if( 0x00 != i_err ) { return i_err; }
+
+ i_err = LibGoblin_ProgInfo_Term();
+ if( 0x00 != i_err ) { return i_err; }
+
+ i_err = LibFileType_Term();
+ if( 0x00 != i_err ) { return i_err; }
+
+ return 0x00;
+}
+
+
+/* EOF of drd64_.c ----------------------------------- */
}
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBGOBLIN_BINARYFILE_EXTERN
+LibGoblin_BinaryFile *
+ BinaryFile_SearchBinaryFile(
+ char *pstr_filename,
+ char *pstr_localpath,
+ char *pstr_remotepath )
+{
+ int i_cnt;
+ int i_result;
+ LibGoblin_BinaryFile *p_bfile;
+
+ assert( NULL != pstr_filename);
+ assert( NULL != pstr_localpath );
+
+ for( i_cnt = 0; i_cnt < gi_max_binary_file; i_cnt++ ) {
+ p_bfile = BINFILE( i_cnt );
+
+ if( -0x01 == p_bfile->i_id ) { continue; }
+
+ i_result = strncmp( pstr_filename, p_bfile->str_filename, DRD64_MAX_PATH );
+ if( 0x00 != i_result ) { continue; }
+
+ i_result = strncmp( pstr_localpath, p_bfile->str_localpath, DRD64_MAX_PATH );
+ if( 0x00 != i_result ) { continue; }
+
+ if( NULL != pstr_remotepath ) {
+ i_result = strncmp( pstr_remotepath, p_bfile->str_remotepath, DRD64_MAX_PATH );
+ if( 0x00 != i_result ) { continue; }
+ }
+
+ goto goto_BinaryFile_SearchBinaryFile_post;
+ }
+
+ p_bfile = NULL;
+
+goto_BinaryFile_SearchBinaryFile_post:
+ return p_bfile;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBGOBLIN_BINARYFILE_EXTERN
+LibGoblin_BinaryFile *
+ BinaryFile_DispenseBinaryFile(
+ LibGoblin_BinaryInfo *p_binfo,
+ char *pstr_localpath,
+ char *pstr_remotepath )
+{
+ LibGoblin_BinaryFile *p_bfile;
+
+ assert( NULL != p_binfo );
+
+ p_bfile = BinaryFile_SearchBinaryFile(
+ p_binfo->str_filename, pstr_localpath, pstr_remotepath );
+ if( NULL != p_bfile ) {
+ p_bfile->i_refcount++;
+ }
+ else {
+ p_bfile = BinaryFile_AllocBinaryFile();
+ }
+
+ strncpy( p_bfile->str_filename, p_binfo->str_filename, DRD64_MAX_PATH );
+ strncpy( p_bfile->str_localpath, pstr_localpath, DRD64_MAX_PATH );
+ if( NULL != pstr_remotepath ) {
+ strncpy( p_bfile->str_remotepath, pstr_remotepath, DRD64_MAX_PATH );
+ }
+
+ return p_bfile;
+}
+
/*----------------------------------------------------------------------
OK
if( -0x01 == p_binfile->i_id ) { return 0x00; }
- i_id = p_binfile->i_id;
- BinaryFile_ClearBinaryFile( p_binfile );
+ p_binfile->i_refcount--;
+
+ if( 0 == p_binfile->i_refcount ) {
+ i_id = p_binfile->i_id;
+ BinaryFile_ClearBinaryFile( p_binfile );
- if( gi_max_binary_file == (i_id + 1) )
- { gi_max_binary_file--; }
+ if( gi_max_binary_file == (i_id + 1) )
+ { gi_max_binary_file--; }
- gi_now_binary_file--;
- if( 0 == gi_now_binary_file ) { gi_max_binary_file = 0; }
+ gi_now_binary_file--;
+ if( 0 == gi_now_binary_file ) { gi_max_binary_file = 0; }
+ }
return 0x00;
}
LIBGOBLIN_BINARYFILE_EXTERN
LibGoblin_BinaryFile *BinaryFile_GetBinaryFile( int i_libid );
-/*
-LIBGOBLIN_BINARYFILE_EXTERN
- LibGoblin_BinaryInfo *LibGoblin_BinaryFile_AddBinaryInfo(
- LibGoblin_ProgramInfo *p_pginfo, const char *pstr_binname, int i_req_bid );
-*/
LIBGOBLIN_BINARYFILE_EXTERN
LibGoblin_BinaryFile *BinaryFile_AllocBinaryFile( void );
LIBGOBLIN_BINARYFILE_EXTERN
+ LibGoblin_BinaryFile *BinaryFile_SearchBinaryFile(
+ char *pstr_filename, char *pstr_localpath, char *pstr_remotepath );
+LIBGOBLIN_BINARYFILE_EXTERN
+ LibGoblin_BinaryFile *BinaryFile_DispenseBinaryFile(
+ LibGoblin_BinaryInfo *p_binfo, char *pstr_localpath, char *pstr_remotepath );
+LIBGOBLIN_BINARYFILE_EXTERN
int BinaryFile_FreeBinaryFile( LibGoblin_BinaryFile *p_libinfo );
LIBGOBLIN_BINARYFILE_EXTERN
int BinaryFile_Init( void );
char *pstr_rpath )
{
const char *pcstr_result;
+ LibGoblin_BinaryFile *p_binfile;
assert( NULL != p_binfo );
+ p_binfile = p_binfo->p_binfile;
+ assert( NULL != p_binfile );
if( NULL != pstr_rpath ) {
- strncpy( pstr_rpath, p_binfo->str_rpath, DRD64_MAX_PATH );
+ strncpy( pstr_rpath, p_binfile->str_rpath, DRD64_MAX_PATH );
pcstr_result = (const char *)pstr_rpath;
}
else {
- pcstr_result = (const char *)p_binfo->str_rpath;
+ pcstr_result = (const char *)p_binfile->str_rpath;
}
return pcstr_result;
----------------------------------------------------------------------*/
LIBGOBLIN_BINFO_EXTERN
int
+ BinInfo_AppendChain(
+ LibGoblin_BinaryInfo *p_binfo_now )
+{
+ LibGoblin_BinaryInfo *p_binfo_top;
+ LibGoblin_BinaryInfo *p_binfo_end;
+
+ assert( NULL != p_binfo_now );
+
+ p_binfo_top = p_binfo_now;
+ while( -1 < p_binfo_top->i_parent_bid )
+ { p_binfo_top = BINFO( p_binfo_top->i_parent_bid ); }
+
+ if( p_binfo_now == p_binfo_top )
+ { return 0x00; }
+
+ p_binfo_end = p_binfo_top;
+ while( ( NULL != p_binfo_end->pv_binfo_next )
+ && ( p_binfo_end != p_binfo_now ) ) {
+ p_binfo_end = (LibGoblin_BinaryInfo *)p_binfo_end->pv_binfo_next;
+ }
+
+ assert( NULL != p_binfo_end );
+
+ p_binfo_end->pv_binfo_next = (void *)p_binfo_now;
+
+ return 0x00;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBGOBLIN_BINFO_EXTERN
+int
+ BinInfo_DeleteChain(
+ LibGoblin_BinaryInfo *p_binfo_del )
+{
+ LibGoblin_BinaryInfo *p_binfo_top;
+ LibGoblin_BinaryInfo *p_binfo_now;
+ LibGoblin_BinaryInfo *p_binfo_before;
+
+ assert( NULL != p_binfo_del );
+
+ p_binfo_top = p_binfo_del;
+ while( -1 < p_binfo_top->i_parent_bid )
+ { p_binfo_top = BINFO( p_binfo_top->i_parent_bid ); }
+
+ p_binfo_before = NULL;
+ p_binfo_now = p_binfo_top;
+ while( p_binfo_now != p_binfo_del ) {
+ assert( NULL != p_binfo_now );
+ p_binfo_before = p_binfo_now;
+ p_binfo_now = (LibGoblin_BinaryInfo *)p_binfo_now->pv_binfo_next;
+ }
+
+ if( NULL != p_binfo_before ) {
+ p_binfo_before->pv_binfo_next = (LibGoblin_BinaryInfo *)p_binfo_now->pv_binfo_next;
+ }
+ p_binfo_del->pv_binfo_next = NULL;
+
+ return 0x00;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBGOBLIN_BINFO_EXTERN
+int
LibGoblin_BinInfo_SetRPath(
LibGoblin_BinaryInfo *p_binfo,
const char *pstr_rpath )
char str_src[MAXPATHLEN];
char str_dest[MAXPATHLEN];
char *pstr_result;
+ char *pstr_rbasepath;
+ LibGoblin_BinaryFile *p_binfile;
if( LIBGOBLIN_BINFO_PHASE_SETPROG > p_binfo->b_phase ) {
return -0x01;
}
+ p_binfile = p_binfo->p_binfile;
+ assert( NULL != p_binfile );
+
memset( str_src, 0x00, MAXPATHLEN );
- i_len = strnlen( p_binfo->str_path, DRD64_MAX_PATH );
- strncpy( str_src, p_binfo->str_path, i_len + 1 );
+ // p_binfo->str_path is current path
+ if( 0x00 != p_binfile->str_remotepath[0] )
+ { pstr_rbasepath = p_binfile->str_remotepath; }
+ else
+ { pstr_rbasepath = p_binfile->str_localpath; }
+
+
+ i_len = strnlen( pstr_rbasepath, DRD64_MAX_PATH );
+ strncpy( str_src, pstr_rbasepath, i_len + 1 );
str_src[ i_len ] = '/';
strncat( str_src, pstr_rpath, (MAXPATHLEN - i_len - 1) );
if( DRD64_MAX_PATH <= i_len ) {
return -0x03;
}
- strncpy( p_binfo->str_rpath, str_dest, DRD64_MAX_PATH );
-
- return 0x00;
-}
-
-
-/*----------------------------------------------------------------------
-----------------------------------------------------------------------*/
-LIBGOBLIN_BINFO_EXTERN
-int
- LibGoblin_BinInfo_SetProgramName(
- LibGoblin_BinaryInfo *p_binfo,
- const char *pstr_progname,
- int i_req_bid )
-{
- assert( NULL != p_binfo );
-
- // Check BinaryInfo & BinaryFile struct status ---
- if( LIBGOBLIN_BINFO_PHASE_ALLOCED < p_binfo->b_phase ) {
- return -0x01;
- }
-
- strncpy( p_binfo->str_filename, pstr_progname, DRD64_MAX_PATH );
- p_binfo->i_req_bid = i_req_bid;
- p_binfo->b_phase = LIBGOBLIN_BINFO_PHASE_SETNAME;
+ strncpy( p_binfile->str_rpath, str_dest, DRD64_MAX_PATH );
return 0x00;
}
int
LibGoblin_BinInfo_SetProgramPath(
LibGoblin_BinaryInfo *p_binfo,
- const char *pstr_progpath,
- const char *pstr_realpath )
+ const char *pstr_remotepath,
+ const char *pstr_localpath )
{
int i_len;
- char str_temp[MAXPATHLEN];
+ char str_local[MAXPATHLEN];
+ char str_remote[MAXPATHLEN];
char *pstr_result;
- char *pstr_temp;
+ char *pstr_remote;
LibGoblin_BinaryFile *p_bfile;
if( LIBGOBLIN_BINFO_PHASE_SETPROG <= p_binfo->b_phase ) {
return -0x01;
}
- if(( LIBGOBLIN_BINFO_PHASE_SETNAME == p_binfo->b_phase )
- && ( '\0' == p_binfo->str_filename[0] )) {
- return -0x02;
- }
- p_bfile = p_binfo->p_binfile;
- if( '\0' != p_bfile->str_path[0] ) {
- return -0x03;
+ // localpath convert to RelativePath to AbsolutePath ---
+ pstr_result = realpath( pstr_localpath, str_local );
+ if( NULL == pstr_result ) {
+ return -0x04;
}
+ i_len = strnlen( str_local, DRD64_MAX_PATH );
+ if( '/' == str_local[ i_len ] ) { str_local[ i_len ] = '\0'; }
+
+ // remotepath convert to RelativePath to AbsolutePath ---
+ pstr_remote = NULL;
+ if( NULL != pstr_remotepath ) {
+ if( '\0' != *pstr_remotepath ) {
+ pstr_result = realpath( pstr_remotepath, str_remote );
+ if( NULL == pstr_result ) {
+ return -0x05;
+ }
+ i_len = strnlen( str_remote, DRD64_MAX_PATH );
+ if( '/' == str_remote[ i_len ] ) { str_remote[ i_len ] = '\0'; }
-
- if( pstr_progpath == pstr_realpath )
- { strncpy( str_temp, pstr_progpath, DRD64_MAX_PATH ); }
- else if( 0x00 == strncmp( pstr_progpath, pstr_realpath, DRD64_MAX_PATH ) )
- { strncpy( str_temp, pstr_progpath, DRD64_MAX_PATH ); }
- else {
- // Convert relative-filepath to absolute-filepath.
- pstr_result = realpath( pstr_progpath, str_temp );
- if( NULL == pstr_result ) {
- return -0x04;
+ pstr_remote = str_remote;
}
}
- i_len = strnlen( str_temp, MAXPATHLEN );
- if( DRD64_MAX_PATH <= i_len ) {
- return -0x05;
+ // Alloc BinaryFile struct & Set File Path ---
+ p_bfile = BinaryFile_DispenseBinaryFile( p_binfo, str_local, pstr_remote);
+ if( NULL == p_bfile ) {
+ return -0x06;
}
-
- // Set Real-BinaryFile Path to LibGoblin_BinaryFile ---
- strncpy( p_bfile->str_path, pstr_realpath, DRD64_MAX_PATH );
-
- // Set ProgramFile Path to LibGoblin_BinaryInfo ---
- for( pstr_temp = str_temp + i_len;
- ((pstr_temp != str_temp) && ('/' != *pstr_temp)); pstr_temp-- );
- *pstr_temp = '\0';
-
- strncpy( p_binfo->str_filename, (pstr_temp + 1), DRD64_MAX_PATH );
- strncpy( p_binfo->str_path, str_temp, DRD64_MAX_PATH );
+ p_binfo->p_binfile = p_bfile;
p_binfo->b_phase = LIBGOBLIN_BINFO_PHASE_SETPROG;
return 0x00;
LibGoblin_BinaryInfo *
LibGoblin_BinInfo_AllocBinInfo(
LibGoblin_ProgramInfo *p_pginfo,
- const char *pstr_filename,
- const char *pstr_path )
+ const char *pstr_filename,
+ int i_parent_bid )
{
int i_cnt;
int i_id_now;
LibGoblin_BinaryInfo *p_binfo_base;
LibGoblin_BinaryInfo *p_binfo_now;
- LibGoblin_BinaryFile *p_binfile;
p_binfo_now = NULL;
i_id_now = -1;
assert( NULL != p_binfo_now );
- p_binfile = BinaryFile_AllocBinaryFile();
- if( NULL == p_binfile ) {
- return NULL;
- }
-
LibGoblin_BinInfo_ClearBinInfo( p_binfo_now );
p_binfo_now->i_id = i_id_now;
- p_binfo_now->b_phase = LIBGOBLIN_BINFO_PHASE_ALLOCED;
- p_binfo_now->p_binfile = p_binfile;
+ //p_binfo_now->b_phase = LIBGOBLIN_BINFO_PHASE_ALLOCED;
p_binfo_now->pv_pginfo = (void *)p_pginfo;
+ p_binfo_now->i_parent_bid = i_parent_bid;
+ strncpy( p_binfo_now->str_filename, pstr_filename, DRD64_MAX_PATH );
+ p_binfo_now->b_phase = LIBGOBLIN_BINFO_PHASE_SETNAME;
+ p_binfo_now->pv_binfo_next = NULL;
- return p_binfo_now;
-}
-
-
-/***********************************************************************
-***********************************************************************/
-LIBGOBLIN_API_BINFO
-int
- LibGoblin_AllocBinInfo(
- int i_pgid,
- const char *pstr_filename,
- const char *pstr_path )
-{
- LibGoblin_ProgramInfo *p_pginfo = NULL;
- LibGoblin_BinaryInfo *p_binfo = NULL;
-
- p_pginfo = LibGoblin_ProgInfo_GetProgInfo( i_pgid );
-
- p_binfo = LibGoblin_BinInfo_AllocBinInfo( p_pginfo, pstr_filename, pstr_path );
- if( NULL == p_binfo ) {
- return -0x01;
- }
+ BinInfo_AppendChain( p_binfo_now );
- return p_binfo->i_id;
+ return p_binfo_now;
}
return -0x02;
}
- if( NULL == p_binfo->p_binfile->p_elf ) {
- free( p_binfo->p_binfile->p_elf );
- p_binfo->p_binfile->p_elf = NULL;
+ if( NULL != p_binfo->p_binfile ) {
+ if( NULL == p_binfo->p_binfile->p_elf ) {
+ free( p_binfo->p_binfile->p_elf );
+ p_binfo->p_binfile->p_elf = NULL;
+ }
+
+ BinaryFile_FreeBinaryFile( p_binfo->p_binfile );
+ p_binfo->p_binfile = NULL;
}
- BinaryFile_FreeBinaryFile( p_binfo->p_binfile );
- p_binfo->p_binfile = NULL;
+ BinInfo_DeleteChain( p_binfo );
i_binfoid = p_binfo->i_id;
LibGoblin_BinInfo_ClearBinInfo( p_binfo );
}
-/***********************************************************************
-***********************************************************************/
-LIBGOBLIN_API_BINFO
-int
- LibGoblin_FreeBinInfo(
- int i_binfoid )
-{
- int i_result;
- LibGoblin_BinaryInfo *p_binfo = NULL;
-
- p_binfo = LibGoblin_BinInfo_GetBinInfo( i_binfoid );
- if( NULL == p_binfo ) {
- return -0x01;
- }
-
- i_result = LibGoblin_BinInfo_FreeBinInfo( p_binfo );
- if( 0x00 != i_result ) {
- return -0x02;
- }
-
- return i_result;
-}
-
-
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
LIBGOBLIN_BINFO_EXTERN
int LibGoblin_BinInfo_SetRPath(
LibGoblin_BinaryInfo *p_binfo, const char *pstr_rpath );
LIBGOBLIN_BINFO_EXTERN
- int LibGoblin_BinInfo_SetProgramName(
- LibGoblin_BinaryInfo *p_binfo, const char *pstr_progname, int i_req_bid );
-LIBGOBLIN_BINFO_EXTERN
int LibGoblin_BinInfo_SetProgramPath(
LibGoblin_BinaryInfo *p_binfo, const char *pstr_progpath, const char *pstr_realpath );
LIBGOBLIN_BINFO_EXTERN
LibGoblin_BinaryInfo *LibGoblin_BinInfo_AllocBinInfo(
- LibGoblin_ProgramInfo *p_pginfo, const char *pstr_filename, const char *pstr_path );
+ LibGoblin_ProgramInfo *p_pginfo, const char *pstr_filename, int i_parent_bid );
LIBGOBLIN_BINFO_EXTERN
int LibGoblin_BinInfo_FreeBinInfo( LibGoblin_BinaryInfo *p_binfo );
LIBGOBLIN_BINFO_EXTERN
----------------------------------------------------------------------*/
LIBGOBLIN_DEBUG_ELF_EXTERN
int
- LibGoblin_Debug_Elf_PrintLibFileList(
- LibGoblin_LibraryFileList *p_libflist,
- Byte b_level )
-{
- int i_cnt;
-
- if( 0x00 < b_level )
- { puts("[DEBUG] Load Library List -------------------------------------------"); }
-
- for( i_cnt = p_libflist->i_start; i_cnt < p_libflist->i_end; i_cnt++ ) {
- if( 0x00 < b_level ) {
- printf(" [%2d]: %s\t(%s)\n", i_cnt,
- p_libflist->str_libfilepath[ i_cnt - p_libflist->i_start ],
- p_libflist->str_librealpath[ i_cnt - p_libflist->i_start ] );
- }
- }
-
- if( 0x00 < b_level ) {
- puts("-----------------------------------------------------------------------");
- puts("");
- }
-
- return 0x00;
-}
-
-
-/*----------------------------------------------------------------------
-----------------------------------------------------------------------*/
-LIBGOBLIN_DEBUG_ELF_EXTERN
-int
LibGoblin_Debug_Elf_PrintSectionTable(
LibGoblin_BinaryInfo *p_binfo,
Byte b_level )
#endif
LIBGOBLIN_DEBUG_ELF_EXTERN
- int LibGoblin_Debug_Elf_PrintLibFileList(
- LibGoblin_LibraryFileList *p_libflist, Byte b_level );
-LIBGOBLIN_DEBUG_ELF_EXTERN
int LibGoblin_Debug_Elf_PrintSectionTable(
LibGoblin_BinaryInfo *p_binfo, Byte b_level );
else
{ i_sz_elfdyn = sizeof( Elf32_Dyn ); }
-
do {
if( IsBinfoType_Elf64( p_binfo ) ) {
p_dyn64 = (Elf64_Dyn *)pb_data;
if( DT_NEEDED == qw_tag ) {
p_bintmp = LibGoblin_ProgInfo_AddBinaryInfo(
- p_pginfo, ((char *)(pb_dynstr + qw_value)), NULL, p_binfo->i_id );
+ p_pginfo, ((char *)(pb_dynstr + qw_value)), p_binfo->i_id );
}
else if( DT_RPATH == qw_tag ) {
LibGoblin_BinInfo_SetRPath( p_binfo, (const char *)(pb_dynstr + qw_value) );
}
- /*
- else if( DT_SONAME == qw_tag ) { }
- */
+ //else if( DT_SONAME == qw_tag ) { }
pb_data += i_sz_elfdyn;
}while( DT_NULL != qw_tag );
#define DRD64_SRC_LIBGOBLIN_LOADPROG
#include"drd64_libgoblin.h"
+
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
LIBGOBLIN_LOADPROG_EXTERN
int
- LibGoblin_LoadProg_LoadBinaryInfo_fromFileList(
- LibGoblin_ProgramInfo *p_pginfo,
- LibGoblin_LibraryFileList *p_libflist )
+ LibGoblin_LoadProg_LoadBinaryInfo(
+ LibGoblin_BinaryInfo *p_binfo )
{
int i_result;
- int i_readed_bid;
- int i_now_bid;
- int i_max_bid;
- int i_idxflist;
- LibGoblin_BinaryInfo *p_binfo;
LibGoblin_BinaryFile *p_bfile;
- assert( NULL != p_pginfo );
- assert( NULL != p_libflist );
-
- i_now_bid = p_libflist->i_start;
- i_max_bid = p_libflist->i_end;
- i_idxflist = 0;
-
- for( ; i_now_bid < i_max_bid; i_now_bid++, i_idxflist++ ) {
- p_binfo = p_pginfo->p_binfo[ i_now_bid ];
-
- i_result = LibGoblin_BinInfo_SetProgramPath(
- p_binfo, p_libflist->str_libfilepath[i_idxflist],
- p_libflist->str_librealpath[i_idxflist] );
- if( 0x00 != i_result ) {
- return -0x02;
- }
-
- i_result = LibGoblin_ReadBinary_File( p_binfo, NULL );
- if( 0x00 != i_result ) {
- return -0x03;
- }
+ assert( NULL != p_binfo );
- p_bfile = p_binfo->p_binfile;
- if( 0x00 == (DRD64_LIBFILETYPE_SUB_ELF & p_bfile->t_ftype.w_subtype) ) {
- return -0x04;
- }
-
- //i_result = LibGoblin_Elf_ReadELF_Phase1( p_binfo, LIBGOBLIN_BINFO_FILE_EXEC );
- i_result = LibGoblin_Elf_ReadELF_Phase1( p_binfo );
- if( 0x00 != i_result ) {
- return -0x05;
- }
+ i_result = LibGoblin_ReadBinary_File( p_binfo );
+ if( 0x00 != i_result ) {
+ return -0x03;
}
- memset( p_libflist, 0x00, sizeof( LibGoblin_LibraryFileList ) );
-
- i_readed_bid = i_max_bid;
- i_now_bid = i_max_bid;
- i_max_bid = LibGoblin_ProgInfo_GetBinaryInfos( p_pginfo );
- for( ; i_now_bid < i_max_bid; i_now_bid++ ) {
- p_binfo = p_pginfo->p_binfo[ i_now_bid ];
- assert( NULL != p_binfo );
-
- strncpy( p_libflist->str_libfilepath[ i_now_bid - i_readed_bid ],
- p_binfo->str_filename, DRD64_MAX_PATH );
- LibGoblin_GetRPath_fromBinInfo(
- p_binfo->i_req_bid, p_libflist->str_rpath[ i_now_bid - i_readed_bid ] );
+ p_bfile = p_binfo->p_binfile;
+ if( 0x00 == (DRD64_LIBFILETYPE_SUB_ELF & p_bfile->t_ftype.w_subtype) ) {
+ return -0x04;
}
-
- p_libflist->i_start = i_readed_bid;
- p_libflist->i_end = i_max_bid;
- return 0x00;
-}
-
-
-/***********************************************************************
-***********************************************************************/
-LIBGOBLIN_API_LOADPROG
-int
- LibGoblin_LoadProgram_Library(
- int i_pgid,
- LibGoblin_LibraryFileList *p_libflist )
-{
- int i_result;
- LibGoblin_ProgramInfo *p_pginfo;
-
- p_pginfo = LibGoblin_ProgInfo_GetProgInfo( i_pgid );
- if( NULL == p_pginfo ) {
- return -0x01;
+ i_result = LibGoblin_Elf_ReadELF_Phase1( p_binfo );
+ if( 0x00 != i_result ) {
+ return -0x05;
}
- if( NULL == p_libflist ) {
- return -0x02;
- }
-
- i_result = LibGoblin_LoadProg_LoadBinaryInfo_fromFileList( p_pginfo, p_libflist );
-
- return i_result;
+ return 0x00;
}
int
LibGoblin_LoadProgram_Main(
int i_pgid,
- const char *pstr_progpath,
- const char *pstr_realpath,
- LibGoblin_LibraryFileList *p_libflist )
+ const char *pstr_remotefull,
+ const char *pstr_localfull )
{
int i_result;
- char *pstr_temp;
- char *pstr_progfile;
- char *pstr_path;
+
+ char str_filename[DRD64_MAX_PATH];
+ char str_localpath[DRD64_MAX_PATH];
+ char *pstr_remotepath;
LibGoblin_ProgramInfo *p_pginfo;
LibGoblin_BinaryInfo *p_binfo;
return -0x01;
}
- if( NULL == p_libflist ) {
- return -0x02;
- }
-
- strncpy( p_libflist->str_libfilepath[0], pstr_progpath, DRD64_MAX_PATH );
- strncpy( p_libflist->str_librealpath[0], pstr_realpath, DRD64_MAX_PATH );
- p_libflist->i_start = 0;
- p_libflist->i_end = 1;
+ strncpy( str_filename, basename( pstr_localfull ), DRD64_MAX_PATH );
+ strncpy( str_localpath, dirname( pstr_localfull ), DRD64_MAX_PATH );
- // XXX
- pstr_temp = alloca( DRD64_MAX_PATH + 1);
- strncpy( pstr_temp, pstr_progpath, DRD64_MAX_PATH );
- pstr_progfile = basename( pstr_temp );
-
- pstr_temp = alloca( DRD64_MAX_PATH + 1);
- strncpy( pstr_temp, pstr_progpath, DRD64_MAX_PATH );
- pstr_path = basename( pstr_temp );
+ pstr_remotepath = NULL;
+ if( NULL != pstr_remotefull ) {
+ pstr_remotepath = (char *)alloca( DRD64_MAX_PATH + 1 );
+ strncpy( pstr_remotepath, dirname( pstr_remotefull ), DRD64_MAX_PATH );
+ }
- p_binfo = LibGoblin_ProgInfo_AddBinaryInfo( p_pginfo, pstr_progfile, pstr_path, 0 );
+ p_binfo = LibGoblin_ProgInfo_AddBinaryInfo( p_pginfo, str_filename, -1 );
if( NULL == p_binfo ) {
return -0x01;
}
- i_result = LibGoblin_LoadProg_LoadBinaryInfo_fromFileList( p_pginfo, p_libflist );
+ i_result = LibGoblin_BinInfo_SetProgramPath(
+ p_binfo, pstr_remotepath, str_localpath );
+ if( 0x00 != i_result ) {
+ return -0x02;
+ }
+
+ i_result = LibGoblin_LoadProg_LoadBinaryInfo( p_binfo );
return i_result;
}
#endif
LIBGOBLIN_LOADPROG_EXTERN
- int LibGoblin_LoadProg_LoadBinaryInfo_fromFileList(
- LibGoblin_ProgramInfo *p_pginfo, LibGoblin_LibraryFileList *p_libflist );
-LIBGOBLIN_LOADPROG_EXTERN
- int LibGoblin_LoadProg_LoadProgram_Main(
- LibGoblin_ProgramInfo *p_pginfo, const char *pstr_progpath,
- const char *pstr_realpath, LibGoblin_LibraryFileList *p_libflist );
+ int LibGoblin_LoadProg_LoadBinaryInfo(
+ LibGoblin_BinaryInfo *p_binfo );
#endif /* DRD64_HEADER_XXX */
}
-/***********************************************************************
-***********************************************************************/
-LIBGOBLIN_API_PROGINFO
-LibGoblin_LibraryFileList *
- LibGoblin_GetLibraryFileListArea(
- int i_pgid )
-{
- LibGoblin_ProgramInfo *p_pginfo = NULL;
- LibGoblin_LibraryFileList *p_libflist = NULL;
-
- p_pginfo = LibGoblin_ProgInfo_GetProgInfo( i_pgid );
- if( NULL == p_pginfo ) {
- return NULL;
- }
-
- p_libflist = &(p_pginfo->t_libflist);
- assert( NULL != p_libflist );
-
- memset( p_libflist, 0x00, sizeof( LibGoblin_LibraryFileList ) );
-
- return p_libflist;
-}
-
-
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
LIBGOBLIN_PROGINFO_EXTERN
LibGoblin_ProgInfo_AddBinaryInfo(
LibGoblin_ProgramInfo *p_pginfo,
const char *pstr_binfilename,
- const char *pstr_binpath,
int i_req_bid )
{
int i_binfoid;
- int i_result;
- int i_cnt;
LibGoblin_BinaryInfo *p_binfo = NULL;
assert( NULL != p_pginfo );
return NULL;
}
+/*
// Check Alloced Same-Library ---
for( i_cnt = 0; i_cnt < p_pginfo->i_num_binfo; i_cnt++ ) {
- if( !strncmp( (p_pginfo->p_binfo[ i_cnt ])->str_filename,
+ p_binfo = p_pginfo->p_binfo[ i_cnt ];
+ p_binfile = p_binfo->p_binfile;
+
+ if( !strncmp( p_binfile->str_filename,
pstr_binfilename, DRD64_MAX_PATH ) ) {
- return p_pginfo->p_binfo[ i_cnt ];
+ return p_binfo;
}
}
+*/
// Alloc BinaryInfo ---
- p_binfo = LibGoblin_BinInfo_AllocBinInfo( p_pginfo, pstr_binfilename, pstr_binpath );
+ p_binfo = LibGoblin_BinInfo_AllocBinInfo( p_pginfo, pstr_binfilename, i_req_bid );
if( NULL == p_binfo ) {
return NULL;
}
p_pginfo->p_binfo[ i_binfoid ] = p_binfo;
p_pginfo->i_num_binfo++;
- i_result = LibGoblin_BinInfo_SetProgramName( p_binfo, pstr_binfilename, i_req_bid );
- if( 0x00 != i_result ) {
- LibGoblin_BinInfo_FreeBinInfo( p_binfo );
- // XXX - error check!
-
- return NULL;
- }
-
return p_binfo;
}
}
-/***********************************************************************
-***********************************************************************/
-LIBGOBLIN_API_PROGINFO
-int
- LibGoblin_AllocProgInfo(
- void )
-{
- LibGoblin_ProgramInfo *p_pginfo = NULL;
-
- p_pginfo = LibGoblin_ProgInfo_AllocProgInfo();
- if( NULL == p_pginfo ) {
- return -0x01;
- }
-
- return p_pginfo->i_id;
-}
-
-
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
LIBGOBLIN_PROGINFO_EXTERN
}
-/***********************************************************************
-***********************************************************************/
-LIBGOBLIN_API_PROGINFO
-int
- LibGoblin_FreeProgInfo(
- int i_pgid )
-{
- int i_result;
- LibGoblin_ProgramInfo *p_pginfo;
-
- p_pginfo = LibGoblin_ProgInfo_GetProgInfo( i_pgid );
- if( NULL == p_pginfo ) {
- return -0x01;
- }
- assert( p_pginfo->i_id == i_pgid );
-
- i_result = LibGoblin_ProgInfo_FreeProgInfo( p_pginfo );
- if( 0x00 != i_result ) {
- return -0x02;
- }
-
- return 0x00;
-}
-
-
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
LIBGOBLIN_PROGINFO_EXTERN
int LibGoblin_ProgInfo_GetBinaryInfos( LibGoblin_ProgramInfo *p_pginfo );
LIBGOBLIN_PROGINFO_EXTERN
LibGoblin_BinaryInfo *LibGoblin_ProgInfo_AddBinaryInfo(
- LibGoblin_ProgramInfo *p_pginfo, const char *pstr_binfilename, const char *pstr_binpath, int i_req_bid );
+ LibGoblin_ProgramInfo *p_pginfo, const char *pstr_binfilename, int i_req_bid );
LIBGOBLIN_PROGINFO_EXTERN
LibGoblin_ProgramInfo *LibGoblin_ProgInfo_AllocProgInfo( void );
LIBGOBLIN_PROGINFO_EXTERN
LIBGOBLIN_READBIN_EXTERN
int
LibGoblin_ReadBinary_File(
- LibGoblin_BinaryInfo *p_binfo,
- const char *pstr_filepath )
+ LibGoblin_BinaryInfo *p_binfo )
+ //,const char *pstr_filepath )
{
int i_result = 0x00;
int i_err;
int i_fd = -0x01;
const char *pstr_binfile;
+ char str_binfilepath[DRD64_MAX_PATH];
Byte *pb_head;
LibFileType_FileType t_ftype;
LibGoblin_BinaryFile *p_bfile;
p_bfile = p_binfo->p_binfile;
assert( NULL != p_bfile );
+ if ( LIBGOBLIN_BINFO_PHASE_SETPROG != p_binfo->b_phase ) {
+ return -0x01;
+ }
+
+ strncpy( str_binfilepath, p_bfile->str_localpath, DRD64_MAX_PATH);
+ strcat( str_binfilepath, "/" );
+ strncat( str_binfilepath, p_bfile->str_filename, DRD64_MAX_PATH);
+ pstr_binfile = p_bfile->str_localpath;
+ if( '\0' == pstr_binfile ) {
+ return -0x02;
+ }
+
+/*
if( NULL == pstr_filepath ) {
if ( LIBGOBLIN_BINFO_PHASE_SETPROG != p_binfo->b_phase ) {
return -0x01;
}
- pstr_binfile = p_bfile->str_path;
+ strncpy( str_binfilepath, p_bfile->str_localpath, DRD64_MAX_PATH);
+ strcat( str_binfilepath, "/" );
+ strncat( str_binfilepath, p_bfile->str_filename, DRD64_MAX_PATH);
+ pstr_binfile = p_bfile->str_localpath;
if( '\0' == pstr_binfile ) {
return -0x02;
}
return -0x03;
}
- pstr_binfile = pstr_filepath;
+ // SetProgramPath ??!!
+ //pstr_binfile = pstr_filepath;
+ strncpy( str_binfilepath, pstr_filepath, DRD64_MAX_PATH);
+ return -0xff;
}
+*/
/* Open Test LM */
- i_fd = open( pstr_binfile, O_RDONLY );
+ i_fd = open( str_binfilepath, O_RDONLY );
if( -1 >= i_fd ) {
i_result = -0x10;
goto goto_LibGoblin_ReadBinary_File_post;
}
/* Get FileSize & FileType by LibFileType */
- i_err = LibFileType_CheckFileType( &t_ftype, pstr_binfile, i_fd );
+ i_err = LibFileType_CheckFileType( &t_ftype, str_binfilepath, i_fd );
if( 0x00 != i_err ) {
close( i_fd );
i_result = -0x11;
p_bfile->i_fd = i_fd;
p_bfile->dw_flag = LIBGOBLIN_BINFO_FILE_MMAP;
p_binfo->b_phase = LIBGOBLIN_BINFO_PHASE_BINREAD;
- if( NULL != pstr_filepath )
- { strncpy( p_bfile->str_path, pstr_binfile, DRD64_MAX_PATH ); }
+ // XXX NO use??
+ //if( NULL != pstr_filepath )
+ //{ strncpy( p_bfile->str_localpath, pstr_binfile, DRD64_MAX_PATH ); }
//i_result = LibGoblin_AnalyzeBinary( p_binfo, i_filetype );
LIBGOBLIN_READBIN_EXTERN
int LibGoblin_ReadBinary_File(
- LibGoblin_BinaryInfo *p_binfo, const char *pstr_filepath );
+ LibGoblin_BinaryInfo *p_binfo );
+ //LibGoblin_BinaryInfo *p_binfo, const char *pstr_filepath );
LIBGOBLIN_READBIN_EXTERN
int LibGoblin_ReadBinary_Memory(
LibGoblin_BinaryInfo *p_binfo, Byte *pb_data, DWord dw_size );
+++ /dev/null
-/*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
-
- D r . D e a m o n 6 4
- for INTEL64(R), AMD64(R)
-
- Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
-OF THE POSSIBILITY OF SUCH DAMAGE.
-
-DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
-
-/* File Info -----------------------------------------------------------
-File: drd64_.c
-Function:
-Comment:
-----------------------------------------------------------------------*/
-
-#define DRD64_SRC_LIBGOBLIN_SYSTEM
-#include"drd64_libgoblin.h"
-
-
-/*----------------------------------------------------------------------
-----------------------------------------------------------------------*/
-LIBGOBLIN_API_SYSTEM
-int
- LibGoblin_Init(
- void )
-{
- int i_err;
-
- i_err = LibFileType_Init();
- if( 0x00 != i_err ) { return i_err; }
-
- i_err = LibGoblin_ProgInfo_Init();
- if( 0x00 != i_err ) { return i_err; }
-
- i_err = LibGoblin_BinInfo_Init();
- if( 0x00 != i_err ) { return i_err; }
-
- i_err = LibGoblin_SymWork_Init();
- if( 0x00 != i_err ) { return i_err; }
-
- return 0x00;
-}
-
-
-/*----------------------------------------------------------------------
-----------------------------------------------------------------------*/
-LIBGOBLIN_API_SYSTEM
-int
- LibGoblin_Term(
- void )
-{
- int i_err;
-
- i_err = LibGoblin_SymWork_Term();
- if( 0x00 != i_err ) { return i_err; }
-
- i_err = LibGoblin_BinInfo_Term();
- if( 0x00 != i_err ) { return i_err; }
-
- i_err = LibGoblin_ProgInfo_Term();
- if( 0x00 != i_err ) { return i_err; }
-
- i_err = LibFileType_Term();
- if( 0x00 != i_err ) { return i_err; }
-
- return 0x00;
-}
-
-
-/* EOF of drd64_.c ----------------------------------- */
/*=====================================================================*/
-/*
-typedef struct {
- int i_id;
- char str_libfilepath[DRD64_MAX_PATH];
- char str_librealpath[DRD64_MAX_PATH];
- char str_rpath[DRD64_MAX_PATH];
- void *p_nextlib;
-} LibGoblin_LibraryInfo;
-*/
-
-/*=====================================================================*/
typedef struct {
int i_id;
int i_refcount;
/* Binary-File Info. */
int i_fd;
DWord dw_flag;
+
+ // EXEC-program / shared lib. filename (without directry)
char str_filename[DRD64_MAX_PATH];
- char str_path[DRD64_MAX_PATH];
- char str_rpath[DRD64_MAX_PATH]; // .dyn Section rpath
+ //char str_newpath[DRD64_MAX_PATH]; // nonuse
+ char str_localpath[DRD64_MAX_PATH]; // filepath in local machine path.(transported)
+ char str_remotepath[DRD64_MAX_PATH]; // filepath in remote machine path.(local machine is NULL)
+
+ // .dynamic Section - rpath (.so location path - converted real-path)
+ char str_rpath[DRD64_MAX_PATH];
+
LibFileType_FileType t_ftype;
/* Binary-File Memory Image Access Info. */
#define LIBGOBLIN_BINFO_PHASE_SETNAME 0x20
#define LIBGOBLIN_BINFO_PHASE_SETPROG 0x30
#define LIBGOBLIN_BINFO_PHASE_BINREAD 0x40
+#define LIBGOBLIN_BINFO_PHASE_ELF1READ 0x51
+#define LIBGOBLIN_BINFO_PHASE_ELF2READ 0x52
#define LIBGOBLIN_BINFO_PHASE_ANALYZED 0x50
#define LIBGOBLIN_BINFO_MAXFILES 3
DWord dw_max_addrinfo;
/* Exec. File Info. */
+ int i_parent_bid;
char str_filename[DRD64_MAX_PATH];
- char str_path[DRD64_MAX_PATH];
- char str_rpath[DRD64_MAX_PATH]; // .dynamic Section - rpath (.so location path)
- int i_req_bid;
LibGoblin_BinaryFile *p_binfile;
LibGoblin_SectionInfo t_section[LIBGOBLIN_SECTION_ID_MAX];
void *pv_pginfo;
- void *pv_lib_binfile_next; // NEW
+ void *pv_binfo_next; // NEW
} LibGoblin_BinaryInfo;
int i_opened_bid;
-
- // Working Area
- LibGoblin_LibraryFileList t_libflist;
-
} LibGoblin_ProgramInfo;
Test_LibGoblin_BinInfo();
Test_LibGoblin_ProgInfo();
Test_LibGoblin_BinaryFile();
- Test_LibGoblin_ReadBinary();
Test_LibGoblin_SymWork();
+ Test_LibGoblin_ReadBinary();
Test_LibGoblin_LoadProg();
CU_basic_run_tests();
#include"test_libgoblin.h"
-/*--------------------------------------------------------------------*/
-int
- Test_LibGoblin_LoadProg_ResolvLibraryFileList(
- LibGoblin_LibraryFileList *p_libflist )
-{
- int i_cnt;
- int i_result;
- int i_items;
- char str_libname[DRD64_MAX_PATH];
- char *pstr_ldpath;
-
- i_items = p_libflist->i_end - p_libflist->i_start;
-
- pstr_ldpath = LibBrownie_GetLoadLibraryPath( LIBBROWNIE_LDHINTS_ELF64 );
- if( NULL == pstr_ldpath ) { return -0x01; }
-
- for( i_cnt = 0; i_cnt < i_items; i_cnt++ ) {
- strncpy( str_libname, p_libflist->str_libfilepath[ i_cnt ], DRD64_MAX_PATH );
-
- i_result = LibBrownie_GetLibraryPath(
- p_libflist->str_libfilepath[ i_cnt ], str_libname,
- p_libflist->str_rpath[ i_cnt ], pstr_ldpath );
- if( 0x00 != i_result ) { return -0x02; }
-
- strncpy( p_libflist->str_librealpath[i_cnt],
- p_libflist->str_libfilepath[i_cnt], DRD64_MAX_PATH );
- }
-
- return 0x00;
-}
-
-
/* LibGoblin_LoadProgram() API ****************************************/
/*--------------------------------------------------------------------*/
void Test_LibGoblin_LoadProg_API_LoadProgram_test00_001( void )
{
int i_pgid;
int i_result;
+ char *pstr_ldpath;
- LibGoblin_LibraryFileList *p_libflist;
+ LibGoblin_ObjectFilePath t_objpath;
i_result = LibBrownie_Init();
CU_ASSERT( 0x00 == i_result );
+ pstr_ldpath = LibBrownie_GetLoadLibraryPath( LIBBROWNIE_LDHINTS_ELF64 );
+ if( NULL == pstr_ldpath )
+ { goto goto_Test_LibGoblin_LoadProg_API_LoadProgram_test00_001_post; }
+
i_result = LibGoblin_Init();
CU_ASSERT( 0x00 == i_result );
i_pgid = LibGoblin_AllocProgInfo();
CU_ASSERT( 0x00 <= i_result );
- p_libflist = LibGoblin_GetLibraryFileListArea( i_pgid );
- CU_ASSERT( NULL != p_libflist );
-
i_result = LibGoblin_LoadProgram_Main( i_pgid, "../testdata/dwarftest",
- "../testdata/dwarftest", p_libflist );
+ "../testdata/dwarftest" );
CU_ASSERT( 0x00 == i_result );
- do {
- i_result = Test_LibGoblin_LoadProg_ResolvLibraryFileList( p_libflist );
+
+ while( 0x00 < LibGoblin_GetUnresolv_ObjectFilePath( i_pgid, &t_objpath ) ) {
+ i_result = LibBrownie_GetLibraryPath(
+ t_objpath.str_localpath,
+ t_objpath.str_filename, t_objpath.str_rpath, pstr_ldpath );
CU_ASSERT( 0x00 == i_result );
+ if( 0x00 != i_result )
+ { goto goto_Test_LibGoblin_LoadProg_API_LoadProgram_test00_001_post; }
- LibGoblin_Debug_Elf_PrintLibFileList( p_libflist, 0xff );
+ printf(" file= %s, rpath= %s\n => localpath: %s\n",
+ t_objpath.str_filename, t_objpath.str_rpath, t_objpath.str_localpath );
- i_result = LibGoblin_LoadProgram_Library( i_pgid, p_libflist );
+ i_result = LibGoblin_SetPathAndLoad_ObjectFilePath( &t_objpath );
CU_ASSERT( 0x00 == i_result );
- }while( p_libflist->i_start < p_libflist->i_end );
-
- LibBrownie_FreeLoadLibraryPath( LIBBROWNIE_LDHINTS_ELF64 );
+ if( 0x00 != i_result )
+ { goto goto_Test_LibGoblin_LoadProg_API_LoadProgram_test00_001_post; }
+ }
i_result = LibGoblin_FreeProgInfo( i_pgid );
CU_ASSERT( 0x00 == i_result );
i_result = LibGoblin_Term();
CU_ASSERT( 0x00 == i_result );
+ LibBrownie_FreeLoadLibraryPath( LIBBROWNIE_LDHINTS_ELF64 );
+
+goto_Test_LibGoblin_LoadProg_API_LoadProgram_test00_001_post:
LibBrownie_Term();
return;
i_result = LibGoblin_Init();
CU_ASSERT( 0x00 == i_result );
- i_binfoid = LibGoblin_AllocBinInfo( -1, "dwarftest", "../testdata/" );
+ i_binfoid = LibGoblin_AllocBinInfo( -1, "dwarftest" );
CU_ASSERT( 0x00 == i_binfoid );
p_binfo = LibGoblin_BinInfo_GetBinInfo( i_binfoid );
CU_ASSERT( NULL != p_binfo );
- i_result = LibGoblin_ReadBinary_File( p_binfo,
- "../testdata/dwarftest" );
+ i_result = LibGoblin_BinInfo_SetProgramPath( p_binfo, NULL, "../testdata" );
+ CU_ASSERT( 0x00 == i_result );
+
+ i_result = LibGoblin_ReadBinary_File( p_binfo );
CU_ASSERT( 0x00 == i_result );
i_result = LibGoblin_Debug_Elf_PrintSectionTable( p_binfo, 0xff );
i_result = LibGoblin_Init();
CU_ASSERT( 0x00 == i_result );
- i_binfoid = LibGoblin_AllocBinInfo( -1, "dwarftest", "../testdata/" );
+ i_binfoid = LibGoblin_AllocBinInfo( -1, "dwarftest" );
CU_ASSERT( 0x00 == i_binfoid );
p_binfo = LibGoblin_BinInfo_GetBinInfo( i_binfoid );
CU_ASSERT( NULL != p_binfo );
i_result = LibGoblin_BinInfo_SetProgramPath( p_binfo,
- "../testdata/dwarftest", "../testdata/dwarftest" );
+ "../testdata/", "../testdata/" );
+ CU_ASSERT( 0x00 == i_result );
- i_result = LibGoblin_ReadBinary_File( p_binfo, NULL );
+ i_result = LibGoblin_ReadBinary_File( p_binfo );
CU_ASSERT( 0x00 == i_result );
i_result = LibGoblin_ReadBinary_FreeBinary( p_binfo );
i_result = LibGoblin_Init();
CU_ASSERT( 0x00 == i_result );
- i_binfoid = LibGoblin_AllocBinInfo( -1, "dwarftest", "../testdata/" );
+ i_binfoid = LibGoblin_AllocBinInfo( -1, "dwarftest" );
CU_ASSERT( 0x00 == i_binfoid );
p_binfo = LibGoblin_BinInfo_GetBinInfo( i_binfoid );
CU_ASSERT( NULL != p_binfo );
+ i_result = LibGoblin_BinInfo_SetProgramPath( p_binfo, NULL, "../testdata" );
+ CU_ASSERT( 0x00 == i_result );
+
i_fd = open( "../testdata/dwarftest", O_RDONLY );
CU_ASSERT( 0 <= i_fd );
Test_LibGoblin_ReadBinary_File_test00_002 );
CU_add_test( pt_goblin, "LibGoblin_ReadBinary_Memory_test00_001",
Test_LibGoblin_ReadBinary_Memory_test00_001 );
-
return 0x00;
}