Skip to content

Commit

Permalink
Merge pull request #123 from lheckemann/multiple-args
Browse files Browse the repository at this point in the history
Allow multiple filenames to patch
  • Loading branch information
edolstra committed Jan 29, 2018
2 parents 48452cf + 936bae4 commit 1fa4d36
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/patchelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static bool debugMode = false;

static bool forceRPath = false;

static std::string fileName;
static std::vector<std::string> fileNames;
static int pageSize = PAGESIZE;

typedef std::shared_ptr<std::vector<unsigned char>> FileContents;
Expand Down Expand Up @@ -1556,7 +1556,7 @@ static bool printNeeded = false;
static bool noDefaultLib = false;

template<class ElfFile>
static void patchElf2(ElfFile && elfFile)
static void patchElf2(ElfFile && elfFile, std::string fileName)
{
if (printInterpreter)
printf("%s\n", elfFile.getInterpreter().c_str());
Expand Down Expand Up @@ -1598,17 +1598,19 @@ static void patchElf2(ElfFile && elfFile)

static void patchElf()
{
if (!printInterpreter && !printRPath && !printSoname && !printNeeded)
debug("patching ELF file '%s'\n", fileName.c_str());
for (auto fileName : fileNames) {
if (!printInterpreter && !printRPath && !printSoname && !printNeeded)
debug("patching ELF file '%s'\n", fileName.c_str());

debug("Kernel page size is %u bytes\n", getPageSize());
debug("Kernel page size is %u bytes\n", getPageSize());

auto fileContents = readFile(fileName);
auto fileContents = readFile(fileName);

if (getElfType(fileContents).is32Bit)
patchElf2(ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off, Elf32_Dyn, Elf32_Sym, Elf32_Verneed>(fileContents));
else
patchElf2(ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off, Elf64_Dyn, Elf64_Sym, Elf64_Verneed>(fileContents));
if (getElfType(fileContents).is32Bit)
patchElf2(ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off, Elf32_Dyn, Elf32_Sym, Elf32_Verneed>(fileContents), fileName);
else
patchElf2(ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off, Elf64_Dyn, Elf64_Sym, Elf64_Verneed>(fileContents), fileName);
}
}


Expand Down Expand Up @@ -1731,11 +1733,12 @@ int mainWrapped(int argc, char * * argv)
printf(PACKAGE_STRING "\n");
return 0;
}
else break;
else {
fileNames.push_back(arg);
}
}

if (i == argc) error("missing filename");
fileName = argv[i];
if (fileNames.empty()) error("missing filename");

patchElf();

Expand Down

0 comments on commit 1fa4d36

Please sign in to comment.