Skip to content

Commit 8ad5ca3

Browse files
committed
Read .pyc files
1 parent 92e6a2d commit 8ad5ca3

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

marshal/marshal.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ package marshal
44
import (
55
"encoding/binary"
66
"errors"
7+
"fmt"
78
"github.com/ncw/gpython/py"
89
"io"
910
"strconv"
10-
"fmt"
1111
)
1212

1313
const (
@@ -56,6 +56,7 @@ func ReadObject(r io.Reader) (obj py.Object, err error) {
5656

5757
//flag := code & FLAG_REF
5858
Type := code &^ FLAG_REF
59+
fmt.Printf("Type = %q\n", Type)
5960

6061
switch Type {
6162
case TYPE_NULL:
@@ -317,3 +318,24 @@ func ReadObject(r io.Reader) (obj py.Object, err error) {
317318

318319
return
319320
}
321+
322+
// The header on a .pyc file
323+
type PycHeader struct {
324+
Magic uint32
325+
Timestamp int32
326+
Length int32
327+
}
328+
329+
// Reads a pyc file
330+
func ReadPyc(r io.Reader) (obj py.Object, err error) {
331+
var header PycHeader
332+
if err = binary.Read(r, binary.LittleEndian, &header); err != nil {
333+
return
334+
}
335+
// FIXME do something with timestamp & lengt?
336+
if header.Magic>>16 != 0x0a0d {
337+
return nil, errors.New("Bad magic in .pyc file")
338+
}
339+
fmt.Printf("header = %v\n", header)
340+
return ReadObject(r)
341+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy