Skip to content

Commit 1fa4d36

Browse files
authored
Merge pull request #123 from lheckemann/multiple-args
Allow multiple filenames to patch
2 parents 48452cf + 936bae4 commit 1fa4d36

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/patchelf.cc

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static bool debugMode = false;
4545

4646
static bool forceRPath = false;
4747

48-
static std::string fileName;
48+
static std::vector<std::string> fileNames;
4949
static int pageSize = PAGESIZE;
5050

5151
typedef std::shared_ptr<std::vector<unsigned char>> FileContents;
@@ -1556,7 +1556,7 @@ static bool printNeeded = false;
15561556
static bool noDefaultLib = false;
15571557

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

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

1604-
debug("Kernel page size is %u bytes\n", getPageSize());
1605+
debug("Kernel page size is %u bytes\n", getPageSize());
16051606

1606-
auto fileContents = readFile(fileName);
1607+
auto fileContents = readFile(fileName);
16071608

1608-
if (getElfType(fileContents).is32Bit)
1609-
patchElf2(ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off, Elf32_Dyn, Elf32_Sym, Elf32_Verneed>(fileContents));
1610-
else
1611-
patchElf2(ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off, Elf64_Dyn, Elf64_Sym, Elf64_Verneed>(fileContents));
1609+
if (getElfType(fileContents).is32Bit)
1610+
patchElf2(ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off, Elf32_Dyn, Elf32_Sym, Elf32_Verneed>(fileContents), fileName);
1611+
else
1612+
patchElf2(ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off, Elf64_Dyn, Elf64_Sym, Elf64_Verneed>(fileContents), fileName);
1613+
}
16121614
}
16131615

16141616

@@ -1731,11 +1733,12 @@ int mainWrapped(int argc, char * * argv)
17311733
printf(PACKAGE_STRING "\n");
17321734
return 0;
17331735
}
1734-
else break;
1736+
else {
1737+
fileNames.push_back(arg);
1738+
}
17351739
}
17361740

1737-
if (i == argc) error("missing filename");
1738-
fileName = argv[i];
1741+
if (fileNames.empty()) error("missing filename");
17391742

17401743
patchElf();
17411744

0 commit comments

Comments
 (0)