-
Notifications
You must be signed in to change notification settings - Fork 3
/
bypass.clj
67 lines (64 loc) · 1.8 KB
/
bypass.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(ns cljotdr.bypass
(:require [cljotdr.utils :refer :all])
(:gen-class))
(defn process
"process TBD block; use this as a template as a starting point
to write a new block readers"
[raf fmtno bname pos bsize results]
(.seek (raf :fh) pos)
(if (get results "debug")
(do
(println "")
(println (format "MAIN: %s block: %d bytes, start pos 0x%X (%d)"
bname bsize pos pos))
)
)
;; get block header
(if (= fmtno 2)
(let [ _bname_ (get-string raf)]
(if (not= bname _bname_)
(println "!!!" bname " block header does not match! is " _bname_)
)
) ; end let
) ; end if
;; read to end (to get checksum correct)
(let [
curr-pos (.getFilePointer (raf :fh))
readsize (- curr-pos pos)
bsize2 (- bsize readsize)
]
;; (println "DEBUG: read size is " readsize)
(doall
(map (fn [_] (myread raf)) (range bsize2))
)
)
(let [
status true
]
(if (get results "debug")
(do
(println (format " : nothing to process yet"))
)
)
(-> results
(assoc-in [bname "ignore"] status)
)
); end let
)
;; ==========================================================================
(defn copy-block
[bname results-map input output]
(let [
pos (get-in results-map ["blocks" bname "pos"])
bsize (get-in results-map ["blocks" bname "size"])
]
;; (println "- writing " bsize " bytes for " bname " at pos " pos)
(println "! Not processing/altering the " bname " block; copying " bsize "bytes")
(.seek (input :fh) pos)
;; we'll assume output is at the end-of-file position to append
(doall
(map (fn [x] (.write (output :fh) (.read (input :fh))))
(range bsize))
);do all
); let
)