Highlighted
Super Contributor.
Super Contributor.
329 views

Convert HEX string to ASCII in logger report

Jump to solution

Hi 

I have some audit events where the commands are in HEX format. I think that I can use Formula Fields to convert the HEX string, but I do not know how to do it. 

eg. 7073202D6566 --> "ps -ef"
6D6B6469722074657374 --> "mkdir test"

Anyone have an idea? 

 

Labels (1)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Super Contributor.
Super Contributor.

Hi Marius 

now its working, still needs some working to make sure that it actually a HEX string and not just a normal string. 

var hex = Command_executed.toString();
var str  = ' ';
var len = hex.length();

if (len > 3) {
  for (var n = 0; (n < len); n += 2) 
     str += String.fromCharCode(parseInt(hex.substr(n, 2), 16));
} else {
  str = Command_executed;
}
command = str;

 

View solution in original post

0 Likes
4 Replies
Highlighted
Super Contributor.
Super Contributor.

I have found some that should work, but it doesn't ... yet 

var hex = Command_executed.toString();
var str = '';
  for (var n = 0; n < hex.length; n += 2) {
  str += String.fromCharCode(parseInt(hex.substr(n, 2), 16));
  }
command = str;

It returns an empty result. 

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Never worked with Formulas, but in development the function has to return something if you want it to work.

Since str now belongs inside the "str" function, when you run it outside the scope without returning anything then it wont work.

-----------------------------------------------------------------------------------------
All topics and replies made is based on my personal opinion, viewpoint and experience, it does not represent the viewpoints of MicroFocus.
All replies is based on best effort, and can not be taken as official support replies.
//Marius
0 Likes
Highlighted
Super Contributor.
Super Contributor.

Hi Marius 

now its working, still needs some working to make sure that it actually a HEX string and not just a normal string. 

var hex = Command_executed.toString();
var str  = ' ';
var len = hex.length();

if (len > 3) {
  for (var n = 0; (n < len); n += 2) 
     str += String.fromCharCode(parseInt(hex.substr(n, 2), 16));
} else {
  str = Command_executed;
}
command = str;

 

View solution in original post

0 Likes
Highlighted
Super Contributor.
Super Contributor.

now with string validation 

 

var hex = Command_executed.toString();
var str  = ' ';
var len = hex.length();
var re = /[0-9A-Fa-f]/g;

if (re.test(hex)) 
  {
    for (var n = 0; (n < len); n += 2) 
       str += String.fromCharCode(parseInt(hex.substr(n, 2), 16));
  } else {
    str = Command_executed.toString();
  }
   
command = str;
re.lastIndex = 0;
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.