Skip to content

Commit

Permalink
nwlib: cleanup code to handle arch_header transparent way
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalak committed Jun 4, 2024
1 parent 63fb699 commit 89e25d3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
8 changes: 4 additions & 4 deletions bld/nwlib/c/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ static size_t ARstrlen( const char * str )
return( c - str );
}

char *GetARName( libfile io, ar_header *header, arch_dict *dict )
/***************************************************************/
char *GetARName( libfile io, const ar_header *header, arch_dict *dict )
/*********************************************************************/
{
char buffer[AR_NAME_LEN + 1];
char *buf;
Expand Down Expand Up @@ -147,7 +147,7 @@ static void GetARValue( const char *element, ar_len len, char delimiter, char *b
buffer[len] = '\0';
}

void GetARHeaderValues( ar_header *header, arch_header * arch )
void GetARHeaderValues( const ar_header *header, arch_header *arch )
{
arch->date = GetARNumeric( header->date, AR_DATE_LEN );
arch->uid = GetARNumeric( header->uid, AR_UID_LEN );
Expand All @@ -156,7 +156,7 @@ void GetARHeaderValues( ar_header *header, arch_header * arch )
arch->size = GetARNumeric( header->size, AR_SIZE_LEN );
}

static void PutARPadding( char * element, ar_len current_len, ar_len desired_len )
static void PutARPadding( char *element, ar_len current_len, ar_len desired_len )
{
ar_len loop;

Expand Down
25 changes: 19 additions & 6 deletions bld/nwlib/c/implib.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,17 @@ static bool elfAddImport( libfile io, long header_offset, const arch_header *arc
string_sec = ORLSecGetStringTable( sym_sec );
ORLSecGetContents( string_sec, (unsigned_8 **)&strings );

tmp_arch.ffname = arch->name;
dllName.name = tmp_arch.name = dll_name = MemDupStr( TrimPath( arch->name ) );
tmp_arch.date = arch->date;
tmp_arch.uid = arch->uid;
tmp_arch.gid = arch->gid;
tmp_arch.mode = arch->mode;
tmp_arch.size = arch->size;
tmp_arch.libtype = arch->libtype;

dllName.name = dll_name = MemDupStr( TrimPath( arch->name ) );
dllName.len = strlen( dllName.name );
tmp_arch.name = dll_name;
tmp_arch.ffname = NULL;

ElfMKImport( &tmp_arch, ELF, export_size, &dllName, strings, export_table, sym_table, processor );

Expand Down Expand Up @@ -421,11 +429,16 @@ static void peAddImport( libfile io, long header_offset, const arch_header *arch
ord_table = (Coff32_EOrd *)(edata + export_header->OrdTableRVA - export_base.u._32[I64LO32] + adjust);
ordinal_base = export_header->ordBase;

tmp_arch = *arch;
tmp_arch.name = edata + export_header->nameRVA - export_base.u._32[I64LO32] + adjust;
tmp_arch.ffname = NULL;
dllName.name = tmp_arch.name;
tmp_arch.date = arch->date;
tmp_arch.uid = arch->uid;
tmp_arch.gid = arch->gid;
tmp_arch.mode = arch->mode;
tmp_arch.size = arch->size;
tmp_arch.libtype = arch->libtype;

dllName.name = tmp_arch.name = edata + export_header->nameRVA - export_base.u._32[I64LO32] + adjust;
dllName.len = strlen( dllName.name );
tmp_arch.ffname = NULL;

if( coff_obj ) {
coffAddImportOverhead( &tmp_arch, &dllName, processor );
Expand Down
2 changes: 1 addition & 1 deletion bld/nwlib/c/proclib.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static void ProcessLibOrObj( const char *filename, objproc obj, libwalk_fn *proc
} else {
LibClose( io );
}
// FreeNewArch( &arch ); temporary fix until AddImport processing will be fixed
FreeNewArch( &arch );
}

static void WalkInputLib( void )
Expand Down
8 changes: 7 additions & 1 deletion bld/nwlib/c/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,17 @@ static sym_file *NewSymFile( const arch_header *arch, file_type obj_type )

sfile = MemAlloc( sizeof( sym_file ) );
sfile->obj_type = obj_type;
sfile->arch = *arch;
sfile->first = NULL;
sfile->next = NULL;
sfile->impsym = NULL;
sfile->inlib_offset = 0;
sfile->full_name = MemDupStr( arch->name );
sfile->arch.date = arch->date;
sfile->arch.uid = arch->uid;
sfile->arch.gid = arch->gid;
sfile->arch.mode = arch->mode;
sfile->arch.size = arch->size;
sfile->arch.libtype = arch->libtype;
if( Options.trim_path ) {
sfile->arch.name = MemDupStr( TrimPath( arch->name ) );
} else {
Expand All @@ -234,6 +239,7 @@ static sym_file *NewSymFile( const arch_header *arch, file_type obj_type )
sfile->arch.ffname = MemDupStr( arch->ffname );
sfile->ffname_length = strlen( sfile->arch.ffname );
} else {
sfile->arch.ffname = NULL;
sfile->ffname_length = 0;
}
*(FileTable.add_to) = sfile;
Expand Down
2 changes: 1 addition & 1 deletion bld/nwlib/c/wlibutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ libfile NewArchLibOpen( arch_header *arch, const char *filename )
return( LibOpen( filename, LIBOPEN_READ ) );
}

void FreeNewArch( arch_header *arch )
void FreeNewArch( const arch_header *arch )
{
MemFree( arch->name );
}
Expand Down
4 changes: 2 additions & 2 deletions bld/nwlib/h/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
****************************************************************************/


extern char *GetARName( libfile io, ar_header *header, arch_dict *dict );
extern char *GetARName( libfile io, const ar_header *header, arch_dict *dict );
extern char *GetFFName( arch_dict *dict );
extern void GetARHeaderValues( ar_header *header, arch_header *arch );
extern void GetARHeaderValues( const ar_header *header, arch_header *arch );
extern void CreateARHeader( ar_header *ar, const arch_header *arch );
2 changes: 1 addition & 1 deletion bld/nwlib/h/wlibutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extern bool IsSameModuleCase( const char *a, const char *b, int cmp_mode );
extern int SymbolNameCmp( const char *s1, const char *s2);
extern bool IsExt( const char *a, const char *b );
extern libfile NewArchLibOpen( arch_header *arch, const char *filename );
extern void FreeNewArch( arch_header *arch );
extern void FreeNewArch( const arch_header *arch );
extern void DefaultExtension( char *name, const char *def_ext );
extern char *TrimPath( const char * );
extern void TrimPathInPlace( char * );
Expand Down

0 comments on commit 89e25d3

Please sign in to comment.