weggli-rs / weggli

weggli is a fast and robust semantic search tool for C and C++ codebases. It is designed to help security researchers identify interesting functionality in large codebases.
Apache License 2.0
2.32k stars 127 forks source link

Cannot find the switch, case, To<> pattern #73

Closed YizhuoZhai closed 1 year ago

YizhuoZhai commented 1 year ago

Hi: I'm using the weggli to find the code pattern, but it returns nothing. I wonder if you have any hints for me to solve this problem. The pattern I want to find is :

switch(A) {
  case AA: {
       B = To<C>(D);
  }
}

An example from Chromiun is :

  switch (basic_shape->GetType()) {
    case BasicShape::kBasicShapeCircleType: {
      const BasicShapeCircle* circle = To<BasicShapeCircle>(basic_shape);
      ...
      break;
    }
...
}

The command I use is:

weggli '{
   switch(_) {
    $x=To<_>(_);
   }
}' /path/to/code/

I appreciate any help you can give.

felixwilhelm commented 1 year ago

Hi,

sorry for the slow response. This should work if you use the -X / --cpp flag to enable C++ mode.


weggli % weggli -X '{    
   switch(_) {
        $x=$f<_>(_);
   }
}' /tmp/test.cc
/tmp/test.cc:1
int test() {
switch(A) {
  case AA: {
       B = To<C>(D);
  }
}
}```