Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix awk&typo #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tools/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ function perr(string $txt, $die = false)
/**
* @return int
*/
function getELFSectionAddr(string $elf, string $section)
function getELFSectionAddr(string $elf, string $section, int $pos)
{
$secAddr = exec(
sprintf('readelf -S \'%s\' | grep -E \'\s%s\s\' | awk \'{ print $5 }\'', $elf, str_replace('.', '\.', $section))
sprintf('readelf -S \'%1$s\' | grep -E \'\s%2$s\s\' | awk -F\'%2$s\' \'{ print $2 }\' | awk \'{ print $%3$d }\'', $elf, str_replace('.', '\.', $section), $pos)
);
if (!$secAddr) {
perr("$section section not found in $elf file\n", true);
Expand Down
6 changes: 3 additions & 3 deletions tools/patch-boot_params-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* - values of ORs are 1/2/4/8 respectively
* - [const-ptr] is always the same
*
* Usage: php patch-header-check.php vmlinux vmlinux-mod
* Usage: php patch-boot_params-check.php vmlinux vmlinux-mod
*/

require __DIR__ . '/common.php';
Expand All @@ -24,7 +24,7 @@
perr("\nGenerating patch for $file\n");

//The function will reside in init code part. We don't care we may potentially search beyond as we expect it to be found
$codeAddr = getELFSectionAddr($file, '.init.text');
$codeAddr = getELFSectionAddr($file, '.init.text', 3);

//Finding a function boundary is non-trivial really as patters can vary, we can have multiple exit points, and in CISC
// there are many things which may match e.g. "PUSH EBP". Implementing even a rough disassembler is pointless.
Expand Down Expand Up @@ -128,7 +128,7 @@

perr("Patching OR to AND @ file offset (dec)$seqFileOffset\n");
fseek($fp, $seqFileOffset);
fwrite($fp, "\x25"); //0x80 is OR, 0x25 is AND
fwrite($fp, "\x25"); //0x0d is OR, 0x25 is AND
}

if (!isset($argv[2])) {
Expand Down
4 changes: 2 additions & 2 deletions tools/patch-ramdisk-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
perr("\nGenerating patch for $file\n");

//Strings (e.g. error for printk()) reside in .rodata - start searching there to save time
$rodataAddr = getELFSectionAddr($file, '.rodata');
$rodataAddr = getELFSectionAddr($file, '.rodata', 2);

//Locate the precise location of "ramdisk error" string
$rdErrAddr = getELFStringLoc($file, '3ramdisk corrupt');
Expand All @@ -37,7 +37,7 @@
if ($printkPos === -1) {
perr("printk pos not found!\n", true);
}
perr("Found pritk arg @ " . decTo32bUFhex($printkPos) . "\n");
perr("Found printk arg @ " . decTo32bUFhex($printkPos) . "\n");

//double check if it's a MOV reg,VAL (where reg is EAX/ECX/EDX/EBX/ESP/EBP/ESI/EDI)
fseek($fp, $printkPos - 3);
Expand Down