Skip to content

Commit d28fdef

Browse files
committed
[WARP] Update python example to fix adding a source to a "read-only" container
1 parent 27dbc3f commit d28fdef

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

plugins/warp/api/python/warp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,13 @@ def all() -> List['WarpContainer']:
350350
warpcore.BNWARPFreeContainerList(containers, count.value)
351351
return result
352352

353+
@staticmethod
354+
def by_name(name: str) -> Optional['WarpContainer']:
355+
for container in WarpContainer:
356+
if container.name == name:
357+
return container
358+
return None
359+
353360
@property
354361
def name(self) -> str:
355362
return warpcore.BNWARPContainerGetName(self.handle)

plugins/warp/examples/create_signatures.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ def process_binary(input_file: str, output_dir: str) -> None:
1414
if not bv:
1515
return
1616

17-
# Sources exist only in containers, so we will just pull off the first available container.
18-
# In the future we might make container construction available to the API.
19-
container = WarpContainer.all()[0]
17+
# For the sake of this example we are going to assume the container "User"
18+
# is available, in the future we might want to make containers constructable
19+
container = WarpContainer.by_name("User")
2020
output_file = output_dir / f"{input_path.stem}_analysis.warp"
2121
# Add the source so we can add functions to it and then commit it (write to disk)
2222
source = container.add_source(str(output_file))
23+
if source is None:
24+
print(f"Failed to create source {str(output_file)}")
25+
return
2326

2427
# NOTE: You probably want to pull the platform from the function, but for this example it's fine.
2528
target = WarpTarget(bv.platform)
@@ -30,6 +33,7 @@ def process_binary(input_file: str, output_dir: str) -> None:
3033
# Actually write the warp file to disk.
3134
container.commit_source(source)
3235
bv.file.close()
36+
print(f"committed {len(functions_to_warp)} functions to {output_file}")
3337

3438
if __name__ == "__main__":
3539
if len(sys.argv) != 3:

0 commit comments

Comments
 (0)