Page 1 of 3

Bitness Column

Posted: 27 Aug 2020 13:15
by admin
The new get("bitness") function can easily make a nice column:
ColumnBitness.png
Configuration in Configuration | Information | Custom Columns:
ColumnBitnessConf.png

Code: Select all

$bits = get("bitness", <cc_item>);
if ($bits == 32) {
  return "32-bit";
} elseif ($bits == 64) {
  return "64-bit";
} else {
  return "unknown";
}

Re: Bitness Column

Posted: 28 Aug 2020 16:42
by admin
Changes in next beta:

Code: Select all

    * SC get("bitness"): Changed the return from numbers to a full string (not 
      translated by MSL so you know what to expect), and added 2 new cases so we 
      have 5 possible returns now:
        "16-bit"
        "32-bit"
        "64-bit"
        "64-bit Itanium"
        "(unknown)"
      Tip: In a Custom Column you can use this line in the Script field:
        return get("bitness", <cc_item>);
      Note that there is quite a number of file types that can have the 
      PE-format, not just EXE and DLL, for example: acm, ax, com, cpl, dat, dll, 
      drv, exe, iec, lrc, ocx, rll, rs, scr, tlb, tsp.

Re: Bitness Column

Posted: 01 Jun 2021 21:37
by sl23
I've tried to adapt your code to show only 32, 64 or ? instead of 32-bit, 64-bit and unknown, but it doen't work.
Could I please get some help. I have searched the help file but don't really now what I'm looking for!
Thanks

Code: Select all

$bits = get("bitness", <cc_item>);
if ($bits == 32) {
  return "32";
} elseif ($bits == 64) {
  return "64";
} else {
  return "?";
}

Re: Bitness Column

Posted: 01 Jun 2021 22:07
by highend
get("bitness") returns a string instead of a number and your comparison does what?...

Re: Bitness Column

Posted: 01 Jun 2021 22:10
by sl23
Thanks for your reply highend...
No worries, solved it:

Code: Select all

get("bitness", <cc_item>);
if ("bitness", <cc_item> == 32) {
  return "32";
} elseif ("bitness", <cc_item> == 64) {
  return "64";
} else {
  return "?";
}

Re: Bitness Column

Posted: 01 Jun 2021 22:19
by highend
No, you did not or aren't you recognizing that all files are now 32-bit, regardless if they are 64-bit ones?

Re: Bitness Column

Posted: 01 Jun 2021 22:22
by sl23
Damn! ok. Would you please provide a non cryptic tip?

Re: Bitness Column

Posted: 01 Jun 2021 22:28
by sl23
highend wrote: 01 Jun 2021 22:07 get("bitness") returns a string instead of a number and your comparison does what?...
But I already tried this:

Code: Select all

if ("bitness", <cc_item> == 32-bit) {
  return "32";
but I just get ? for everything!!!

Can you help please highend?

Re: Bitness Column

Posted: 02 Jun 2021 00:24
by notabot
I think you overlooked this post:
admin wrote: 28 Aug 2020 16:42

Code: Select all

* SC get("bitness"): Changed the return from numbers to a full string (not 
      translated by MSL so you know what to expect), and added 2 new cases so we 
      have 5 possible returns now:
        "16-bit"
        "32-bit"
        "64-bit"
        "64-bit Itanium"
        "(unknown)"
      Tip: In a Custom Column you can use this line in the Script field:
        return get("bitness", <cc_item>);
So get("bitness") no longer returns a number (64) , but a textstring ("64-bit").
Taht makes comparisons different.
Compare variable with a number: if ($variable == 123)
Compare variable with text: if ($variable == "some text")

If you only want to see 32-bit and 64-bit in the cusom column (so no 16-bit, 64-bit Itanium), you can use the following:

Code: Select all

$bits = get("bitness", <cc_item>);
if ($bits == "32-bit") {
  return "32-bit";
} elseif ($bits == "64-bit") {
  return "64-bit";
} else {
  return "unknown";
}
Same results, but less typing:

Code: Select all

$bits = get("bitness", <cc_item>);
if ($bits == "32-bit" OR $bits == "64-bit") {
  return $bits;
} else {
  return "unknown";
}


If you want to see all possible bitnesses (??):

Code: Select all

$bits = get("bitness", <cc_item>);
return $bits;

or even:

Code: Select all

return get("bitness", <cc_item>);

Re: Bitness Column

Posted: 02 Jun 2021 08:31
by sl23
Thanks very much for your help.

I didn't overlook it, I just didn't understand it! :kidding:

So does a string need to be enclosed in double quotes then?

What I'm actually after is to show just 32 or 6I or ?, not the original text. I sort of got there, just need a little adjusting maybe?

Thanks

Re: Bitness Column

Posted: 02 Jun 2021 09:15
by RalphM
You could try something along the lines of:

Code: Select all

$bits = get("bitness", <cc_item>);
if (left($bits, 2) = "32") {
  return "32";
} elseif (left($bits, 2) = "64") {
  return "64";
} else {
  return "?";
}

Re: Bitness Column

Posted: 02 Jun 2021 10:35
by highend
@RalphM

Without a user defined function for left?

Re: Bitness Column

Posted: 02 Jun 2021 10:49
by RalphM
Well, I would have expected that scripting command to exist.
On double check I was wrong, so instead one could use:

Code: Select all

substr($bits, 0, 2)
.

Re: Bitness Column

Posted: 02 Jun 2021 17:55
by sl23
Thank you for your help.

That doesn't work, unless I did it wrong?
Assume you meant this:

Code: Select all

$bits = get("bitness", <cc_item>);
if (substr($bits, 0, 2) = "32") {
  return "32";
} elseif (substr($bits, 0, 2) = "64") {
  return "64";
} else {
  return "?";
}

Re: Bitness Column

Posted: 02 Jun 2021 18:06
by highend
It doesn't work because it's NOT a comparison anymore...