Pass argument of struct type to call_state()
See original GitHub issueHi, I want to make a calling state with an argument of struct type by calling proj.factory.call_state
, but angr
seems to replace the argument with the address of the argument before the calling. Here is the code:
typedef struct _A {
int a;
char b;
short c;
void* d;
int e;
} A;
void func(A a) {
// ...
}
I want to pass an argument with values (a=10, b=11, c=12, d=0x66666666, e=13)
to func
. And the following code I used didn’t work as I expected:
import angr
# loading binary
proj = angr.Project('bins/exe', load_options={
'auto_load_libs': False,
'main_opts': {
'base_addr': 0
}
})
# getting rebased address of func
func_addr = proj.loader.find_symbol('func').rebased_addr
# function definition
ty = angr.types.parse_defns('void foo(struct a {int a; char b; short c; void* d; int e; } x);')['foo']
cc = proj.factory.cc(ty=ty)
s = proj.factory.call_state(func_addr, (10, 11, 12, 0x66666666, 13), cc=cc, ret_addr=0x12345678)
and when I call s.stack_read
, I got following data:
s.regs.esp # 0x7ffeffe9
s.stack_read(0, 4) # 0x12345678 ret_addr
s.stack_read(4, 4) # 0x7ffefff1 the address of struct argument
s.stack_read(8, 4) # 10 a.a
s.stack_read(12, 4) # 11 a.b
but when I compile the source code with gcc 7.5.0
on 'unbuntu 18.04 x86, and I make a
breakpointin
func` to inspect the stack, then I got this
with nothing between ret_addr
and the start of argument a
.
There must be some mistakes I made while calling proj.factory.call_state
, but I can’t figure out.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Passing struct to function
This is how to pass the struct by reference. This means that your function can access the struct outside of the function and...
Read more >Documentation: 15: 38.10. C-Language Functions
It has three arguments: the argument of type HeapTupleHeader passed into the function, the name of the desired attribute, and a return parameter...
Read more >Method Parameters - C# Reference
In C#, arguments can be passed to parameters either by value or by reference. Remember that C# types can be either reference types...
Read more >Using the State Hook
If you write a function component and realize you need to add some state to it, ... The only argument to the useState()...
Read more >C Struct and Functions
Here, a struct variable s1 of type struct student is created. The variable is passed to the display() function using display(s1); statement. Return...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
this has finally been resolved! see #2961. You may now use a dict (or a tuple, or a SimStructValue) to pass structs by value, provided you follow the new guidelines for providing function prototypes to call_state.
Well, I found that
angr
do the same to arguments with typelong long
, it convertslong long
to pointers tolong long
as well, while it can handledouble
correctly, confusing.Source code:
Python with
angr
: