keydet89 / RegRipper3.0

RegRipper3.0
Other
554 stars 123 forks source link

rip.pl doesn't find `plugins` on Linux/Unix when run from a different working directory #42

Closed janstarke closed 10 months ago

janstarke commented 3 years ago

I think the problem is that rip.pl ignores the $str variable in line 70 which is finally written in line 63: https://github.com/keydet89/RegRipper3.0/blob/d40efd1a18e3fa67d234cbbbe8d65db2c831fe74/rip.pl#L70

I suggest the following change:

diff --git a/Analysis/RegRipper3.0/rip.pl b/Analysis/RegRipper3.0/rip.pl
index 8f626a7..9027209 100644
--- a/Analysis/RegRipper3.0/rip.pl
+++ b/Analysis/RegRipper3.0/rip.pl
@@ -67,7 +67,7 @@ $str =~ s/($path[scalar(@path) - 1])//;
 # code updated 20190318
 my $plugindir;
 ($^O eq "MSWin32") ? ($plugindir = $str."plugins/")
-                   : ($plugindir = File::Spec->catfile("plugins"));
+                   : ($plugindir = File::Spec->catfile($str, "plugins"));
 #my $plugindir = $str."plugins/";
 #my $plugindir = File::Spec->catfile("plugins");
 #print "Plugins Dir = ".$plugindir."\n";

This work very well on my system. The final question is: do we assume to have plugins in the current folder or in the folder where rip.pl ist stored in? Both variants are fine, but I'd like to have the same behavior in Windows and non-Windows.

Kind regards (and thx for your work), Jan

Karneades commented 1 year ago

do we assume to have plugins in the current folder or in the folder where rip.pl ist stored in?

Late answer, but nevertheless I comment here. The plugin directory is in the same directory as rip.pl.

rip.pl doesn't find plugins on Linux/Unix when run from a different working directory

True, the plugindir is incomplete when running on Linux. The dir path is missing completely.

Error message for each plugin similar to this:

Error: Can't locate plugins/processor_architecture.pl in @INC [...]  at rip.pl line 103.

This comes from require $p;. Don't understand why the file is required there which is then looked up in @INC.

There are lines commented out below your code change which did the same as you do, adding the path to the pluginsdir.

While looking at the history, I found a now reverted PR for improving the path handling (https://github.com/keydet89/RegRipper3.0/pull/34). It improved the path handling but missed the plugin-directory and a required include, if I don't miss something.

I suggest to improve the path handling using the Cwd module and remove the obsolete code. I made these tests and they worked.

RegRipper$ perl rip.pl -l
OutsideOfRegRipper$ perl RegRipper3.0/rip.pl -l
OutsideOfRegRipper$ ln -s RegRipper3.0/rip.pl rip.pl
OutsideOfRegRipper$ perl rip.pl -l

@keydet89 Could you shortly comment on this and give some hints if the compiled Windows version gets a regression after these changes? I would propose a PR later if needed.

use File::Spec;
+use File::Basename;
 use Encode::Unicode;
 use JSON::PP;
+use Cwd;

 # Included to permit compiling via Perl2Exe
 #perl2exe_include "Parse/Win32Registry.pm";
@@ -60,21 +62,14 @@ GetOptions(\%config,qw(reg|r=s file|f=s csv|c dirty|d auto|a autoTLN|aT guess|g

 # Code updated 20090102
 my @path;
-my $str = $0;
-($^O eq "MSWin32") ? (@path = split(/\\/,$0))
-                   : (@path = split(/\//,$0));
-$str =~ s/($path[scalar(@path) - 1])//;
-
-# Suggested addition by Hal Pomeranz for compatibility with Linux
-#push(@INC,$str);
-# code updated 20190318
+
+my $scriptpath = Cwd::realpath($0);
+my $scriptdir = File::Basename::dirname($scriptpath);
+
 my $plugindir;
-($^O eq "MSWin32") ? ($plugindir = $str."plugins/")
-                   : ($plugindir = File::Spec->catfile("plugins"));
-#my $plugindir = $str."plugins/";
-#my $plugindir = File::Spec->catfile("plugins");
-#print "Plugins Dir = ".$plugindir."\n";
-# End code update
+($^O eq "MSWin32") ? ($plugindir = $scriptdir."plugins/")
+                   : ($plugindir = File::Spec->catfile($scriptdir,"plugins"));
bharathpofficial commented 10 months ago

Updated RegRipper might have patched this already.!! but for the old version that present on SIFT-WORKSTATION ubuntu.

adding this one line of code in the perl script (i.e rip.pl)

63 # Retrieves absolute path of parent directory 
64 my $scriptdir = File::Basename::dirname($scriptpath);
65 my $plugindir = File::Spec->catfile($scriptdir, "plugins"); # here i added.

my $plugindir = File::Spec->catfile($scriptdir,"plugins");

D3vil0p3r commented 3 days ago

https://github.com/keydet89/RegRipper3.0/pull/68