mirror of
https://github.com/golang/go
synced 2024-11-22 00:34:40 -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:
parent
7b03f2a990
commit
2ad58d48fb
@ -147,7 +147,7 @@ ldpe(Biobuf *f, char *pkg, int64 len, char *pn)
|
|||||||
goto bad;
|
goto bad;
|
||||||
obj->sect[i].size = obj->sect[i].sh.SizeOfRawData;
|
obj->sect[i].size = obj->sect[i].sh.SizeOfRawData;
|
||||||
obj->sect[i].name = (char*)obj->sect[i].sh.Name;
|
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
|
// load string table
|
||||||
Bseek(f, base+obj->fh.PointerToSymbolTable+18*obj->fh.NumberOfSymbols, 0);
|
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;
|
etextp = s;
|
||||||
}
|
}
|
||||||
sect->sym = s;
|
sect->sym = s;
|
||||||
|
if(strcmp(sect->name, ".rsrc") == 0)
|
||||||
|
setpersrc(sect->sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
// load relocations
|
// load relocations
|
||||||
@ -259,6 +261,7 @@ ldpe(Biobuf *f, char *pkg, int64 len, char *pn)
|
|||||||
rp->type = D_PCREL;
|
rp->type = D_PCREL;
|
||||||
rp->add = 0;
|
rp->add = 0;
|
||||||
break;
|
break;
|
||||||
|
case IMAGE_REL_I386_DIR32NB:
|
||||||
case IMAGE_REL_I386_DIR32:
|
case IMAGE_REL_I386_DIR32:
|
||||||
rp->type = D_ADDR;
|
rp->type = D_ADDR;
|
||||||
// load addend from image
|
// load addend from image
|
||||||
|
@ -34,6 +34,8 @@ static char dosstub[] =
|
|||||||
0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static Sym *rsrcsym;
|
||||||
|
|
||||||
static char symnames[256];
|
static char symnames[256];
|
||||||
static int nextsymoff;
|
static int nextsymoff;
|
||||||
|
|
||||||
@ -458,6 +460,48 @@ addsymtable(void)
|
|||||||
cflush();
|
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
|
void
|
||||||
asmbpe(void)
|
asmbpe(void)
|
||||||
{
|
{
|
||||||
@ -492,7 +536,9 @@ asmbpe(void)
|
|||||||
addexports(nextfileoff);
|
addexports(nextfileoff);
|
||||||
|
|
||||||
addsymtable();
|
addsymtable();
|
||||||
|
|
||||||
|
addpersrc();
|
||||||
|
|
||||||
fh.NumberOfSections = nsect;
|
fh.NumberOfSections = nsect;
|
||||||
fh.TimeDateStamp = time(0);
|
fh.TimeDateStamp = time(0);
|
||||||
fh.Characteristics = IMAGE_FILE_RELOCS_STRIPPED|
|
fh.Characteristics = IMAGE_FILE_RELOCS_STRIPPED|
|
||||||
|
@ -175,3 +175,5 @@ typedef struct {
|
|||||||
uint32 NumberOfRvaAndSizes;
|
uint32 NumberOfRvaAndSizes;
|
||||||
IMAGE_DATA_DIRECTORY DataDirectory[16];
|
IMAGE_DATA_DIRECTORY DataDirectory[16];
|
||||||
} PE64_IMAGE_OPTIONAL_HEADER;
|
} PE64_IMAGE_OPTIONAL_HEADER;
|
||||||
|
|
||||||
|
void setpersrc(Sym *sym);
|
||||||
|
Loading…
Reference in New Issue
Block a user