Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Need Help with java


  • Please log in to reply
8 replies to this topic

#1 ApInflux

ApInflux

  • Members
  • 28 posts
  • OFFLINE
  •  
  • Local time:06:47 AM

Posted 15 October 2009 - 09:19 PM

When i try to compile this script it reads kernelutils.java:268: not a statement
ie;
^

1error

I'm not sure what this is, Any Fix?

Here is the part that's trouble....

mi.put("postal_code", ui.get("zip"));
		}
		Kernel.getInstance().saveState();
		return true;
		InterruptedException ie;
		ie;
		logger.warn("Interrupted while waiting for UpdateUserInfoResponse.  This should never happen.");
		return false;
	}

	public static void setupThresholdValue()
	{
		try
		{


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:47 AM

Posted 15 October 2009 - 09:27 PM

ie; is not a statement, meaning it is not a statement, nor is it a function call. At any rate, the code will never get that far. The return statement two lines above prevents it. You can remove everything after that.

#3 ApInflux

ApInflux
  • Topic Starter

  • Members
  • 28 posts
  • OFFLINE
  •  
  • Local time:06:47 AM

Posted 15 October 2009 - 09:48 PM

If ie; is not a statement do you have any suggestions to what i should put to make this work? I'm fairly new to this and need a lot of help

#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:47 AM

Posted 15 October 2009 - 09:58 PM

Remove it. Even if it was a valid statement, it would never get executed. What are you trying to do with your code?

#5 ApInflux

ApInflux
  • Topic Starter

  • Members
  • 28 posts
  • OFFLINE
  •  
  • Local time:06:47 AM

Posted 15 October 2009 - 10:04 PM

Well its not my code im trying to help someone out with it, i only have the class file witch then made a java file out of it. Now trying to work from that

Edited by ApInflux, 15 October 2009 - 10:24 PM.


#6 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:47 AM

Posted 15 October 2009 - 11:04 PM

I don't know how to explain all of what is wrong with just that little bit of code because it would take explaining programming fundamentals, which would really take months. Remove everything below "return true" to "return false", including the statement "return false." That will get rid of your error.

#7 ApInflux

ApInflux
  • Topic Starter

  • Members
  • 28 posts
  • OFFLINE
  •  
  • Local time:06:47 AM

Posted 17 October 2009 - 09:43 AM

Ok i tried it but it didn't work, here is the whole code im trying to work with

package com.porivo.kernel;

import com.porivo.common.Globals;
import com.porivo.common.Parameters;
import com.porivo.common.include.Response;
import com.porivo.common.modules.traceroute.TracerouteNode;
import com.porivo.common.modules.traceroute.WinTraceroute;
import com.porivo.common.state.*;
import com.porivo.common.util.NetUtils;
import com.porivo.http.HttpClient;
import java.io.*;
import java.net.*;
import java.util.Iterator;
import java.util.List;
import javax.swing.JOptionPane;
import org.apache.log4j.Logger;

// Referenced classes of package com.porivo.kernel:
//			BootException, StateFile, KernelState, Kernel, 
//			GUIUtils

public class KernelUtils
{

	static Logger logger = Logger.getLogger(com/porivo/kernel/KernelUtils.getName());
	public static final String BIN = "bin";
	public static final String CACHE = "cache";
	public static final String KERNEL = "Kernel.jar";
	public static final String WEBSERVER = "http://websitehere.com";

	public KernelUtils()
	{
	}

	public static void sendShutdown()
	{
		try
		{
			Socket clientSocket = new Socket(InetAddress.getByName("127.0.0.1"), 6555);
			System.out.println("Connecting to Peer process");
			clientSocket.getOutputStream().write(1);
			System.out.println("Sending shutdown message to Peer process");
			clientSocket.getOutputStream().flush();
			System.out.println("Flushing shutdown message to Peer process");
		}
		catch(IOException ioe)
		{
			logger.error("Error sending shutdown message!");
		}
	}

	public static void verifySocket()
	{
		try
		{
			Globals.setSocket(new ServerSocket(6555, 1, InetAddress.getByName("127.0.0.1")));
			logger.warn("Creation of socket lock worked");
		}
		catch(Exception e)
		{
			logger.fatal("Creation of socket lock failed, trying to communicate with running peer");
			try
			{
				Socket clientSock = new Socket(InetAddress.getLocalHost(), 6555);
				clientSock.getOutputStream().write(2);
				clientSock.getOutputStream().flush();
			}
			catch(Exception e2)
			{
				logger.error("caught an exception", e2);
				if(Kernel.realizedGUI)
				{
					JOptionPane.showMessageDialog(null, "Message TExt Here"
, "Title Text here", 0, GUIUtils.getImage("peer.gif"));
				} else
				{
					System.out.println("Only one instance of the PEER may be run at a time.");
				}
			}
		}
	}

	public static void verifyFilesDirs(String homedir, String file)
	{
		File homeDirectory = new File(homedir);
		if(!homeDirectory.exists() || !homeDirectory.isDirectory())
		{
			logger.fatal("Kernel panic.  Home directory doesn't exist.");
			throw new BootException("Kernel panic.  Home directory doesn't exist.");
		}
		if(!homeDirectory.canRead() || !homeDirectory.canWrite())
		{
			logger.fatal("Kernel panic.  Home directory permissions are wrong.");
			throw new BootException("Kernel panic.  Home directory permissions are wrong.");
		}
		Globals.setHomeDirectory(homeDirectory);
		File cacheDirectory = new File(homeDirectory, "cache");
		if(!cacheDirectory.exists())
		{
			cacheDirectory.mkdir();
		}
		if(!cacheDirectory.isDirectory())
		{
			logger.fatal("Kernel panic.  Cache directory doesn't exist.");
			throw new BootException("Kernel panic.  Cache directory doesn't exist.");
		}
		if(!cacheDirectory.canRead() || !cacheDirectory.canWrite())
		{
			logger.fatal("Kernel panic.  Cache directory permissions are wrong.");
			throw new BootException("Kernel panic.  Cache directory permissions are wrong.");
		}
		Globals.setCacheDirectory(cacheDirectory);
		File jreDirectory = new File(homeDirectory, "jre");
		File libDirectory = new File(jreDirectory, "lib");
		File extDirectory = new File(libDirectory, "ext");
		if(!extDirectory.isDirectory())
		{
			logger.fatal("Kernel panic.  Ext directory doesn't exist.");
			throw new BootException("Kernel panic.  Ext directory doesn't exist.");
		}
		if(!extDirectory.canRead() || !extDirectory.canWrite())
		{
			logger.fatal("Kernel panic.  Ext directory permissions are wrong.");
			throw new BootException("Kernel panic.  Ext directory permissions are wrong.");
		}
		Globals.setExtDirectory(extDirectory);
		File binDirectory = new File(homeDirectory, "bin");
		if(!binDirectory.exists())
		{
			binDirectory.mkdir();
		}
		if(!binDirectory.isDirectory())
		{
			logger.fatal("Kernel panic.  Bin directory doesn't exist.");
			throw new BootException("Kernel panic.  Bin directory doesn't exist.");
		}
		if(!binDirectory.canRead() || !binDirectory.canWrite())
		{
			logger.debug("Kernel panic.  Bin directory permissions are wrong.");
			throw new BootException("Kernel panic.  Bin directory permissions are wrong.");
		} else
		{
			Globals.setBinDirectory(binDirectory);
			return;
		}
	}

	private static void cleanCache()
	{
		String cache[] = Globals.getCacheDirectory().list();
		for(int k = 0; k < cache.length; k++)
		{
			if(cache[k].endsWith("loader"))
			{
				logger.warn((new StringBuilder()).append("Deleting old temp file ").append(cache[k]).toString());
				(new File(Globals.getCacheDirectory(), cache[k])).delete();
			}
		}

	}

	private static void cleanBin()
	{
		File oldExec = null;
		if(Globals.getOS().equals("Windows"))
		{
			oldExec = new File(Globals.getBinDirectory(), "peer.exeold");
		} else
		{
			oldExec = new File(Globals.getHomeDirectory(), "Peerold");
		}
		if(oldExec.exists())
		{
			if(!oldExec.delete())
			{
				logger.error("Failed to delete old executable");
			} else
			{
				logger.error("Deleted old executable");
			}
		}
	}

	public static void cleanVersioningDetritus(File root)
	{
		File files[] = root.listFiles();
		for(int i = 0; i < files.length; i++)
		{
			if(files[i].isDirectory())
			{
				cleanVersioningDetritus(files[i]);
				continue;
			}
			if(!files[i].getName().endsWith("new"))
			{
				continue;
			}
			logger.debug((new StringBuilder()).append("Version update file ").append(files[i]).append(" deleted").toString());
			try
			{
				files[i].delete();
			}
			catch(Throwable t)
			{
				logger.error("Error deleting versioning detritus");
			}
		}

	}

	public static boolean isAuthenticated()
	{
		return !Kernel.getInstance().getMachineInfo().get("sysid").equals("-1");
	}

	public static boolean sendUserInfoToServer()
	{
		Response res;
		res = null;
		if(isAuthenticated())
		{
			verifyISP();
		}
		res = Kernel.getInstance().issueRequest(new UpdateUserInfoRequest(Kernel.getInstance().getKernelState().getUserInfo(), Kernel.getInstance().getKernelState().getMachineInfo()));
		if(res == null)
		{
			return false;
		}
		if(res instanceof UpdateUserInfoResponse)
		{
			Globals.setNeedToUpdateUser(false);
			break MISSING_BLOCK_LABEL_77;
		}
		Globals.setNeedToUpdateUser(true);
		logger.warn("Invalid response.  Pausing Kernel.");
		return false;
		UpdateUserInfoResponse in = (UpdateUserInfoResponse)res;
		KernelState ks = Kernel.getInstance().getKernelState();
		if(ks == null)
		{
			logger.debug("Null kernel state");
		}
		MachineInfo mi = ks.getMachineInfo();
		if(mi == null)
		{
			logger.debug("Null machine info");
		}
		UserInfo ui = ks.getUserInfo();
		if(ui == null)
		{
			logger.debug("Null user info");
		}
		mi.putAll(in.getMachineInfo());
		ui.putAll(in.getUserInfo());
		ui.remove("pwd");
		if(mi.get("country_alpha") == null && ui.get("country") != null)
		{
			mi.put("country_alpha", ui.get("country"));
		}
		if(mi.get("postal_code") == null && ui.get("zip") != null)
		{
			mi.put("postal_code", ui.get("zip"));
		}
		Kernel.getInstance().saveState();
		return true;
		InterruptedException ie;
		ie;
		logger.warn("Interrupted while waiting for UpdateUserInfoResponse.  This should never happen.");
		return false;
	}

	public static void setupThresholdValue()
	{
		try
		{
			String threshStr = Kernel.getInstance().getMachineInfo().get("usage_threshold");
			if(threshStr != null)
			{
				int pauseTime = Integer.parseInt(threshStr);
				pauseTime = pauseTime <= -1 || pauseTime >= 6 ? 0 : pauseTime;
				logger.warn((new StringBuilder()).append("User usage threshold found.  Setting to ").append(pauseTime).toString());
				Globals.setPauseTime(pauseTime);
			} else
			{
				logger.warn("No UsageThreshold found.  Setting to 0");
				Globals.setPauseTime(0);
				Kernel.getInstance().getMachineInfo().put("usage_threshold", Integer.toString(0));
			}
		}
		catch(NumberFormatException e)
		{
			logger.warn("Threshold formatted improperly -- defaulting to 0");
			Globals.setPauseTime(0);
			Kernel.getInstance().getMachineInfo().put("usage_threshold", Integer.toString(0));
		}
		catch(NullPointerException e)
		{
			logger.warn("Null pointer grabbing threshold -- defaulting to 0");
			Globals.setPauseTime(0);
			Kernel.getInstance().getMachineInfo().put("usage_threshold", Integer.toString(0));
		}
	}

	public static void restartKernel()
	{
		logger.fatal("***************** Restarting Kernel *******************");
		System.exit(1);
	}

	public static void restartExecutable(String executableName)
	{
		logger.fatal("***************** Restarting the executable ******************");
		if(Globals.getOS().equals("Windows"))
		{
			File defaultJavaExec = new File((new StringBuilder()).append(Globals.getHomeDirectory()).append(File.separator).append("jre").append(File.separator).append("bin").append(File.separator).append("javaw.exe").toString());
			String javaExecutable = defaultJavaExec.getAbsolutePath();
			logger.error((new StringBuilder()).append("Found java installed at ").append(javaExecutable).toString());
			String classpath = Globals.getCacheDirectory().getAbsolutePath();
			StringBuffer executable = new StringBuffer();
			executable.append("\"");
			executable.append(javaExecutable);
			executable.append("\"");
			executable.append(" -cp ");
			executable.append("\"");
			executable.append(classpath);
			executable.append("\"");
			if(Kernel.getInstance().isPrivatePeer())
			{
				executable.append(" RespawnSvc ");
			} else
			{
				executable.append(" Respawn ");
			}
			executable.append("\"");
			executable.append(executableName);
			executable.append("\"");
			logger.error((new StringBuilder()).append("Starting respawn daemon: ").append(executable.toString()).toString());
			try
			{
				Runtime.getRuntime().exec(executable.toString());
			}
			catch(Exception e)
			{
				logger.error((new StringBuilder()).append("Error starting respawn daemon: ").append(e.getMessage()).toString());
				StringWriter sw = new StringWriter();
				e.printStackTrace(new PrintWriter(sw));
				JOptionPane.showMessageDialog(null, (new StringBuilder()).append("PEER Updated....please restart\n").append(sw.getBuffer().toString()).toString(), "PEER Message", 2, null);
			}
		}
		System.exit(0);
	}

	public static void verifyOS()
	{
		String osName = System.getProperty("os.name").toLowerCase();
		if(osName.indexOf("win") != -1)
		{
			Globals.setOS("Windows");
		} else
		if(osName.indexOf("linux") != -1)
		{
			Globals.setOS("Linux");
		} else
		{
			Globals.setOS("Solaris");
		}
	}

	public static void verifyISP()
		throws InterruptedException
	{
		String ip;
		InetAddress addr;
label0:
		{
			ip = null;
			if(Kernel.NO_VERSIONING)
			{
				return;
			}
			logger.info("Sending request for peer IP Address...");
			boolean enableIPResolver = false;
			int retries = 2;
			try
			{
				retries = Integer.parseInt(Parameters.getInstance().getParam("kernel.KernelUtils.IPResolverRetries", "2"));
			}
			catch(NumberFormatException nfe) { }
			enableIPResolver = Parameters.getInstance().getParam("kernel.KernelUtils.IPResolverEnable", "true").equalsIgnoreCase("true");
			for(int i = 0; enableIPResolver && i < retries && ip == null; i++)
			{
				try
				{
					String sys_id = Kernel.getInstance().getMachineInfo().get("sysid");
					URL ipecho = new URL((new StringBuilder()).append("http://websitehere.com").append(sys_id).toString());
					InputStream in = null;
					ProxyInfo proxyInfo = Kernel.getInstance().getKernelState().getProxyInfo();
					if(proxyInfo != null && proxyInfo.isProxyEnabled())
					{
						HttpClient client = new HttpClient();
						in = client.openInputStream(ipecho);
					} else
					{
						in = ipecho.openConnection().getInputStream();
					}
					BufferedReader br = new BufferedReader(new InputStreamReader(in));
					ip = br.readLine();
					if(ip != null && ip.equals("127.0.0.1"))
					{
						ip = null;
					}
					InetAddress addr;
					try
					{
						addr = InetAddress.getByName(ip);
					}
					catch(UnknownHostException uhe)
					{
						ip = null;
					}
					catch(NullPointerException npe)
					{
						ip = null;
					}
					continue;
				}
				catch(IOException ioe)
				{
					logger.error(ioe.toString());
				}
				logger.warn("Pausing for 5 to 60 seconds before retrying server connection.");
				Thread.sleep((int)(Math.random() * 55D + 5D) * 1000);
			}

			try
			{
				addr = InetAddress.getByName(ip);
			}
			catch(UnknownHostException uhe)
			{
				ip = "0.0.0.0";
			}
			catch(NullPointerException npe)
			{
				ip = "0.0.0.0";
			}
			if(ip != null && !ip.equalsIgnoreCase("0.0.0.0"))
			{
				break label0;
			}
			WinTraceroute tracert = null;
			try
			{
				InetAddress addr = InetAddress.getByName("www.google.com");
				tracert = new WinTraceroute(addr);
				List results = tracert.trace();
				Iterator i$ = results.iterator();
				TracerouteNode node;
				boolean isPrivate;
				do
				{
					if(!i$.hasNext())
					{
						break label0;
					}
					node = (TracerouteNode)i$.next();
					isPrivate = NetUtils.isKnownPrivate(node.ipaddr);
				} while(isPrivate);
				ip = node.ipaddr;
			}
			catch(UnknownHostException e)
			{
				ip = "0.0.0.0";
			}
		}
		try
		{
			tracert = InetAddress.getByName(ip);
		}
		catch(UnknownHostException uhe)
		{
			ip = "0.0.0.0";
		}
		catch(NullPointerException npe)
		{
			ip = "0.0.0.0";
		}
		if(!ip.equals(Kernel.getInstance().getMachineInfo().get("isp_ip")) && !ip.equals("0.0.0.0"))
		{
			Globals.setNeedToUpdateUser(true);
			Kernel.getInstance().getMachineInfo().put("isp_ip", ip);
		}
		logger.warn((new StringBuilder()).append("Found netblk :").append(ip).toString());
	}

	public static void setupSystem(String homedir, String file)
	{
		verifySocket();
		verifyFilesDirs(homedir, file);
		verifyOS();
		cleanCache();
		cleanBin();
		Kernel.getInstance().setStateFile(new StateFile(homedir, file));
		Globals.setWebServer("http://websitehere.com");
	}

}

Edited by groovicus, 17 October 2009 - 11:14 AM.
Added code tags.


#8 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:47 AM

Posted 17 October 2009 - 11:24 AM

What do you propose that I do? I told you what to remove. You said that you did that and is still doesn't work. What does that mean? If you removed the code that I suggested you removed, then one of two things would have happened. Your code would threw a completely different error, or the code didn't do what you expected it to do. :thumbsup:

#9 ApInflux

ApInflux
  • Topic Starter

  • Members
  • 28 posts
  • OFFLINE
  •  
  • Local time:06:47 AM

Posted 17 October 2009 - 11:48 AM

Yea it threw like 89 errors at me, and i meant that the code did not run like it was suppose to run with the java javac.exe I don't know what to do any more i give up. Thanks for your help tho




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users