Skip to content

Commit

Permalink
Support auto create bss block.
Browse files Browse the repository at this point in the history
  • Loading branch information
dark-lbp committed Jan 21, 2020
1 parent 0b2175e commit c23378d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
10 changes: 7 additions & 3 deletions firmware_tools/ghidra/vxhunter_analysis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from vxhunter_core import *
from vxhunter_utility.function_analyzer import *
from vxhunter_utility.symbol import *
from vxhunter_utility.common import create_uninitialized_block
from ghidra.program.model.symbol import RefType, SourceType


Expand All @@ -27,9 +28,12 @@ def analyze_bss():
print("bss_end_address: {}".format(hex(bss_start_address + bss_length - 1)))
print("bss_length: {}".format(hex(bss_length)))
if not is_address_in_current_program(toAddr(bss_start_address)):
print("bss block not in current program, you should add it manually")
# TODO: automatic create bss block, after find out how createBlock function work.
# createBlock("bss", toAddr(bss_start_address), bss_length)
print("bss block not in current program, adding...")
if create_initialized_block(block_name=".bss", start_address=toAddr(bss_start_address),
length=bss_length):
print("bss block created")
else:
print("Can't create bss block, you can create it manually")

else:
print("Can't find bzero function in firmware")
Expand Down
27 changes: 26 additions & 1 deletion firmware_tools/ghidra/vxhunter_utility/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# coding=utf-8
from ghidra.app.util.demangler import DemangledException
from ghidra.app.util.demangler.gnu import GnuDemangler
from ghidra.program.model.mem import *
from ghidra.program.model.mem import Memory
from ghidra.util.task import TaskMonitor
import struct
import logging
import time
Expand Down Expand Up @@ -106,3 +107,27 @@ def demangle_function(demangle_string):
# get function return
function_return = demangle_string[:function_name_start]
return function_return, function_name, function_parameters


def create_uninitialized_block(block_name, start_address, length, overlay=False):
# createUninitializedBlock

try:
memory = currentProgram.memory
memory.createUninitializedBlock(block_name, start_address, length, overlay)
return True

except:
return False


def create_initialized_block(block_name, start_address, length, fill=0x00, monitor=TaskMonitor.DUMMY, overlay=False):
# createUninitializedBlock

try:
memory = currentProgram.memory
memory.createInitializedBlock(block_name, start_address, length, fill, monitor, overlay)
return True

except:
return False

0 comments on commit c23378d

Please sign in to comment.