Find Hidden Miners in Go (Hidden windows + commandlines) - go

I found this C# and I want to improve on it in Go: https://github.com/roachadam/MinerKiller/blob/master/MinerKiller/MinerKiller.cs
My first question, is how do I detect if a process window is hidden. ie this code:
if (p.MainWindowHandle == IntPtr.Zero )
My Second question is how to get the command line of a process. ie this C# code
private string GetCommandLine(Process process)
{
string cmdLine = null;
using (var searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id))
{
var matchEnum = searcher.Get().GetEnumerator();
if (matchEnum.MoveNext())
{
cmdLine = matchEnum.Current["CommandLine"]?.ToString();
}
}
return cmdLine;
}

While the go standard library's os package provides a lot of nice utilities for interfacing with operating system functionality, they are much "lower level" then what you are referencing from the .NET System.Management classes. You will most likely have to implement the behavior of these classes yourself to achieve the desired outcome (using the tool from Go's os package as your primary "building blocks")
That said, there is a psutil port in Go (gopsutil - https://github.com/shirou/gopsutil/) that provides utilities for retrieving info on running processes as well as system utilization. This will most likely provide the higher level abstraction you can use to implement your program.
If gopsutil is too opinionated or high level for you needs, I would also check out the operating system specific packages in the golang subrepositories.
Documented here: https://godoc.org/golang.org/x/sys
Source here: https://github.com/golang/sys/

Related

boost interprocess file_lock understanding/usage

I have been having issues using an anonymous mutex (boost::interprocess::interprocess_mutex) in a boost::interprocess::managed_shared_memory instance. Namely, issues arise if the software crashes; the mutex may remain locked (depending on its state at time of crash). It can make debugging interesting too :).
My understanding is that I can substitute the interprocess_mutex with boost::interprocess::file_lock (FL). #DaveF posted some questions that I would like to build upon. I'd like to have a good understanding what I'm getting myself into before I put FL into use.
Can I use an anonymous boost::interprocess::condition_variable (CV) with FL? Having looked through the code, it appears that it will work.
In using a CV, am I opening myself up to the same problems I have experienced when using mutex (ie. if the application unexpectedly ends without proper cleanup/finalisation)?
What is the best way to create a FL. I've thought about something similar to the following...
Note code may not compile:
namespace bi = boost::interprocess;
namespace bf = boost::filesystem;
const std::string strSharedMemName = std::string("cp_shdmem_") + std::to_string(nIdx);
const std::string strNamedMutexName = strSharedMemName + "_mtx";
// I'm working on Linux, but would like to Boost to create a temporary file path.
const bf::path pathTmpFile =
bf::temp_directory_path() / (strNamedMutexName + ".txt");
{
// 1. So can I just create the file? What happens if it exists? Boost docs say this
// about the file_lock constructor:
// "Throws interprocess_exception if the file does not exist
// or there are no operating system resources."
// 2. What happens if file already exists?
bf::ofstream f(pathTmpFile);
}
// Create.
bi::file_lock lockFile(pathTmpFile.string().c_str());
// Lock.
bi::scoped_lock<bi::file_lock> lockNamed(lockFile);
Platform specifics:
Ubuntu 17.10
Boost 1.63
GCC 7.2

How to export a GMF diagram outside eclipse?

One of the features of Papyrus that I find really useful is the ability to programmatically interrogate the UML models that it creates by using the UML2 runtime outside the Eclipse UI. This is great for running simple tools to, e.g., produce documentation using POI or write model driven configuration for the Talend MDM tool. However, while traversing and processing the model tree is easily achieved by loading up the resources in a resource set, manipulating the diagrams in the .notation files has proven to be more of a challenge.
I have got to the point (by examining the source for org.eclipse.papyrus.infra.export.ExportAllDiagrams) where I can load all the resources and find the Diagram elements from the .notation file thus:
File uml = new File(model + ".uml");
File di = new File(model + ".di");
File notation = new File(model + ".notation");
URI umlUri = URI.createFileURI(uml.getAbsolutePath());
URI diUri = URI.createFileURI(di.getAbsolutePath());
URI notationUri = URI.createFileURI(notation.getAbsolutePath());
final ModelSet resourceSet = new ModelSet();
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
resourceSet.getPackageRegistry().put(NotationPackage.eNS_URI, NotationPackage.eINSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("notation", new XMIResourceFactoryImpl());
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
try {
resourceSet.getLoadOptions().put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true);
resourceSet.getLoadOptions().put(XMLResource.OPTION_DEFER_ATTACHMENT, true);
resourceSet.getResource(diUri, true);
resourceSet.getResource(umlUri, true);
resourceSet.getResource(notationUri, true);
List<Diagram> diagrams = new ArrayList<Diagram>();
for (Iterator<Notifier> i = resourceSet.getAllContents(); i.hasNext();) {
Notifier n = i.next();
if (n instanceof Diagram) {
diagrams.add((Diagram) n);
}
}
//export(diagrams);
} finally {
// Unload the resource set so that we don't leak loads of UML content in the CacheAdapter
unload(resourceSet);
}
However, the ExportAllDiagrams class ultimately uses org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUtil to render the diagram, at which point it fails because it relies on the DiagramUIRenderPlugin and DiagramUIRenderPlugin.getInstance() returns null.
I then had a look at org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramSVGGenerator but had similar problems with the need for various eclipse plugins to be initialised.
I have no experience of the Eclipse plugin system but I am assuming that that the platform loads and initialises plugins and, therefore, the approaches tried so far need to be running within Eclipse GUI environment in order to work. Is there any other method that could be used to easily render the diagrams to SVG without relying on the whole of the Eclipse runtime?

Motorola MC65 - EMDK .NET 2.6 - E_SCN_READTIMEOUT using ScanWait()

I'm looking to integrate the Barcode2 class in the EDMK 2.6 library into our existing Barcode scanning interface.
I've wired the example code up to our interface method StartScan() and always get E_SCN_READTIMEOUT as the result even though the code seems to be responding to the scan. (the breakpoint at if (scan.Result == Results.SUCCESS) is hit in response to the scan
public void StartScan()
{
if (!barcode.IsScanPending)
{
ScanData scan = barcode.ScanWait(2000); // 2 second timeout
if (scan.Result == Results.SUCCESS)
{
if (scan.IsText)
{
textbox1.Text = scan.Text;
}
}
}
}
The result is always E_SCN_READTIMEOUT, I suspect this may be a conflict with DataWedge 3.4 running on the device, but the functionality of the scanner and triggers seem to be dependent on it.
Getting barcode scans to the clipboard using DataWedge is not an option for us, is there a way to get the library to function despite DataWedge(assuming that is causing the read timeouts)?
The DataWedge application did need to be disabled, (this can be done programmatically via the datawedge API from Motorola, Thanks Abdel for the hint here!).
https://docs.symbol.com/ReleaseNotes/Release%20Notes%20-%20DataWedge_3.3.htm
A little background on our Windows Mobile application for reference, we have a hardware singleton that contains interfaces for all hardware components and loads related types and assemblies via reflection. If we referenced types directly the code above worked.
The end solution ended up being to use the Symbol.Barcode library instead of Symbol.Barcode2.

Perl for Windows GUI

I searched the internet before coming here. I guess everyone's needs are different. I want a Windows GUI program that will get information from database and show it in grid and have a delete button next to each record. I also want it to have a link, for example if the id number of the record is clicked, it opens new browser and navigates to a page associated with it, and completes forms then submits by itself.
The question is: Since there are many modules out there, which one is the best for this?
(Perl Nubie)
Nobody can truly say what is BEST, but the option of the Tk module with a backend of, in your case, DBD::MySQL, is maybe the most "standard" for things like this in Perl. Examples for both can be found all around online.
Here are some for SQL with mySQL and DBD :
http://sql-info.de/mysql/examples/Perl-DBI-examples.html
Here is a good document of examples for perl TK:
http://www.ibm.com/developerworks/aix/library/au-perltkmodule/index.html
As far as opening a browser - a simple system command will do:
my #command = ('start', $url);
system(#command);
^That is for Windows. It looks like you have a decently large application you want to build - opening a browser is just a small part of it - you will want to execute the above when a button is pressed, no doubt.
The last part...submitting data to forms on the web, is a topic called "web crawling"... WWW::Mechanize is a library to look into - Google "perl web crawler" and you are bound to get more good examples.
I found this with a little searching - it looks to be of use to you:
http://www.stratos.me/2009/05/writing-a-simple-web-crawler-in-perl/
Give one (nasty) precondition, ca. 25 lines of HTML
<html>
<head>
<hta:application id="demo" scroll="No"></hta>
<title>Demo</title>
<script language = "PerlScript"
src = "demo.pl"
type = "text/perlscript"
></script>
</head>
<body onload="DoOnLoad()" onunload="DoOnUnLoad()">
<object classid = "clsid:67397AA3-7FB1-11D0-B148-00A0C922E820"
id = "id_oDC"
style = "position:relative;width:1px;height:1px"
></object>
<object classid = "clsid:CDE57A43-8B86-11D0-B3C6-00A0C90AEA82"
id = "id_oDG"
style = "position:relative;width:100%;height:95%"
></object>
</body>
</html>
and ca. 40 lines of Perl:
use strict;
use warnings;
use Win32::OLE qw( in );
use Win32::OLE::Const 'Microsoft ActiveX Data Objects';
use vars qw( $window );
my $oAdoDC;
my $oAdoDG;
sub DoOnLoad {
my $owda = $window->document->all;
$oAdoDC = $owda->id_oDC;
$oAdoDC->{ConnectionString} = 'DSN=SakilaGent';
$oAdoDG = $owda->id_oDG;
$oAdoDC->{CursorType} = adOpenKeyset;
$oAdoDG->Font->{Name} = "Arial";
$oAdoDG->Font->{Size} = "8";
$oAdoDG->HeadFont->{Name} = "Arial";
$oAdoDG->HeadFont->{Size} = "8";
$oAdoDC->{RecordSource} = "select * from customer";
$oAdoDG->{Caption} = $oAdoDC->{RecordSource};
$oAdoDC->Refresh();
$oAdoDG->{DataSource} = $oAdoDC;
}
sub DoOnUnLoad {
$oAdoDG->{ DataSource }->Close();
$oAdoDC->{ Recordset }->Close();
$oAdoDG = undef;
$oAdoDC = undef;
}
will give you a flexible 'display/edit every recordset from every database accessible by ADO' type of data grid:
at no costs. A person familiar with HTML (but not Tk or Wx) and ADO/Access/Excel (but not DBI) could build a nice Database GUI easily/effiently. The precondition (i.e. drawback) is: Even the deployment computers need to have the "Microsoft DataGrid Control 6.0 (OLEDB)" (there are a plain tabular, a hierarchical, and a flexible hierarchical grid control too; maybe more modern controls can be used also) installed in a development/design-time enabled mode.
I would suggest using:
Wx for the user interface (provides a more modern/native look than Tk; see also the main site wxWidgets)
DBD::SQLite for local database storage
WWW::Mechanize - submitting forms
Since you're using Windows, your best bet would be to install Strawberry Perl which includes SQLite and Mechanize. Installing Wx or Tk is an extra step, but you should be able to find tutorials on the web from others who have done so. You may also want to look at Padre, the Perl IDE which is a Perl editor / development environment (it also happens to use Wx).

How to run "ipconfig" and get the output in adobe AIR in windows?

import flash.desktop.NativeProcess;
import flash.desktop.NativeProcessStartupInfo;
if (NativeProcess.isSupported) {
var npsi:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var processpath:File = File.applicationDirectory.resolvePath("MyApplication.whatever");
var process:NativeProcess = new NativeProcess();
npsi.executable = processpath;
process.start(npsi);
}
The above can only run a sub-application, but how to run an independent application(command) like ipconfig and get the result?
You in fact can scrape STDOUT and STDERR:
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onError);
process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);
public function onError(event:ProgressEvent):void
{
trace(event);
trace(process.standardError.readUTFBytes(process.standardError.bytesAvailable));
}
public function inputProgressListener(event:ProgressEvent):void
{
process.closeInput();
}
public function onOutputData(event:ProgressEvent):void
{
trace(event);
trace(process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable));
}
More info at: http://help.adobe.com/en_US/as3/dev/WSb2ba3b1aad8a27b060d22f991220f00ad8a-8000.html
And: http://www.as3offcuts.com/2010/08/air-2-native-process-example-mouse-screen-position/
Edit: realised maybe your question is also how to launch an external application? Here's an example how to run 'top' in OSX:
npsi.executable = new File("/usr/bin/top");
If you need network configuration information, you could use NetworkInfo.networkInfo.findInterfaces(). Will save you the trouble of interacting with another process and it's also portable.
http://help.adobe.com/en_US/air/reference/html/flash/net/NetworkInfo.html
If you want to run ipconfig.exe without knowing where it is located, you can run cmd.exe with arguments "/C" "ipconfig.exe ...". Of course, this requires to know where is cmd.exe. I had just included it with my AIR app (windows version).
I don't think you can, it's a self-impossed limitation of the NativeProcess API. However, you can create a little Windows binary yourself that calls ipconfig and passes the information back to the AIR app.
If creating that binary seems like a big deal, take a look to Haxe and xCross, you can get it done with a fairly similar language to ActionScript.

Resources