1
0
mirror of https://github.com/golang/go synced 2024-11-22 00:04:41 -07:00

8l: emit resources (.rsrc) in Windows PE.

R=alex.brainman, rsc
CC=golang-dev, vcc.163
https://golang.org/cl/4516055
This commit is contained in:
Wei Guangjing 2011-05-25 07:53:00 -04:00 committed by Russ Cox
parent 7b03f2a990
commit 2ad58d48fb
3 changed files with 53 additions and 2 deletions

View File

@ -147,7 +147,7 @@ ldpe(Biobuf *f, char *pkg, int64 len, char *pn)
goto bad;
obj->sect[i].size = obj->sect[i].sh.SizeOfRawData;
obj->sect[i].name = (char*)obj->sect[i].sh.Name;
// TODO return error if found .cormeta .rsrc
// TODO return error if found .cormeta
}
// load string table
Bseek(f, base+obj->fh.PointerToSymbolTable+18*obj->fh.NumberOfSymbols, 0);
@ -222,6 +222,8 @@ ldpe(Biobuf *f, char *pkg, int64 len, char *pn)
etextp = s;
}
sect->sym = s;
if(strcmp(sect->name, ".rsrc") == 0)
setpersrc(sect->sym);
}
// load relocations
@ -259,6 +261,7 @@ ldpe(Biobuf *f, char *pkg, int64 len, char *pn)
rp->type = D_PCREL;
rp->add = 0;
break;
case IMAGE_REL_I386_DIR32NB:
case IMAGE_REL_I386_DIR32:
rp->type = D_ADDR;
// load addend from image

View File

@ -34,6 +34,8 @@ static char dosstub[] =
0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static Sym *rsrcsym;
static char symnames[256];
static int nextsymoff;
@ -458,6 +460,48 @@ addsymtable(void)
cflush();
}
void
setpersrc(Sym *sym)
{
if(rsrcsym != nil)
diag("too many .rsrc sections");
rsrcsym = sym;
}
void
addpersrc(void)
{
IMAGE_SECTION_HEADER *h;
uchar *p;
uint32 val;
Reloc *r;
if(rsrcsym == nil)
return;
h = addpesection(".rsrc", rsrcsym->size, rsrcsym->size, 0);
h->Characteristics = IMAGE_SCN_MEM_READ|
IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_INITIALIZED_DATA;
// relocation
for(r=rsrcsym->r; r<rsrcsym->r+rsrcsym->nr; r++) {
p = rsrcsym->p + r->off;
val = h->VirtualAddress + r->add;
// 32-bit little-endian
p[0] = val;
p[1] = val>>8;
p[2] = val>>16;
p[3] = val>>24;
}
ewrite(cout, rsrcsym->p, rsrcsym->size);
strnput("", h->SizeOfRawData - rsrcsym->size);
cflush();
// update data directory
dd[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress = h->VirtualAddress;
dd[IMAGE_DIRECTORY_ENTRY_RESOURCE].Size = h->VirtualSize;
}
void
asmbpe(void)
{
@ -492,7 +536,9 @@ asmbpe(void)
addexports(nextfileoff);
addsymtable();
addpersrc();
fh.NumberOfSections = nsect;
fh.TimeDateStamp = time(0);
fh.Characteristics = IMAGE_FILE_RELOCS_STRIPPED|

View File

@ -175,3 +175,5 @@ typedef struct {
uint32 NumberOfRvaAndSizes;
IMAGE_DATA_DIRECTORY DataDirectory[16];
} PE64_IMAGE_OPTIONAL_HEADER;
void setpersrc(Sym *sym);