1

So to cut straight to the chase - I'm lazy, IDA is mysterious, I need to use IDA arrays in my IDC code for convenience. Because IDC is like C(++) in its syntax I figured I could do:

auto lala[4] = {0,1,2,3};

But that doesn't work. Neither do round or square brackets. Trying to do lala[0] produces this output:

Cannot use [] operator on scalars

What gives?

1 Answer 1

2

IDC is closer to C than C++ but both limited in some ways and more flexible in others than C. It supports several variable types but arrays is not one of them:

A variable can contain:

  • LONG: a 32-bit signed long integer (64-bit in 64-bit version of IDA)
  • INT64: a 64-bit signed long integer
  • STR: a character string
  • FLOAT: a floating point number (extra precision, up to 25 decimal digits)
  • OBJECT: an object with attributes and methods (a concept very close to C++ class) more
  • REF: a reference to another variable
  • FUNC: a function reference

However, you can use slice syntax with objects to simulate arrays:

auto x = object();
x[0] = value1;
x[1] = "value2";
2
  • Thanks! I actually needed an easy way to initialise these arrays. Given a list of bytes, I wanted to be able to just put them inside braces et voila but I guess that isn't possible. I ended up using regex instead.
    – swaggg
    Mar 26 at 16:01
  • I looked up your profile. It's really cool you work for Hex Rays. Maybe you guys could implement arrays at some point too ;).
    – swaggg
    Mar 26 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.