Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Bobowski committed Jun 14, 2023
1 parent 731dd57 commit 96e5709
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 45 deletions.
42 changes: 20 additions & 22 deletions cakefuzzer/instrumentation/override.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import asyncio
from dataclasses import dataclass
from pathlib import Path

from pydantic import BaseModel

from cakefuzzer.instrumentation.remove_annotations import install_php_parser
from cakefuzzer.instrumentation.remove_annotations import (
install_php_parser,
php_parser_semaphore,
)
from cakefuzzer.instrumentation import InstrumentationError



class FunctionCallRenameInstrumentation(BaseModel):
path: Path
rename_from: str
Expand All @@ -20,27 +21,24 @@ async def is_applied(self) -> bool:
return False

async def apply(self) -> None:

await install_php_parser()

command = [
"php",
"cakefuzzer/phpfiles/instrumentation/rename_function_call.php",
str(self.path),
self.rename_from,
self.rename_to,
]

proc = await asyncio.create_subprocess_exec(*command)
await proc.wait()
if proc.returncode != 0:
print(proc.returncode)
print("err", proc.stderr)
print("out", proc.stdout)
raise InstrumentationError(
error="Error while instrumenting, got non-zero response from subprocess",
hint=" ".join(command),
)
async with php_parser_semaphore:
command = [
"php",
"cakefuzzer/phpfiles/instrumentation/rename_function_call.php",
str(self.path),
self.rename_from,
self.rename_to,
]

proc = await asyncio.create_subprocess_exec(*command)
await proc.wait()
if proc.returncode != 0:
raise InstrumentationError(
error="Error while instrumenting, got non-zero response from subprocess",
hint=" ".join(command),
)

async def revert(self) -> None:
for backup_file in self.path.rglob("*.prerename"):
Expand Down
54 changes: 31 additions & 23 deletions cakefuzzer/instrumentation/remove_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@
from cakefuzzer.instrumentation import InstrumentationError


php_parser_semaphore = asyncio.Semaphore(1)


async def install_php_parser() -> None:
if Path("php-parser").exists():
return

command = ["bash", "cakefuzzer/phpfiles/instrumentation/install_php_parser.sh"]
# We only want to install php-parser once so we use a semaphore to make sure
# that only one process can install it at a time
async with php_parser_semaphore:
if Path("php-parser").exists():
return

proc = await asyncio.create_subprocess_exec(*command)
await proc.wait()
if proc.returncode != 0:
raise InstrumentationError(
error="Error while installing php-parser, got non-zero response from subprocess",
hint=" ".join(command),
)
command = ["bash", "cakefuzzer/phpfiles/instrumentation/install_php_parser.sh"]

proc = await asyncio.create_subprocess_exec(*command)
await proc.wait()
if proc.returncode != 0:
raise InstrumentationError(
error="Error while installing php-parser, got non-zero response from subprocess",
hint=" ".join(command),
)

class RemoveAnnotationsInstrumentation(BaseModel):
path: Path
Expand All @@ -32,19 +39,20 @@ async def apply(self) -> None:

await install_php_parser()

command = [
"php",
"cakefuzzer/phpfiles/instrumentation/remove_annotations.php",
str(self.path),
]

proc = await asyncio.create_subprocess_exec(*command)
await proc.wait()
if proc.returncode != 0:
raise InstrumentationError(
error="Error while instrumenting, got non-zero response from subprocess",
hint=" ".join(command),
)
async with php_parser_semaphore:
command = [
"php",
"cakefuzzer/phpfiles/instrumentation/remove_annotations.php",
str(self.path),
]

proc = await asyncio.create_subprocess_exec(*command)
await proc.wait()
if proc.returncode != 0:
raise InstrumentationError(
error="Error while instrumenting, got non-zero response from subprocess",
hint=" ".join(command),
)

async def revert(self) -> None:
for backup_file in self.path.rglob("*.preannotation"):
Expand Down

0 comments on commit 96e5709

Please sign in to comment.