Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cwe_checker
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
cwe_checker
Commits
6313165c
Commit
6313165c
authored
Nov 03, 2020
by
Melvin Klimke
Committed by
Enkelmann
Nov 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Indirect call flows (#96)
parent
514be103
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
7 deletions
+26
-7
PcodeExtractor.java
ghidra/p_code_extractor/PcodeExtractor.java
+26
-7
No files found.
ghidra/p_code_extractor/PcodeExtractor.java
View file @
6313165c
...
...
@@ -56,6 +56,7 @@ public class PcodeExtractor extends GhidraScript {
Term
<
Program
>
program
=
null
;
FunctionManager
funcMan
;
HashMap
<
String
,
Integer
>
functionEntryPoints
;
ghidra
.
program
.
model
.
listing
.
Program
ghidraProgram
;
VarnodeContext
context
;
String
cpuArch
;
...
...
@@ -79,6 +80,8 @@ public class PcodeExtractor extends GhidraScript {
cpuArch
=
getCpuArchitecture
();
program
=
createProgramTerm
();
functionEntryPoints
=
new
HashMap
<
String
,
Integer
>();
setFunctionEntryPoints
();
Project
project
=
createProject
();
program
=
iterateFunctions
(
simpleBM
,
listing
);
...
...
@@ -91,6 +94,24 @@ public class PcodeExtractor extends GhidraScript {
/**
* Adds all entry points of internal and external function to a global hash map
* This will later speed up the cast of indirect Calls.
*/
protected
void
setFunctionEntryPoints
()
{
// Add external symbols and internal function addresses to hash map
int
funcCounter
=
0
;
for
(
ExternSymbol
sym
:
program
.
getTerm
().
getExternSymbols
()){
functionEntryPoints
.
put
(
sym
.
getAddress
(),
funcCounter
);
funcCounter
++;
}
for
(
Function
func
:
funcMan
.
getFunctionsNoStubs
(
true
))
{
functionEntryPoints
.
put
(
func
.
getEntryPoint
().
toString
(),
funcCounter
);
funcCounter
++;
}
}
/**
*
* @return: CPU architecture as string.
*
...
...
@@ -998,13 +1019,11 @@ public class PcodeExtractor extends GhidraScript {
* Resolves the target id for an indirect jump
*/
protected
Tid
getTargetTid
(
Varnode
target
)
{
if
(!
target
.
isRegister
()
&&
!
target
.
isUnique
())
{
Reference
[]
referenced
=
ghidraProgram
.
getReferenceManager
().
getReferencesFrom
(
target
.
getAddress
());
if
(
referenced
.
length
!=
0
)
{
for
(
ExternSymbol
symbol
:
program
.
getTerm
().
getExternSymbols
())
{
if
(
symbol
.
getAddress
().
equals
(
referenced
[
0
].
getToAddress
().
toString
()))
{
return
symbol
.
getTid
();
}
Address
[]
flowDestinations
=
PcodeBlockData
.
instruction
.
getFlows
();
if
(
flowDestinations
.
length
==
1
)
{
for
(
Address
flow
:
flowDestinations
)
{
if
(
functionEntryPoints
.
containsKey
(
flow
.
toString
())){
return
new
Tid
(
String
.
format
(
"sub_%s"
,
flow
.
toString
()),
flow
.
toString
());
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment