fit-hack 2017 - LEDflashing - WriteUp

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@darkstar-42·
0.000 HBD
fit-hack 2017 - LEDflashing - WriteUp
<center>http://darkstar.bplaced.net/ctf/fit-hack2017/led.jpg</center>

<div class=pull-left>
At this Challenge there was a 27 minutes long video, the title picture is from this video, where you could watch 2 Led's flashing. The first assumption was that one of the Led's should represent the one and the other Led representing zero. Since this could take a bit longer manually, I decided to use a small Java program. The question was, how do I get to the individual frames of the video? A short web search didn't deliver anything helpful, and before spending more time searching I'd rather create a <a href='https://steemit.com/programming/@darkstar-42/how-to-use-the-java-native-interface-so-verwenden-sie-das-java-native-interface'>JNI wrapper for the FFMPEG library</a>. After the access to the individual frames was made possible, the position of the LEDs and the color areas on or off were quickly determined. After the individual bits had been read in, they only had to be converted into representable characters, but the first attempt failed because only 7 bits were used instead of 8 bits per character as expected.

Translated with [DeepL.com](www.DeepL.com/Translator)

</div>

<div class=pull-right>
Bei dieser Challenge gab es eine ca 27 Minuten langes Video, das Titelbild ist aus diesem Video, in dem man 2 Led's beim blinken zu schauen konnte. Die erste Vermutung war das eine der Led's die Eins und die andere Led die Null repräsentieren soll. Da das ganze manuell etwas länger dauern könnte habe ich mich hier für ein kleines Java Programm entschieden. Die Frage war nur, wie komme ich an die einzelnen Frames des Videos? Eine kurze web suche hat nichts hilfreiches geliefert, und bevor ich noch mehr Zeit mit suchen verbringe würde erstellte ich lieber einen <a href='https://steemit.com/programming/@darkstar-42/how-to-use-the-java-native-interface-so-verwenden-sie-das-java-native-interface'>JNI Wrapper für die FFMPEG-Library</a>. Nach dem der zugriff auf die einzelnen Frames möglich war, war auch die Postion der LED's und die Farbbereiche die  an bzw. aus repräsentierten rasch ermittelt. Nach dem die einzelnen Bits eingelesen waren mussten diese nur noch in darstellbare Zeichen umgewandelt werden, der erste versuch scheiterte aber, da nicht wie erwartet 8 Bit je Zeichen sondern nur 7 Bit verwendet wurden.
</div>

<br />

---

```
import java.awt.image.BufferedImage;
import java.io.StringWriter;

public class LEDflashing {

    // check collors to determine if the led is on or off
    private boolean led(int rgb, int l) {
    	
    	int r = (rgb >> 16) &0xff;
    	int g = (rgb >>  8) &0xff;
    	int b = (rgb >>  0) &0xff;
    	
    	if (r>0xa0 && g>0x50 && b>0x30)
    		return true;
    	
    	return false;
    	
    }

    public LEDflashing() {
		JFFMPEG.initFFMPEG("LED flashing-P7yKZqAk2OY.mp4");

		StringWriter sw = new StringWriter();
		
		boolean getNext = false;
		JFFMPEG.get();
		try {
		for (int i=1; i<50251; i++) {
			if (i%500==0) 
				System.out.print(".");
			
			BufferedImage frame = JFFMPEG.get();
			
			if (frame==null)
				break;
			
			boolean led1 = led(frame.getRGB(182, 122), 0);
			boolean led2 = led(frame.getRGB(208, 122), 1);
			
			if (led1 && led2) {
				throw new RuntimeException("check Frame "+i);
			}
			if (!led1 && !led2) {
				getNext = true;
			} else if (getNext) {
				if (led1) {
					sw.append('0');
				} else {
					sw.append('1');
				}
				getNext = false;
			}
		}
		} catch(Exception e) {
			e.printStackTrace();
		}
		System.out.println(sw.toString());
		String bits = sw.toString();
		while (bits.length()>0) {
			int c = Integer.parseInt(bits.substring(0,7),2);
			System.out.print((char)c);
			bits = bits.substring(7);
		}
		JFFMPEG.exitFFMPEG();
    }
    
	public static void main(String[] args) {
		new LEDflashing();
	}

}

```
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,