Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
234 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* FatELF; support multiple ELF binaries in one file. | ||
* | ||
* Please see the file LICENSE.txt in the source's root directory. | ||
* | ||
* This file written by Ryan C. Gordon. | ||
*/ | ||
|
||
#define FATELF_UTILS 1 | ||
#include "fatelf-utils.h" | ||
|
||
static int fatelf_extract(const char *out, const char *fname, | ||
const char *target) | ||
{ | ||
const int fd = xopen(fname, O_RDONLY, 0755); | ||
FATELF_header *header = xread_fatelf_header(fname, fd); | ||
const int recidx = xfind_fatelf_record(header, target); | ||
const int outfd = xopen(out, O_WRONLY | O_CREAT | O_TRUNC, 0755); | ||
const FATELF_record *rec = &header->records[recidx]; | ||
|
||
unlink_on_xfail = out; | ||
|
||
xcopyfile_range(fname, fd, out, outfd, rec->offset, rec->size); | ||
xclose(out, outfd); | ||
xclose(fname, fd); | ||
free(header); | ||
|
||
unlink_on_xfail = NULL; | ||
|
||
return 0; // success. | ||
} // fatelf_extract | ||
|
||
|
||
int main(int argc, const char **argv) | ||
{ | ||
xfatelf_init(argc, argv); | ||
if (argc != 4) // this could stand to use getopt(), later. | ||
xfail("USAGE: %s <out> <in> <target>", argv[0]); | ||
return fatelf_extract(argv[1], argv[2], argv[3]); | ||
} // main | ||
|
||
// end of fatelf-extract.c ... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters